~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/kspread/excel/sidewinder/ustring.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#ifndef SWINDER_USTRING_H_
23
23
#define SWINDER_USTRING_H_
24
24
 
25
 
namespace Swinder {
26
 
 
27
 
  /**
28
 
   * @return True if d is not a number (platform support required).
29
 
   */
30
 
  bool isNaN(double d);
31
 
 
32
 
  bool isPosInf(double d);
33
 
  bool isNegInf(double d);
34
 
 
35
 
  class UCharReference;
36
 
  class UString;
37
 
  class UConstString;
38
 
 
39
 
  /**
40
 
   * @short Unicode character.
41
 
   *
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.
45
 
   */
46
 
  struct UChar {
 
25
namespace Swinder
 
26
{
 
27
 
 
28
/**
 
29
 * @return True if d is not a number (platform support required).
 
30
 */
 
31
bool isNaN(double d);
 
32
 
 
33
bool isPosInf(double d);
 
34
bool isNegInf(double d);
 
35
 
 
36
class UCharReference;
 
37
class UString;
 
38
class UConstString;
 
39
 
 
40
/**
 
41
 * @short Unicode character.
 
42
 *
 
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.
 
46
 */
 
47
struct UChar {
47
48
    /**
48
49
     * Construct a character with value 0.
49
50
     */
63
64
    /**
64
65
     * @return The higher byte of the character.
65
66
     */
66
 
    unsigned char high() const { return uc >> 8; }
 
67
    unsigned char high() const {
 
68
        return uc >> 8;
 
69
    }
67
70
    /**
68
71
     * @return The lower byte of the character.
69
72
     */
70
 
    unsigned char low() const { return uc & 0xFF; }
 
73
    unsigned char low() const {
 
74
        return uc & 0xFF;
 
75
    }
71
76
    /**
72
77
     * @return the 16 bit Unicode value of the character
73
78
     */
74
 
    unsigned short unicode() const { return uc; }
75
 
  public:
 
79
    unsigned short unicode() const {
 
80
        return uc;
 
81
    }
 
82
public:
76
83
    /**
77
84
     * @return The character converted to lower case.
78
85
     */
85
92
     * A static instance of UChar(0).
86
93
     */
87
94
    static UChar null;
88
 
  private:
 
95
private:
89
96
    friend class UCharReference;
90
97
    friend class UString;
91
98
    friend bool operator==(const UChar &c1, const UChar &c2);
93
100
    friend bool operator<(const UString& s1, const UString& s2);
94
101
 
95
102
    unsigned short uc;
96
 
  };
97
 
 
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) { }
101
 
 
102
 
  /**
103
 
   * @short Dynamic reference to a string character.
104
 
   *
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):
108
 
   * <pre>
109
 
   * UString s("hello world");
110
 
   * s[0] = 'H';
111
 
   * </pre>
112
 
   *
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.
115
 
   */
116
 
  class UCharReference {
 
103
};
 
104
 
 
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) { }
 
108
 
 
109
/**
 
110
 * @short Dynamic reference to a string character.
 
111
 *
 
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):
 
115
 * <pre>
 
116
 * UString s("hello world");
 
117
 * s[0] = 'H';
 
118
 * </pre>
 
119
 *
 
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.
 
122
 */
 
123
class UCharReference
 
124
{
117
125
    friend class UString;
118
126
    UCharReference(UString *s, unsigned int off) : str(s), offset(off) { }
119
 
  public:
 
127
public:
120
128
    /**
121
129
     * Set the referenced character to c.
122
130
     */
124
132
    /**
125
133
     * Same operator as above except the argument that it takes.
126
134
     */
127
 
    UCharReference& operator=(char c) { return operator=(UChar(c)); }
 
135
    UCharReference& operator=(char c) {
 
136
        return operator=(UChar(c));
 
137
    }
128
138
    /**
129
139
     * @return Unicode value.
130
140
     */
131
 
    unsigned short unicode() const { return ref().unicode(); }
 
141
    unsigned short unicode() const {
 
142
        return ref().unicode();
 
143
    }
132
144
    /**
133
145
     * @return Lower byte.
134
146
     */
135
 
    unsigned char low() const { return ref().uc & 0xFF; }
 
147
    unsigned char low() const {
 
148
        return ref().uc & 0xFF;
 
149
    }
136
150
    /**
137
151
     * @return Higher byte.
138
152
     */
139
 
    unsigned char high() const { return ref().uc >> 8; }
 
153
    unsigned char high() const {
 
154
        return ref().uc >> 8;
 
155
    }
140
156
    /**
141
157
     * @return Character converted to lower case.
142
158
     */
143
 
    UChar toLower() const { return ref().toLower(); }
 
159
    UChar toLower() const {
 
160
        return ref().toLower();
 
161
    }
144
162
    /**
145
163
     * @return Character converted to upper case.
146
164
     */
147
 
    UChar toUpper() const  { return ref().toUpper(); }
148
 
  private:
 
165
    UChar toUpper() const  {
 
166
        return ref().toUpper();
 
167
    }
 
168
private:
149
169
    // not implemented, can only be constructed from UString
150
170
    UCharReference();
151
171
 
152
172
    UChar& ref() const;
153
173
    UString *str;
154
174
    int offset;
155
 
  };
 
175
};
156
176
 
157
 
  /**
158
 
   * @short 8 bit char based string class
159
 
   */
