tdf#130857 qt weld: Support "Insert Breaks" dialog
[LibreOffice.git] / include / svl / sharedstring.hxx
blob09261dd5addbf5a3e6bde2d07d10e6f39ed0906c
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 #ifndef INCLUDED_SVL_SHAREDSTRING_HXX
11 #define INCLUDED_SVL_SHAREDSTRING_HXX
13 #include <svl/svldllapi.h>
14 #include <rtl/ustring.hxx>
16 #include <utility>
18 namespace svl {
20 class SVL_DLLPUBLIC SharedString
22 rtl_uString* mpData = nullptr;
23 rtl_uString* mpDataIgnoreCase = nullptr;
24 public:
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;
34 ~SharedString();
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;
51 bool isValid() const;
52 bool isEmpty() const;
54 sal_Int32 getLength() const;
57 inline SharedString::SharedString( rtl_uString* pData, rtl_uString* pDataIgnoreCase ) :
58 mpData(pData), mpDataIgnoreCase(pDataIgnoreCase)
60 if (mpData)
61 rtl_uString_acquire(mpData);
62 if (mpDataIgnoreCase)
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)
73 if (mpData)
74 rtl_uString_acquire(mpData);
75 if (mpDataIgnoreCase)
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()
87 if (mpData)
88 rtl_uString_release(mpData);
89 if (mpDataIgnoreCase)
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
96 // much faster.
97 if (mpData)
98 rtl_uString_release(mpData);
99 if (mpDataIgnoreCase)
100 rtl_uString_release(mpDataIgnoreCase);
102 mpData = std::exchange(r.mpData, nullptr);
103 mpDataIgnoreCase = std::exchange(r.mpDataIgnoreCase, nullptr);
105 return *this;
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()
125 return mpData;
128 inline const rtl_uString* SharedString::getData() const
130 return mpData;
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;
160 #endif
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */