Commit f55eb123 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

added one more optional createFromString method that lets you specify the...

added one more optional createFromString method that lets you specify the source file name for better error reporting


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@707 e5f2f494-b856-4b98-b285-d166d9295462
parent c6feaf2e
...@@ -316,17 +316,23 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line, int& ...@@ -316,17 +316,23 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line, int&
std::string cur_map_key; std::string cur_map_key;
ElementPtr cur_map_element; ElementPtr cur_map_element;
skip_chars(in, " \t\n", line, pos); skip_chars(in, " \t\n", line, pos);
while (c != EOF && c != '}') { c = in.peek();
p.first = str_from_stringstream(in, file, line, pos); if (c == '}') {
skip_to(in, file, line, pos, ":", " \t\n"); // empty map, skip closing curly
// skip the :
in.get();
pos++;
p.second = Element::createFromString(in, file, line, pos);
m.insert(p);
skip_to(in, file, line, pos, ",}", " \t\n");
c = in.get(); c = in.get();
pos++; } else {
while (c != EOF && c != '}') {
p.first = str_from_stringstream(in, file, line, pos);
skip_to(in, file, line, pos, ":", " \t\n");
// skip the :
in.get();
pos++;
p.second = Element::createFromString(in, file, line, pos);
m.insert(p);
skip_to(in, file, line, pos, ",}", " \t\n");
c = in.get();
pos++;
}
} }
return Element::create(m); return Element::create(m);
} }
...@@ -335,7 +341,14 @@ ElementPtr ...@@ -335,7 +341,14 @@ ElementPtr
Element::createFromString(std::istream &in) throw(ParseError) Element::createFromString(std::istream &in) throw(ParseError)
{ {
int line = 1, pos = 1; int line = 1, pos = 1;
return createFromString(in, "<unknown>", line, pos); return createFromString(in, "<istream>", line, pos);
}
ElementPtr
Element::createFromString(std::istream &in, const std::string& file_name) throw(ParseError)
{
int line = 1, pos = 1;
return createFromString(in, file_name, line, pos);
} }
ElementPtr ElementPtr
...@@ -403,7 +416,7 @@ Element::createFromString(const std::string &in) ...@@ -403,7 +416,7 @@ Element::createFromString(const std::string &in)
{ {
std::stringstream ss; std::stringstream ss;
ss << in; ss << in;
return createFromString(ss); return createFromString(ss, "<string>");
} }
// //
......
...@@ -284,6 +284,7 @@ public: ...@@ -284,6 +284,7 @@ public:
/// \return An ElementPtr that contains the element(s) specified /// \return An ElementPtr that contains the element(s) specified
/// in the given input stream. /// in the given input stream.
static ElementPtr createFromString(std::istream& in) throw(ParseError); static ElementPtr createFromString(std::istream& in) throw(ParseError);
static ElementPtr createFromString(std::istream& in, const std::string& file_name) throw(ParseError);
/// Creates an Element from the given input stream, where we keep /// Creates an Element from the given input stream, where we keep
/// track of the location in the stream for error reporting. /// track of the location in the stream for error reporting.
/// ///
......
...@@ -75,7 +75,7 @@ TEST(Element, from_and_to_str) { ...@@ -75,7 +75,7 @@ TEST(Element, from_and_to_str) {
Element::createFromString("{1}"); Element::createFromString("{1}");
} catch (isc::data::ParseError pe) { } catch (isc::data::ParseError pe) {
std::string s = std::string(pe.what()); std::string s = std::string(pe.what());
EXPECT_EQ(s, "String expected in <unknown>:1:3"); EXPECT_EQ(s, "String expected in <string>:1:3");
} }
sv.clear(); sv.clear();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment