25const char DIRECTIVE_FLAG =
'$';
26const char MESSAGE_FLAG =
'%';
43 ifstream infile(file.c_str());
52 getline(infile, line);
55 while (infile.good()) {
58 getline(infile, line);
80 }
else if (text[0] == DIRECTIVE_FLAG) {
84 }
else if (text[0] == MESSAGE_FLAG) {
85 parseMessage(text, mode);
96MessageReader::parseDirective(
const std::string& text) {
104 if (tokens[0] ==
"$PREFIX") {
107 }
else if (tokens[0] ==
"$NAMESPACE") {
108 parseNamespace(tokens);
113 isc_throw_3(MessageException,
"Unrecognized directive",
121MessageReader::parsePrefix(
const vector<string>& tokens) {
132 }
else if (
tokens.size() == 2) {
138 if (invalidSymbol(prefix_)) {
146 isc_throw_2(MessageException,
"Too many arguments",
156MessageReader::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])));
171MessageReader::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",
218 static string delimiters(
"\t\n ");
225 if (text.size() == 1) {
231 string message_line =
str::trim(text.substr(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));
272 added = dictionary_->
replace(ident, message_line.substr(first_text));
275 not_added_.push_back(ident);
virtual bool replace(const MessageID &ident, const std::string &text)
Replace Message.
virtual bool add(const MessageID &ident, const std::string &text)
Add Message.
virtual void processLine(const std::string &line, Mode mode=ADD)
Process Line.
virtual void readFile(const std::string &file, Mode mode=ADD)
Read File.
#define isc_throw_3(type, stream, param1, param2, param3)
Similar as isc_throw, but allows the exception to have three additional parameters (the stream/text g...
#define isc_throw_2(type, stream, param1, param2)
Similar as isc_throw, but allows the exception to have two additional parameters (the stream/text goe...
#define isc_throw_4(type, stream, param1, param2, param3, param4)
Similar as isc_throw, but allows the exception to have four additional parameters (the stream/text go...
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
const isc::log::MessageID LOG_UNRECOGNIZED_DIRECTIVE
const isc::log::MessageID LOG_NAMESPACE_INVALID_ARG
const isc::log::MessageID LOG_NO_MESSAGE_TEXT
const isc::log::MessageID LOG_READ_ERROR
const isc::log::MessageID LOG_NO_MESSAGE_ID
const isc::log::MessageID LOG_NAMESPACE_EXTRA_ARGS
const isc::log::MessageID LOG_DUPLICATE_NAMESPACE
const isc::log::MessageID LOG_PREFIX_EXTRA_ARGS
const isc::log::MessageID LOG_INPUT_OPEN_FAIL
const isc::log::MessageID LOG_INVALID_MESSAGE_ID
const isc::log::MessageID LOG_NAMESPACE_NO_ARGS
const isc::log::MessageID LOG_PREFIX_INVALID_ARG
vector< string > tokens(const string &text, const string &delim, bool escape)
Split string into tokens.
string trim(const string &input)
Trim leading and trailing spaces.
void uppercase(string &text)
Convert string to uppercase.
Defines the logger used by the top-level component of kea-lfc.