00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef DeprecatedString_h
00027 #define DeprecatedString_h
00028
00029 #include "DeprecatedCString.h"
00030 #include <wtf/ASCIICType.h>
00031 #include <wtf/unicode/Unicode.h>
00032
00033
00034
00035 #if COMPILER(GCC) && PLATFORM(FORCE_PACK)
00036 #define PACK_STRUCT __attribute__((packed))
00037 #else
00038 #define PACK_STRUCT
00039 #endif
00040
00041 #if PLATFORM(CF)
00042 typedef const struct __CFString * CFStringRef;
00043 #endif
00044
00045 #if PLATFORM(MAC)
00046 #ifdef __OBJC__
00047 @class NSString;
00048 #else
00049 class NSString;
00050 #endif
00051 #endif
00052
00053 #if PLATFORM(QT)
00054 class QString;
00055 #endif
00056
00057 #ifdef __OWB_JS__
00058 namespace KJS {
00059 class Identifier;
00060 class UString;
00061 }
00062 #endif //__OWB_JS__
00063
00064 namespace WebCore {
00065
00066 class RegularExpression;
00067
00068 class DeprecatedChar {
00069 public:
00070 DeprecatedChar();
00071 DeprecatedChar(char);
00072 DeprecatedChar(unsigned char);
00073 DeprecatedChar(short);
00074 DeprecatedChar(unsigned short);
00075 DeprecatedChar(int);
00076 DeprecatedChar(unsigned);
00077
00078 unsigned short unicode() const;
00079 char latin1() const;
00080 bool isSpace() const;
00081 DeprecatedChar lower() const;
00082 DeprecatedChar upper() const;
00083
00084 private:
00085 unsigned short c;
00086 } PACK_STRUCT;
00087
00088 inline DeprecatedChar::DeprecatedChar() : c(0)
00089 {
00090 }
00091
00092 inline DeprecatedChar::DeprecatedChar(char ch) : c((unsigned char) ch)
00093 {
00094 }
00095
00096 inline DeprecatedChar::DeprecatedChar(unsigned char uch) : c(uch)
00097 {
00098 }
00099
00100 inline DeprecatedChar::DeprecatedChar(short n) : c(n)
00101 {
00102 }
00103
00104 inline DeprecatedChar::DeprecatedChar(unsigned short n) : c(n)
00105 {
00106 }
00107
00108 inline DeprecatedChar::DeprecatedChar(unsigned n) : c(n)
00109 {
00110 }
00111
00112 inline DeprecatedChar::DeprecatedChar(int n) : c(n)
00113 {
00114 }
00115
00116 inline unsigned short DeprecatedChar::unicode() const
00117 {
00118 return c;
00119 }
00120
00121 inline bool DeprecatedChar::isSpace() const
00122 {
00123 #if USE(ICU_UNICODE)
00124 #ifdef __OWB__
00125 return ::BAL::getBIInternationalization()->isSpace(c);
00126 #else
00127
00128
00129 return c <= 0x7F ? WTF::isASCIISpace(c) : (u_charDirection(c) == U_WHITE_SPACE_NEUTRAL);
00130 #endif // __OWB__
00131 #elif USE(QT4_UNICODE)
00132 return QChar(c).isSpace();
00133 #endif
00134 }
00135
00136 inline DeprecatedChar DeprecatedChar::lower() const
00137 {
00138 #if USE(ICU_UNICODE)
00139 #ifdef __OWB__
00140 return ::BAL::getBIInternationalization()->toLower(c);
00141 #else
00142
00143 return c <= 0x7F ? WTF::toASCIILower(c) : u_tolower(c);
00144 #endif // __OWB__
00145 #elif USE(QT4_UNICODE)
00146 return QChar(c).toLower().unicode();
00147 #endif
00148 }
00149
00150 inline DeprecatedChar DeprecatedChar::upper() const
00151 {
00152 #if USE(ICU_UNICODE)
00153 #ifdef __OWB__
00154 return ::BAL::getBIInternationalization()->toUpper(c);
00155 #else
00156
00157 return c <= 0x7F ? WTF::toASCIIUpper(c) : u_toupper(c);
00158 #endif //__OWB__
00159 #elif USE(QT4_UNICODE)
00160 return QChar(c).toUpper().unicode();
00161 #endif
00162 }
00163
00164 inline char DeprecatedChar::latin1() const
00165 {
00166 return c > 0xff ? 0 : c;
00167 }
00168
00169 inline bool operator==(DeprecatedChar qc1, DeprecatedChar qc2)
00170 {
00171 return qc1.unicode() == qc2.unicode();
00172 }
00173
00174 inline bool operator==(DeprecatedChar qc, char ch)
00175 {
00176 return qc.unicode() == (unsigned char) ch;
00177 }
00178
00179 inline bool operator==(char ch, DeprecatedChar qc)
00180 {
00181 return (unsigned char) ch == qc.unicode();
00182 }
00183
00184 inline bool operator!=(DeprecatedChar qc1, DeprecatedChar qc2)
00185 {
00186 return qc1.unicode() != qc2.unicode();
00187 }
00188
00189 inline bool operator!=(DeprecatedChar qc, char ch)
00190 {
00191 return qc.unicode() != (unsigned char) ch;
00192 }
00193
00194 inline bool operator!=(char ch, DeprecatedChar qc)
00195 {
00196 return (unsigned char) ch != qc.unicode();
00197 }
00198
00199
00200
00201
00202 #define WEBCORE_DS_INTERNAL_BUFFER_SIZE 20
00203 #define WEBCORE_DS_INTERNAL_BUFFER_CHARS WEBCORE_DS_INTERNAL_BUFFER_SIZE-1
00204 #define WEBCORE_DS_INTERNAL_BUFFER_UCHARS WEBCORE_DS_INTERNAL_BUFFER_SIZE/2
00205
00206 struct DeprecatedStringData
00207 {
00208
00209 DeprecatedStringData();
00210 void initialize();
00211
00212
00213 DeprecatedStringData(DeprecatedChar *u, unsigned l, unsigned m);
00214 void initialize(DeprecatedChar *u, unsigned l, unsigned m);
00215
00216
00217 DeprecatedStringData(const DeprecatedChar *u, unsigned l);
00218 void initialize(const DeprecatedChar *u, unsigned l);
00219
00220
00221 DeprecatedStringData(const char *u, unsigned l);
00222 void initialize(const char *u, unsigned l);
00223
00224
00225 static DeprecatedStringData* createAndAdopt(DeprecatedStringData &);
00226
00227 ~DeprecatedStringData();
00228
00229 #ifdef WEBCORE_DS_DEBUG_ALLOCATIONS
00230 void* operator new(size_t s);
00231 void operator delete(void*p);
00232 #endif
00233
00234 inline void ref() { refCount++; }
00235 inline void deref() { if (--refCount == 0 && _isHeapAllocated) delete this; }
00236
00237 char *ascii();
00238 char *makeAscii();
00239 void increaseAsciiSize(unsigned size);
00240
00241 DeprecatedChar *unicode();
00242 DeprecatedChar *makeUnicode();
00243 void increaseUnicodeSize(unsigned size);
00244
00245 bool isUnicodeInternal() const { return (char *)_unicode == _internalBuffer; }
00246 bool isAsciiInternal() const { return _ascii == _internalBuffer; }
00247
00248 unsigned refCount;
00249 unsigned _length;
00250 mutable DeprecatedChar *_unicode;
00251 mutable char *_ascii;
00252
00253 unsigned _maxUnicode : 30;
00254 bool _isUnicodeValid : 1;
00255 bool _isHeapAllocated : 1;
00256 unsigned _maxAscii : 31;
00257 bool _isAsciiValid : 1;
00258
00259
00260
00261 char _internalBuffer[WEBCORE_DS_INTERNAL_BUFFER_SIZE];
00262
00263 private:
00264 void adopt(DeprecatedStringData&);
00265
00266 DeprecatedStringData(const DeprecatedStringData &);
00267 DeprecatedStringData &operator=(const DeprecatedStringData &);
00268 };
00269
00270 class DeprecatedString;
00271
00272 bool operator==(const DeprecatedString&, const DeprecatedString&);
00273 bool operator==(const DeprecatedString&, const char*);
00274
00275 class DeprecatedString {
00276 public:
00277 static const char * const null;
00278
00279 DeprecatedString();
00280 DeprecatedString(DeprecatedChar);
00281 DeprecatedString(const DeprecatedChar *, unsigned);
00282 DeprecatedString(const char *);
00283 DeprecatedString(const char *, int len);
00284 #ifdef __OWB_JS__
00285 DeprecatedString(const KJS::Identifier&);
00286 DeprecatedString(const KJS::UString&);
00287 #endif //__OWB_JS__
00288
00289 DeprecatedString(const DeprecatedString &);
00290 DeprecatedString &operator=(const DeprecatedString &);
00291
00292 ~DeprecatedString();
00293
00294 #ifdef __OWB_JS__
00295 operator KJS::Identifier() const;
00296 operator KJS::UString() const;
00297 #endif //__OWB_JS__
00298
00299 #if PLATFORM(QT)
00300 DeprecatedString(const QString&);
00301 operator QString() const;
00302 #endif
00303
00304 static DeprecatedString fromLatin1(const char *);
00305 static DeprecatedString fromLatin1(const char *, int len);
00306 static DeprecatedString fromUtf8(const char *);
00307 static DeprecatedString fromUtf8(const char *, int len);
00308 #if PLATFORM(CF)
00309 static DeprecatedString fromCFString(CFStringRef);
00310 #endif
00311 #if PLATFORM(MAC)
00312 static DeprecatedString fromNSString(NSString*);
00313 #endif
00314 #if PLATFORM(SYMBIAN)
00315 static DeprecatedString fromDes(const TDesC&);
00316 static DeprecatedString fromDes(const TDesC8&);
00317 #endif
00318 DeprecatedString &operator=(char);
00319 DeprecatedString &operator=(DeprecatedChar);
00320 DeprecatedString &operator=(const char *);
00321 DeprecatedString &operator=(const DeprecatedCString &);
00322
00323 unsigned length() const;
00324
00325 const DeprecatedChar *unicode() const;
00326 const DeprecatedChar *stableUnicode();
00327 const char *latin1() const;
00328 const char *ascii() const;
00329 bool isAllASCII() const;
00330 bool isAllLatin1() const;
00331 bool hasFastLatin1() const;
00332 void copyLatin1(char *buffer, unsigned position = 0, unsigned length = 0xffffffff) const;
00333 DeprecatedCString utf8() const { int length; return utf8(length); }
00334 DeprecatedCString utf8(int &length) const;
00335
00336 bool isNull() const;
00337 bool isEmpty() const;
00338
00339 DeprecatedChar at(unsigned) const;
00340
00341 int compare(const DeprecatedString &) const;
00342 int compare(const char *) const;
00343
00344 bool startsWith(const DeprecatedString &) const;
00345 bool startsWith(const char *) const;
00346 bool startsWith(const char *, bool caseSensitive) const;
00347
00348 int find(char, int index = 0) const;
00349 int find(DeprecatedChar, int index = 0) const;
00350 int find(const char *, int index = 0, bool cs = true) const;
00351 int find(const DeprecatedString &, int index = 0, bool cs = true) const;
00352 int find(const RegularExpression &, int index = 0) const;
00353
00354 int findRev(char, int index = -1) const;
00355 int findRev(const DeprecatedString& str, int index, bool cs = true) const;
00356 int findRev(const char *, int index = -1) const;
00357
00358 int contains(char) const;
00359 int contains(const char *, bool cs = true) const;
00360 int contains(const DeprecatedString &, bool cs = true) const;
00361 int contains(DeprecatedChar c, bool cs = true) const;
00362
00363 bool endsWith(const DeprecatedString &) const;
00364
00365 short toShort(bool *ok = 0, int base = 10) const;
00366 unsigned short toUShort(bool *ok = 0, int base = 10) const;
00367 int toInt(bool *ok = 0, int base = 10) const;
00368 int64_t toInt64(bool *ok = 0, int base = 10) const;
00369 unsigned toUInt(bool *ok = 0, int base = 10) const;
00370 uint64_t toUInt64(bool *ok = 0, int base = 10) const;
00371
00372 double toDouble(bool *ok = 0) const;
00373 float toFloat(bool* ok = 0) const;
00374
00375 static DeprecatedString number(int);
00376 static DeprecatedString number(unsigned);
00377 static DeprecatedString number(long);
00378 static DeprecatedString number(unsigned long);
00379 static DeprecatedString number(double);
00380
00381 DeprecatedString left(unsigned) const;
00382 DeprecatedString right(unsigned) const;
00383 DeprecatedString mid(unsigned, unsigned len=0xffffffff) const;
00384
00385 DeprecatedString copy() const;
00386
00387 DeprecatedString lower() const;
00388 DeprecatedString stripWhiteSpace() const;
00389 DeprecatedString simplifyWhiteSpace() const;
00390
00391 DeprecatedString &setUnicode(const DeprecatedChar *, unsigned);
00392 DeprecatedString &setLatin1(const char *, int len=-1);
00393
00394 DeprecatedString &setNum(short);
00395 DeprecatedString &setNum(unsigned short);
00396 DeprecatedString &setNum(int);
00397 DeprecatedString &setNum(unsigned);
00398 DeprecatedString &setNum(long);
00399 DeprecatedString &setNum(unsigned long);
00400 DeprecatedString &setNum(double);
00401
00402 DeprecatedString& format(const char *, ...)
00403 #if __GNUC__
00404 __attribute__ ((format (printf, 2, 3)))
00405 #endif
00406 ;
00407
00408 DeprecatedString &append(const DeprecatedString &);
00409 DeprecatedString &append(DeprecatedChar);
00410 DeprecatedString &append(char);
00411 DeprecatedString &insert(unsigned, const DeprecatedString &);
00412 DeprecatedString &insert(unsigned, DeprecatedChar);
00413 DeprecatedString &insert(unsigned, char);
00414 DeprecatedString &insert(unsigned index, const char *insertChars, unsigned insertLength);
00415 DeprecatedString &prepend(const DeprecatedString &);
00416 DeprecatedString &remove(unsigned, unsigned);
00417 DeprecatedString &remove(const DeprecatedChar &c) { return replace(DeprecatedString(c), ""); }
00418 DeprecatedString &remove(const DeprecatedString &s) { return replace(s, ""); }
00419 DeprecatedString &replace(unsigned index, unsigned len, const DeprecatedString &s);
00420 DeprecatedString &replace(char, const DeprecatedString &);
00421 DeprecatedString &replace(DeprecatedChar, const DeprecatedString &);
00422 DeprecatedString &replace(const DeprecatedString &, const DeprecatedString &);
00423 DeprecatedString &replace(const RegularExpression &, const DeprecatedString &);
00424 DeprecatedString &replace(DeprecatedChar, DeprecatedChar);
00425
00426 DeprecatedString &append(const DeprecatedChar *, unsigned length);
00427 DeprecatedString &append(const char *, unsigned length);
00428 DeprecatedString &insert(unsigned position, const DeprecatedChar *, unsigned length);
00429 DeprecatedString &prepend(const DeprecatedChar *, unsigned length);
00430
00431 void fill(DeprecatedChar, int len=-1);
00432 void truncate(unsigned);
00433
00434 void reserve(unsigned);
00435
00436 bool operator!() const;
00437
00438 const DeprecatedChar operator[](int) const;
00439
00440 DeprecatedString &operator+=(const DeprecatedString &s) { return append(s); }
00441 DeprecatedString &operator+=(DeprecatedChar c) { return append(c); }
00442 DeprecatedString &operator+=(char c) { return append(c); }
00443
00444 #if PLATFORM(CF)
00445 CFStringRef getCFString() const;
00446 void setBufferFromCFString(CFStringRef);
00447 #endif
00448
00449 #if PLATFORM(MAC)
00450 NSString *getNSString() const;
00451
00452 #ifdef __OBJC__
00453 operator NSString*() const { return getNSString(); }
00454 #endif
00455
00456 #endif
00457
00458 #if PLATFORM(SYMBIAN)
00459 TPtrC des() const;
00460 TPtrC8 des8() const;
00461 void setBufferFromDes(const TDesC&);
00462 void setBufferFromDes(const TDesC8&);
00463 #endif
00464
00465 private:
00466
00467 DeprecatedString(DeprecatedStringData *constData, bool );
00468 void detach();
00469 void detachAndDiscardCharacters();
00470 void detachIfInternal();
00471 void detachInternal();
00472 void deref();
00473 DeprecatedChar *forceUnicode();
00474 void setLength(unsigned);
00475
00476 DeprecatedStringData **dataHandle;
00477 DeprecatedStringData internalData;
00478
00479 static DeprecatedStringData *shared_null;
00480 static DeprecatedStringData *makeSharedNull();
00481 static DeprecatedStringData **shared_null_handle;
00482 static DeprecatedStringData **makeSharedNullHandle();
00483
00484 friend bool operator==(const DeprecatedString &, const DeprecatedString &);
00485 friend bool operator==(const DeprecatedString &, const char *);
00486 friend bool equalIgnoringCase(const DeprecatedString&, const DeprecatedString&);
00487
00488 friend class DeprecatedConstString;
00489 friend class QGDict;
00490 friend struct DeprecatedStringData;
00491 };
00492
00493 DeprecatedString operator+(const DeprecatedString &, const DeprecatedString &);
00494 DeprecatedString operator+(const DeprecatedString &, const char *);
00495 DeprecatedString operator+(const DeprecatedString &, DeprecatedChar);
00496 DeprecatedString operator+(const DeprecatedString &, char);
00497 DeprecatedString operator+(const char *, const DeprecatedString &);
00498 DeprecatedString operator+(DeprecatedChar, const DeprecatedString &);
00499 DeprecatedString operator+(char, const DeprecatedString &);
00500
00501 bool equalIgnoringCase(const DeprecatedString&, const DeprecatedString&);
00502 inline bool equalIgnoringCase(const DeprecatedString& a, const char* b) { return equalIgnoringCase(a, DeprecatedString(b)); }
00503 inline bool equalIgnoringCase(const char* a, const DeprecatedString& b) { return equalIgnoringCase(DeprecatedString(a), b); }
00504
00505 inline char *DeprecatedStringData::ascii()
00506 {
00507 return _isAsciiValid ? _ascii : makeAscii();
00508 }
00509
00510 inline DeprecatedChar *DeprecatedStringData::unicode()
00511 {
00512 return _isUnicodeValid ? _unicode : makeUnicode();
00513 }
00514
00515 inline unsigned DeprecatedString::length() const
00516 {
00517 return dataHandle[0]->_length;
00518 }
00519
00520 inline bool DeprecatedString::isEmpty() const
00521 {
00522 return dataHandle[0]->_length == 0;
00523 }
00524
00525 inline const char *DeprecatedString::latin1() const
00526 {
00527 return dataHandle[0]->ascii();
00528 }
00529
00530 inline const DeprecatedChar *DeprecatedString::unicode() const
00531 {
00532 return dataHandle[0]->unicode();
00533 }
00534
00535 #if PLATFORM(MAC)
00536 #if PLATFORM(CF)
00537 inline CFStringRef DeprecatedString::getCFString() const
00538 {
00539 return (CFStringRef)getNSString();
00540 }
00541 #endif
00542 #endif
00543
00544 inline DeprecatedString DeprecatedString::fromLatin1(const char *chs)
00545 {
00546 return chs;
00547 }
00548
00549 inline DeprecatedString DeprecatedString::fromLatin1(const char *chs, int length)
00550 {
00551 return DeprecatedString(chs, length);
00552 }
00553
00554 inline const char *DeprecatedString::ascii() const
00555 {
00556 return latin1();
00557 }
00558
00559 inline bool DeprecatedString::operator!() const
00560 {
00561 return isNull();
00562 }
00563
00564 inline const DeprecatedChar DeprecatedString::operator[](int index) const
00565 {
00566 return at(index);
00567 }
00568
00569 inline bool operator==(const char *chs, const DeprecatedString &qs)
00570 {
00571 return qs == chs;
00572 }
00573
00574 inline bool operator!=(const DeprecatedString &qs1, const DeprecatedString &qs2)
00575 {
00576 return !(qs1 == qs2);
00577 }
00578
00579 inline bool operator!=(const DeprecatedString &qs, const char *chs)
00580 {
00581 return !(qs == chs);
00582 }
00583
00584 inline bool operator!=(const char *chs, const DeprecatedString &qs)
00585 {
00586 return !(qs == chs);
00587 }
00588
00589 inline bool operator<(const DeprecatedString &qs1, const DeprecatedString &qs2)
00590 {
00591 return qs1.compare(qs2) < 0;
00592 }
00593
00594 inline bool operator<(const DeprecatedString &qs, const char *chs)
00595 {
00596 return qs.compare(chs) < 0;
00597 }
00598
00599 inline bool operator<(const char *chs, const DeprecatedString &qs)
00600 {
00601 return qs.compare(chs) > 0;
00602 }
00603
00604 inline bool operator<=(const DeprecatedString &qs1, const DeprecatedString &qs2)
00605 {
00606 return qs1.compare(qs2) <= 0;
00607 }
00608
00609 inline bool operator<=(const DeprecatedString &qs, const char *chs)
00610 {
00611 return qs.compare(chs) <= 0;
00612 }
00613
00614 inline bool operator<=(const char *chs, const DeprecatedString &qs)
00615 {
00616 return qs.compare(chs) >= 0;
00617 }
00618
00619 inline bool operator>(const DeprecatedString &qs1, const DeprecatedString &qs2)
00620 {
00621 return qs1.compare(qs2) > 0;
00622 }
00623
00624 inline bool operator>(const DeprecatedString &qs, const char *chs)
00625 {
00626 return qs.compare(chs) > 0;
00627 }
00628
00629 inline bool operator>(const char *chs, const DeprecatedString &qs)
00630 {
00631 return qs.compare(chs) < 0;
00632 }
00633
00634 inline bool operator>=(const DeprecatedString &qs1, const DeprecatedString &qs2)
00635 {
00636 return qs1.compare(qs2) >= 0;
00637 }
00638
00639 inline bool operator>=(const DeprecatedString &qs, const char *chs)
00640 {
00641 return qs.compare(chs) >= 0;
00642 }
00643
00644 inline bool operator>=(const char *chs, const DeprecatedString &qs)
00645 {
00646 return qs.compare(chs) <= 0;
00647 }
00648
00649 class DeprecatedConstString : private DeprecatedString {
00650 public:
00651 DeprecatedConstString(const DeprecatedChar *, unsigned);
00652 ~DeprecatedConstString();
00653 const DeprecatedString &string() const { return *this; }
00654 };
00655
00656 }
00657
00658 #endif