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
3 // found in the LICENSE file.
5 #include "chrome/tools/convert_dict/hunspell_reader.h"
7 #include "base/strings/string_util.h"
9 namespace convert_dict
{
11 // This silly 64K buffer is just copied from Hunspell's way of parsing.
12 const int kLineBufferLen
= 65535;
13 char line_buffer
[kLineBufferLen
];
15 // Shortcut for trimming whitespace from both ends of the line.
16 void TrimLine(std::string
* line
) {
17 if (line
->size() > 3 &&
18 static_cast<unsigned char>((*line
)[0]) == 0xef &&
19 static_cast<unsigned char>((*line
)[1]) == 0xbb &&
20 static_cast<unsigned char>((*line
)[2]) == 0xbf)
21 *line
= line
->substr(3);
23 // Treat this text as an ASCII text and trim whitespace characters as
24 // hunspell does. The returned text is to be converted into UTF-8 text with
25 // the encoding defined in an affix file.
26 base::TrimWhitespace(*line
, base::TRIM_ALL
, line
);
29 std::string
ReadLine(FILE* file
) {
30 const char* line
= fgets(line_buffer
, kLineBufferLen
- 1, file
);
34 std::string str
= line
;
39 void StripComment(std::string
* line
) {
40 for (size_t i
= 0; i
< line
->size(); i
++) {
41 if ((*line
)[i
] == '#') {
49 } // namespace convert_dict