160
 
  class CString {
161
 
  public:
 
177
/**
 
178
 * @short 8 bit char based string class
 
179
 */
 
180
class CString
 
181
{
 
182
public:
162
183
    CString() : data(0L) { }
163
184
    explicit CString(const char *c);
164
185
    CString(const CString &);
171
192
    CString &operator+=(const CString &);
172
193
 
173
194
    int length() const;
174
 
    const char *c_str() const { return data; }
175
 
  private:
 
195
    const char *c_str() const {
 
196
        return data;
 
197
    }
 
198
private:
176
199
    char *data;
177
 
  };
 
200
};
178
201
 
179
 
  /**
180
 
   * @short Unicode string class
181
 
   */
182
 
  class UString {
 
202
/**
 
203
 * @short Unicode string class
 
204
 */
 
205
class UString
 
206
{
183
207
    friend bool operator==(const UString&, const UString&);
184
208
    friend class UCharReference;
185
209
    friend class UConstString;
187
211
     * @internal
188
212
     */
189
213
    struct Rep {
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; }
195
 
 
196
 
      inline void ref() { rc++; }
197
 
      inline int deref() { return --rc; }
198
 
 
199
 
      UChar *dat;
200
 
      int len;
201
 
      int rc;
202
 
      static Rep null;
 
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 {
 
218
            return dat;
 
219
        }
 
220
        inline int length() const {
 
221
            return len;
 
222
        }
 
223
 
 
224
        inline void ref() {
 
225
            rc++;
 
226
        }
 
227
        inline int deref() {
 
228
            return --rc;
 
229
        }
 
230
 
 
231
        UChar *dat;
 
232
        int len;
 
233
        int rc;
 
234
        static Rep null;
203
235
    };
204
236
 
205
 
  public:
 
237
public:
206
238
    /**
207
239
     * Constructs a null string.
208
240
     */
287
319
    /**
288
320
     * @return A pointer to the internal Unicode data.
289
321
     */
290
 
    const UChar* data() const { return rep->data(); }
 
322
    const UChar* data() const {
 
323
        return rep->data();
 
324
    }
291
325
    /**
292
326
     * @return True if null.
293
327
     */
294
 
    bool isNull() const { return (rep == &Rep::null); }
 
328
    bool isNull() const {
 
329
        return (rep == &Rep::null);
 
330
    }
295
331
    /**
296
332
     * @return True if null or zero length.
297
333
     */
298
 
    bool isEmpty() const { return (!rep->len); }
 
334
    bool isEmpty() const {
 
335
        return (!rep->len);
 
336
    }
299
337
    /**
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
307
345
    /**
308
346
     * @return The length of the string.
309
347
     */
310
 
    int length() const { return rep->length(); }
 
348
    int length() const {
 
349
        return rep->length();
 
350
    }
311
351
    /**
312
352
     * Const character at specified position.
313
353
     */
350
390
     */
351
391
    static UString null;
352
392
 
353
 
  private:
 
393
private:
354
394
    void attach(Rep *r);
355
395
    void detach();
356
396
    void release();
357
397
    Rep *rep;
358
 
  };
 
398
};
359
399
 
360
 
  inline bool operator==(const UChar &c1, const UChar &c2) {
 
400
inline bool operator==(const UChar &c1, const UChar &c2)
 
401
{
361
402
    return (c1.uc == c2.uc);
362
 
  }
363
 
  inline bool operator!=(const UChar &c1, const UChar &c2) {
 
403
}
 
404
inline bool operator!=(const UChar &c1, const UChar &c2)
 
405
{
364
406
    return !(c1 == c2);
365
 
  }
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);
369
 
  }
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);
374
 
  }
375
 
  inline bool operator==(const char *s1, const UString& s2) {
 
407
}
 
408
bool operator==(const UString& s1, const UString& s2);
 
409
inline bool operator!=(const UString& s1, const UString& s2)
 
410
{
 
411
    return !Swinder::operator==(s1, s2);
 
412
}
 
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)
 
416
{
 
417
    return !Swinder::operator==(s1, s2);
 
418
}
 
419
inline bool operator==(const char *s1, const UString& s2)
 
420
{
376
421
    return operator==(s2, s1);
377
 
  }
378
 
  inline bool operator!=(const char *s1, const UString& s2) {
 
422
}
 
423
inline bool operator!=(const char *s1, const UString& s2)
 
424
{
379
425
    return !Swinder::operator==(s1, s2);
380
 
  }
381
 
  bool operator==(const CString& s1, const CString& s2);
382
 
  UString operator+(const UString& s1, const UString& s2);
383
 
 
384
 
 
385
 
  class UConstString : private UString {
386
 
    public:
387
 
      UConstString( UChar* data, unsigned int length );
388
 
      ~UConstString();
389
 
 
390
 
      const UString& string() const { return *this; }
391
 
  };
 
426
}
 
427
bool operator==(const CString& s1, const CString& s2);
 
428
UString operator+(const UString& s1, const UString& s2);
 
429
 
 
430
 
 
431
class UConstString : private UString
 
432
{
 
433
public:
 
434
    UConstString(UChar* data, unsigned int length);
 
435
    ~UConstString();
 
436
 
 
437
    const UString& string() const {
 
438
        return *this;
 
439
    }
 
440
};
392
441
 
393
442
} // namespace SWINDER_USTRING_H
394
443