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 #ifndef INCLUDED_SVL_SHAREDSTRING_HXX
11 #define INCLUDED_SVL_SHAREDSTRING_HXX
13 #include <svl/svldllapi.h>
14 #include <rtl/ustring.hxx>
20 class SVL_DLLPUBLIC SharedString
22 rtl_uString
* mpData
= nullptr;
23 rtl_uString
* mpDataIgnoreCase
= nullptr;
26 static const SharedString
& getEmptyString();
27 static const OUString EMPTY_STRING
;
29 SharedString() = default;
30 SharedString( rtl_uString
* pData
, rtl_uString
* pDataIgnoreCase
);
31 explicit SharedString( const OUString
& rStr
);
32 SharedString( const SharedString
& r
);
33 SharedString(SharedString
&& r
) noexcept
;
36 SharedString
& operator= ( const SharedString
& r
);
37 SharedString
& operator=(SharedString
&& r
) noexcept
;
39 bool operator== ( const SharedString
& r
) const;
40 bool operator!= ( const SharedString
& r
) const;
42 const OUString
& getString() const;
43 const OUString
& getIgnoreCaseString() const;
45 rtl_uString
* getData();
46 const rtl_uString
* getData() const;
48 rtl_uString
* getDataIgnoreCase();
49 const rtl_uString
* getDataIgnoreCase() const;
54 sal_Int32
getLength() const;
57 inline SharedString::SharedString( rtl_uString
* pData
, rtl_uString
* pDataIgnoreCase
) :
58 mpData(pData
), mpDataIgnoreCase(pDataIgnoreCase
)
61 rtl_uString_acquire(mpData
);
63 rtl_uString_acquire(mpDataIgnoreCase
);
66 inline SharedString::SharedString( const OUString
& rStr
) : mpData(rStr
.pData
)
68 rtl_uString_acquire(mpData
);
71 inline SharedString::SharedString( const SharedString
& r
) : mpData(r
.mpData
), mpDataIgnoreCase(r
.mpDataIgnoreCase
)
74 rtl_uString_acquire(mpData
);
76 rtl_uString_acquire(mpDataIgnoreCase
);
79 inline SharedString::SharedString(SharedString
&& r
) noexcept
80 : mpData(std::exchange(r
.mpData
, nullptr))
81 , mpDataIgnoreCase(std::exchange(r
.mpDataIgnoreCase
, nullptr))
85 inline SharedString::~SharedString()
88 rtl_uString_release(mpData
);
90 rtl_uString_release(mpDataIgnoreCase
);
93 inline SharedString
& SharedString::operator=(SharedString
&& r
) noexcept
95 // Having this inline helps Calc's mdds::multi_type_vector to do some operations
98 rtl_uString_release(mpData
);
100 rtl_uString_release(mpDataIgnoreCase
);
102 mpData
= std::exchange(r
.mpData
, nullptr);
103 mpDataIgnoreCase
= std::exchange(r
.mpDataIgnoreCase
, nullptr);
108 inline bool SharedString::operator!= ( const SharedString
& r
) const
110 return !operator== (r
);
113 inline const OUString
& SharedString::getString() const
115 return mpData
? OUString::unacquired(&mpData
) : EMPTY_STRING
;
118 inline const OUString
& SharedString::getIgnoreCaseString() const
120 return mpDataIgnoreCase
? OUString::unacquired(&mpDataIgnoreCase
) : EMPTY_STRING
;
123 inline rtl_uString
* SharedString::getData()
128 inline const rtl_uString
* SharedString::getData() const
133 inline rtl_uString
* SharedString::getDataIgnoreCase()
135 return mpDataIgnoreCase
;
138 inline const rtl_uString
* SharedString::getDataIgnoreCase() const
140 return mpDataIgnoreCase
;
143 inline bool SharedString::isValid() const
145 return mpData
!= nullptr;
148 inline bool SharedString::isEmpty() const
150 return mpData
== nullptr || mpData
->length
== 0;
153 inline sal_Int32
SharedString::getLength() const
155 return mpData
? mpData
->length
: 0;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */