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>
18 class SVL_DLLPUBLIC SharedString
21 rtl_uString
* mpDataIgnoreCase
;
24 static const SharedString
& getEmptyString();
27 SharedString( rtl_uString
* pData
, rtl_uString
* pDataIgnoreCase
);
28 explicit SharedString( const OUString
& rStr
);
29 SharedString( const SharedString
& r
);
30 SharedString(SharedString
&& r
) noexcept
;
33 SharedString
& operator= ( const SharedString
& r
);
34 SharedString
& operator=(SharedString
&& r
) noexcept
;
36 bool operator== ( const SharedString
& r
) const;
37 bool operator!= ( const SharedString
& r
) const;
39 OUString
getString() const;
41 rtl_uString
* getData();
42 const rtl_uString
* getData() const;
44 rtl_uString
* getDataIgnoreCase();
45 const rtl_uString
* getDataIgnoreCase() const;
50 sal_Int32
getLength() const;
53 inline SharedString::SharedString() : mpData(nullptr), mpDataIgnoreCase(nullptr) {}
55 inline SharedString::SharedString( rtl_uString
* pData
, rtl_uString
* pDataIgnoreCase
) :
56 mpData(pData
), mpDataIgnoreCase(pDataIgnoreCase
)
59 rtl_uString_acquire(mpData
);
61 rtl_uString_acquire(mpDataIgnoreCase
);
64 inline SharedString::SharedString( const OUString
& rStr
) : mpData(rStr
.pData
), mpDataIgnoreCase(nullptr)
66 rtl_uString_acquire(mpData
);
69 inline SharedString::SharedString( const SharedString
& r
) : mpData(r
.mpData
), mpDataIgnoreCase(r
.mpDataIgnoreCase
)
72 rtl_uString_acquire(mpData
);
74 rtl_uString_acquire(mpDataIgnoreCase
);
77 inline SharedString::SharedString(SharedString
&& r
) noexcept
: mpData(r
.mpData
), mpDataIgnoreCase(r
.mpDataIgnoreCase
)
80 r
.mpDataIgnoreCase
= nullptr;
83 inline SharedString::~SharedString()
86 rtl_uString_release(mpData
);
88 rtl_uString_release(mpDataIgnoreCase
);
91 inline bool SharedString::operator!= ( const SharedString
& r
) const
93 return !operator== (r
);
96 inline OUString
SharedString::getString() const
98 return mpData
? OUString(mpData
) : OUString();
101 inline rtl_uString
* SharedString::getData()
106 inline const rtl_uString
* SharedString::getData() const
111 inline rtl_uString
* SharedString::getDataIgnoreCase()
113 return mpDataIgnoreCase
;
116 inline const rtl_uString
* SharedString::getDataIgnoreCase() const
118 return mpDataIgnoreCase
;
121 inline bool SharedString::isValid() const
123 return mpData
!= nullptr;
126 inline bool SharedString::isEmpty() const
128 return mpData
== nullptr || mpData
->length
== 0;
131 inline sal_Int32
SharedString::getLength() const
133 return mpData
? mpData
->length
: 0;
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */