Chromium Code Reviews| 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 // Non-word characters are things like punctuation and spaces. | |
| 77 IS_WORD_BREAK, | |
| 78 // Characters that the iterator can skip past, such as punctuation, | |
| 79 // whitespace, and, if using RULE_BASED mode, characters from another | |
| 80 // character set. | |
| 81 IS_SKIPPABLE_WORD, | |
| 82 // Only used if not in BREAK_WORD or RULE_BASED mode. This is returned for | |
| 83 // newlines, line breaks, and character breaks. | |
| 84 IS_LINE_OR_CHAR_BREAK | |
| 85 }; | |
| 86 | |
| 74 // Requires |str| to live as long as the BreakIterator does. | 87 // Requires |str| to live as long as the BreakIterator does. |
| 75 BreakIterator(const StringPiece16& str, BreakType break_type); | 88 BreakIterator(const StringPiece16& str, BreakType break_type); |
| 76 // Make a rule-based iterator. BreakType == RULE_BASED is implied. | 89 // Make a rule-based iterator. BreakType == RULE_BASED is implied. |
| 77 // TODO(andrewhayden): This signature could easily be misinterpreted as | 90 // TODO(andrewhayden): This signature could easily be misinterpreted as |
| 78 // "(const string16& str, const string16& locale)". We should do something | 91 // "(const string16& str, const string16& locale)". We should do something |
| 79 // better. | 92 // better. |
| 80 BreakIterator(const StringPiece16& str, const string16& rules); | 93 BreakIterator(const StringPiece16& str, const string16& rules); |
| 81 ~BreakIterator(); | 94 ~BreakIterator(); |
| 82 | 95 |
| 83 // Init() must be called before any of the iterators are valid. | 96 // 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 | 107 // if Init() had been called again. Any old state is lost. Returns true |
| 95 // unless there is an error setting the text. | 108 // unless there is an error setting the text. |
| 96 bool SetText(const base::char16* text, const size_t length); | 109 bool SetText(const base::char16* text, const size_t length); |
| 97 | 110 |
| 98 // Under BREAK_WORD mode, returns true if the break we just hit is the | 111 // 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. | 112 // end of a word. (Otherwise, the break iterator just skipped over e.g. |
| 100 // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes, | 113 // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes, |
| 101 // this distinction doesn't apply and it always returns false. | 114 // this distinction doesn't apply and it always returns false. |
| 102 bool IsWord() const; | 115 bool IsWord() const; |
| 103 | 116 |
| 117 // Under BREAK_WORD mode, returns IS_WORD_BREAK if the break we just hit is | |
| 118 // the end of a string of word characters. IS_SKIPPABLE_WORD is returned if | |
|
please use gerrit instead
2015/08/10 17:24:42
|string| is an overloaded term. Say "sequence", if
Julius
2015/08/10 18:56:19
Done.
| |
| 119 // punctuation, spaces, or, under RULE_BASED mode, characters outside the | |
| 120 // character set are found. If not under BREAK_WORD or RULE_BASED modes, this | |
| 121 // always returns IS_LINE_OR_CHAR_BREAK. | |
| 122 BreakIterator::WordBreakStatus IsWordBreak() const; | |
|
please use gerrit instead
2015/08/10 17:24:42
I think IsSomething() is best for functions that r
Julius
2015/08/10 18:56:19
Done.
| |
| 123 | |
| 104 // Under BREAK_WORD mode, returns true if |position| is at the end of word or | 124 // 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 | 125 // at the start of word. It always returns false under BREAK_LINE and |
| 106 // BREAK_NEWLINE modes. | 126 // BREAK_NEWLINE modes. |
| 107 bool IsEndOfWord(size_t position) const; | 127 bool IsEndOfWord(size_t position) const; |
| 108 bool IsStartOfWord(size_t position) const; | 128 bool IsStartOfWord(size_t position) const; |
| 109 | 129 |
| 110 // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode | 130 // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode |
| 111 // grapheme boundary. | 131 // grapheme boundary. |
| 112 bool IsGraphemeBoundary(size_t position) const; | 132 bool IsGraphemeBoundary(size_t position) const; |
| 113 | 133 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 144 // Previous and current iterator positions. | 164 // Previous and current iterator positions. |
| 145 size_t prev_, pos_; | 165 size_t prev_, pos_; |
| 146 | 166 |
| 147 DISALLOW_COPY_AND_ASSIGN(BreakIterator); | 167 DISALLOW_COPY_AND_ASSIGN(BreakIterator); |
| 148 }; | 168 }; |
| 149 | 169 |
| 150 } // namespace i18n | 170 } // namespace i18n |
| 151 } // namespace base | 171 } // namespace base |
| 152 | 172 |
| 153 #endif // BASE_I18N_BREAK_ITERATOR_H_ | 173 #endif // BASE_I18N_BREAK_ITERATOR_H_ |
| OLD | NEW |