Allowing 'string' type quoting
authordeba
Thu, 19 Apr 2007 15:14:34 +0000
changeset 24266e1027a05d73
parent 2425 08b64ae5a564
child 2427 d40c31b08d6f
Allowing 'string' type quoting
lemon/bits/item_reader.h
lemon/bits/item_writer.h
     1.1 --- a/lemon/bits/item_reader.h	Thu Apr 19 15:12:59 2007 +0000
     1.2 +++ b/lemon/bits/item_reader.h	Thu Apr 19 15:14:34 2007 +0000
     1.3 @@ -30,6 +30,9 @@
     1.4  #include <deque>
     1.5  #include <list>
     1.6  #include <set>
     1.7 +#include <map>
     1.8 +
     1.9 +#include <lemon/error.h>
    1.10  
    1.11  namespace lemon {
    1.12    
    1.13 @@ -172,9 +175,10 @@
    1.14        char c;
    1.15        value.clear();
    1.16        is >> std::ws;
    1.17 -      if (!is.get(c) || c != '\"') 
    1.18 +      if (!is.get(c) || (c != '\"' && c != '\'')) 
    1.19  	throw DataFormatError("Quoted format error");
    1.20 -      while (is.get(c) && c != '\"') {
    1.21 +      char quote = c;
    1.22 +      while (is.get(c) && c != quote) {
    1.23  	if (escaped && c == '\\') {
    1.24  	  value += readEscape(is);
    1.25  	} else {
     2.1 --- a/lemon/bits/item_writer.h	Thu Apr 19 15:12:59 2007 +0000
     2.2 +++ b/lemon/bits/item_writer.h	Thu Apr 19 15:14:34 2007 +0000
     2.3 @@ -31,6 +31,9 @@
     2.4  #include <deque>
     2.5  #include <list>
     2.6  #include <set>
     2.7 +#include <map>
     2.8 +
     2.9 +#include <lemon/error.h>
    2.10  
    2.11  namespace lemon {
    2.12    
    2.13 @@ -146,13 +149,14 @@
    2.14      ///
    2.15      /// Constructor for the writer. If the given parameter is true
    2.16      /// the writer creates escape sequences from special characters.
    2.17 -    QuotedStringWriter(bool _escaped = true) : escaped(_escaped) {}
    2.18 +    QuotedStringWriter(bool _escaped = true, char _quote = '\"') 
    2.19 +      : escaped(_escaped), quote(_quote) {}
    2.20  
    2.21      /// \brief Writes a quoted string to the given stream.
    2.22      ///
    2.23      /// Writes a quoted string to the given stream.
    2.24      void write(std::ostream& os, const std::string& value) const {
    2.25 -      os << "\"";
    2.26 +      os << quote;
    2.27        if (escaped) {
    2.28  	std::ostringstream ls;
    2.29  	for (int i = 0; i < int(value.size()); ++i) {
    2.30 @@ -162,7 +166,7 @@
    2.31        } else {
    2.32  	os << value;
    2.33        }
    2.34 -      os << "\"";
    2.35 +      os << quote;
    2.36      }
    2.37  
    2.38    private:
    2.39 @@ -213,6 +217,7 @@
    2.40      }
    2.41    private:
    2.42      bool escaped;
    2.43 +    char quote;
    2.44    };
    2.45  
    2.46    /// \ingroup item_io