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 { | |
75 // The end of text that the iterator recognizes as word characters. | |
76 IS_WORD_BREAK, | |
77 // Characters that the iterator can skip past, such as punctuation, | |
78 // whitespace, and characters from another character set. | |
79 IS_SKIPPABLE_WORD, | |
80 // Only used if not in BREAK_WORD or RULE_BASED mode. | |
please use gerrit instead
2015/08/07 20:53:10
What does returning this value mean? It's nice to
Julius
2015/08/10 16:06:37
Done.
| |
81 IS_NOT_WORD_BREAK | |
82 }; | |
83 | |
74 // Requires |str| to live as long as the BreakIterator does. | 84 // Requires |str| to live as long as the BreakIterator does. |
75 BreakIterator(const StringPiece16& str, BreakType break_type); | 85 BreakIterator(const StringPiece16& str, BreakType break_type); |
76 // Make a rule-based iterator. BreakType == RULE_BASED is implied. | 86 // Make a rule-based iterator. BreakType == RULE_BASED is implied. |
77 // TODO(andrewhayden): This signature could easily be misinterpreted as | 87 // TODO(andrewhayden): This signature could easily be misinterpreted as |
78 // "(const string16& str, const string16& locale)". We should do something | 88 // "(const string16& str, const string16& locale)". We should do something |
79 // better. | 89 // better. |
80 BreakIterator(const StringPiece16& str, const string16& rules); | 90 BreakIterator(const StringPiece16& str, const string16& rules); |
81 ~BreakIterator(); | 91 ~BreakIterator(); |
82 | 92 |
83 // Init() must be called before any of the iterators are valid. | 93 // Init() must be called before any of the iterators are valid. |
(...skipping 10 matching lines...) Expand all Loading... | |
94 // if Init() had been called again. Any old state is lost. Returns true | 104 // if Init() had been called again. Any old state is lost. Returns true |
95 // unless there is an error setting the text. | 105 // unless there is an error setting the text. |
96 bool SetText(const base::char16* text, const size_t length); | 106 bool SetText(const base::char16* text, const size_t length); |
97 | 107 |
98 // Under BREAK_WORD mode, returns true if the break we just hit is the | 108 // 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. | 109 // end of a word. (Otherwise, the break iterator just skipped over e.g. |
100 // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes, | 110 // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes, |
101 // this distinction doesn't apply and it always returns false. | 111 // this distinction doesn't apply and it always returns false. |
102 bool IsWord() const; | 112 bool IsWord() const; |
103 | 113 |
114 // Under BREAK_WORD mode, returns IS_WORD_BREAK if the break we just hit is | |
115 // the end of a word. Under BREAK_LINE and BREAK_NEWLINE modes, this | |
116 // distinction doesn't apply and it returns IS_NOT_WORD_BREAK. Otherwise, the | |
please use gerrit instead
2015/08/07 20:53:10
This "Otherwise" is confusing. Please be explicit
Julius
2015/08/10 16:06:37
Done.
| |
117 // iterator found skippable characters and it returns IS_SKIPPABLE_WORD. | |
118 BreakIterator::WordBreakStatus IsWordBreak() const; | |
119 | |
104 // Under BREAK_WORD mode, returns true if |position| is at the end of word or | 120 // 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 | 121 // at the start of word. It always returns false under BREAK_LINE and |
106 // BREAK_NEWLINE modes. | 122 // BREAK_NEWLINE modes. |
107 bool IsEndOfWord(size_t position) const; | 123 bool IsEndOfWord(size_t position) const; |
108 bool IsStartOfWord(size_t position) const; | 124 bool IsStartOfWord(size_t position) const; |
109 | 125 |
110 // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode | 126 // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode |
111 // grapheme boundary. | 127 // grapheme boundary. |
112 bool IsGraphemeBoundary(size_t position) const; | 128 bool IsGraphemeBoundary(size_t position) const; |
113 | 129 |
(...skipping 30 matching lines...) Expand all Loading... | |
144 // Previous and current iterator positions. | 160 // Previous and current iterator positions. |
145 size_t prev_, pos_; | 161 size_t prev_, pos_; |
146 | 162 |
147 DISALLOW_COPY_AND_ASSIGN(BreakIterator); | 163 DISALLOW_COPY_AND_ASSIGN(BreakIterator); |
148 }; | 164 }; |
149 | 165 |
150 } // namespace i18n | 166 } // namespace i18n |
151 } // namespace base | 167 } // namespace base |
152 | 168 |
153 #endif // BASE_I18N_BREAK_ITERATOR_H_ | 169 #endif // BASE_I18N_BREAK_ITERATOR_H_ |
OLD | NEW |