tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / svl / source / misc / sharedstring.cxx
blob4edf6dc1039aa9a708c7e9442d3604715f7e6168
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <svl/sharedstring.hxx>
12 namespace svl {
14 const OUString SharedString::EMPTY_STRING;
16 const SharedString & SharedString::getEmptyString()
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;
26 SharedString& SharedString::operator= ( const SharedString& r )
28 if(this == &r)
29 return *this;
31 if (mpData)
32 rtl_uString_release(mpData);
33 if (mpDataIgnoreCase)
34 rtl_uString_release(mpDataIgnoreCase);
36 mpData = r.mpData;
37 mpDataIgnoreCase = r.mpDataIgnoreCase;
39 if (mpData)
40 rtl_uString_acquire(mpData);
41 if (mpDataIgnoreCase)
42 rtl_uString_acquire(mpDataIgnoreCase);
44 return *this;
47 bool SharedString::operator== ( const SharedString& r ) const
49 // Compare only the original (not case-folded) string.
51 if (mpData == r.mpData)
52 return true;
54 if (!mpData || !r.mpData)
55 return false;
57 if (mpData->length != r.mpData->length)
58 return false;
60 return rtl_ustr_reverseCompare_WithLength(mpData->buffer, mpData->length, r.mpData->buffer, r.mpData->length) == 0;
65 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */