1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <svl/sharedstring.hxx>
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
)
29 rtl_uString_acquire(mpData
);
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
)
42 rtl_uString_acquire(mpData
);
44 rtl_uString_acquire(mpDataIgnoreCase
);
47 SharedString::~SharedString()
50 rtl_uString_release(mpData
);
52 rtl_uString_release(mpDataIgnoreCase
);
55 SharedString
& SharedString::operator= ( const SharedString
& r
)
58 rtl_uString_release(mpData
);
60 rtl_uString_release(mpDataIgnoreCase
);
63 mpDataIgnoreCase
= r
.mpDataIgnoreCase
;
66 rtl_uString_acquire(mpData
);
68 rtl_uString_acquire(mpDataIgnoreCase
);
73 bool SharedString::operator== ( const SharedString
& r
) const
75 // Only compare case sensitive strings.
76 if (mpData
== r
.mpData
)
84 if (mpData
->length
!= r
.mpData
->length
)
87 return rtl_ustr_reverseCompare_WithLength(mpData
->buffer
, mpData
->length
, r
.mpData
->buffer
, r
.mpData
->length
) == 0;
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()
108 const rtl_uString
* SharedString::getData() const
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: */