22
22
#ifndef SWINDER_USTRING_H_
23
23
#define SWINDER_USTRING_H_
28
* @return True if d is not a number (platform support required).
32
bool isPosInf(double d);
33
bool isNegInf(double d);
40
* @short Unicode character.
42
* UChar represents a 16 bit Unicode character. It's internal data
43
* representation is compatible to XChar2b and QChar. It's therefore
44
* possible to exchange data with X and Qt with shallow copies.
29
* @return True if d is not a number (platform support required).
33
bool isPosInf(double d);
34
bool isNegInf(double d);
41
* @short Unicode character.
43
* UChar represents a 16 bit Unicode character. It's internal data
44
* representation is compatible to XChar2b and QChar. It's therefore
45
* possible to exchange data with X and Qt with shallow copies.
48
49
* Construct a character with value 0.
64
65
* @return The higher byte of the character.
66
unsigned char high() const { return uc >> 8; }
67
unsigned char high() const {
68
71
* @return The lower byte of the character.
70
unsigned char low() const { return uc & 0xFF; }
73
unsigned char low() const {
72
77
* @return the 16 bit Unicode value of the character
74
unsigned short unicode() const { return uc; }
79
unsigned short unicode() const {
77
84
* @return The character converted to lower case.
93
100
friend bool operator<(const UString& s1, const UString& s2);
95
102
unsigned short uc;
98
inline UChar::UChar() : uc(0) { }
99
inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { }
100
inline UChar::UChar(unsigned short u) : uc(u) { }
103
* @short Dynamic reference to a string character.
105
* UCharReference is the dynamic counterpart of @ref UChar. It's used when
106
* characters retrieved via index from a @ref UString are used in an
107
* assignment expression (and therefore can't be treated as being const):
109
* UString s("hello world");
113
* If that sounds confusing your best bet is to simply forget about the
114
* existence of this class and treat it as being identical to @ref UChar.
116
class UCharReference {
105
inline UChar::UChar() : uc(0) { }
106
inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { }
107
inline UChar::UChar(unsigned short u) : uc(u) { }
110
* @short Dynamic reference to a string character.
112
* UCharReference is the dynamic counterpart of @ref UChar. It's used when
113
* characters retrieved via index from a @ref UString are used in an
114
* assignment expression (and therefore can't be treated as being const):
116
* UString s("hello world");
120
* If that sounds confusing your best bet is to simply forget about the
121
* existence of this class and treat it as being identical to @ref UChar.
117
125
friend class UString;
118
126
UCharReference(UString *s, unsigned int off) : str(s), offset(off) { }
121
129
* Set the referenced character to c.
125
133
* Same operator as above except the argument that it takes.
127
UCharReference& operator=(char c) { return operator=(UChar(c)); }
135
UCharReference& operator=(char c) {
136
return operator=(UChar(c));
129
139
* @return Unicode value.
131
unsigned short unicode() const { return ref().unicode(); }
141
unsigned short unicode() const {
142
return ref().unicode();
133
145
* @return Lower byte.
135
unsigned char low() const { return ref().uc & 0xFF; }
147
unsigned char low() const {
148
return ref().uc & 0xFF;
137
151
* @return Higher byte.
139
unsigned char high() const { return ref().uc >> 8; }
153
unsigned char high() const {
154
return ref().uc >> 8;
141
157
* @return Character converted to lower case.
143
UChar toLower() const { return ref().toLower(); }
159
UChar toLower() const {
160
return ref().toLower();
145
163
* @return Character converted to upper case.
147
UChar toUpper() const { return ref().toUpper(); }
165
UChar toUpper() const {
166
return ref().toUpper();
149
169
// not implemented, can only be constructed from UString
150
170
UCharReference();
152
172
UChar& ref() const;
158
* @short 8 bit char based string class
178
* @short 8 bit char based string class
162
183
CString() : data(0L) { }
163
184
explicit CString(const char *c);
164
185
CString(const CString &);
171
192
CString &operator+=(const CString &);
173
194
int length() const;
174
const char *c_str() const { return data; }
195
const char *c_str() const {
180
* @short Unicode string class
203
* @short Unicode string class
183
207
friend bool operator==(const UString&, const UString&);
184
208
friend class UCharReference;
185
209
friend class UConstString;
190
friend class UString;
191
friend bool operator==(const UString&, const UString&);
192
static Rep *create(UChar *d, int l);
193
inline UChar *data() const { return dat; }
194
inline int length() const { return len; }
196
inline void ref() { rc++; }
197
inline int deref() { return --rc; }
214
friend class UString;
215
friend bool operator==(const UString&, const UString&);
216
static Rep *create(UChar *d, int l);
217
inline UChar *data() const {
220
inline int length() const {
207
239
* Constructs a null string.
288
320
* @return A pointer to the internal Unicode data.
290
const UChar* data() const { return rep->data(); }
322
const UChar* data() const {
292
326
* @return True if null.
294
bool isNull() const { return (rep == &Rep::null); }
328
bool isNull() const {
329
return (rep == &Rep::null);
296
332
* @return True if null or zero length.
298
bool isEmpty() const { return (!rep->len); }
334
bool isEmpty() const {
300
338
* Use this if you want to make sure that this string is a plain ASCII
301
339
* string. For example, if you don't want to lose any information when
351
391
static UString null;
354
394
void attach(Rep *r);
360
inline bool operator==(const UChar &c1, const UChar &c2) {
400
inline bool operator==(const UChar &c1, const UChar &c2)
361
402
return (c1.uc == c2.uc);
363
inline bool operator!=(const UChar &c1, const UChar &c2) {
404
inline bool operator!=(const UChar &c1, const UChar &c2)
364
406
return !(c1 == c2);
366
bool operator==(const UString& s1, const UString& s2);
367
inline bool operator!=(const UString& s1, const UString& s2) {
368
return !Swinder::operator==(s1, s2);
370
bool operator<(const UString& s1, const UString& s2);
371
bool operator==(const UString& s1, const char *s2);
372
inline bool operator!=(const UString& s1, const char *s2) {
373
return !Swinder::operator==(s1, s2);
375
inline bool operator==(const char *s1, const UString& s2) {
408
bool operator==(const UString& s1, const UString& s2);
409
inline bool operator!=(const UString& s1, const UString& s2)
411
return !Swinder::operator==(s1, s2);
413
bool operator<(const UString& s1, const UString& s2);
414
bool operator==(const UString& s1, const char *s2);
415
inline bool operator!=(const UString& s1, const char *s2)
417
return !Swinder::operator==(s1, s2);
419
inline bool operator==(const char *s1, const UString& s2)
376
421
return operator==(s2, s1);
378
inline bool operator!=(const char *s1, const UString& s2) {
423
inline bool operator!=(const char *s1, const UString& s2)
379
425
return !Swinder::operator==(s1, s2);
381
bool operator==(const CString& s1, const CString& s2);
382
UString operator+(const UString& s1, const UString& s2);
385
class UConstString : private UString {
387
UConstString( UChar* data, unsigned int length );
390
const UString& string() const { return *this; }
427
bool operator==(const CString& s1, const CString& s2);
428
UString operator+(const UString& s1, const UString& s2);
431
class UConstString : private UString
434
UConstString(UChar* data, unsigned int length);
437
const UString& string() const {
393
442
} // namespace SWINDER_USTRING_H