Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: base/i18n/break_iterator.h

Issue 1272683002: Creates BreakIterator::GetWordBreakStatus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated Khmer tests and ASCII-fied comments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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:
118 // - Returns IS_SKIPPABLE_WORD if non-word characters, such as punctuation or
119 // spaces, are found.
120 // - Returns IS_WORD_BREAK if the break we just hit is the end of a sequence
121 // of word characters.
122 // Under RULE_BASED mode:
123 // - Returns IS_SKIPPABLE_WORD if characters outside the rules' character set
124 // or non-word characters, such as punctuation or spaces, are found.
125 // - Returns IS_WORD_BREAK if the break we just hit is the end of a sequence
126 // of word characters that are in the rules' character set.
127 // Not under BREAK_WORD or RULE_BASED mode:
128 // - Returns IS_LINE_OR_CHAR_BREAK.
129 BreakIterator::WordBreakStatus GetWordBreakStatus() const;
130
104 // Under BREAK_WORD mode, returns true if |position| is at the end of word or 131 // 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 132 // at the start of word. It always returns false under BREAK_LINE and
106 // BREAK_NEWLINE modes. 133 // BREAK_NEWLINE modes.
107 bool IsEndOfWord(size_t position) const; 134 bool IsEndOfWord(size_t position) const;
108 bool IsStartOfWord(size_t position) const; 135 bool IsStartOfWord(size_t position) const;
109 136
110 // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode 137 // Under BREAK_CHARACTER mode, returns whether |position| is a Unicode
111 // grapheme boundary. 138 // grapheme boundary.
112 bool IsGraphemeBoundary(size_t position) const; 139 bool IsGraphemeBoundary(size_t position) const;
113 140
(...skipping 30 matching lines...) Expand all
144 // Previous and current iterator positions. 171 // Previous and current iterator positions.
145 size_t prev_, pos_; 172 size_t prev_, pos_;
146 173
147 DISALLOW_COPY_AND_ASSIGN(BreakIterator); 174 DISALLOW_COPY_AND_ASSIGN(BreakIterator);
148 }; 175 };
149 176
150 } // namespace i18n 177 } // namespace i18n
151 } // namespace base 178 } // namespace base
152 179
153 #endif // BASE_I18N_BREAK_ITERATOR_H_ 180 #endif // BASE_I18N_BREAK_ITERATOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/i18n/break_iterator.cc » ('j') | chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698