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

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

Issue 270203003: Refactor code to avoid direct dependency upon ICU: spellcheck_worditerator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactoring_icu_usage
Patch Set: Simplify Created 6 years, 7 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
« no previous file with comments | « no previous file | base/i18n/break_iterator.cc » ('j') | base/i18n/break_iterator.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 public: 59 public:
60 enum BreakType { 60 enum BreakType {
61 BREAK_WORD, 61 BREAK_WORD,
62 BREAK_LINE, 62 BREAK_LINE,
63 // TODO(jshin): Remove this after reviewing call sites. 63 // TODO(jshin): Remove this after reviewing call sites.
64 // If call sites really need break only on space-like characters 64 // If call sites really need break only on space-like characters
65 // implement it separately. 65 // implement it separately.
66 BREAK_SPACE = BREAK_LINE, 66 BREAK_SPACE = BREAK_LINE,
67 BREAK_NEWLINE, 67 BREAK_NEWLINE,
68 BREAK_CHARACTER, 68 BREAK_CHARACTER,
69 // But don't remove this one!
70 RULE_BASED,
69 }; 71 };
70 72
71 // Requires |str| to live as long as the BreakIterator does. 73 // Requires |str| to live as long as the BreakIterator does.
72 BreakIterator(const string16& str, BreakType break_type); 74 BreakIterator(const string16& str, BreakType break_type);
75 // Make a rule-based iterator. BreakType == RULE_BASED is implied.
76 // TODO(andrewhayden): This signature could easily be misinterpreted as
77 // "(const string16& str, const string16& locale)". We should do something
78 // better.
79 BreakIterator(const string16& str, const string16& rules);
73 ~BreakIterator(); 80 ~BreakIterator();
74 81
75 // Init() must be called before any of the iterators are valid. 82 // Init() must be called before any of the iterators are valid.
76 // Returns false if ICU failed to initialize. 83 // Returns false if ICU failed to initialize.
77 bool Init(); 84 bool Init();
78 85
79 // Advance to the next break. Returns false if we've run past the end of 86 // Advance to the next break. Returns false if we've run past the end of
80 // the string. (Note that the very last "break" is after the final 87 // the string. (Note that the very last "break" is after the final
81 // character in the string, and when we advance to that position it's the 88 // character in the string, and when we advance to that position it's the
82 // last time Advance() returns true.) 89 // last time Advance() returns true.)
83 bool Advance(); 90 bool Advance();
84 91
92 // Updates the text used by the iterator, resetting the iterator as if
93 // if Init() had been called again. Any old state is lost. Returns true
94 // unless there is an error setting the text.
95 bool SetText(const base::char16* text, const size_t length);
96
85 // Under BREAK_WORD mode, returns true if the break we just hit is the 97 // Under BREAK_WORD mode, returns true if the break we just hit is the
86 // end of a word. (Otherwise, the break iterator just skipped over e.g. 98 // end of a word. (Otherwise, the break iterator just skipped over e.g.
87 // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes, 99 // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes,
88 // this distinction doesn't apply and it always returns false. 100 // this distinction doesn't apply and it always returns false.
89 bool IsWord() const; 101 bool IsWord() const;
90 102
91 // Under BREAK_WORD mode, returns true if |position| is at the end of word or 103 // Under BREAK_WORD mode, returns true if |position| is at the end of word or
92 // at the start of word. It always returns false under BREAK_LINE and 104 // at the start of word. It always returns false under BREAK_LINE and
93 // BREAK_NEWLINE modes. 105 // BREAK_NEWLINE modes.
94 bool IsEndOfWord(size_t position) const; 106 bool IsEndOfWord(size_t position) const;
(...skipping 16 matching lines...) Expand all
111 return pos_ != static_cast<size_t>(-1); 123 return pos_ != static_cast<size_t>(-1);
112 } 124 }
113 125
114 private: 126 private:
115 // ICU iterator, avoiding ICU ubrk.h dependence. 127 // ICU iterator, avoiding ICU ubrk.h dependence.
116 // This is actually an ICU UBreakiterator* type, which turns out to be 128 // This is actually an ICU UBreakiterator* type, which turns out to be
117 // a typedef for a void* in the ICU headers. Using void* directly prevents 129 // a typedef for a void* in the ICU headers. Using void* directly prevents
118 // callers from needing access to the ICU public headers directory. 130 // callers from needing access to the ICU public headers directory.
119 void* iter_; 131 void* iter_;
120 132
121 // The string we're iterating over. 133 // The string we're iterating over. Can be changed with SetText(...)
122 const string16& string_; 134 const string16& string_;
123 135
124 // The breaking style (word/space/newline). 136 // Rules for our iterator. Mutually exclusive with break_type_.
137 const string16 rules_;
138
139 // The breaking style (word/space/newline). Mutually exclusive with rules_
125 BreakType break_type_; 140 BreakType break_type_;
126 141
127 // Previous and current iterator positions. 142 // Previous and current iterator positions.
128 size_t prev_, pos_; 143 size_t prev_, pos_;
129 144
130 DISALLOW_COPY_AND_ASSIGN(BreakIterator); 145 DISALLOW_COPY_AND_ASSIGN(BreakIterator);
131 }; 146 };
132 147
133 } // namespace i18n 148 } // namespace i18n
134 } // namespace base 149 } // namespace base
135 150
136 #endif // BASE_I18N_BREAK_ITERATOR_H_ 151 #endif // BASE_I18N_BREAK_ITERATOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/i18n/break_iterator.cc » ('j') | base/i18n/break_iterator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698