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

Side by Side Diff: chrome/tools/convert_dict/aff_reader.cc

Issue 3750001: base: Move SplitString functions into the base namespace and update the callers. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: brett review, reverted changes in o3d due to it's using an old base revision Created 10 years, 2 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 | « chrome/test/webdriver/dispatch.h ('k') | chrome_frame/chrome_frame_activex.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) 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 #include "chrome/tools/convert_dict/aff_reader.h" 5 #include "chrome/tools/convert_dict/aff_reader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/i18n/icu_string_conversions.h" 10 #include "base/i18n/icu_string_conversions.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 part = rule->substr(part_start); // From here to end. 214 part = rule->substr(part_start); // From here to end.
215 215
216 if (part.find('-') != std::string::npos) { 216 if (part.find('-') != std::string::npos) {
217 // This rule has a morph rule used by old Hungarian dictionaries. 217 // This rule has a morph rule used by old Hungarian dictionaries.
218 // When a line has a morph rule, its format becomes as listed below. 218 // When a line has a morph rule, its format becomes as listed below.
219 // AFX D 0 d e - M 219 // AFX D 0 d e - M
220 // To make hunspell work more happily, replace this morph rule with 220 // To make hunspell work more happily, replace this morph rule with
221 // a compound flag as listed below. 221 // a compound flag as listed below.
222 // AFX D 0 d/M e 222 // AFX D 0 d/M e
223 std::vector<std::string> tokens; 223 std::vector<std::string> tokens;
224 SplitString(part, ' ', &tokens); 224 base::SplitString(part, ' ', &tokens);
225 if (tokens.size() >= 5) { 225 if (tokens.size() >= 5) {
226 part = StringPrintf("%s %s/%s %s", 226 part = StringPrintf("%s %s/%s %s",
227 tokens[0].c_str(), 227 tokens[0].c_str(),
228 tokens[1].c_str(), tokens[4].c_str(), 228 tokens[1].c_str(), tokens[4].c_str(),
229 tokens[2].c_str()); 229 tokens[2].c_str());
230 } 230 }
231 } 231 }
232 232
233 size_t slash_index = part.find('/'); 233 size_t slash_index = part.find('/');
234 if (slash_index != std::string::npos && !has_indexed_affixes()) { 234 if (slash_index != std::string::npos && !has_indexed_affixes()) {
235 // This can also have a rule string associated with it following a 235 // This can also have a rule string associated with it following a
236 // slash. For example: 236 // slash. For example:
237 // PFX P 0 foo/Y . 237 // PFX P 0 foo/Y .
238 // The "Y" is a flag. For example, the aff file might have a line: 238 // The "Y" is a flag. For example, the aff file might have a line:
239 // COMPOUNDFLAG Y 239 // COMPOUNDFLAG Y
240 // so that means that this prefix would be a compound one. 240 // so that means that this prefix would be a compound one.
241 // 241 //
242 // It expects these rules to use the same alias rules as the .dic 242 // It expects these rules to use the same alias rules as the .dic
243 // file. We've forced it to use aliases, which is a numberical index 243 // file. We've forced it to use aliases, which is a numberical index
244 // instead of these character flags, and this needs to be consistent. 244 // instead of these character flags, and this needs to be consistent.
245 245
246 std::string before_flags = part.substr(0, slash_index + 1); 246 std::string before_flags = part.substr(0, slash_index + 1);
247 247
248 // After the slash are both the flags, then whitespace, then the part 248 // After the slash are both the flags, then whitespace, then the part
249 // that tells us what to strip. 249 // that tells us what to strip.
250 std::vector<std::string> after_slash; 250 std::vector<std::string> after_slash;
251 SplitString(part.substr(slash_index + 1), ' ', &after_slash); 251 base::SplitString(part.substr(slash_index + 1), ' ', &after_slash);
252 if (after_slash.size() < 2) { 252 if (after_slash.size() < 2) {
253 // Note that we may get a third term here which is the 253 // Note that we may get a third term here which is the
254 // morphological description of this rule. This happens in the tests 254 // morphological description of this rule. This happens in the tests
255 // only, so we can just ignore it. 255 // only, so we can just ignore it.
256 printf("ERROR: Didn't get enough after the slash\n"); 256 printf("ERROR: Didn't get enough after the slash\n");
257 return; 257 return;
258 } 258 }
259 259
260 part = StringPrintf("%s%d %s", before_flags.c_str(), 260 part = StringPrintf("%s%d %s", before_flags.c_str(),
261 GetAFIndexForAFString(after_slash[0]), 261 GetAFIndexForAFString(after_slash[0]),
(...skipping 18 matching lines...) Expand all
280 } 280 }
281 281
282 void AffReader::AddReplacement(std::string* rule) { 282 void AffReader::AddReplacement(std::string* rule) {
283 TrimLine(rule); 283 TrimLine(rule);
284 284
285 std::string utf8rule; 285 std::string utf8rule;
286 if (!EncodingToUTF8(*rule, &utf8rule)) 286 if (!EncodingToUTF8(*rule, &utf8rule))
287 return; 287 return;
288 288
289 std::vector<std::string> split; 289 std::vector<std::string> split;
290 SplitString(utf8rule, ' ', &split); 290 base::SplitString(utf8rule, ' ', &split);
291 291
292 // There should be two parts. 292 // There should be two parts.
293 if (split.size() != 2) 293 if (split.size() != 2)
294 return; 294 return;
295 295
296 // Underscores are used to represent spaces 296 // Underscores are used to represent spaces
297 // (since the line is parsed on spaces). 297 // (since the line is parsed on spaces).
298 std::replace(split[0].begin(), split[0].end(), '_', ' '); 298 std::replace(split[0].begin(), split[0].end(), '_', ' ');
299 std::replace(split[1].begin(), split[1].end(), '_', ' '); 299 std::replace(split[1].begin(), split[1].end(), '_', ' ');
300 300
301 replacements_.push_back(std::make_pair(split[0], split[1])); 301 replacements_.push_back(std::make_pair(split[0], split[1]));
302 } 302 }
303 303
304 void AffReader::HandleRawCommand(const std::string& line) { 304 void AffReader::HandleRawCommand(const std::string& line) {
305 other_commands_.push_back(line); 305 other_commands_.push_back(line);
306 } 306 }
307 307
308 void AffReader::HandleEncodedCommand(const std::string& line) { 308 void AffReader::HandleEncodedCommand(const std::string& line) {
309 std::string utf8; 309 std::string utf8;
310 if (EncodingToUTF8(line, &utf8)) 310 if (EncodingToUTF8(line, &utf8))
311 other_commands_.push_back(utf8); 311 other_commands_.push_back(utf8);
312 } 312 }
313 313
314 } // namespace convert_dict 314 } // namespace convert_dict
OLDNEW
« no previous file with comments | « chrome/test/webdriver/dispatch.h ('k') | chrome_frame/chrome_frame_activex.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698