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) { |