ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

ustr.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_USTR_H
00024 #define COMMON_USTR_H
00025 
00026 #include "common/scummsys.h"
00027 
00028 namespace Common {
00029 
00030 class String;
00031 
00044 class U32String {
00045 public:
00046     static const uint32 npos = 0xFFFFFFFF;
00047 
00048     typedef uint32 value_type;
00049     typedef uint32 unsigned_type;
00050 private:
00056     static const uint32 _builtinCapacity = 32;
00057 
00061     uint32 _size;
00062 
00067     value_type  *_str;
00068 
00069 
00070     union {
00074         value_type _storage[_builtinCapacity];
00079         struct {
00080             mutable int *_refCount;
00081             uint32       _capacity;
00082         } _extern;
00083     };
00084 
00085     inline bool isStorageIntern() const {
00086         return _str == _storage;
00087     }
00088 
00089 public:
00091     U32String() : _size(0), _str(_storage) { _storage[0] = 0; }
00092 
00094     explicit U32String(const value_type *str);
00095 
00097     U32String(const value_type *str, uint32 len);
00098 
00100     U32String(const value_type *beginP, const value_type *endP);
00101 
00103     U32String(const U32String &str);
00104 
00106     explicit U32String(const char *str);
00107 
00109     U32String(const char *str, uint32 len);
00110 
00112     U32String(const char *beginP, const char *endP);
00113 
00115     U32String(const String &str);
00116 
00117     ~U32String();
00118 
00119     U32String &operator=(const U32String &str);
00120     U32String &operator=(const String &str);
00121     U32String &operator=(const value_type *str);
00122     U32String &operator=(const char *str);
00123     U32String &operator+=(const U32String &str);
00124     U32String &operator+=(value_type c);
00125     bool operator==(const U32String &x) const;
00126     bool operator==(const String &x) const;
00127     bool operator==(const value_type *x) const;
00128     bool operator==(const char *x) const;
00129     bool operator!=(const U32String &x) const;
00130     bool operator!=(const String &x) const;
00131     bool operator!=(const value_type *x) const;
00132     bool operator!=(const char *x) const;
00133 
00138     bool equals(const U32String &x) const;
00139 
00144     bool equals(const String &x) const;
00145 
00146     bool contains(value_type x) const;
00147 
00148     inline const value_type *c_str() const { return _str; }
00149     inline uint32 size() const             { return _size; }
00150 
00151     inline bool empty() const { return (_size == 0); }
00152 
00153     value_type operator[](int idx) const {
00154         assert(_str && idx >= 0 && idx < (int)_size);
00155         return _str[idx];
00156     }
00157 
00163     void deleteChar(uint32 p);
00164 
00166     void clear();
00167 
00174     void toLowercase();
00175 
00182     void toUppercase();
00183 
00184     uint32 find(const U32String &str, uint32 pos = 0) const;
00185 
00186     typedef value_type *        iterator;
00187     typedef const value_type *  const_iterator;
00188 
00189     iterator begin() {
00190         // Since the user could potentially
00191         // change the string via the returned
00192         // iterator we have to assure we are
00193         // pointing to a unique storage.
00194         makeUnique();
00195 
00196         return _str;
00197     }
00198 
00199     iterator end() {
00200         return begin() + size();
00201     }
00202 
00203     const_iterator begin() const {
00204         return _str;
00205     }
00206 
00207     const_iterator end() const {
00208         return begin() + size();
00209     }
00210 
00211 private:
00212     void makeUnique();
00213     void ensureCapacity(uint32 new_size, bool keep_old);
00214     void incRefCount() const;
00215     void decRefCount(int *oldRefCount);
00216     void initWithCStr(const value_type *str, uint32 len);
00217     void initWithCStr(const char *str, uint32 len);
00218 };
00219 
00220 U32String convertUtf8ToUtf32(const String &str);
00221 
00222 enum CodePage {
00223     kUtf8,
00224     kWindows1250,
00225     kWindows1251,
00226     kWindows1252,
00227     kWindows1255
00228 };
00229 
00230 U32String convertToU32String(const char *str, CodePage page = kUtf8);
00231 
00232 } // End of namespace Common
00233 
00234 #endif


Generated on Sat Mar 16 2019 05:02:00 for ResidualVM by doxygen 1.7.1
curved edge   curved edge