Changeset 1799 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Aug 12, 2002, 1:14:02 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r1791 r1799 116 116 UChar UChar::null; 117 117 UString::Rep UString::Rep::null = { 0, 0, 0, 1 }; 118 UString::Rep UString::Rep::empty = { 0, 0, 0, 1 }; 118 119 UString UString::null; 119 120 const int normalStatBufferSize = 4096; … … 191 192 } 192 193 int length = strlen(c); 194 if (length == 0) { 195 attach(&Rep::empty); 196 return; 197 } 193 198 UChar *d = new UChar[length]; 194 199 for (int i = 0; i < length; i++) … … 199 204 UString::UString(const UChar *c, int length) 200 205 { 206 if (length == 0) { 207 attach(&Rep::empty); 208 return; 209 } 201 210 UChar *d = new UChar[length]; 202 211 memcpy(d, c, length * sizeof(UChar)); … … 206 215 UString::UString(UChar *c, int length, bool copy) 207 216 { 217 if (length == 0) { 218 attach(&Rep::empty); 219 return; 220 } 208 221 UChar *d; 209 222 if (copy) { … … 224 237 int aSize = a.size(); 225 238 int bSize = b.size(); 226 UChar *d = new UChar[aSize + bSize]; 239 int length = aSize + bSize; 240 if (length == 0) { 241 attach(&Rep::empty); 242 return; 243 } 244 UChar *d = new UChar[length]; 227 245 memcpy(d, a.data(), aSize * sizeof(UChar)); 228 246 memcpy(d + aSize, b.data(), bSize * sizeof(UChar)); 229 rep = Rep::create(d, aSize + bSize);247 rep = Rep::create(d, length); 230 248 } 231 249 … … 467 485 int UString::find(const UString &f, int pos) const 468 486 { 469 if ( isNull())487 if (size() < f.size()) 470 488 return -1; 471 long fsize = f.size() * sizeof(UChar);472 489 if (pos < 0) 473 490 pos = 0; 474 491 const UChar *end = data() + size() - f.size(); 492 long fsize = f.size() * sizeof(UChar); 493 const void *fdata = f.data(); 475 494 for (const UChar *c = data() + pos; c <= end; c++) 476 if (!memcmp( (void*)c, (void*)f.data(), fsize))495 if (!memcmp(c, fdata, fsize)) 477 496 return (c-data()); 478 497 … … 480 499 } 481 500 501 int UString::find(UChar ch, int pos) const 502 { 503 if (pos < 0) 504 pos = 0; 505 const UChar *end = data() + size(); 506 for (const UChar *c = data() + pos; c < end; c++) 507 if (*c == ch) 508 return (c-data()); 509 510 return -1; 511 } 512 482 513 int UString::rfind(const UString &f, int pos) const 483 514 { 484 if ( isNull())515 if (size() < f.size()) 485 516 return -1; 486 517 if (pos + f.size() >= size()) 487 518 pos = size() - f.size(); 488 519 long fsize = f.size() * sizeof(UChar); 520 const void *fdata = f.data(); 489 521 for (const UChar *c = data() + pos; c >= data(); c--) { 490 if (!memcmp( (void*)c, (void*)f.data(), fsize))522 if (!memcmp(c, fdata, fsize)) 491 523 return (c-data()); 492 524 } … … 495 527 } 496 528 529 int UString::rfind(UChar ch, int pos) const 530 { 531 if (isEmpty()) 532 return -1; 533 if (pos + 1 >= size()) 534 pos = size() - 1; 535 for (const UChar *c = data() + pos; c >= data(); c--) { 536 if (*c == ch) 537 return (c-data()); 538 } 539 540 return -1; 541 } 542 497 543 UString UString::substr(int pos, int len) const 498 544 { 499 if (isNull())500 return UString();501 545 if (pos < 0) 502 546 pos = 0; … … 552 596 bool KJS::operator==(const UString& s1, const char *s2) 553 597 { 554 if (s2 == 0L && s1.isNull()) 555 return true; 556 557 if (s1.size() != (int) strlen(s2)) 598 if (s2 == 0) { 599 return s1.isEmpty(); 600 } 601 602 if (s1.size() != (int)strlen(s2)) 558 603 return false; 559 604 560 605 const UChar *u = s1.data(); 561 606 while (*s2) { 562 if (u->uc != *s2)607 if (u->uc != (unsigned char)*s2) 563 608 return false; 564 609 s2++; … … 583 628 } 584 629 if (l < lmin) 585 return (c1->u nicode() < c2->unicode());630 return (c1->uc < c2->uc); 586 631 587 632 return (l1 < l2);
Note:
See TracChangeset
for help on using the changeset viewer.