This source file includes following definitions.
- TrimLine
- ReadLine
- StripComment
#include "chrome/tools/convert_dict/hunspell_reader.h"
#include "base/strings/string_util.h"
namespace convert_dict {
const int kLineBufferLen = 65535;
char line_buffer[kLineBufferLen];
void TrimLine(std::string* line) {
if (line->size() > 3 &&
static_cast<unsigned char>((*line)[0]) == 0xef &&
static_cast<unsigned char>((*line)[1]) == 0xbb &&
static_cast<unsigned char>((*line)[2]) == 0xbf)
*line = line->substr(3);
base::TrimWhitespace(*line, base::TRIM_ALL, line);
}
std::string ReadLine(FILE* file) {
const char* line = fgets(line_buffer, kLineBufferLen - 1, file);
if (!line)
return std::string();
std::string str = line;
TrimLine(&str);
return str;
}
void StripComment(std::string* line) {
for (size_t i = 0; i < line->size(); i++) {
if ((*line)[i] == '#') {
line->resize(i);
TrimLine(line);
return;
}
}
}
}