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

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: jungshik@ comments 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') | no next file with comments »
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 11 matching lines...) Expand all
106 // or BreakIterator::npos when done. 118 // or BreakIterator::npos when done.
107 size_t pos() const { return pos_; } 119 size_t pos() const { return pos_; }
108 120
109 private: 121 private:
110 // ICU iterator, avoiding ICU ubrk.h dependence. 122 // ICU iterator, avoiding ICU ubrk.h dependence.
111 // This is actually an ICU UBreakiterator* type, which turns out to be 123 // This is actually an ICU UBreakiterator* type, which turns out to be
112 // a typedef for a void* in the ICU headers. Using void* directly prevents 124 // a typedef for a void* in the ICU headers. Using void* directly prevents
113 // callers from needing access to the ICU public headers directory. 125 // callers from needing access to the ICU public headers directory.
114 void* iter_; 126 void* iter_;
115 127
116 // The string we're iterating over. 128 // The string we're iterating over. Can be changed with SetText(...)
117 const string16& string_; 129 const string16& string_;
118 130
119 // The breaking style (word/space/newline). 131 // Rules for our iterator. Mutually exclusive with break_type_.
132 const string16 rules_;
133
134 // The breaking style (word/space/newline). Mutually exclusive with rules_
120 BreakType break_type_; 135 BreakType break_type_;
121 136
122 // Previous and current iterator positions. 137 // Previous and current iterator positions.
123 size_t prev_, pos_; 138 size_t prev_, pos_;
124 139
125 DISALLOW_COPY_AND_ASSIGN(BreakIterator); 140 DISALLOW_COPY_AND_ASSIGN(BreakIterator);
126 }; 141 };
127 142
128 } // namespace i18n 143 } // namespace i18n
129 } // namespace base 144 } // namespace base
130 145
131 #endif // BASE_I18N_BREAK_ITERATOR_H_ 146 #endif // BASE_I18N_BREAK_ITERATOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/i18n/break_iterator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698