OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__ | 5 #ifndef CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__ |
6 #define CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__ | 6 #define CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/string16.h" |
12 | 13 |
13 #include "unicode/uscript.h" | 14 #include "unicode/uscript.h" |
14 | 15 |
15 // A class which handles character attributes dependent on a spellchecker and | 16 // A class which handles character attributes dependent on a spellchecker and |
16 // its dictionary. | 17 // its dictionary. |
17 // This class is used by the SpellcheckWordIterator class to determine whether | 18 // This class is used by the SpellcheckWordIterator class to determine whether |
18 // or not a character is one used by the spellchecker and its dictinary. | 19 // or not a character is one used by the spellchecker and its dictinary. |
19 class SpellcheckCharAttribute { | 20 class SpellcheckCharAttribute { |
20 public: | 21 public: |
21 SpellcheckCharAttribute(); | 22 SpellcheckCharAttribute(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 public: | 87 public: |
87 SpellcheckWordIterator(); | 88 SpellcheckWordIterator(); |
88 | 89 |
89 ~SpellcheckWordIterator(); | 90 ~SpellcheckWordIterator(); |
90 | 91 |
91 // Initializes a word-iterator object. | 92 // Initializes a word-iterator object. |
92 // Parameters | 93 // Parameters |
93 // * attribute [in] (const SpellcheckCharAttribute*) | 94 // * attribute [in] (const SpellcheckCharAttribute*) |
94 // Represents a set of character attributes used for filtering out | 95 // Represents a set of character attributes used for filtering out |
95 // non-word characters. | 96 // non-word characters. |
96 // * word [in] (const wchar_t*) | 97 // * word [in] (const char16*) |
97 // Represents a string from which this object extracts words. | 98 // Represents a string from which this object extracts words. |
98 // (This string does not have to be NUL-terminated.) | 99 // (This string does not have to be NUL-terminated.) |
99 // * length [in] (size_t) | 100 // * length [in] (size_t) |
100 // Represents the length of the given string, in UTF-16 characters. | 101 // Represents the length of the given string, in UTF-16 characters. |
101 // This value should not include terminating NUL characters. | 102 // This value should not include terminating NUL characters. |
102 // * allow_contraction [in] (bool) | 103 // * allow_contraction [in] (bool) |
103 // Represents a flag to control whether or not this object should split a | 104 // Represents a flag to control whether or not this object should split a |
104 // possible contraction (e.g. "isn't", "in'n'out", etc.) | 105 // possible contraction (e.g. "isn't", "in'n'out", etc.) |
105 // Return values | 106 // Return values |
106 // * true | 107 // * true |
107 // This word-iterator object is initialized successfully. | 108 // This word-iterator object is initialized successfully. |
108 // * false | 109 // * false |
109 // An error occured while initializing this object. | 110 // An error occured while initializing this object. |
110 void Initialize(const SpellcheckCharAttribute* attribute, | 111 void Initialize(const SpellcheckCharAttribute* attribute, |
111 const wchar_t* word, | 112 const char16* word, |
112 size_t length, | 113 size_t length, |
113 bool allow_contraction); | 114 bool allow_contraction); |
114 | 115 |
115 // Retrieves a word (or a contraction). | 116 // Retrieves a word (or a contraction). |
116 // Parameters | 117 // Parameters |
117 // * word_string [out] (std::wstring*) | 118 // * word_string [out] (string16*) |
118 // Represents a word (or a contraction) to be checked its spelling. | 119 // Represents a word (or a contraction) to be checked its spelling. |
119 // This |word_string| has been already normalized to its canonical form | 120 // This |word_string| has been already normalized to its canonical form |
120 // (i.e. decomposed ligatures, replaced full-width latin characters to | 121 // (i.e. decomposed ligatures, replaced full-width latin characters to |
121 // its ASCII alternatives, etc.) so that a SpellChecker object can check | 122 // its ASCII alternatives, etc.) so that a SpellChecker object can check |
122 // its spelling without any additional operations. | 123 // its spelling without any additional operations. |
123 // On the other hand, a substring of the input string | 124 // On the other hand, a substring of the input string |
124 // std::wstring str(&word[word_start], word_length); | 125 // string16 str(&word[word_start], word_length); |
125 // represents the non-normalized version of this extracted word. | 126 // represents the non-normalized version of this extracted word. |
126 // * word_start [out] (int*) | 127 // * word_start [out] (int*) |
127 // Represents the offset of this word from the beginning of the input | 128 // Represents the offset of this word from the beginning of the input |
128 // string, in UTF-16 characters. | 129 // string, in UTF-16 characters. |
129 // * word_length [out] (int*) | 130 // * word_length [out] (int*) |
130 // Represents the length of an extracted word before normalization, in | 131 // Represents the length of an extracted word before normalization, in |
131 // UTF-16 characters. | 132 // UTF-16 characters. |
132 // When the input string contains ligatures, this value may not be equal | 133 // When the input string contains ligatures, this value may not be equal |
133 // to the length of the |word_string|. | 134 // to the length of the |word_string|. |
134 // Return values | 135 // Return values |
135 // * true | 136 // * true |
136 // Found a word (or a contraction) to be checked its spelling. | 137 // Found a word (or a contraction) to be checked its spelling. |
137 // * false | 138 // * false |
138 // Not found any more words or contractions to be checked their spellings. | 139 // Not found any more words or contractions to be checked their spellings. |
139 bool GetNextWord(std::wstring* word_string, | 140 bool GetNextWord(string16* word_string, |
140 int* word_start, | 141 int* word_start, |
141 int* word_length); | 142 int* word_length); |
142 | 143 |
143 private: | 144 private: |
144 // Retrieves a segment consisting of word characters (and contraction | 145 // Retrieves a segment consisting of word characters (and contraction |
145 // characters if the |allow_contraction| value is true). | 146 // characters if the |allow_contraction| value is true). |
146 void GetSegment(int* segment_start, | 147 void GetSegment(int* segment_start, |
147 int* segment_end); | 148 int* segment_end); |
148 | 149 |
149 // Discards non-word characters at the beginning and the end of the given | 150 // Discards non-word characters at the beginning and the end of the given |
150 // segment. | 151 // segment. |
151 void TrimSegment(int segment_start, | 152 void TrimSegment(int segment_start, |
152 int segment_end, | 153 int segment_end, |
153 int* word_start, | 154 int* word_start, |
154 int* word_length) const; | 155 int* word_length) const; |
155 | 156 |
156 // Normalizes the given segment of the |word_| variable and write its | 157 // Normalizes the given segment of the |word_| variable and write its |
157 // canonical form to the |output_string|. | 158 // canonical form to the |output_string|. |
158 bool Normalize(int input_start, | 159 bool Normalize(int input_start, |
159 int input_length, | 160 int input_length, |
160 std::wstring* output_string) const; | 161 string16* output_string) const; |
161 | 162 |
162 private: | 163 private: |
163 // The pointer to the input string from which we are extracting words. | 164 // The pointer to the input string from which we are extracting words. |
164 const wchar_t* word_; | 165 const char16* word_; |
165 | 166 |
166 // The length of the original string. | 167 // The length of the original string. |
167 int length_; | 168 int length_; |
168 | 169 |
169 // The current position in the original string. | 170 // The current position in the original string. |
170 int position_; | 171 int position_; |
171 | 172 |
172 // The flag to control whether or not this object should extract possible | 173 // The flag to control whether or not this object should extract possible |
173 // contractions. | 174 // contractions. |
174 bool allow_contraction_; | 175 bool allow_contraction_; |
175 | 176 |
176 // The character attributes used for filtering out non-word characters. | 177 // The character attributes used for filtering out non-word characters. |
177 const SpellcheckCharAttribute* attribute_; | 178 const SpellcheckCharAttribute* attribute_; |
178 | 179 |
179 DISALLOW_EVIL_CONSTRUCTORS(SpellcheckWordIterator); | 180 DISALLOW_EVIL_CONSTRUCTORS(SpellcheckWordIterator); |
180 }; | 181 }; |
181 | 182 |
182 #endif // CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__ | 183 #endif // CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__ |
183 | 184 |
OLD | NEW |