Changeset 1791 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Aug 9, 2002, 9:31:50 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r1623 r1791 104 104 } 105 105 106 CString &CString::operator+=(const CString &str)107 {108 return append(str.c_str());109 }110 111 106 int CString::size() const 112 107 { … … 120 115 121 116 UChar UChar::null; 122 #ifdef APPLE_CHANGES123 117 UString::Rep UString::Rep::null = { 0, 0, 0, 1 }; 124 #else125 UString::Rep UString::Rep::null = { 0, 0, 1 };126 #endif127 118 UString UString::null; 128 #ifdef APPLE_CHANGES 129 static pthread_once_t statBufferKeyOnce = PTHREAD_ONCE_INIT; 130 static pthread_key_t statBufferKey; 131 #else 132 static char *statBuffer = 0L; 133 #endif 119 const int normalStatBufferSize = 4096; 120 static char *statBuffer = 0; 121 static int statBufferSize = 0; 134 122 135 123 UChar::UChar(const UCharReference &c) … … 140 128 UChar UChar::toLower() const 141 129 { 142 // ### properly supp rot unicode tolower130 // ### properly support unicode tolower 143 131 if (uc >= 256 || islower(uc)) 144 132 return *this; 145 133 146 return UChar(tolower(uc));134 return (unsigned char)tolower(uc); 147 135 } 148 136 … … 152 140 return *this; 153 141 154 return UChar(toupper(uc));142 return (unsigned char)toupper(uc); 155 143 } 156 144 … … 177 165 r->dat = d; 178 166 r->len = l; 179 #ifdef APPLE_CHANGES180 167 r->capacity = l; 181 #endif182 168 r->rc = 1; 183 169 … … 194 180 { 195 181 UChar *d = new UChar[1]; 196 d[0] = UChar(0, c);182 d[0] = c; 197 183 rep = Rep::create(d, 1); 198 184 } … … 200 186 UString::UString(const char *c) 201 187 { 202 attach(&Rep::null); 203 operator=(c); 188 if (!c) { 189 attach(&Rep::null); 190 return; 191 } 192 int length = strlen(c); 193 UChar *d = new UChar[length]; 194 for (int i = 0; i < length; i++) 195 d[i].uc = c[i]; 196 rep = Rep::create(d, length); 204 197 } 205 198 … … 227 220 } 228 221 229 UString::~UString() 230 { 231 release(); 222 UString::UString(const UString &a, const UString &b) 223 { 224 int aSize = a.size(); 225 int bSize = b.size(); 226 UChar *d = new UChar[aSize + bSize]; 227 memcpy(d, a.data(), aSize * sizeof(UChar)); 228 memcpy(d + aSize, b.data(), bSize * sizeof(UChar)); 229 rep = Rep::create(d, aSize + bSize); 232 230 } 233 231 … … 275 273 UString &UString::append(const UString &t) 276 274 { 277 #ifdef APPLE_CHANGES278 275 int l = size(); 279 276 int tLen = t.size(); … … 292 289 rep = Rep::create(n, newLen); 293 290 rep->capacity = newCapacity; 294 #else295 int l = size();296 UChar *n = new UChar[l+t.size()];297 memcpy(n, data(), l * sizeof(UChar));298 memcpy(n+l, t.data(), t.size() * sizeof(UChar));299 release();300 rep = Rep::create(n, l + t.size());301 #endif302 291 303 292 return *this; … … 306 295 CString UString::cstring() const 307 296 { 308 return CString(ascii()); 309 } 310 311 #ifdef APPLE_CHANGES 312 static void statBufferKeyCleanup(void *statBuffer) 313 { 314 if (statBuffer != NULL) 315 delete [] (char *)statBuffer; 316 } 317 318 static void statBufferKeyInit(void) 319 { 320 pthread_key_create(&statBufferKey, statBufferKeyCleanup); 321 } 322 #endif 297 return ascii(); 298 } 323 299 324 300 char *UString::ascii() const 325 301 { 326 #ifdef APPLE_CHANGES 327 pthread_once(&statBufferKeyOnce, statBufferKeyInit); 328 char *statBuffer = (char *)pthread_getspecific(statBufferKey); 329 #endif 330 if (statBuffer) 302 // Never make the buffer smaller than normalStatBufferSize. 303 // Thus we almost never need to reallocate. 304 int length = size(); 305 int neededSize = length + 1; 306 if (neededSize < normalStatBufferSize) { 307 neededSize = normalStatBufferSize; 308 } 309 if (neededSize != statBufferSize) { 331 310 delete [] statBuffer; 332 333 statBuffer = new char[size()+1]; 334 for(int i = 0; i < size(); i++) 335 statBuffer[i] = data()[i].low(); 336 statBuffer[size()] = '\0'; 337 338 #ifdef APPLE_CHANGES 339 pthread_setspecific(statBufferKey, statBuffer); 340 #endif 311 statBuffer = new char [neededSize]; 312 statBufferSize = neededSize; 313 } 314 315 const UChar *p = data(); 316 char *q = statBuffer; 317 const UChar *limit = p + length; 318 while (p != limit) { 319 *q = p->uc; 320 ++p; 321 ++q; 322 } 323 *q = '\0'; 324 341 325 return statBuffer; 342 326 } … … 346 330 { 347 331 delete [] statBuffer; 348 statBuffer = 0L; 332 statBuffer = 0; 333 statBufferSize = 0; 349 334 } 350 335 #endif … … 352 337 UString &UString::operator=(const char *c) 353 338 { 354 #ifdef APPLE_CHANGES355 339 int l = c ? strlen(c) : 0; 356 340 UChar *d; … … 363 347 } 364 348 for (int i = 0; i < l; i++) 365 d[i].uc = (uchar)c[i];366 #else367 release();368 int l = c ? strlen(c) : 0;369 370 UChar *d = new UChar[l];371 for (int i = 0; i < l; i++)372 349 d[i].uc = c[i]; 373 rep = Rep::create(d, l);374 #endif375 350 376 351 return *this; … … 386 361 } 387 362 388 UString &UString::operator+=(const UString &s)389 {390 return append(s);391 }392 393 363 bool UString::is8Bit() const 394 364 { 395 365 const UChar *u = data(); 396 for(int i = 0; i < size(); i++, u++) 366 const UChar *limit = u + size(); 367 while (u < limit) { 397 368 if (u->uc > 0xFF) 398 369 return false; 370 ++u; 371 } 399 372 400 373 return true; … … 422 395 return NaN; 423 396 424 CString str = cstring(); 425 const char *c = str.c_str(); 397 const char *c = ascii(); 426 398 427 399 // skip leading white space … … 615 587 return (l1 < l2); 616 588 } 617 618 UString KJS::operator+(const UString& s1, const UString& s2)619 {620 UString tmp(s1);621 tmp.append(s2);622 623 return tmp;624 }
Note:
See TracChangeset
for help on using the changeset viewer.