crashtesting: crash seen on exporting forum-it-5909.ods to xlsx
[LibreOffice.git] / include / svl / sharedstring.hxx
blob050bd8dd9e551e4302dbfacf9b4afedef2c38838
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 namespace svl {
18 class SVL_DLLPUBLIC SharedString
20 rtl_uString* mpData;
21 rtl_uString* mpDataIgnoreCase;
22 public:
24 static const SharedString & getEmptyString();
26 SharedString();
27 SharedString( rtl_uString* pData, rtl_uString* pDataIgnoreCase );
28 explicit SharedString( const OUString& rStr );
29 SharedString( const SharedString& r );
30 SharedString(SharedString&& r) noexcept;
31 ~SharedString();
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;
47 bool isValid() const;
48 bool isEmpty() 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)
58 if (mpData)
59 rtl_uString_acquire(mpData);
60 if (mpDataIgnoreCase)
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)
71 if (mpData)
72 rtl_uString_acquire(mpData);
73 if (mpDataIgnoreCase)
74 rtl_uString_acquire(mpDataIgnoreCase);
77 inline SharedString::SharedString(SharedString&& r) noexcept : mpData(r.mpData), mpDataIgnoreCase(r.mpDataIgnoreCase)
79 r.mpData = nullptr;
80 r.mpDataIgnoreCase = nullptr;
83 inline SharedString::~SharedString()
85 if (mpData)
86 rtl_uString_release(mpData);
87 if (mpDataIgnoreCase)
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()
103 return mpData;
106 inline const rtl_uString* SharedString::getData() const
108 return mpData;
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;
138 #endif
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */