mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-29 09:06:03 +02:00
mv CommentStyle to .cpp
This commit is contained in:
parent
c41609b9f9
commit
db75cdf21e
@ -92,13 +92,13 @@ features without losing binary-compatibility.
|
|||||||
\code
|
\code
|
||||||
// For convenience, use `writeString()` with a specialized builder.
|
// For convenience, use `writeString()` with a specialized builder.
|
||||||
Json::StreamWriterBuilder wbuilder;
|
Json::StreamWriterBuilder wbuilder;
|
||||||
wbuilder.settings_["indentation"] = "\t";
|
wbuilder.settings_["indentation"] = "\t"; // simple Json::Value
|
||||||
std::string document = Json::writeString(wbuilder, root);
|
std::string document = Json::writeString(wbuilder, root);
|
||||||
|
|
||||||
// Here, using a specialized Builder, we discard comments and
|
// Here, using a specialized Builder, we discard comments and
|
||||||
// record errors as we parse.
|
// record errors as we parse.
|
||||||
Json::CharReaderBuilder rbuilder;
|
Json::CharReaderBuilder rbuilder;
|
||||||
rbuilder.settings_["collectComments"] = false;
|
rbuilder.settings_["collectComments"] = false; // simple Json::Value
|
||||||
std::string errs;
|
std::string errs;
|
||||||
bool ok = Json::parseFromStream(rbuilder, std::cin, &root, &errs);
|
bool ok = Json::parseFromStream(rbuilder, std::cin, &root, &errs);
|
||||||
\endcode
|
\endcode
|
||||||
|
@ -41,16 +41,6 @@ class JSON_API StreamWriter {
|
|||||||
protected:
|
protected:
|
||||||
std::ostream* sout_; // not owned; will not delete
|
std::ostream* sout_; // not owned; will not delete
|
||||||
public:
|
public:
|
||||||
/// Scoped enums are not available until C++11.
|
|
||||||
struct CommentStyle {
|
|
||||||
/// Decide whether to write comments.
|
|
||||||
enum Enum {
|
|
||||||
None, ///< Drop all comments.
|
|
||||||
Most, ///< Recover odd behavior of previous versions (not implemented yet).
|
|
||||||
All ///< Keep all comments.
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
StreamWriter();
|
StreamWriter();
|
||||||
virtual ~StreamWriter();
|
virtual ~StreamWriter();
|
||||||
/** Write Value into document as configured in sub-class.
|
/** Write Value into document as configured in sub-class.
|
||||||
|
@ -676,11 +676,21 @@ bool StyledStreamWriter::hasCommentForValue(const Value& value) {
|
|||||||
//////////////////////////
|
//////////////////////////
|
||||||
// BuiltStyledStreamWriter
|
// BuiltStyledStreamWriter
|
||||||
|
|
||||||
|
/// Scoped enums are not available until C++11.
|
||||||
|
struct CommentStyle {
|
||||||
|
/// Decide whether to write comments.
|
||||||
|
enum Enum {
|
||||||
|
None, ///< Drop all comments.
|
||||||
|
Most, ///< Recover odd behavior of previous versions (not implemented yet).
|
||||||
|
All ///< Keep all comments.
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
struct BuiltStyledStreamWriter : public StreamWriter
|
struct BuiltStyledStreamWriter : public StreamWriter
|
||||||
{
|
{
|
||||||
BuiltStyledStreamWriter(
|
BuiltStyledStreamWriter(
|
||||||
std::string const& indentation,
|
std::string const& indentation,
|
||||||
StreamWriter::CommentStyle::Enum cs,
|
CommentStyle::Enum cs,
|
||||||
std::string const& colonSymbol,
|
std::string const& colonSymbol,
|
||||||
std::string const& nullSymbol,
|
std::string const& nullSymbol,
|
||||||
std::string const& endingLineFeedSymbol);
|
std::string const& endingLineFeedSymbol);
|
||||||
@ -713,7 +723,7 @@ private:
|
|||||||
};
|
};
|
||||||
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
|
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
|
||||||
std::string const& indentation,
|
std::string const& indentation,
|
||||||
StreamWriter::CommentStyle::Enum cs,
|
CommentStyle::Enum cs,
|
||||||
std::string const& colonSymbol,
|
std::string const& colonSymbol,
|
||||||
std::string const& nullSymbol,
|
std::string const& nullSymbol,
|
||||||
std::string const& endingLineFeedSymbol)
|
std::string const& endingLineFeedSymbol)
|
||||||
@ -963,11 +973,11 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const
|
|||||||
|
|
||||||
std::string indentation = settings_["indentation"].asString();
|
std::string indentation = settings_["indentation"].asString();
|
||||||
std::string cs_str = settings_["commentStyle"].asString();
|
std::string cs_str = settings_["commentStyle"].asString();
|
||||||
StreamWriter::CommentStyle::Enum cs = StreamWriter::CommentStyle::All;
|
CommentStyle::Enum cs = CommentStyle::All;
|
||||||
if (cs_str == "All") {
|
if (cs_str == "All") {
|
||||||
cs = StreamWriter::CommentStyle::All;
|
cs = CommentStyle::All;
|
||||||
} else if (cs_str == "None") {
|
} else if (cs_str == "None") {
|
||||||
cs = StreamWriter::CommentStyle::None;
|
cs = CommentStyle::None;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1031,7 +1041,7 @@ StreamWriter* OldCompressingStreamWriterBuilder::newStreamWriter() const
|
|||||||
endingLineFeedSymbol = "";
|
endingLineFeedSymbol = "";
|
||||||
}
|
}
|
||||||
return new BuiltStyledStreamWriter(
|
return new BuiltStyledStreamWriter(
|
||||||
"", StreamWriter::CommentStyle::None,
|
"", CommentStyle::None,
|
||||||
colonSymbol, nullSymbol, endingLineFeedSymbol);
|
colonSymbol, nullSymbol, endingLineFeedSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user