OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_WORD_ITERATOR_H_ | 5 #ifndef BASE_I18N_WORD_ITERATOR_H_ |
6 #define BASE_I18N_WORD_ITERATOR_H_ | 6 #define BASE_I18N_WORD_ITERATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "unicode/ubrk.h" | 11 #include "unicode/ubrk.h" |
12 #include "unicode/uchar.h" | 12 #include "unicode/uchar.h" |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 | 16 |
17 // The WordIterator class iterates through the words and word breaks | 17 // The WordIterator class iterates through the words and word breaks |
18 // in a string. (In the string " foo bar! ", the word breaks are at the | 18 // in a string. (In the string " foo bar! ", the word breaks are at the |
19 // periods in ". .foo. .bar.!. .".) | 19 // periods in ". .foo. .bar.!. .".) |
20 // | 20 // |
21 // To extract the words from a string, move a WordIterator through the | 21 // To extract the words from a string, move a WordIterator through the |
22 // string and test whether IsWord() is true. E.g., | 22 // string and test whether IsWord() is true. E.g., |
23 // WordIterator iter(&str, WordIterator::BREAK_WORD); | 23 // WordIterator iter(&str, WordIterator::BREAK_WORD); |
24 // if (!iter.Init()) return false; | 24 // if (!iter.Init()) return false; |
25 // while (iter.Advance()) { | 25 // while (iter.Advance()) { |
26 // if (iter.IsWord()) { | 26 // if (iter.IsWord()) { |
27 // // region [iter.prev(),iter.pos()) contains a word. | 27 // // region [iter.prev(),iter.pos()) contains a word. |
28 // LOG(INFO) << "word: " << iter.GetWord(); | 28 // VLOG(1) << "word: " << iter.GetWord(); |
29 // } | 29 // } |
30 // } | 30 // } |
31 | 31 |
32 | 32 |
33 class WordIterator { | 33 class WordIterator { |
34 public: | 34 public: |
35 enum BreakType { | 35 enum BreakType { |
36 BREAK_WORD, | 36 BREAK_WORD, |
37 BREAK_LINE | 37 BREAK_LINE |
38 }; | 38 }; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // The breaking style (word/line). | 80 // The breaking style (word/line). |
81 BreakType break_type_; | 81 BreakType break_type_; |
82 | 82 |
83 // Previous and current iterator positions. | 83 // Previous and current iterator positions. |
84 size_t prev_, pos_; | 84 size_t prev_, pos_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(WordIterator); | 86 DISALLOW_COPY_AND_ASSIGN(WordIterator); |
87 }; | 87 }; |
88 | 88 |
89 #endif // BASE_I18N_WORD_ITERATOR_H__ | 89 #endif // BASE_I18N_WORD_ITERATOR_H__ |
OLD | NEW |