bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / misc / sharedstring.cxx
blob81379520a3d9b553adc6a85c85a62369618dd93f
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 SharedString SharedString::getEmptyString()
16 // unicode string array for empty string is globally shared in OUString.
17 // Let's take advantage of that.
18 rtl_uString* pData = NULL;
19 rtl_uString_new(&pData);
20 return SharedString(pData, pData);
23 SharedString::SharedString() : mpData(NULL), mpDataIgnoreCase(NULL) {}
25 SharedString::SharedString( rtl_uString* pData, rtl_uString* pDataIgnoreCase ) :
26 mpData(pData), mpDataIgnoreCase(pDataIgnoreCase)
28 if (mpData)
29 rtl_uString_acquire(mpData);
30 if (mpDataIgnoreCase)
31 rtl_uString_acquire(mpDataIgnoreCase);
34 SharedString::SharedString( const OUString& rStr ) : mpData(rStr.pData), mpDataIgnoreCase(NULL)
36 rtl_uString_acquire(mpData);
39 SharedString::SharedString( const SharedString& r ) : mpData(r.mpData), mpDataIgnoreCase(r.mpDataIgnoreCase)
41 if (mpData)
42 rtl_uString_acquire(mpData);
43 if (mpDataIgnoreCase)
44 rtl_uString_acquire(mpDataIgnoreCase);
47 SharedString::~SharedString()
49 if (mpData)
50 rtl_uString_release(mpData);
51 if (mpDataIgnoreCase)
52 rtl_uString_release(mpDataIgnoreCase);
55 SharedString& SharedString::operator= ( const SharedString& r )
57 if (mpData)
58 rtl_uString_release(mpData);
59 if (mpDataIgnoreCase)
60 rtl_uString_release(mpDataIgnoreCase);
62 mpData = r.mpData;
63 mpDataIgnoreCase = r.mpDataIgnoreCase;
65 if (mpData)
66 rtl_uString_acquire(mpData);
67 if (mpDataIgnoreCase)
68 rtl_uString_acquire(mpDataIgnoreCase);
70 return *this;
73 bool SharedString::operator== ( const SharedString& r ) const
75 // Only compare case sensitive strings.
76 if (mpData == r.mpData)
77 return true;
79 if (mpData)
81 if (!r.mpData)
82 return false;
84 if (mpData->length != r.mpData->length)
85 return false;
87 return rtl_ustr_reverseCompare_WithLength(mpData->buffer, mpData->length, r.mpData->buffer, r.mpData->length) == 0;
90 return !r.mpData;
93 bool SharedString::operator!= ( const SharedString& r ) const
95 return !operator== (r);
98 OUString SharedString::getString() const
100 return mpData ? OUString(mpData) : OUString();
103 rtl_uString* SharedString::getData()
105 return mpData;
108 const rtl_uString* SharedString::getData() const
110 return mpData;
113 rtl_uString* SharedString::getDataIgnoreCase()
115 return mpDataIgnoreCase;
118 const rtl_uString* SharedString::getDataIgnoreCase() const
120 return mpDataIgnoreCase;
123 bool SharedString::isValid() const
125 return mpData != NULL;
128 bool SharedString::isEmpty() const
130 return mpData == NULL || mpData->length == 0;
133 sal_Int32 SharedString::getLength() const
135 return mpData ? mpData->length : 0;
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */