25 const char DIRECTIVE_FLAG =
'$';
26 const char MESSAGE_FLAG =
'%';
43 ifstream infile(file.c_str());
52 getline(infile, line);
55 while (infile.good()) {
57 processLine(line, mode);
58 getline(infile, line);
80 }
else if (text[0] == DIRECTIVE_FLAG) {
84 }
else if (text[0] == MESSAGE_FLAG) {
85 parseMessage(text, mode);
96 MessageReader::parseDirective(
const std::string& text) {
104 if (
tokens[0] ==
string(
"$PREFIX")) {
107 }
else if (
tokens[0] ==
string(
"$NAMESPACE")) {
113 isc_throw_3(MessageException,
"Unrecognized directive",
121 MessageReader::parsePrefix(
const vector<string>&
tokens) {
132 }
else if (
tokens.size() == 2) {
138 if (invalidSymbol(prefix_)) {
146 isc_throw_2(MessageException,
"Too many arguments",
156 MessageReader::invalidSymbol(
const string& symbol) {
157 static const string valid_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
158 "abcdefghijklmnopqrstuvwxyz"
160 return ( symbol.empty() ||
161 (symbol.find_first_not_of(valid_chars) != string::npos) ||
162 (std::isdigit(symbol[0])));
171 MessageReader::parseNamespace(
const vector<string>&
tokens) {
178 }
else if (
tokens.size() > 2) {
179 isc_throw_2(MessageException,
"Too many arguments",
188 static const string valid_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
189 "abcdefghijklmnopqrstuvwxyz"
191 if (
tokens[1].find_first_not_of(valid_chars) != string::npos) {
197 if (ns_.size() != 0) {
198 isc_throw_2(MessageException,
"Duplicate namespace",
216 MessageReader::parseMessage(
const std::string& text, MessageReader::Mode mode) {
218 static string delimiters(
"\t\n ");
222 assert((text.size() >= 1) && (text[0] == MESSAGE_FLAG));
225 if (text.size() == 1) {
234 size_t first_delim = message_line.find_first_of(delimiters);
235 if (first_delim == string::npos) {
239 message_line, lineno_);
246 string ident = prefix_ + message_line.substr(0, first_delim);
247 if (prefix_.empty()) {
248 if (invalidSymbol(ident)) {
249 isc_throw_3(MessageException,
"Invalid message ID",
256 size_t first_text = message_line.find_first_not_of(delimiters, first_delim);
257 if (first_text == string::npos) {
263 message_line, lineno_);
270 added = dictionary_->add(ident, message_line.substr(first_text));
273 added = dictionary_->replace(ident, message_line.substr(first_text));
276 not_added_.push_back(ident);