LibreOffice Module svl (master) 1
sharedstring.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <svl/sharedstring.hxx>
11
12namespace svl {
13
14const OUString SharedString::EMPTY_STRING;
15
17{
18 // ref-counting traffic associated with SharedString temporaries can be significant,
19 // so use a singleton here, so we can return a const& from getEmptyString.
20 // unicode string array for empty string is globally shared in OUString.
21 // Let's take advantage of that.
22 static const SharedString EMPTY_SHARED_STRING(EMPTY_STRING.pData, EMPTY_STRING.pData);
23 return EMPTY_SHARED_STRING;
24}
25
27{
28 if(this == &r)
29 return *this;
30
31 if (mpData)
32 rtl_uString_release(mpData);
34 rtl_uString_release(mpDataIgnoreCase);
35
36 mpData = r.mpData;
38
39 if (mpData)
40 rtl_uString_acquire(mpData);
42 rtl_uString_acquire(mpDataIgnoreCase);
43
44 return *this;
45}
46
48{
49 // Compare only the original (not case-folded) string.
50
51 if (mpData == r.mpData)
52 return true;
53
54 if (mpData)
55 {
56 if (!r.mpData)
57 return false;
58
59 if (mpData->length != r.mpData->length)
60 return false;
61
62 return rtl_ustr_reverseCompare_WithLength(mpData->buffer, mpData->length, r.mpData->buffer, r.mpData->length) == 0;
63 }
64
65 return !r.mpData;
66}
67
68}
69
70/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl_uString * mpDataIgnoreCase
static const OUString EMPTY_STRING
SharedString & operator=(const SharedString &r)
bool operator==(const SharedString &r) const
rtl_uString * mpData
static const SharedString & getEmptyString()