소스 검색

Add parse msg to improve error reporting

[SVN r16643]
Beman Dawes 23 년 전
부모
커밋
d37255c712
2개의 변경된 파일15개의 추가작업 그리고 12개의 파일을 삭제
  1. 13 10
      tools/regression/detail/tiny_xml.cpp
  2. 2 2
      tools/regression/detail/tiny_xml.hpp

+ 13 - 10
tools/regression/detail/tiny_xml.cpp

@@ -32,11 +32,13 @@ namespace
     return result;
   }
 
-  void eat_delim( char & c, std::istream & in, char delim )
+  void eat_delim( char & c, std::istream & in,
+                  char delim, const std::string & msg )
   {
     eat_whitespace( c, in );
     if ( c != delim )
-      throw (std::string("xml syntax error, expected ") + delim);
+      throw std::string("xml syntax error, expected ") + delim
+       + " (" + msg + ")";
     in.get( c );
   }
 
@@ -61,7 +63,7 @@ namespace boost
 
   //  parse  -----------------------------------------------------------------//
 
-    element_ptr parse( std::istream & in )
+    element_ptr parse( std::istream & in, const std::string & msg )
     {
       char c = 0;  // current character
       element_ptr e( new element );
@@ -78,8 +80,8 @@ namespace boost
         attribute a;
         a.name = get_name( c, in );
 
-        eat_delim( c, in, '=' );
-        eat_delim( c, in, '\"' );
+        eat_delim( c, in, '=', msg );
+        eat_delim( c, in, '\"', msg );
 
         a.value = get_value( c, in );
 
@@ -93,7 +95,7 @@ namespace boost
       while ( c == '<' )
       {
         if ( in.peek() == '/' ) break;
-        e->elements.push_back( parse( in ) );
+        e->elements.push_back( parse( in, msg ) );
         in.get( c ); // next after '>'
         eat_whitespace( c, in );
       }
@@ -112,13 +114,14 @@ namespace boost
       assert( c == '<' );
       in.get( c ); // next after '<'
 
-      eat_delim( c, in, '/' );
+      eat_delim( c, in, '/', msg );
       std::string end_name( get_name( c, in ) );
       if ( e->name != end_name )
-        throw (std::string("xml syntax error: beginning name ") +
-          e->name + " did not match end name " + end_name);
+        throw std::string("xml syntax error: beginning name ")
+          + e->name + " did not match end name " + end_name
+          + " (" + msg + ")";
 
-      eat_delim( c, in, '>' );
+      eat_delim( c, in, '>', msg );
       return e;
     }
 

+ 2 - 2
tools/regression/detail/tiny_xml.hpp

@@ -52,13 +52,13 @@ namespace boost
       explicit element( const std::string & name ) : name(name) {}
     };
 
-    element_ptr parse( std::istream & in );
+    element_ptr parse( std::istream & in, const std::string & msg );
     // Precondition: stream positioned at either the initial "<"
     // or the first character after the initial "<".
     // Postcondition: stream positioned at the first character after final
     //  ">" (or eof).
     // Returns: an element_ptr to an element representing the parsed stream.
-    // Throws: std::string on syntax error.
+    // Throws: std::string on syntax error. msg appended to what() string.
 
     void write( const element & e, std::ostream & out );
 

粤ICP备19079148号