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
= nullptr;
19 rtl_uString_new(&pData
);
20 return SharedString(pData
, pData
);
23 SharedString::SharedString() : mpData(nullptr), mpDataIgnoreCase(nullptr) {}
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(nullptr)
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(SharedString
&& r
) noexcept
: mpData(r
.mpData
), mpDataIgnoreCase(r
.mpDataIgnoreCase
)
50 r
.mpDataIgnoreCase
= nullptr;
53 SharedString::~SharedString()
56 rtl_uString_release(mpData
);
58 rtl_uString_release(mpDataIgnoreCase
);
61 SharedString
& SharedString::operator= ( const SharedString
& r
)
67 rtl_uString_release(mpData
);
69 rtl_uString_release(mpDataIgnoreCase
);
72 mpDataIgnoreCase
= r
.mpDataIgnoreCase
;
75 rtl_uString_acquire(mpData
);
77 rtl_uString_acquire(mpDataIgnoreCase
);
82 SharedString
& SharedString::operator=(SharedString
&& r
) noexcept
85 rtl_uString_release(mpData
);
87 rtl_uString_release(mpDataIgnoreCase
);
90 mpDataIgnoreCase
= r
.mpDataIgnoreCase
;
93 r
.mpDataIgnoreCase
= nullptr;
98 bool SharedString::operator== ( const SharedString
& r
) const
100 // Compare only the original (not case-folded) string.
102 if (mpData
== r
.mpData
)
110 if (mpData
->length
!= r
.mpData
->length
)
113 return rtl_ustr_reverseCompare_WithLength(mpData
->buffer
, mpData
->length
, r
.mpData
->buffer
, r
.mpData
->length
) == 0;
119 bool SharedString::operator!= ( const SharedString
& r
) const
121 return !operator== (r
);
124 OUString
SharedString::getString() const
126 return mpData
? OUString(mpData
) : OUString();
129 rtl_uString
* SharedString::getData()
134 const rtl_uString
* SharedString::getData() const
139 rtl_uString
* SharedString::getDataIgnoreCase()
141 return mpDataIgnoreCase
;
144 const rtl_uString
* SharedString::getDataIgnoreCase() const
146 return mpDataIgnoreCase
;
149 bool SharedString::isValid() const
151 return mpData
!= nullptr;
154 bool SharedString::isEmpty() const
156 return mpData
== nullptr || mpData
->length
== 0;
159 sal_Int32
SharedString::getLength() const
161 return mpData
? mpData
->length
: 0;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */