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 #ifndef BASE_I18N_BREAK_ITERATOR_H_ | 5 #ifndef BASE_I18N_BREAK_ITERATOR_H_ |
6 #define BASE_I18N_BREAK_ITERATOR_H_ | 6 #define BASE_I18N_BREAK_ITERATOR_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/i18n/base_i18n_export.h" | 9 #include "base/i18n/base_i18n_export.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 // TODO(jshin): Remove this after reviewing call sites. | 64 // TODO(jshin): Remove this after reviewing call sites. |
65 // If call sites really need break only on space-like characters | 65 // If call sites really need break only on space-like characters |
66 // implement it separately. | 66 // implement it separately. |
67 BREAK_SPACE = BREAK_LINE, | 67 BREAK_SPACE = BREAK_LINE, |
68 BREAK_NEWLINE, | 68 BREAK_NEWLINE, |
69 BREAK_CHARACTER, | 69 BREAK_CHARACTER, |
70 // But don't remove this one! | 70 // But don't remove this one! |
71 RULE_BASED, | 71 RULE_BASED, |
72 }; | 72 }; |
73 | 73 |
74 enum WordBreakStatus { IS_WORD_BREAK, IS_SKIPPABLE_WORD, IS_NOT_WORD_BREAK }; | |
75 | |
74 // Requires |str| to live as long as the BreakIterator does. | 76 // Requires |str| to live as long as the BreakIterator does. |
75 BreakIterator(const StringPiece16& str, BreakType break_type); | 77 BreakIterator(const StringPiece16& str, BreakType break_type); |
76 // Make a rule-based iterator. BreakType == RULE_BASED is implied. | 78 // Make a rule-based iterator. BreakType == RULE_BASED is implied. |
77 // TODO(andrewhayden): This signature could easily be misinterpreted as | 79 // TODO(andrewhayden): This signature could easily be misinterpreted as |
78 // "(const string16& str, const string16& locale)". We should do something | 80 // "(const string16& str, const string16& locale)". We should do something |
79 // better. | 81 // better. |
80 BreakIterator(const StringPiece16& str, const string16& rules); | 82 BreakIterator(const StringPiece16& str, const string16& rules); |
81 ~BreakIterator(); | 83 ~BreakIterator(); |
82 | 84 |
83 // Init() must be called before any of the iterators are valid. | 85 // Init() must be called before any of the iterators are valid. |
84 // Returns false if ICU failed to initialize. | 86 // Returns false if ICU failed to initialize. |
85 bool Init(); | 87 bool Init(); |
86 | 88 |
87 // Advance to the next break. Returns false if we've run past the end of | 89 // Advance to the next break. Returns false if we've run past the end of |
88 // the string. (Note that the very last "break" is after the final | 90 // the string. (Note that the very last "break" is after the final |
89 // character in the string, and when we advance to that position it's the | 91 // character in the string, and when we advance to that position it's the |
90 // last time Advance() returns true.) | 92 // last time Advance() returns true.) |
91 bool Advance(); | 93 bool Advance(); |
92 | 94 |
93 // Updates the text used by the iterator, resetting the iterator as if | 95 // Updates the text used by the iterator, resetting the iterator as if |
94 // if Init() had been called again. Any old state is lost. Returns true | 96 // if Init() had been called again. Any old state is lost. Returns true |
95 // unless there is an error setting the text. | 97 // unless there is an error setting the text. |
96 bool SetText(const base::char16* text, const size_t length); | 98 bool SetText(const base::char16* text, const size_t length); |
97 | 99 |
100 | |
Matt Giuca
2015/08/06 00:32:15
nit: No extra blank line.
Julius
2015/08/06 20:43:54
Done.
| |
98 // Under BREAK_WORD mode, returns true if the break we just hit is the | 101 // Under BREAK_WORD mode, returns true if the break we just hit is the |
99 // end of a word. (Otherwise, the break iterator just skipped over e.g. | 102 // end of a word. (Otherwise, the break iterator just skipped over e.g. |
100 // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes, | 103 // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes, |
101 // this distinction doesn't apply and it always returns false. | 104 // this distinction doesn't apply and it always returns false. |
102 bool IsWord() const; | 105 bool IsWord() const; |
103 | 106 |
107 // Under BREAK_WORD mode, returns IS_WORD_BREAK if the break we just hit is | |
108 // the end of a word. Under BREAK_LINE and BREAK_NEWLINE modes, this | |
109 // distinction doesn't apply and it always returns IS_NOT_WORD_BREAK. | |
110 // Otherwise, the iterator just skipped over e.g. whitespace, punctuation, or | |
111 // unknown characters and returns IS_SKIPPABLE_WORD. | |
112 BreakIterator::WordBreakStatus IsWordBreak() const; | |
113 | |
104 // Under BREAK_WORD mode, returns true if |position| is at the end of word or | 114 // Under BREAK_WORD mode, returns true if |position| is at the end of word or |
105 // at the start of word. It always returns false under BREAK_LINE and | 115 // at the start of word. It always returns false under BREAK_LINE and |
106 // BREAK_NEWLINE modes. | 116 // BREAK_NEWLINE modes. |
107 bool IsEndOfWord(size_t position) const; | 117 bool IsEndOfWord(size_t position) const; |
108 bool IsStartOfWord(size_t position) const; | 118 bool IsStartOfWord(size_t position) const; |
109 | 119 |
110 // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode | 120 // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode |
111 // grapheme boundary. | 121 // grapheme boundary. |
112 bool IsGraphemeBoundary(size_t position) const; | 122 bool IsGraphemeBoundary(size_t position) const; |
113 | 123 |
(...skipping 30 matching lines...) Expand all Loading... | |
144 // Previous and current iterator positions. | 154 // Previous and current iterator positions. |
145 size_t prev_, pos_; | 155 size_t prev_, pos_; |
146 | 156 |
147 DISALLOW_COPY_AND_ASSIGN(BreakIterator); | 157 DISALLOW_COPY_AND_ASSIGN(BreakIterator); |
148 }; | 158 }; |
149 | 159 |
150 } // namespace i18n | 160 } // namespace i18n |
151 } // namespace base | 161 } // namespace base |
152 | 162 |
153 #endif // BASE_I18N_BREAK_ITERATOR_H_ | 163 #endif // BASE_I18N_BREAK_ITERATOR_H_ |
OLD | NEW |