Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / chrome / tools / convert_dict / hunspell_reader.cc
blob6555fb7be3bbd2d18cd6418670e020b381a16d9e
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);
31 if (!line)
32 return std::string();
34 std::string str = line;
35 TrimLine(&str);
36 return str;
39 void StripComment(std::string* line) {
40 for (size_t i = 0; i < line->size(); i++) {
41 if ((*line)[i] == '#') {
42 line->resize(i);
43 TrimLine(line);
44 return;
49 } // namespace convert_dict