| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/i18n/break_iterator.h" | 5 #include "base/i18n/break_iterator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/icu/source/common/unicode/ubrk.h" | 8 #include "third_party/icu/source/common/unicode/ubrk.h" |
| 9 #include "third_party/icu/source/common/unicode/uchar.h" | 9 #include "third_party/icu/source/common/unicode/uchar.h" |
| 10 #include "third_party/icu/source/common/unicode/ustring.h" | 10 #include "third_party/icu/source/common/unicode/ustring.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 prev_ = npos; | 131 prev_ = npos; |
| 132 if (U_FAILURE(status)) { | 132 if (U_FAILURE(status)) { |
| 133 NOTREACHED() << "ubrk_setText failed"; | 133 NOTREACHED() << "ubrk_setText failed"; |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 string_ = StringPiece16(text, length); | 136 string_ = StringPiece16(text, length); |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool BreakIterator::IsWord() const { | 140 bool BreakIterator::IsWord() const { |
| 141 return GetWordBreakStatus() == IS_WORD_BREAK; |
| 142 } |
| 143 |
| 144 BreakIterator::WordBreakStatus BreakIterator::GetWordBreakStatus() const { |
| 141 int32_t status = ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)); | 145 int32_t status = ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)); |
| 142 if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) | 146 if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) |
| 143 return false; | 147 return IS_LINE_OR_CHAR_BREAK; |
| 144 return status != UBRK_WORD_NONE; | 148 return status == UBRK_WORD_NONE ? IS_SKIPPABLE_WORD : IS_WORD_BREAK; |
| 145 } | 149 } |
| 146 | 150 |
| 147 bool BreakIterator::IsEndOfWord(size_t position) const { | 151 bool BreakIterator::IsEndOfWord(size_t position) const { |
| 148 if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) | 152 if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) |
| 149 return false; | 153 return false; |
| 150 | 154 |
| 151 UBreakIterator* iter = static_cast<UBreakIterator*>(iter_); | 155 UBreakIterator* iter = static_cast<UBreakIterator*>(iter_); |
| 152 UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position)); | 156 UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position)); |
| 153 int32_t status = ubrk_getRuleStatus(iter); | 157 int32_t status = ubrk_getRuleStatus(iter); |
| 154 return (!!boundary && status != UBRK_WORD_NONE); | 158 return (!!boundary && status != UBRK_WORD_NONE); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 177 return GetStringPiece().as_string(); | 181 return GetStringPiece().as_string(); |
| 178 } | 182 } |
| 179 | 183 |
| 180 StringPiece16 BreakIterator::GetStringPiece() const { | 184 StringPiece16 BreakIterator::GetStringPiece() const { |
| 181 DCHECK(prev_ != npos && pos_ != npos); | 185 DCHECK(prev_ != npos && pos_ != npos); |
| 182 return string_.substr(prev_, pos_ - prev_); | 186 return string_.substr(prev_, pos_ - prev_); |
| 183 } | 187 } |
| 184 | 188 |
| 185 } // namespace i18n | 189 } // namespace i18n |
| 186 } // namespace base | 190 } // namespace base |
| OLD | NEW |