Commit f55eb123 authored by Jelte Jansen's avatar Jelte Jansen

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&
std::string cur_map_key;
ElementPtr cur_map_element;
skip_chars(in, " \t\n", line, pos);
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.peek();
if (c == '}') {
// empty map, skip closing curly
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);
}
......@@ -335,7 +341,14 @@ ElementPtr
Element::createFromString(std::istream &in) throw(ParseError)
{
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
......@@ -403,7 +416,7 @@ Element::createFromString(const std::string &in)
{
std::stringstream ss;
ss << in;
return createFromString(ss);
return createFromString(ss, "<string>");
}
//
......
......@@ -284,6 +284,7 @@ public:
/// \return An ElementPtr that contains the element(s) specified
/// in the given input stream.
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
/// track of the location in the stream for error reporting.
///
......
......@@ -75,7 +75,7 @@ TEST(Element, from_and_to_str) {
Element::createFromString("{1}");
} catch (isc::data::ParseError pe) {
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();
......
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