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 "unicode/ubrk.h" | 8 #include "unicode/ubrk.h" |
9 #include "unicode/uchar.h" | 9 #include "unicode/uchar.h" |
10 #include "unicode/ustring.h" | 10 #include "unicode/ustring.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 NOTREACHED() << "invalid break_type_"; | 85 NOTREACHED() << "invalid break_type_"; |
86 return false; | 86 return false; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 bool BreakIterator::IsWord() const { | 90 bool BreakIterator::IsWord() const { |
91 int32_t status = ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)); | 91 int32_t status = ubrk_getRuleStatus(static_cast<UBreakIterator*>(iter_)); |
92 return (break_type_ == BREAK_WORD && status != UBRK_WORD_NONE); | 92 return (break_type_ == BREAK_WORD && status != UBRK_WORD_NONE); |
93 } | 93 } |
94 | 94 |
| 95 bool BreakIterator::IsWordBreakAt(size_t position) { |
| 96 // TODO(msw): Improve break detection, handle other platforms and languages. |
| 97 UBreakIterator* iter = static_cast<UBreakIterator*>(iter_); |
| 98 UBool boundary = ubrk_isBoundary(iter, static_cast<int32_t>(position)); |
| 99 int32_t status = ubrk_getRuleStatus(iter); |
| 100 // Check the next word boundary type, but ignore the position. |
| 101 ubrk_next(iter); |
| 102 int32_t next_status = ubrk_getRuleStatus(iter); |
| 103 return (!!boundary && status == UBRK_WORD_NONE && |
| 104 next_status != UBRK_WORD_NONE); |
| 105 } |
| 106 |
95 string16 BreakIterator::GetString() const { | 107 string16 BreakIterator::GetString() const { |
96 DCHECK(prev_ != npos && pos_ != npos); | 108 DCHECK(prev_ != npos && pos_ != npos); |
97 return string_.substr(prev_, pos_ - prev_); | 109 return string_.substr(prev_, pos_ - prev_); |
98 } | 110 } |
99 | 111 |
100 } // namespace i18n | 112 } // namespace i18n |
101 } // namespace base | 113 } // namespace base |
OLD | NEW |