OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) | 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r
ights reserved. |
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "wtf/RefCounted.h" | 39 #include "wtf/RefCounted.h" |
40 #include <unistd.h> | 40 #include <unistd.h> |
41 #endif | 41 #endif |
42 | 42 |
43 using namespace std; | 43 using namespace std; |
44 | 44 |
45 namespace WTF { | 45 namespace WTF { |
46 | 46 |
47 using namespace Unicode; | 47 using namespace Unicode; |
48 | 48 |
49 COMPILE_ASSERT(sizeof(StringImpl) == 2 * sizeof(int) + 2 * sizeof(void*), String
Impl_should_stay_small); | 49 COMPILE_ASSERT(sizeof(StringImpl) == 3 * sizeof(int), StringImpl_should_stay_sma
ll); |
50 | 50 |
51 #ifdef STRING_STATS | 51 #ifdef STRING_STATS |
52 | 52 |
53 static Mutex& statsMutex() | 53 static Mutex& statsMutex() |
54 { | 54 { |
55 DEFINE_STATIC_LOCAL(Mutex, mutex, ()); | 55 DEFINE_STATIC_LOCAL(Mutex, mutex, ()); |
56 return mutex; | 56 return mutex; |
57 } | 57 } |
58 | 58 |
59 static HashSet<void*>& liveStrings() | 59 static HashSet<void*>& liveStrings() |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return create(string, length); | 384 return create(string, length); |
385 } | 385 } |
386 | 386 |
387 bool StringImpl::containsOnlyWhitespace() | 387 bool StringImpl::containsOnlyWhitespace() |
388 { | 388 { |
389 // FIXME: The definition of whitespace here includes a number of characters | 389 // FIXME: The definition of whitespace here includes a number of characters |
390 // that are not whitespace from the point of view of RenderText; I wonder if | 390 // that are not whitespace from the point of view of RenderText; I wonder if |
391 // that's a problem in practice. | 391 // that's a problem in practice. |
392 if (is8Bit()) { | 392 if (is8Bit()) { |
393 for (unsigned i = 0; i < m_length; ++i) { | 393 for (unsigned i = 0; i < m_length; ++i) { |
394 UChar c = m_data8[i]; | 394 UChar c = characters8()[i]; |
395 if (!isASCIISpace(c)) | 395 if (!isASCIISpace(c)) |
396 return false; | 396 return false; |
397 } | 397 } |
398 | 398 |
399 return true; | 399 return true; |
400 } | 400 } |
401 | 401 |
402 for (unsigned i = 0; i < m_length; ++i) { | 402 for (unsigned i = 0; i < m_length; ++i) { |
403 UChar c = m_data16[i]; | 403 UChar c = characters16()[i]; |
404 if (!isASCIISpace(c)) | 404 if (!isASCIISpace(c)) |
405 return false; | 405 return false; |
406 } | 406 } |
407 return true; | 407 return true; |
408 } | 408 } |
409 | 409 |
410 PassRefPtr<StringImpl> StringImpl::substring(unsigned start, unsigned length) | 410 PassRefPtr<StringImpl> StringImpl::substring(unsigned start, unsigned length) |
411 { | 411 { |
412 if (start >= m_length) | 412 if (start >= m_length) |
413 return empty(); | 413 return empty(); |
414 unsigned maxLength = m_length - start; | 414 unsigned maxLength = m_length - start; |
415 if (length >= maxLength) { | 415 if (length >= maxLength) { |
416 if (!start) | 416 if (!start) |
417 return this; | 417 return this; |
418 length = maxLength; | 418 length = maxLength; |
419 } | 419 } |
420 if (is8Bit()) | 420 if (is8Bit()) |
421 return create(m_data8 + start, length); | 421 return create(characters8() + start, length); |
422 | 422 |
423 return create(m_data16 + start, length); | 423 return create(characters16() + start, length); |
424 } | 424 } |
425 | 425 |
426 UChar32 StringImpl::characterStartingAt(unsigned i) | 426 UChar32 StringImpl::characterStartingAt(unsigned i) |
427 { | 427 { |
428 if (is8Bit()) | 428 if (is8Bit()) |
429 return m_data8[i]; | 429 return characters8()[i]; |
430 if (U16_IS_SINGLE(m_data16[i])) | 430 if (U16_IS_SINGLE(characters16()[i])) |
431 return m_data16[i]; | 431 return characters16()[i]; |
432 if (i + 1 < m_length && U16_IS_LEAD(m_data16[i]) && U16_IS_TRAIL(m_data16[i
+ 1])) | 432 if (i + 1 < m_length && U16_IS_LEAD(characters16()[i]) && U16_IS_TRAIL(chara
cters16()[i + 1])) |
433 return U16_GET_SUPPLEMENTARY(m_data16[i], m_data16[i + 1]); | 433 return U16_GET_SUPPLEMENTARY(characters16()[i], characters16()[i + 1]); |
434 return 0; | 434 return 0; |
435 } | 435 } |
436 | 436 |
437 PassRefPtr<StringImpl> StringImpl::lower() | 437 PassRefPtr<StringImpl> StringImpl::lower() |
438 { | 438 { |
439 // Note: This is a hot function in the Dromaeo benchmark, specifically the | 439 // Note: This is a hot function in the Dromaeo benchmark, specifically the |
440 // no-op code path up through the first 'return' statement. | 440 // no-op code path up through the first 'return' statement. |
441 | 441 |
442 // First scan the string for uppercase and non-ASCII characters: | 442 // First scan the string for uppercase and non-ASCII characters: |
443 bool noUpper = true; | 443 bool noUpper = true; |
444 UChar ored = 0; | 444 UChar ored = 0; |
445 if (is8Bit()) { | 445 if (is8Bit()) { |
446 const LChar* end = m_data8 + m_length; | 446 const LChar* end = characters8() + m_length; |
447 for (const LChar* chp = m_data8; chp != end; ++chp) { | 447 for (const LChar* chp = characters8(); chp != end; ++chp) { |
448 if (UNLIKELY(isASCIIUpper(*chp))) | 448 if (UNLIKELY(isASCIIUpper(*chp))) |
449 noUpper = false; | 449 noUpper = false; |
450 ored |= *chp; | 450 ored |= *chp; |
451 } | 451 } |
452 // Nothing to do if the string is all ASCII with no uppercase. | 452 // Nothing to do if the string is all ASCII with no uppercase. |
453 if (noUpper && !(ored & ~0x7F)) | 453 if (noUpper && !(ored & ~0x7F)) |
454 return this; | 454 return this; |
455 | 455 |
456 RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>
::max())); | 456 RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>
::max())); |
457 int32_t length = m_length; | 457 int32_t length = m_length; |
458 | 458 |
459 LChar* data8; | 459 LChar* data8; |
460 RefPtr<StringImpl> newImpl = createUninitialized(length, data8); | 460 RefPtr<StringImpl> newImpl = createUninitialized(length, data8); |
461 | 461 |
462 if (!(ored & ~0x7F)) { | 462 if (!(ored & ~0x7F)) { |
463 for (int32_t i = 0; i < length; ++i) | 463 for (int32_t i = 0; i < length; ++i) |
464 data8[i] = toASCIILower(m_data8[i]); | 464 data8[i] = toASCIILower(characters8()[i]); |
465 | 465 |
466 return newImpl.release(); | 466 return newImpl.release(); |
467 } | 467 } |
468 | 468 |
469 // Do a slower implementation for cases that include non-ASCII Latin-1 c
haracters. | 469 // Do a slower implementation for cases that include non-ASCII Latin-1 c
haracters. |
470 for (int32_t i = 0; i < length; ++i) | 470 for (int32_t i = 0; i < length; ++i) |
471 data8[i] = static_cast<LChar>(Unicode::toLower(m_data8[i])); | 471 data8[i] = static_cast<LChar>(Unicode::toLower(characters8()[i])); |
472 | 472 |
473 return newImpl.release(); | 473 return newImpl.release(); |
474 } | 474 } |
475 | 475 |
476 const UChar *end = m_data16 + m_length; | 476 const UChar* end = characters16() + m_length; |
477 for (const UChar* chp = m_data16; chp != end; ++chp) { | 477 for (const UChar* chp = characters16(); chp != end; ++chp) { |
478 if (UNLIKELY(isASCIIUpper(*chp))) | 478 if (UNLIKELY(isASCIIUpper(*chp))) |
479 noUpper = false; | 479 noUpper = false; |
480 ored |= *chp; | 480 ored |= *chp; |
481 } | 481 } |
482 // Nothing to do if the string is all ASCII with no uppercase. | 482 // Nothing to do if the string is all ASCII with no uppercase. |
483 if (noUpper && !(ored & ~0x7F)) | 483 if (noUpper && !(ored & ~0x7F)) |
484 return this; | 484 return this; |
485 | 485 |
486 RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>::ma
x())); | 486 RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>::ma
x())); |
487 int32_t length = m_length; | 487 int32_t length = m_length; |
488 | 488 |
489 if (!(ored & ~0x7F)) { | 489 if (!(ored & ~0x7F)) { |
490 UChar* data16; | 490 UChar* data16; |
491 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data16); | 491 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data16); |
492 | 492 |
493 for (int32_t i = 0; i < length; ++i) { | 493 for (int32_t i = 0; i < length; ++i) { |
494 UChar c = m_data16[i]; | 494 UChar c = characters16()[i]; |
495 data16[i] = toASCIILower(c); | 495 data16[i] = toASCIILower(c); |
496 } | 496 } |
497 return newImpl.release(); | 497 return newImpl.release(); |
498 } | 498 } |
499 | 499 |
500 // Do a slower implementation for cases that include non-ASCII characters. | 500 // Do a slower implementation for cases that include non-ASCII characters. |
501 UChar* data16; | 501 UChar* data16; |
502 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data16); | 502 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data16); |
503 | 503 |
504 bool error; | 504 bool error; |
505 int32_t realLength = Unicode::toLower(data16, length, m_data16, m_length, &e
rror); | 505 int32_t realLength = Unicode::toLower(data16, length, characters16(), m_leng
th, &error); |
506 if (!error && realLength == length) | 506 if (!error && realLength == length) |
507 return newImpl.release(); | 507 return newImpl.release(); |
508 | 508 |
509 newImpl = createUninitialized(realLength, data16); | 509 newImpl = createUninitialized(realLength, data16); |
510 Unicode::toLower(data16, realLength, m_data16, m_length, &error); | 510 Unicode::toLower(data16, realLength, characters16(), m_length, &error); |
511 if (error) | 511 if (error) |
512 return this; | 512 return this; |
513 return newImpl.release(); | 513 return newImpl.release(); |
514 } | 514 } |
515 | 515 |
516 PassRefPtr<StringImpl> StringImpl::upper() | 516 PassRefPtr<StringImpl> StringImpl::upper() |
517 { | 517 { |
518 // This function could be optimized for no-op cases the way lower() is, | 518 // This function could be optimized for no-op cases the way lower() is, |
519 // but in empirical testing, few actual calls to upper() are no-ops, so | 519 // but in empirical testing, few actual calls to upper() are no-ops, so |
520 // it wouldn't be worth the extra time for pre-scanning. | 520 // it wouldn't be worth the extra time for pre-scanning. |
521 | 521 |
522 RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>::ma
x())); | 522 RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>::ma
x())); |
523 int32_t length = m_length; | 523 int32_t length = m_length; |
524 | 524 |
525 if (is8Bit()) { | 525 if (is8Bit()) { |
526 LChar* data8; | 526 LChar* data8; |
527 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data8); | 527 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data8); |
528 | 528 |
529 // Do a faster loop for the case where all the characters are ASCII. | 529 // Do a faster loop for the case where all the characters are ASCII. |
530 LChar ored = 0; | 530 LChar ored = 0; |
531 for (int i = 0; i < length; ++i) { | 531 for (int i = 0; i < length; ++i) { |
532 LChar c = m_data8[i]; | 532 LChar c = characters8()[i]; |
533 ored |= c; | 533 ored |= c; |
534 data8[i] = toASCIIUpper(c); | 534 data8[i] = toASCIIUpper(c); |
535 } | 535 } |
536 if (!(ored & ~0x7F)) | 536 if (!(ored & ~0x7F)) |
537 return newImpl.release(); | 537 return newImpl.release(); |
538 | 538 |
539 // Do a slower implementation for cases that include non-ASCII Latin-1 c
haracters. | 539 // Do a slower implementation for cases that include non-ASCII Latin-1 c
haracters. |
540 int numberSharpSCharacters = 0; | 540 int numberSharpSCharacters = 0; |
541 | 541 |
542 // There are two special cases. | 542 // There are two special cases. |
543 // 1. latin-1 characters when converted to upper case are 16 bit charac
ters. | 543 // 1. latin-1 characters when converted to upper case are 16 bit charac
ters. |
544 // 2. Lower case sharp-S converts to "SS" (two characters) | 544 // 2. Lower case sharp-S converts to "SS" (two characters) |
545 for (int32_t i = 0; i < length; ++i) { | 545 for (int32_t i = 0; i < length; ++i) { |
546 LChar c = m_data8[i]; | 546 LChar c = characters8()[i]; |
547 if (UNLIKELY(c == smallLetterSharpS)) | 547 if (UNLIKELY(c == smallLetterSharpS)) |
548 ++numberSharpSCharacters; | 548 ++numberSharpSCharacters; |
549 UChar upper = Unicode::toUpper(c); | 549 UChar upper = Unicode::toUpper(c); |
550 if (UNLIKELY(upper > 0xff)) { | 550 if (UNLIKELY(upper > 0xff)) { |
551 // Since this upper-cased character does not fit in an 8-bit str
ing, we need to take the 16-bit path. | 551 // Since this upper-cased character does not fit in an 8-bit str
ing, we need to take the 16-bit path. |
552 goto upconvert; | 552 goto upconvert; |
553 } | 553 } |
554 data8[i] = static_cast<LChar>(upper); | 554 data8[i] = static_cast<LChar>(upper); |
555 } | 555 } |
556 | 556 |
557 if (!numberSharpSCharacters) | 557 if (!numberSharpSCharacters) |
558 return newImpl.release(); | 558 return newImpl.release(); |
559 | 559 |
560 // We have numberSSCharacters sharp-s characters, but none of the other
special characters. | 560 // We have numberSSCharacters sharp-s characters, but none of the other
special characters. |
561 newImpl = createUninitialized(m_length + numberSharpSCharacters, data8); | 561 newImpl = createUninitialized(m_length + numberSharpSCharacters, data8); |
562 | 562 |
563 LChar* dest = data8; | 563 LChar* dest = data8; |
564 | 564 |
565 for (int32_t i = 0; i < length; ++i) { | 565 for (int32_t i = 0; i < length; ++i) { |
566 LChar c = m_data8[i]; | 566 LChar c = characters8()[i]; |
567 if (c == smallLetterSharpS) { | 567 if (c == smallLetterSharpS) { |
568 *dest++ = 'S'; | 568 *dest++ = 'S'; |
569 *dest++ = 'S'; | 569 *dest++ = 'S'; |
570 } else | 570 } else |
571 *dest++ = static_cast<LChar>(Unicode::toUpper(c)); | 571 *dest++ = static_cast<LChar>(Unicode::toUpper(c)); |
572 } | 572 } |
573 | 573 |
574 return newImpl.release(); | 574 return newImpl.release(); |
575 } | 575 } |
576 | 576 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>::ma
x())); | 634 RELEASE_ASSERT(m_length <= static_cast<unsigned>(numeric_limits<int32_t>::ma
x())); |
635 int32_t length = m_length; | 635 int32_t length = m_length; |
636 | 636 |
637 if (is8Bit()) { | 637 if (is8Bit()) { |
638 // Do a faster loop for the case where all the characters are ASCII. | 638 // Do a faster loop for the case where all the characters are ASCII. |
639 LChar* data; | 639 LChar* data; |
640 RefPtr <StringImpl>newImpl = createUninitialized(m_length, data); | 640 RefPtr <StringImpl>newImpl = createUninitialized(m_length, data); |
641 LChar ored = 0; | 641 LChar ored = 0; |
642 | 642 |
643 for (int32_t i = 0; i < length; ++i) { | 643 for (int32_t i = 0; i < length; ++i) { |
644 LChar c = m_data8[i]; | 644 LChar c = characters8()[i]; |
645 data[i] = toASCIILower(c); | 645 data[i] = toASCIILower(c); |
646 ored |= c; | 646 ored |= c; |
647 } | 647 } |
648 | 648 |
649 if (!(ored & ~0x7F)) | 649 if (!(ored & ~0x7F)) |
650 return newImpl.release(); | 650 return newImpl.release(); |
651 | 651 |
652 // Do a slower implementation for cases that include non-ASCII Latin-1 c
haracters. | 652 // Do a slower implementation for cases that include non-ASCII Latin-1 c
haracters. |
653 for (int32_t i = 0; i < length; ++i) | 653 for (int32_t i = 0; i < length; ++i) |
654 data[i] = static_cast<LChar>(Unicode::toLower(m_data8[i])); | 654 data[i] = static_cast<LChar>(Unicode::toLower(characters8()[i])); |
655 | 655 |
656 return newImpl.release(); | 656 return newImpl.release(); |
657 } | 657 } |
658 | 658 |
659 // Do a faster loop for the case where all the characters are ASCII. | 659 // Do a faster loop for the case where all the characters are ASCII. |
660 UChar* data; | 660 UChar* data; |
661 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); | 661 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); |
662 UChar ored = 0; | 662 UChar ored = 0; |
663 for (int32_t i = 0; i < length; ++i) { | 663 for (int32_t i = 0; i < length; ++i) { |
664 UChar c = m_data16[i]; | 664 UChar c = characters16()[i]; |
665 ored |= c; | 665 ored |= c; |
666 data[i] = toASCIILower(c); | 666 data[i] = toASCIILower(c); |
667 } | 667 } |
668 if (!(ored & ~0x7F)) | 668 if (!(ored & ~0x7F)) |
669 return newImpl.release(); | 669 return newImpl.release(); |
670 | 670 |
671 // Do a slower implementation for cases that include non-ASCII characters. | 671 // Do a slower implementation for cases that include non-ASCII characters. |
672 bool error; | 672 bool error; |
673 int32_t realLength = Unicode::foldCase(data, length, m_data16, m_length, &er
ror); | 673 int32_t realLength = Unicode::foldCase(data, length, characters16(), m_lengt
h, &error); |
674 if (!error && realLength == length) | 674 if (!error && realLength == length) |
675 return newImpl.release(); | 675 return newImpl.release(); |
676 newImpl = createUninitialized(realLength, data); | 676 newImpl = createUninitialized(realLength, data); |
677 Unicode::foldCase(data, realLength, m_data16, m_length, &error); | 677 Unicode::foldCase(data, realLength, characters16(), m_length, &error); |
678 if (error) | 678 if (error) |
679 return this; | 679 return this; |
680 return newImpl.release(); | 680 return newImpl.release(); |
681 } | 681 } |
682 | 682 |
683 template <class UCharPredicate> | 683 template <class UCharPredicate> |
684 inline PassRefPtr<StringImpl> StringImpl::stripMatchedCharacters(UCharPredicate
predicate) | 684 inline PassRefPtr<StringImpl> StringImpl::stripMatchedCharacters(UCharPredicate
predicate) |
685 { | 685 { |
686 if (!m_length) | 686 if (!m_length) |
687 return empty(); | 687 return empty(); |
688 | 688 |
689 unsigned start = 0; | 689 unsigned start = 0; |
690 unsigned end = m_length - 1; | 690 unsigned end = m_length - 1; |
691 | 691 |
692 // skip white space from start | 692 // skip white space from start |
693 while (start <= end && predicate(is8Bit() ? m_data8[start] : m_data16[start]
)) | 693 while (start <= end && predicate(is8Bit() ? characters8()[start] : character
s16()[start])) |
694 ++start; | 694 ++start; |
695 | 695 |
696 // only white space | 696 // only white space |
697 if (start > end) | 697 if (start > end) |
698 return empty(); | 698 return empty(); |
699 | 699 |
700 // skip white space from end | 700 // skip white space from end |
701 while (end && predicate(is8Bit() ? m_data8[end] : m_data16[end])) | 701 while (end && predicate(is8Bit() ? characters8()[end] : characters16()[end])
) |
702 --end; | 702 --end; |
703 | 703 |
704 if (!start && end == m_length - 1) | 704 if (!start && end == m_length - 1) |
705 return this; | 705 return this; |
706 if (is8Bit()) | 706 if (is8Bit()) |
707 return create(m_data8 + start, end + 1 - start); | 707 return create(characters8() + start, end + 1 - start); |
708 return create(m_data16 + start, end + 1 - start); | 708 return create(characters16() + start, end + 1 - start); |
709 } | 709 } |
710 | 710 |
711 class UCharPredicate { | 711 class UCharPredicate { |
712 public: | 712 public: |
713 inline UCharPredicate(CharacterMatchFunctionPtr function): m_function(functi
on) { } | 713 inline UCharPredicate(CharacterMatchFunctionPtr function): m_function(functi
on) { } |
714 | 714 |
715 inline bool operator()(UChar ch) const | 715 inline bool operator()(UChar ch) const |
716 { | 716 { |
717 return m_function(ch); | 717 return m_function(ch); |
718 } | 718 } |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 unsigned startOffset = length() - matchLength; | 1355 unsigned startOffset = length() - matchLength; |
1356 return equalInner(this, startOffset, matchString, matchLength, caseSensitive
); | 1356 return equalInner(this, startOffset, matchString, matchLength, caseSensitive
); |
1357 } | 1357 } |
1358 | 1358 |
1359 PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC) | 1359 PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC) |
1360 { | 1360 { |
1361 if (oldC == newC) | 1361 if (oldC == newC) |
1362 return this; | 1362 return this; |
1363 unsigned i; | 1363 unsigned i; |
1364 for (i = 0; i != m_length; ++i) { | 1364 for (i = 0; i != m_length; ++i) { |
1365 UChar c = is8Bit() ? m_data8[i] : m_data16[i]; | 1365 UChar c = is8Bit() ? characters8()[i] : characters16()[i]; |
1366 if (c == oldC) | 1366 if (c == oldC) |
1367 break; | 1367 break; |
1368 } | 1368 } |
1369 if (i == m_length) | 1369 if (i == m_length) |
1370 return this; | 1370 return this; |
1371 | 1371 |
1372 if (is8Bit()) { | 1372 if (is8Bit()) { |
1373 if (oldC > 0xff) | 1373 if (oldC > 0xff) |
1374 // Looking for a 16 bit char in an 8 bit string, we're done. | 1374 // Looking for a 16 bit char in an 8 bit string, we're done. |
1375 return this; | 1375 return this; |
1376 | 1376 |
1377 if (newC <= 0xff) { | 1377 if (newC <= 0xff) { |
1378 LChar* data; | 1378 LChar* data; |
1379 LChar oldChar = static_cast<LChar>(oldC); | 1379 LChar oldChar = static_cast<LChar>(oldC); |
1380 LChar newChar = static_cast<LChar>(newC); | 1380 LChar newChar = static_cast<LChar>(newC); |
1381 | 1381 |
1382 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); | 1382 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); |
1383 | 1383 |
1384 for (i = 0; i != m_length; ++i) { | 1384 for (i = 0; i != m_length; ++i) { |
1385 LChar ch = m_data8[i]; | 1385 LChar ch = characters8()[i]; |
1386 if (ch == oldChar) | 1386 if (ch == oldChar) |
1387 ch = newChar; | 1387 ch = newChar; |
1388 data[i] = ch; | 1388 data[i] = ch; |
1389 } | 1389 } |
1390 return newImpl.release(); | 1390 return newImpl.release(); |
1391 } | 1391 } |
1392 | 1392 |
1393 // There is the possibility we need to up convert from 8 to 16 bit, | 1393 // There is the possibility we need to up convert from 8 to 16 bit, |
1394 // create a 16 bit string for the result. | 1394 // create a 16 bit string for the result. |
1395 UChar* data; | 1395 UChar* data; |
1396 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); | 1396 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); |
1397 | 1397 |
1398 for (i = 0; i != m_length; ++i) { | 1398 for (i = 0; i != m_length; ++i) { |
1399 UChar ch = m_data8[i]; | 1399 UChar ch = characters8()[i]; |
1400 if (ch == oldC) | 1400 if (ch == oldC) |
1401 ch = newC; | 1401 ch = newC; |
1402 data[i] = ch; | 1402 data[i] = ch; |
1403 } | 1403 } |
1404 | 1404 |
1405 return newImpl.release(); | 1405 return newImpl.release(); |
1406 } | 1406 } |
1407 | 1407 |
1408 UChar* data; | 1408 UChar* data; |
1409 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); | 1409 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); |
1410 | 1410 |
1411 for (i = 0; i != m_length; ++i) { | 1411 for (i = 0; i != m_length; ++i) { |
1412 UChar ch = m_data16[i]; | 1412 UChar ch = characters16()[i]; |
1413 if (ch == oldC) | 1413 if (ch == oldC) |
1414 ch = newC; | 1414 ch = newC; |
1415 data[i] = ch; | 1415 data[i] = ch; |
1416 } | 1416 } |
1417 return newImpl.release(); | 1417 return newImpl.release(); |
1418 } | 1418 } |
1419 | 1419 |
1420 PassRefPtr<StringImpl> StringImpl::replace(unsigned position, unsigned lengthToR
eplace, StringImpl* str) | 1420 PassRefPtr<StringImpl> StringImpl::replace(unsigned position, unsigned lengthToR
eplace, StringImpl* str) |
1421 { | 1421 { |
1422 position = min(position, length()); | 1422 position = min(position, length()); |
1423 lengthToReplace = min(lengthToReplace, length() - position); | 1423 lengthToReplace = min(lengthToReplace, length() - position); |
1424 unsigned lengthToInsert = str ? str->length() : 0; | 1424 unsigned lengthToInsert = str ? str->length() : 0; |
1425 if (!lengthToReplace && !lengthToInsert) | 1425 if (!lengthToReplace && !lengthToInsert) |
1426 return this; | 1426 return this; |
1427 | 1427 |
1428 RELEASE_ASSERT((length() - lengthToReplace) < (numeric_limits<unsigned>::max
() - lengthToInsert)); | 1428 RELEASE_ASSERT((length() - lengthToReplace) < (numeric_limits<unsigned>::max
() - lengthToInsert)); |
1429 | 1429 |
1430 if (is8Bit() && (!str || str->is8Bit())) { | 1430 if (is8Bit() && (!str || str->is8Bit())) { |
1431 LChar* data; | 1431 LChar* data; |
1432 RefPtr<StringImpl> newImpl = | 1432 RefPtr<StringImpl> newImpl = |
1433 createUninitialized(length() - lengthToReplace + lengthToInsert, data); | 1433 createUninitialized(length() - lengthToReplace + lengthToInsert, data); |
1434 memcpy(data, m_data8, position * sizeof(LChar)); | 1434 memcpy(data, characters8(), position * sizeof(LChar)); |
1435 if (str) | 1435 if (str) |
1436 memcpy(data + position, str->m_data8, lengthToInsert * sizeof(LChar)
); | 1436 memcpy(data + position, str->characters8(), lengthToInsert * sizeof(
LChar)); |
1437 memcpy(data + position + lengthToInsert, m_data8 + position + lengthToRe
place, | 1437 memcpy(data + position + lengthToInsert, characters8() + position + leng
thToReplace, |
1438 (length() - position - lengthToReplace) * sizeof(LChar)); | 1438 (length() - position - lengthToReplace) * sizeof(LChar)); |
1439 return newImpl.release(); | 1439 return newImpl.release(); |
1440 } | 1440 } |
1441 UChar* data; | 1441 UChar* data; |
1442 RefPtr<StringImpl> newImpl = | 1442 RefPtr<StringImpl> newImpl = |
1443 createUninitialized(length() - lengthToReplace + lengthToInsert, data); | 1443 createUninitialized(length() - lengthToReplace + lengthToInsert, data); |
1444 if (is8Bit()) | 1444 if (is8Bit()) |
1445 for (unsigned i = 0; i < position; ++i) | 1445 for (unsigned i = 0; i < position; ++i) |
1446 data[i] = m_data8[i]; | 1446 data[i] = characters8()[i]; |
1447 else | 1447 else |
1448 memcpy(data, m_data16, position * sizeof(UChar)); | 1448 memcpy(data, characters16(), position * sizeof(UChar)); |
1449 if (str) { | 1449 if (str) { |
1450 if (str->is8Bit()) | 1450 if (str->is8Bit()) |
1451 for (unsigned i = 0; i < lengthToInsert; ++i) | 1451 for (unsigned i = 0; i < lengthToInsert; ++i) |
1452 data[i + position] = str->m_data8[i]; | 1452 data[i + position] = str->characters8()[i]; |
1453 else | 1453 else |
1454 memcpy(data + position, str->m_data16, lengthToInsert * sizeof(UChar
)); | 1454 memcpy(data + position, str->characters16(), lengthToInsert * sizeof
(UChar)); |
1455 } | 1455 } |
1456 if (is8Bit()) { | 1456 if (is8Bit()) { |
1457 for (unsigned i = 0; i < length() - position - lengthToReplace; ++i) | 1457 for (unsigned i = 0; i < length() - position - lengthToReplace; ++i) |
1458 data[i + position + lengthToInsert] = m_data8[i + position + lengthT
oReplace]; | 1458 data[i + position + lengthToInsert] = characters8()[i + position + l
engthToReplace]; |
1459 } else { | 1459 } else { |
1460 memcpy(data + position + lengthToInsert, characters16() + position + len
gthToReplace, | 1460 memcpy(data + position + lengthToInsert, characters16() + position + len
gthToReplace, |
1461 (length() - position - lengthToReplace) * sizeof(UChar)); | 1461 (length() - position - lengthToReplace) * sizeof(UChar)); |
1462 } | 1462 } |
1463 return newImpl.release(); | 1463 return newImpl.release(); |
1464 } | 1464 } |
1465 | 1465 |
1466 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, StringImpl* replacemen
t) | 1466 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, StringImpl* replacemen
t) |
1467 { | 1467 { |
1468 if (!replacement) | 1468 if (!replacement) |
1469 return this; | 1469 return this; |
1470 | 1470 |
1471 if (replacement->is8Bit()) | 1471 if (replacement->is8Bit()) |
1472 return replace(pattern, replacement->m_data8, replacement->length()); | 1472 return replace(pattern, replacement->characters8(), replacement->length(
)); |
1473 | 1473 |
1474 return replace(pattern, replacement->m_data16, replacement->length()); | 1474 return replace(pattern, replacement->characters16(), replacement->length()); |
1475 } | 1475 } |
1476 | 1476 |
1477 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, const LChar* replaceme
nt, unsigned repStrLength) | 1477 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, const LChar* replaceme
nt, unsigned repStrLength) |
1478 { | 1478 { |
1479 ASSERT(replacement); | 1479 ASSERT(replacement); |
1480 | 1480 |
1481 size_t srcSegmentStart = 0; | 1481 size_t srcSegmentStart = 0; |
1482 unsigned matchCount = 0; | 1482 unsigned matchCount = 0; |
1483 | 1483 |
1484 // Count the matches. | 1484 // Count the matches. |
(...skipping 19 matching lines...) Expand all Loading... |
1504 unsigned srcSegmentLength; | 1504 unsigned srcSegmentLength; |
1505 srcSegmentStart = 0; | 1505 srcSegmentStart = 0; |
1506 unsigned dstOffset = 0; | 1506 unsigned dstOffset = 0; |
1507 | 1507 |
1508 if (is8Bit()) { | 1508 if (is8Bit()) { |
1509 LChar* data; | 1509 LChar* data; |
1510 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1510 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
1511 | 1511 |
1512 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1512 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { |
1513 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1513 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
1514 memcpy(data + dstOffset, m_data8 + srcSegmentStart, srcSegmentLength
* sizeof(LChar)); | 1514 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegment
Length * sizeof(LChar)); |
1515 dstOffset += srcSegmentLength; | 1515 dstOffset += srcSegmentLength; |
1516 memcpy(data + dstOffset, replacement, repStrLength * sizeof(LChar)); | 1516 memcpy(data + dstOffset, replacement, repStrLength * sizeof(LChar)); |
1517 dstOffset += repStrLength; | 1517 dstOffset += repStrLength; |
1518 srcSegmentStart = srcSegmentEnd + 1; | 1518 srcSegmentStart = srcSegmentEnd + 1; |
1519 } | 1519 } |
1520 | 1520 |
1521 srcSegmentLength = m_length - srcSegmentStart; | 1521 srcSegmentLength = m_length - srcSegmentStart; |
1522 memcpy(data + dstOffset, m_data8 + srcSegmentStart, srcSegmentLength * s
izeof(LChar)); | 1522 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegmentLeng
th * sizeof(LChar)); |
1523 | 1523 |
1524 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1524 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
1525 | 1525 |
1526 return newImpl.release(); | 1526 return newImpl.release(); |
1527 } | 1527 } |
1528 | 1528 |
1529 UChar* data; | 1529 UChar* data; |
1530 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1530 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
1531 | 1531 |
1532 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1532 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { |
1533 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1533 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
1534 memcpy(data + dstOffset, m_data16 + srcSegmentStart, srcSegmentLength *
sizeof(UChar)); | 1534 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen
gth * sizeof(UChar)); |
1535 | 1535 |
1536 dstOffset += srcSegmentLength; | 1536 dstOffset += srcSegmentLength; |
1537 for (unsigned i = 0; i < repStrLength; ++i) | 1537 for (unsigned i = 0; i < repStrLength; ++i) |
1538 data[i + dstOffset] = replacement[i]; | 1538 data[i + dstOffset] = replacement[i]; |
1539 | 1539 |
1540 dstOffset += repStrLength; | 1540 dstOffset += repStrLength; |
1541 srcSegmentStart = srcSegmentEnd + 1; | 1541 srcSegmentStart = srcSegmentEnd + 1; |
1542 } | 1542 } |
1543 | 1543 |
1544 srcSegmentLength = m_length - srcSegmentStart; | 1544 srcSegmentLength = m_length - srcSegmentStart; |
1545 memcpy(data + dstOffset, m_data16 + srcSegmentStart, srcSegmentLength * size
of(UChar)); | 1545 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLength
* sizeof(UChar)); |
1546 | 1546 |
1547 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1547 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
1548 | 1548 |
1549 return newImpl.release(); | 1549 return newImpl.release(); |
1550 } | 1550 } |
1551 | 1551 |
1552 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, const UChar* replaceme
nt, unsigned repStrLength) | 1552 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, const UChar* replaceme
nt, unsigned repStrLength) |
1553 { | 1553 { |
1554 ASSERT(replacement); | 1554 ASSERT(replacement); |
1555 | 1555 |
(...skipping 24 matching lines...) Expand all Loading... |
1580 srcSegmentStart = 0; | 1580 srcSegmentStart = 0; |
1581 unsigned dstOffset = 0; | 1581 unsigned dstOffset = 0; |
1582 | 1582 |
1583 if (is8Bit()) { | 1583 if (is8Bit()) { |
1584 UChar* data; | 1584 UChar* data; |
1585 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1585 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
1586 | 1586 |
1587 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1587 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { |
1588 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1588 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
1589 for (unsigned i = 0; i < srcSegmentLength; ++i) | 1589 for (unsigned i = 0; i < srcSegmentLength; ++i) |
1590 data[i + dstOffset] = m_data8[i + srcSegmentStart]; | 1590 data[i + dstOffset] = characters8()[i + srcSegmentStart]; |
1591 | 1591 |
1592 dstOffset += srcSegmentLength; | 1592 dstOffset += srcSegmentLength; |
1593 memcpy(data + dstOffset, replacement, repStrLength * sizeof(UChar)); | 1593 memcpy(data + dstOffset, replacement, repStrLength * sizeof(UChar)); |
1594 | 1594 |
1595 dstOffset += repStrLength; | 1595 dstOffset += repStrLength; |
1596 srcSegmentStart = srcSegmentEnd + 1; | 1596 srcSegmentStart = srcSegmentEnd + 1; |
1597 } | 1597 } |
1598 | 1598 |
1599 srcSegmentLength = m_length - srcSegmentStart; | 1599 srcSegmentLength = m_length - srcSegmentStart; |
1600 for (unsigned i = 0; i < srcSegmentLength; ++i) | 1600 for (unsigned i = 0; i < srcSegmentLength; ++i) |
1601 data[i + dstOffset] = m_data8[i + srcSegmentStart]; | 1601 data[i + dstOffset] = characters8()[i + srcSegmentStart]; |
1602 | 1602 |
1603 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1603 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
1604 | 1604 |
1605 return newImpl.release(); | 1605 return newImpl.release(); |
1606 } | 1606 } |
1607 | 1607 |
1608 UChar* data; | 1608 UChar* data; |
1609 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1609 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
1610 | 1610 |
1611 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1611 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { |
1612 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1612 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
1613 memcpy(data + dstOffset, m_data16 + srcSegmentStart, srcSegmentLength *
sizeof(UChar)); | 1613 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen
gth * sizeof(UChar)); |
1614 | 1614 |
1615 dstOffset += srcSegmentLength; | 1615 dstOffset += srcSegmentLength; |
1616 memcpy(data + dstOffset, replacement, repStrLength * sizeof(UChar)); | 1616 memcpy(data + dstOffset, replacement, repStrLength * sizeof(UChar)); |
1617 | 1617 |
1618 dstOffset += repStrLength; | 1618 dstOffset += repStrLength; |
1619 srcSegmentStart = srcSegmentEnd + 1; | 1619 srcSegmentStart = srcSegmentEnd + 1; |
1620 } | 1620 } |
1621 | 1621 |
1622 srcSegmentLength = m_length - srcSegmentStart; | 1622 srcSegmentLength = m_length - srcSegmentStart; |
1623 memcpy(data + dstOffset, m_data16 + srcSegmentStart, srcSegmentLength * size
of(UChar)); | 1623 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLength
* sizeof(UChar)); |
1624 | 1624 |
1625 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1625 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
1626 | 1626 |
1627 return newImpl.release(); | 1627 return newImpl.release(); |
1628 } | 1628 } |
1629 | 1629 |
1630 PassRefPtr<StringImpl> StringImpl::replace(StringImpl* pattern, StringImpl* repl
acement) | 1630 PassRefPtr<StringImpl> StringImpl::replace(StringImpl* pattern, StringImpl* repl
acement) |
1631 { | 1631 { |
1632 if (!pattern || !replacement) | 1632 if (!pattern || !replacement) |
1633 return this; | 1633 return this; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 // 1. This and replacement are both 8 bit. | 1670 // 1. This and replacement are both 8 bit. |
1671 // 2. This and replacement are both 16 bit. | 1671 // 2. This and replacement are both 16 bit. |
1672 // 3. This is 8 bit and replacement is 16 bit. | 1672 // 3. This is 8 bit and replacement is 16 bit. |
1673 // 4. This is 16 bit and replacement is 8 bit. | 1673 // 4. This is 16 bit and replacement is 8 bit. |
1674 if (srcIs8Bit && replacementIs8Bit) { | 1674 if (srcIs8Bit && replacementIs8Bit) { |
1675 // Case 1 | 1675 // Case 1 |
1676 LChar* data; | 1676 LChar* data; |
1677 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1677 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
1678 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1678 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { |
1679 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1679 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
1680 memcpy(data + dstOffset, m_data8 + srcSegmentStart, srcSegmentLength
* sizeof(LChar)); | 1680 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegment
Length * sizeof(LChar)); |
1681 dstOffset += srcSegmentLength; | 1681 dstOffset += srcSegmentLength; |
1682 memcpy(data + dstOffset, replacement->m_data8, repStrLength * sizeof
(LChar)); | 1682 memcpy(data + dstOffset, replacement->characters8(), repStrLength *
sizeof(LChar)); |
1683 dstOffset += repStrLength; | 1683 dstOffset += repStrLength; |
1684 srcSegmentStart = srcSegmentEnd + patternLength; | 1684 srcSegmentStart = srcSegmentEnd + patternLength; |
1685 } | 1685 } |
1686 | 1686 |
1687 srcSegmentLength = m_length - srcSegmentStart; | 1687 srcSegmentLength = m_length - srcSegmentStart; |
1688 memcpy(data + dstOffset, m_data8 + srcSegmentStart, srcSegmentLength * s
izeof(LChar)); | 1688 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegmentLeng
th * sizeof(LChar)); |
1689 | 1689 |
1690 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1690 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
1691 | 1691 |
1692 return newImpl.release(); | 1692 return newImpl.release(); |
1693 } | 1693 } |
1694 | 1694 |
1695 UChar* data; | 1695 UChar* data; |
1696 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1696 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
1697 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1697 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { |
1698 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1698 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
1699 if (srcIs8Bit) { | 1699 if (srcIs8Bit) { |
1700 // Case 3. | 1700 // Case 3. |
1701 for (unsigned i = 0; i < srcSegmentLength; ++i) | 1701 for (unsigned i = 0; i < srcSegmentLength; ++i) |
1702 data[i + dstOffset] = m_data8[i + srcSegmentStart]; | 1702 data[i + dstOffset] = characters8()[i + srcSegmentStart]; |
1703 } else { | 1703 } else { |
1704 // Case 2 & 4. | 1704 // Case 2 & 4. |
1705 memcpy(data + dstOffset, m_data16 + srcSegmentStart, srcSegmentLengt
h * sizeof(UChar)); | 1705 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmen
tLength * sizeof(UChar)); |
1706 } | 1706 } |
1707 dstOffset += srcSegmentLength; | 1707 dstOffset += srcSegmentLength; |
1708 if (replacementIs8Bit) { | 1708 if (replacementIs8Bit) { |
1709 // Cases 2 & 3. | 1709 // Cases 2 & 3. |
1710 for (unsigned i = 0; i < repStrLength; ++i) | 1710 for (unsigned i = 0; i < repStrLength; ++i) |
1711 data[i + dstOffset] = replacement->m_data8[i]; | 1711 data[i + dstOffset] = replacement->characters8()[i]; |
1712 } else { | 1712 } else { |
1713 // Case 4 | 1713 // Case 4 |
1714 memcpy(data + dstOffset, replacement->m_data16, repStrLength * sizeo
f(UChar)); | 1714 memcpy(data + dstOffset, replacement->characters16(), repStrLength *
sizeof(UChar)); |
1715 } | 1715 } |
1716 dstOffset += repStrLength; | 1716 dstOffset += repStrLength; |
1717 srcSegmentStart = srcSegmentEnd + patternLength; | 1717 srcSegmentStart = srcSegmentEnd + patternLength; |
1718 } | 1718 } |
1719 | 1719 |
1720 srcSegmentLength = m_length - srcSegmentStart; | 1720 srcSegmentLength = m_length - srcSegmentStart; |
1721 if (srcIs8Bit) { | 1721 if (srcIs8Bit) { |
1722 // Case 3. | 1722 // Case 3. |
1723 for (unsigned i = 0; i < srcSegmentLength; ++i) | 1723 for (unsigned i = 0; i < srcSegmentLength; ++i) |
1724 data[i + dstOffset] = m_data8[i + srcSegmentStart]; | 1724 data[i + dstOffset] = characters8()[i + srcSegmentStart]; |
1725 } else { | 1725 } else { |
1726 // Cases 2 & 4. | 1726 // Cases 2 & 4. |
1727 memcpy(data + dstOffset, m_data16 + srcSegmentStart, srcSegmentLength *
sizeof(UChar)); | 1727 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen
gth * sizeof(UChar)); |
1728 } | 1728 } |
1729 | 1729 |
1730 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1730 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
1731 | 1731 |
1732 return newImpl.release(); | 1732 return newImpl.release(); |
1733 } | 1733 } |
1734 | 1734 |
1735 static inline bool stringImplContentEqual(const StringImpl* a, const StringImpl*
b) | 1735 static inline bool stringImplContentEqual(const StringImpl* a, const StringImpl*
b) |
1736 { | 1736 { |
1737 unsigned aLength = a->length(); | 1737 unsigned aLength = a->length(); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 if (!a && b && !b->length()) | 1923 if (!a && b && !b->length()) |
1924 return true; | 1924 return true; |
1925 if (!b && a && !a->length()) | 1925 if (!b && a && !a->length()) |
1926 return true; | 1926 return true; |
1927 return equal(a, b); | 1927 return equal(a, b); |
1928 } | 1928 } |
1929 | 1929 |
1930 WTF::Unicode::Direction StringImpl::defaultWritingDirection(bool* hasStrongDirec
tionality) | 1930 WTF::Unicode::Direction StringImpl::defaultWritingDirection(bool* hasStrongDirec
tionality) |
1931 { | 1931 { |
1932 for (unsigned i = 0; i < m_length; ++i) { | 1932 for (unsigned i = 0; i < m_length; ++i) { |
1933 WTF::Unicode::Direction charDirection = WTF::Unicode::direction(is8Bit()
? m_data8[i] : m_data16[i]); | 1933 WTF::Unicode::Direction charDirection = WTF::Unicode::direction(is8Bit()
? characters8()[i] : characters16()[i]); |
1934 if (charDirection == WTF::Unicode::LeftToRight) { | 1934 if (charDirection == WTF::Unicode::LeftToRight) { |
1935 if (hasStrongDirectionality) | 1935 if (hasStrongDirectionality) |
1936 *hasStrongDirectionality = true; | 1936 *hasStrongDirectionality = true; |
1937 return WTF::Unicode::LeftToRight; | 1937 return WTF::Unicode::LeftToRight; |
1938 } | 1938 } |
1939 if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF::
Unicode::RightToLeftArabic) { | 1939 if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF::
Unicode::RightToLeftArabic) { |
1940 if (hasStrongDirectionality) | 1940 if (hasStrongDirectionality) |
1941 *hasStrongDirectionality = true; | 1941 *hasStrongDirectionality = true; |
1942 return WTF::Unicode::RightToLeft; | 1942 return WTF::Unicode::RightToLeft; |
1943 } | 1943 } |
1944 } | 1944 } |
1945 if (hasStrongDirectionality) | 1945 if (hasStrongDirectionality) |
1946 *hasStrongDirectionality = false; | 1946 *hasStrongDirectionality = false; |
1947 return WTF::Unicode::LeftToRight; | 1947 return WTF::Unicode::LeftToRight; |
1948 } | 1948 } |
1949 | 1949 |
1950 size_t StringImpl::sizeInBytes() const | 1950 size_t StringImpl::sizeInBytes() const |
1951 { | 1951 { |
1952 size_t size = length(); | 1952 size_t size = length(); |
1953 if (!is8Bit()) | 1953 if (!is8Bit()) |
1954 size *= 2; | 1954 size *= 2; |
1955 return size + sizeof(*this); | 1955 return size + sizeof(*this); |
1956 } | 1956 } |
1957 | 1957 |
1958 } // namespace WTF | 1958 } // namespace WTF |
OLD | NEW |