lemon/bits/item_writer.h
changeset 2493 6231d9d3957b
parent 2391 14a343be7a5a
child 2553 bfced05fa852
equal deleted inserted replaced
11:347f22988d55 12:17904a27466f
    29 
    29 
    30 #include <vector>
    30 #include <vector>
    31 #include <deque>
    31 #include <deque>
    32 #include <list>
    32 #include <list>
    33 #include <set>
    33 #include <set>
       
    34 #include <map>
       
    35 
       
    36 #include <lemon/error.h>
    34 
    37 
    35 namespace lemon {
    38 namespace lemon {
    36   
    39   
    37   template <typename Value>
    40   template <typename Value>
    38   class DefaultWriter;
    41   class DefaultWriter;
   144 
   147 
   145     /// \brief Constructor for the writer.
   148     /// \brief Constructor for the writer.
   146     ///
   149     ///
   147     /// Constructor for the writer. If the given parameter is true
   150     /// Constructor for the writer. If the given parameter is true
   148     /// the writer creates escape sequences from special characters.
   151     /// the writer creates escape sequences from special characters.
   149     QuotedStringWriter(bool _escaped = true) : escaped(_escaped) {}
   152     QuotedStringWriter(bool _escaped = true, char _quote = '\"') 
       
   153       : escaped(_escaped), quote(_quote) {}
   150 
   154 
   151     /// \brief Writes a quoted string to the given stream.
   155     /// \brief Writes a quoted string to the given stream.
   152     ///
   156     ///
   153     /// Writes a quoted string to the given stream.
   157     /// Writes a quoted string to the given stream.
   154     void write(std::ostream& os, const std::string& value) const {
   158     void write(std::ostream& os, const std::string& value) const {
   155       os << "\"";
   159       os << quote;
   156       if (escaped) {
   160       if (escaped) {
   157 	std::ostringstream ls;
   161 	std::ostringstream ls;
   158 	for (int i = 0; i < int(value.size()); ++i) {
   162 	for (int i = 0; i < int(value.size()); ++i) {
   159 	  writeEscape(ls, value[i]);
   163 	  writeEscape(ls, value[i]);
   160 	}
   164 	}
   161 	os << ls.str();
   165 	os << ls.str();
   162       } else {
   166       } else {
   163 	os << value;
   167 	os << value;
   164       }
   168       }
   165       os << "\"";
   169       os << quote;
   166     }
   170     }
   167 
   171 
   168   private:
   172   private:
   169     
   173     
   170     static void writeEscape(std::ostream& os, char c) {
   174     static void writeEscape(std::ostream& os, char c) {
   211 	return;
   215 	return;
   212       }     
   216       }     
   213     }
   217     }
   214   private:
   218   private:
   215     bool escaped;
   219     bool escaped;
       
   220     char quote;
   216   };
   221   };
   217 
   222 
   218   /// \ingroup item_io
   223   /// \ingroup item_io
   219   /// \brief Writer class for quoted chars.
   224   /// \brief Writer class for quoted chars.
   220   ///
   225   ///