setIndentation()
authorChristopher Dunn <cdunn2001@gmail.com>
Thu, 22 Jan 2015 22:08:21 +0000 (16:08 -0600)
committerChristopher Dunn <cdunn2001@gmail.com>
Sun, 25 Jan 2015 21:54:40 +0000 (15:54 -0600)
include/json/writer.h
src/lib_json/json_writer.cpp

index d5306c9..2aff642 100644 (file)
@@ -65,6 +65,13 @@ public:
     ~Builder();  // delete underlying StreamWriterBuilder
 
     void setCommentStyle(CommentStyle cs);  /// default: All
+    /** \brief Write in human-friendly style.
+
+        If "", then skip all indentation, newlines, and comments,
+        which implies CommentStyle::None.
+        Default: "\t"
+    */
+    void setIndentation(std::string indentation);
 
     /// Do not take ownership of sout, but maintain a reference.
     StreamWriter* newStreamWriter(std::ostream* sout);
index 15fcf64..14fef06 100644 (file)
@@ -699,17 +699,24 @@ int MyStreamWriter::write(Value const& root) const
 class StreamWriterBuilder {
   typedef StreamWriter::CommentStyle CommentStyle;
   CommentStyle cs_;
+  std::string indentation_;
 public:
   virtual ~StreamWriterBuilder();
   virtual void setCommentStyle(CommentStyle cs);
+  virtual void setIndentation(std::string indentation);
   virtual StreamWriter* newStreamWriter(std::ostream* sout) const;
 };
 StreamWriterBuilder::~StreamWriterBuilder()
 {
 }
-void StreamWriterBuilder::setCommentStyle(CommentStyle cs)
+void StreamWriterBuilder::setCommentStyle(CommentStyle v)
 {
-  cs_ = cs;
+  cs_ = v;
+}
+void StreamWriterBuilder::setIndentation(std::string v)
+{
+  indentation_ = v;
+  if (indentation_.empty()) cs_ = CommentStyle::None;
 }
 StreamWriter* StreamWriterBuilder::newStreamWriter(std::ostream* stream) const
 {
@@ -732,9 +739,17 @@ StreamWriter::Builder::~Builder()
 {
   delete own_;
 }
-void StreamWriter::Builder::setCommentStyle(CommentStyle cs)
+void StreamWriter::Builder::setCommentStyle(CommentStyle v)
+{
+  own_->setCommentStyle(v);
+}
+void StreamWriter::Builder::setIndentation(std::string v)
+{
+  own_->setIndentation(v);
+}
+StreamWriter* StreamWriter::Builder::newStreamWriter(std::ostream* sout)
 {
-  own_->setCommentStyle(cs);
+  return own_->newStreamWriter(sout);
 }
 
 /// Do not take ownership of sout, but maintain a reference.