| 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 #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" |
| 11 #include "base/stringprintf.h" |
| 11 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 12 #include "base/string_util.h" | |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/tools/convert_dict/hunspell_reader.h" | 14 #include "chrome/tools/convert_dict/hunspell_reader.h" |
| 15 | 15 |
| 16 namespace convert_dict { | 16 namespace convert_dict { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Returns true if the given line begins with the given case-sensitive | 20 // Returns true if the given line begins with the given case-sensitive |
| 21 // NULL-terminated ASCII string. | 21 // NULL-terminated ASCII string. |
| 22 bool StringBeginsWith(const std::string& str, const char* with) { | 22 bool StringBeginsWith(const std::string& str, const char* with) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 base::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 = base::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(), |
| 229 tokens[2].c_str()); | 229 tokens[4].c_str(), |
| 230 tokens[2].c_str()); |
| 230 } | 231 } |
| 231 } | 232 } |
| 232 | 233 |
| 233 size_t slash_index = part.find('/'); | 234 size_t slash_index = part.find('/'); |
| 234 if (slash_index != std::string::npos && !has_indexed_affixes()) { | 235 if (slash_index != std::string::npos && !has_indexed_affixes()) { |
| 235 // This can also have a rule string associated with it following a | 236 // This can also have a rule string associated with it following a |
| 236 // slash. For example: | 237 // slash. For example: |
| 237 // PFX P 0 foo/Y . | 238 // PFX P 0 foo/Y . |
| 238 // The "Y" is a flag. For example, the aff file might have a line: | 239 // The "Y" is a flag. For example, the aff file might have a line: |
| 239 // COMPOUNDFLAG Y | 240 // COMPOUNDFLAG Y |
| (...skipping 10 matching lines...) Expand all Loading... |
| 250 std::vector<std::string> after_slash; | 251 std::vector<std::string> after_slash; |
| 251 base::SplitString(part.substr(slash_index + 1), ' ', &after_slash); | 252 base::SplitString(part.substr(slash_index + 1), ' ', &after_slash); |
| 252 if (after_slash.size() < 2) { | 253 if (after_slash.size() < 2) { |
| 253 // Note that we may get a third term here which is the | 254 // Note that we may get a third term here which is the |
| 254 // morphological description of this rule. This happens in the tests | 255 // morphological description of this rule. This happens in the tests |
| 255 // only, so we can just ignore it. | 256 // only, so we can just ignore it. |
| 256 printf("ERROR: Didn't get enough after the slash\n"); | 257 printf("ERROR: Didn't get enough after the slash\n"); |
| 257 return; | 258 return; |
| 258 } | 259 } |
| 259 | 260 |
| 260 part = StringPrintf("%s%d %s", before_flags.c_str(), | 261 part = base::StringPrintf("%s%d %s", |
| 261 GetAFIndexForAFString(after_slash[0]), | 262 before_flags.c_str(), |
| 262 after_slash[1].c_str()); | 263 GetAFIndexForAFString(after_slash[0]), |
| 264 after_slash[1].c_str()); |
| 263 } | 265 } |
| 264 | 266 |
| 265 // Reencode from here | 267 // Reencode from here |
| 266 std::string reencoded; | 268 std::string reencoded; |
| 267 if (!EncodingToUTF8(part, &reencoded)) | 269 if (!EncodingToUTF8(part, &reencoded)) |
| 268 break; | 270 break; |
| 269 | 271 |
| 270 *rule = rule->substr(0, part_start) + reencoded; | 272 *rule = rule->substr(0, part_start) + reencoded; |
| 271 break; | 273 break; |
| 272 } | 274 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 other_commands_.push_back(line); | 307 other_commands_.push_back(line); |
| 306 } | 308 } |
| 307 | 309 |
| 308 void AffReader::HandleEncodedCommand(const std::string& line) { | 310 void AffReader::HandleEncodedCommand(const std::string& line) { |
| 309 std::string utf8; | 311 std::string utf8; |
| 310 if (EncodingToUTF8(line, &utf8)) | 312 if (EncodingToUTF8(line, &utf8)) |
| 311 other_commands_.push_back(utf8); | 313 other_commands_.push_back(utf8); |
| 312 } | 314 } |
| 313 | 315 |
| 314 } // namespace convert_dict | 316 } // namespace convert_dict |
| OLD | NEW |