[Lemon-commits] [lemon_svn] deba: r2025 - hugo/trunk/lemon/bits
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:49:36 CET 2006
Author: deba
Date: Mon Jul 4 18:11:00 2005
New Revision: 2025
Modified:
hugo/trunk/lemon/bits/item_writer.h
Log:
Specialization for string literals.
Modified: hugo/trunk/lemon/bits/item_writer.h
==============================================================================
--- hugo/trunk/lemon/bits/item_writer.h (original)
+++ hugo/trunk/lemon/bits/item_writer.h Mon Jul 4 18:11:00 2005
@@ -56,7 +56,7 @@
void write(std::ostream& os, const std::string& value) {
os << "\"";
if (escaped) {
- std::ostringstream ls;
+ std::ostringstream ls(value);
for (int i = 0; i < (int)value.size(); ++i) {
writeEscape(ls, value[i]);
}
@@ -118,6 +118,34 @@
};
/// \ingroup item_io
+ /// \brief Writer class for quoted char array.
+ ///
+ /// Writer class for quoted char array. It can process the escape
+ /// sequences in the char array.
+ /// \author Balazs Dezso
+ class QuotedCharArrayWriter {
+ public:
+ typedef const char* Value;
+
+ /// \brief Constructor for the writer.
+ ///
+ /// Constructor for the writer. If the given parameter is true
+ /// the writer creates escape sequences from special characters.
+ QuotedCharArrayWriter(bool _escaped = true) : escaped(_escaped) {}
+
+ /// \brief Writes a quoted char array to the given stream.
+ ///
+ /// Writes a quoted char array to the given stream.
+ void write(std::ostream& os, const char* value) {
+ QuotedStringWriter(escaped).write(os, std::string(value));
+ }
+
+ private:
+ bool escaped;
+ };
+
+
+ /// \ingroup item_io
///
/// \brief Writer for standard containers.
///
@@ -181,6 +209,14 @@
class DefaultWriter<std::string>
: public QuotedStringWriter {};
+ template <int length>
+ class DefaultWriter<char[length]>
+ : public QuotedCharArrayWriter {};
+
+ template <int length>
+ class DefaultWriter<const char[length]>
+ : public QuotedCharArrayWriter {};
+
template <typename Item>
class DefaultWriter<std::vector<Item> >
: public IterableWriter<std::vector<Item> > {};
@@ -210,7 +246,9 @@
struct DefaultWriterTraits {
template <typename _Value>
- struct Writer : DefaultWriter<_Value> {};
+ struct Writer : DefaultWriter<_Value> {
+ typedef DefaultWriter<_Value> Parent;
+ };
};
More information about the Lemon-commits
mailing list