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 int32_t status = ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)); | 141 return IsWordBreak() == IS_WORD_BREAK; |
142 } | |
143 | |
144 BreakIterator::WordBreakStatus BreakIterator::IsWordBreak() const { | |
142 if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) | 145 if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) |
143 return false; | 146 return IS_NOT_WORD_BREAK; |
please use gerrit instead
2015/08/07 20:53:10
Call ubrk_getRuleStatus() before the if statement.
Julius
2015/08/10 16:06:37
Done.
| |
144 return status != UBRK_WORD_NONE; | 147 return ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)) == |
148 UBRK_WORD_NONE | |
149 ? IS_SKIPPABLE_WORD | |
150 : IS_WORD_BREAK; | |
145 } | 151 } |
146 | 152 |
147 bool BreakIterator::IsEndOfWord(size_t position) const { | 153 bool BreakIterator::IsEndOfWord(size_t position) const { |
148 if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) | 154 if (break_type_ != BREAK_WORD && break_type_ != RULE_BASED) |
149 return false; | 155 return false; |
150 | 156 |
151 UBreakIterator* iter = static_cast<UBreakIterator*>(iter_); | 157 UBreakIterator* iter = static_cast<UBreakIterator*>(iter_); |
152 UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position)); | 158 UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position)); |
153 int32_t status = ubrk_getRuleStatus(iter); | 159 int32_t status = ubrk_getRuleStatus(iter); |
154 return (!!boundary && status != UBRK_WORD_NONE); | 160 return (!!boundary && status != UBRK_WORD_NONE); |
(...skipping 22 matching lines...) Expand all Loading... | |
177 return GetStringPiece().as_string(); | 183 return GetStringPiece().as_string(); |
178 } | 184 } |
179 | 185 |
180 StringPiece16 BreakIterator::GetStringPiece() const { | 186 StringPiece16 BreakIterator::GetStringPiece() const { |
181 DCHECK(prev_ != npos && pos_ != npos); | 187 DCHECK(prev_ != npos && pos_ != npos); |
182 return string_.substr(prev_, pos_ - prev_); | 188 return string_.substr(prev_, pos_ - prev_); |
183 } | 189 } |
184 | 190 |
185 } // namespace i18n | 191 } // namespace i18n |
186 } // namespace base | 192 } // namespace base |
OLD | NEW |