| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Lars Knoll <lars@trolltech.com> | 2 * Copyright (C) 2006 Lars Knoll <lars@trolltech.com> |
| 3 * Copyright (C) 2007, 2011, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2007, 2011, 2012 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 468 } |
| 469 | 469 |
| 470 static UText emptyText = UTEXT_INITIALIZER; | 470 static UText emptyText = UTEXT_INITIALIZER; |
| 471 | 471 |
| 472 static TextBreakIterator* wordBreakIterator(const LChar* string, int length) | 472 static TextBreakIterator* wordBreakIterator(const LChar* string, int length) |
| 473 { | 473 { |
| 474 UErrorCode errorCode = U_ZERO_ERROR; | 474 UErrorCode errorCode = U_ZERO_ERROR; |
| 475 static TextBreakIterator* breakIter = 0; | 475 static TextBreakIterator* breakIter = 0; |
| 476 if (!breakIter) { | 476 if (!breakIter) { |
| 477 breakIter = icu::BreakIterator::createWordInstance(icu::Locale(currentTe
xtBreakLocaleID()), errorCode); | 477 breakIter = icu::BreakIterator::createWordInstance(icu::Locale(currentTe
xtBreakLocaleID()), errorCode); |
| 478 ASSERT_WITH_MESSAGE(U_SUCCESS(errorCode), "ICU could not open a break it
erator: %s (%d)", u_errorName(errorCode), errorCode); | 478 DCHECK(U_SUCCESS(errorCode)) << "ICU could not open a break iterator: "
<< u_errorName(errorCode) << " (" << errorCode << ")"; |
| 479 if (!breakIter) | 479 if (!breakIter) |
| 480 return 0; | 480 return 0; |
| 481 } | 481 } |
| 482 | 482 |
| 483 UTextWithBuffer textLocal; | 483 UTextWithBuffer textLocal; |
| 484 textLocal.text = emptyText; | 484 textLocal.text = emptyText; |
| 485 textLocal.text.extraSize = sizeof(textLocal.buffer); | 485 textLocal.text.extraSize = sizeof(textLocal.buffer); |
| 486 textLocal.text.pExtra = textLocal.buffer; | 486 textLocal.text.pExtra = textLocal.buffer; |
| 487 | 487 |
| 488 UErrorCode openStatus = U_ZERO_ERROR; | 488 UErrorCode openStatus = U_ZERO_ERROR; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 511 return; | 511 return; |
| 512 iter->setText(&uText, errorCode); | 512 iter->setText(&uText, errorCode); |
| 513 } | 513 } |
| 514 | 514 |
| 515 TextBreakIterator* wordBreakIterator(const UChar* string, int length) | 515 TextBreakIterator* wordBreakIterator(const UChar* string, int length) |
| 516 { | 516 { |
| 517 UErrorCode errorCode = U_ZERO_ERROR; | 517 UErrorCode errorCode = U_ZERO_ERROR; |
| 518 static TextBreakIterator* breakIter = 0; | 518 static TextBreakIterator* breakIter = 0; |
| 519 if (!breakIter) { | 519 if (!breakIter) { |
| 520 breakIter = icu::BreakIterator::createWordInstance(icu::Locale(currentTe
xtBreakLocaleID()), errorCode); | 520 breakIter = icu::BreakIterator::createWordInstance(icu::Locale(currentTe
xtBreakLocaleID()), errorCode); |
| 521 ASSERT_WITH_MESSAGE(U_SUCCESS(errorCode), "ICU could not open a break it
erator: %s (%d)", u_errorName(errorCode), errorCode); | 521 DCHECK(U_SUCCESS(errorCode)) << "ICU could not open a break iterator: "
<< u_errorName(errorCode) << " (" << errorCode << ")"; |
| 522 if (!breakIter) | 522 if (!breakIter) |
| 523 return 0; | 523 return 0; |
| 524 } | 524 } |
| 525 setText16(breakIter, string, length); | 525 setText16(breakIter, string, length); |
| 526 return breakIter; | 526 return breakIter; |
| 527 } | 527 } |
| 528 | 528 |
| 529 TextBreakIterator* wordBreakIterator(const String& string, int start, int length
) | 529 TextBreakIterator* wordBreakIterator(const String& string, int start, int length
) |
| 530 { | 530 { |
| 531 if (string.isEmpty()) | 531 if (string.isEmpty()) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 createIteratorForBuffer(buffer, length); | 643 createIteratorForBuffer(buffer, length); |
| 644 } | 644 } |
| 645 | 645 |
| 646 void NonSharedCharacterBreakIterator::createIteratorForBuffer(const UChar* buffe
r, unsigned length) | 646 void NonSharedCharacterBreakIterator::createIteratorForBuffer(const UChar* buffe
r, unsigned length) |
| 647 { | 647 { |
| 648 m_iterator = nonSharedCharacterBreakIterator; | 648 m_iterator = nonSharedCharacterBreakIterator; |
| 649 bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIt
erator(m_iterator, 0); | 649 bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIt
erator(m_iterator, 0); |
| 650 if (!createdIterator) { | 650 if (!createdIterator) { |
| 651 UErrorCode errorCode = U_ZERO_ERROR; | 651 UErrorCode errorCode = U_ZERO_ERROR; |
| 652 m_iterator = icu::BreakIterator::createCharacterInstance(icu::Locale(cur
rentTextBreakLocaleID()), errorCode); | 652 m_iterator = icu::BreakIterator::createCharacterInstance(icu::Locale(cur
rentTextBreakLocaleID()), errorCode); |
| 653 ASSERT_WITH_MESSAGE(U_SUCCESS(errorCode), "ICU could not open a break it
erator: %s (%d)", u_errorName(errorCode), errorCode); | 653 DCHECK(U_SUCCESS(errorCode)) << "ICU could not open a break iterator: "
<< u_errorName(errorCode) << " (" << errorCode << ")"; |
| 654 } | 654 } |
| 655 | 655 |
| 656 setText16(m_iterator, buffer, length); | 656 setText16(m_iterator, buffer, length); |
| 657 } | 657 } |
| 658 | 658 |
| 659 NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator() | 659 NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator() |
| 660 { | 660 { |
| 661 if (m_is8Bit) | 661 if (m_is8Bit) |
| 662 return; | 662 return; |
| 663 if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator)) | 663 if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator)) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 return TextBreakDone; | 709 return TextBreakDone; |
| 710 return offset + clusterLengthStartingAt(offset); | 710 return offset + clusterLengthStartingAt(offset); |
| 711 } | 711 } |
| 712 | 712 |
| 713 TextBreakIterator* sentenceBreakIterator(const UChar* string, int length) | 713 TextBreakIterator* sentenceBreakIterator(const UChar* string, int length) |
| 714 { | 714 { |
| 715 UErrorCode openStatus = U_ZERO_ERROR; | 715 UErrorCode openStatus = U_ZERO_ERROR; |
| 716 static TextBreakIterator* iterator = 0; | 716 static TextBreakIterator* iterator = 0; |
| 717 if (!iterator) { | 717 if (!iterator) { |
| 718 iterator = icu::BreakIterator::createSentenceInstance(icu::Locale(curre
ntTextBreakLocaleID()), openStatus); | 718 iterator = icu::BreakIterator::createSentenceInstance(icu::Locale(curre
ntTextBreakLocaleID()), openStatus); |
| 719 ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break i
terator: %s (%d)", u_errorName(openStatus), openStatus); | 719 DCHECK(U_SUCCESS(openStatus)) << "ICU could not open a break iterator: "
<< u_errorName(openStatus) << " (" << openStatus << ")"; |
| 720 if (!iterator) | 720 if (!iterator) |
| 721 return 0; | 721 return 0; |
| 722 } | 722 } |
| 723 | 723 |
| 724 setText16(iterator, string, length); | 724 setText16(iterator, string, length); |
| 725 return iterator; | 725 return iterator; |
| 726 } | 726 } |
| 727 | 727 |
| 728 bool isWordTextBreak(TextBreakIterator* iterator) | 728 bool isWordTextBreak(TextBreakIterator* iterator) |
| 729 { | 729 { |
| 730 icu::RuleBasedBreakIterator* ruleBasedBreakIterator = static_cast<icu::RuleB
asedBreakIterator*>(iterator); | 730 icu::RuleBasedBreakIterator* ruleBasedBreakIterator = static_cast<icu::RuleB
asedBreakIterator*>(iterator); |
| 731 int ruleStatus = ruleBasedBreakIterator->getRuleStatus(); | 731 int ruleStatus = ruleBasedBreakIterator->getRuleStatus(); |
| 732 return ruleStatus != UBRK_WORD_NONE; | 732 return ruleStatus != UBRK_WORD_NONE; |
| 733 } | 733 } |
| 734 | 734 |
| 735 static TextBreakIterator* setUpIteratorWithRules(const char* breakRules, const U
Char* string, int length) | 735 static TextBreakIterator* setUpIteratorWithRules(const char* breakRules, const U
Char* string, int length) |
| 736 { | 736 { |
| 737 if (!string) | 737 if (!string) |
| 738 return 0; | 738 return 0; |
| 739 | 739 |
| 740 static TextBreakIterator* iterator = 0; | 740 static TextBreakIterator* iterator = 0; |
| 741 if (!iterator) { | 741 if (!iterator) { |
| 742 UParseError parseStatus; | 742 UParseError parseStatus; |
| 743 UErrorCode openStatus = U_ZERO_ERROR; | 743 UErrorCode openStatus = U_ZERO_ERROR; |
| 744 Vector<UChar> rules; | 744 Vector<UChar> rules; |
| 745 String(breakRules).appendTo(rules); | 745 String(breakRules).appendTo(rules); |
| 746 | 746 |
| 747 iterator = new icu::RuleBasedBreakIterator(icu::UnicodeString(rules.data
(), rules.size()), parseStatus, openStatus); | 747 iterator = new icu::RuleBasedBreakIterator(icu::UnicodeString(rules.data
(), rules.size()), parseStatus, openStatus); |
| 748 ASSERT_WITH_MESSAGE(U_SUCCESS(openStatus), "ICU could not open a break i
terator: %s (%d)", u_errorName(openStatus), openStatus); | 748 DCHECK(U_SUCCESS(openStatus)) << "ICU could not open a break iterator: "
<< u_errorName(openStatus) << " (" << openStatus << ")"; |
| 749 if (!iterator) | 749 if (!iterator) |
| 750 return 0; | 750 return 0; |
| 751 } | 751 } |
| 752 | 752 |
| 753 setText16(iterator, string, length); | 753 setText16(iterator, string, length); |
| 754 return iterator; | 754 return iterator; |
| 755 } | 755 } |
| 756 | 756 |
| 757 TextBreakIterator* cursorMovementIterator(const UChar* string, int length) | 757 TextBreakIterator* cursorMovementIterator(const UChar* string, int length) |
| 758 { | 758 { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 "$Tel1 $TelV $Tel0;" // Telugu Virama (backward) | 836 "$Tel1 $TelV $Tel0;" // Telugu Virama (backward) |
| 837 "$Kan1 $KanV $Kan0;" // Kannada Virama (backward) | 837 "$Kan1 $KanV $Kan0;" // Kannada Virama (backward) |
| 838 "$Mal1 $MalV $Mal0;" // Malayalam Virama (backward) | 838 "$Mal1 $MalV $Mal0;" // Malayalam Virama (backward) |
| 839 "!!safe_reverse;" | 839 "!!safe_reverse;" |
| 840 "!!safe_forward;"; | 840 "!!safe_forward;"; |
| 841 | 841 |
| 842 return setUpIteratorWithRules(kRules, string, length); | 842 return setUpIteratorWithRules(kRules, string, length); |
| 843 } | 843 } |
| 844 | 844 |
| 845 } // namespace blink | 845 } // namespace blink |
| OLD | NEW |