[svn] commit: r707 - in /branches/parkinglot/src/lib/cc/cpp: data.cc data.h data_unittests.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Feb 3 11:38:39 UTC 2010
Author: jelte
Date: Wed Feb 3 11:38:38 2010
New Revision: 707
Log:
added one more optional createFromString method that lets you specify the source file name for better error reporting
Modified:
branches/parkinglot/src/lib/cc/cpp/data.cc
branches/parkinglot/src/lib/cc/cpp/data.h
branches/parkinglot/src/lib/cc/cpp/data_unittests.cc
Modified: branches/parkinglot/src/lib/cc/cpp/data.cc
==============================================================================
--- branches/parkinglot/src/lib/cc/cpp/data.cc (original)
+++ branches/parkinglot/src/lib/cc/cpp/data.cc Wed Feb 3 11:38:38 2010
@@ -316,17 +316,23 @@
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 @@
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 @@
{
std::stringstream ss;
ss << in;
- return createFromString(ss);
+ return createFromString(ss, "<string>");
}
//
Modified: branches/parkinglot/src/lib/cc/cpp/data.h
==============================================================================
--- branches/parkinglot/src/lib/cc/cpp/data.h (original)
+++ branches/parkinglot/src/lib/cc/cpp/data.h Wed Feb 3 11:38:38 2010
@@ -284,6 +284,7 @@
/// \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.
///
Modified: branches/parkinglot/src/lib/cc/cpp/data_unittests.cc
==============================================================================
--- branches/parkinglot/src/lib/cc/cpp/data_unittests.cc (original)
+++ branches/parkinglot/src/lib/cc/cpp/data_unittests.cc Wed Feb 3 11:38:38 2010
@@ -75,7 +75,7 @@
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();
More information about the bind10-changes
mailing list