convert JSONCPP_STRING etc from macros to typedefs

This commit is contained in:
Billy Donahue
2019-01-17 16:35:29 -05:00
parent 6e7cbf8f54
commit 1c2ed7a10f
14 changed files with 416 additions and 444 deletions

View File

@@ -108,9 +108,9 @@ bool Reader::parse(std::istream& is, Value& root, bool collectComments) {
// Those would allow streamed input from a file, if parse() were a
// template function.
// Since JSONCPP_STRING is reference-counted, this at least does not
// Since String is reference-counted, this at least does not
// create an extra copy.
JSONCPP_STRING doc;
String doc;
std::getline(is, doc, (char)EOF);
return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
}
@@ -358,9 +358,8 @@ bool Reader::readComment() {
return true;
}
JSONCPP_STRING Reader::normalizeEOL(Reader::Location begin,
Reader::Location end) {
JSONCPP_STRING normalized;
String Reader::normalizeEOL(Reader::Location begin, Reader::Location end) {
String normalized;
normalized.reserve(static_cast<size_t>(end - begin));
Reader::Location current = begin;
while (current != end) {
@@ -382,7 +381,7 @@ void Reader::addComment(Location begin,
Location end,
CommentPlacement placement) {
assert(collectComments_);
const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
const String& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) {
assert(lastValue_ != nullptr);
lastValue_->setComment(normalized, placement);
@@ -452,7 +451,7 @@ bool Reader::readString() {
bool Reader::readObject(Token& token) {
Token tokenName;
JSONCPP_STRING name;
String name;
Value init(objectValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_);
@@ -472,7 +471,7 @@ bool Reader::readObject(Token& token) {
Value numberName;
if (!decodeNumber(tokenName, numberName))
return recoverFromError(tokenObjectEnd);
name = JSONCPP_STRING(numberName.asCString());
name = String(numberName.asCString());
} else {
break;
}
@@ -609,18 +608,17 @@ bool Reader::decodeDouble(Token& token) {
bool Reader::decodeDouble(Token& token, Value& decoded) {
double value = 0;
JSONCPP_STRING buffer(token.start_, token.end_);
JSONCPP_ISTRINGSTREAM is(buffer);
String buffer(token.start_, token.end_);
IStringStream is(buffer);
if (!(is >> value))
return addError("'" + JSONCPP_STRING(token.start_, token.end_) +
"' is not a number.",
token);
return addError(
"'" + String(token.start_, token.end_) + "' is not a number.", token);
decoded = value;
return true;
}
bool Reader::decodeString(Token& token) {
JSONCPP_STRING decoded_string;
String decoded_string;
if (!decodeString(token, decoded_string))
return false;
Value decoded(decoded_string);
@@ -630,7 +628,7 @@ bool Reader::decodeString(Token& token) {
return true;
}
bool Reader::decodeString(Token& token, JSONCPP_STRING& decoded) {
bool Reader::decodeString(Token& token, String& decoded) {
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
Location current = token.start_ + 1; // skip '"'
Location end = token.end_ - 1; // do not include '"'
@@ -737,9 +735,7 @@ bool Reader::decodeUnicodeEscapeSequence(Token& token,
return true;
}
bool Reader::addError(const JSONCPP_STRING& message,
Token& token,
Location extra) {
bool Reader::addError(const String& message, Token& token, Location extra) {
ErrorInfo info;
info.token_ = token;
info.message_ = message;
@@ -761,7 +757,7 @@ bool Reader::recoverFromError(TokenType skipUntilToken) {
return false;
}
bool Reader::addErrorAndRecover(const JSONCPP_STRING& message,
bool Reader::addErrorAndRecover(const String& message,
Token& token,
TokenType skipUntilToken) {
addError(message, token);
@@ -799,7 +795,7 @@ void Reader::getLocationLineAndColumn(Location location,
++line;
}
JSONCPP_STRING Reader::getLocationLineAndColumn(Location location) const {
String Reader::getLocationLineAndColumn(Location location) const {
int line, column;
getLocationLineAndColumn(location, line, column);
char buffer[18 + 16 + 16 + 1];
@@ -808,12 +804,12 @@ JSONCPP_STRING Reader::getLocationLineAndColumn(Location location) const {
}
// Deprecated. Preserved for backward compatibility
JSONCPP_STRING Reader::getFormatedErrorMessages() const {
String Reader::getFormatedErrorMessages() const {
return getFormattedErrorMessages();
}
JSONCPP_STRING Reader::getFormattedErrorMessages() const {
JSONCPP_STRING formattedMessage;
String Reader::getFormattedErrorMessages() const {
String formattedMessage;
for (const auto& error : errors_) {
formattedMessage +=
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
@@ -837,7 +833,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
return allErrors;
}
bool Reader::pushError(const Value& value, const JSONCPP_STRING& message) {
bool Reader::pushError(const Value& value, const String& message) {
ptrdiff_t const length = end_ - begin_;
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
return false;
@@ -854,7 +850,7 @@ bool Reader::pushError(const Value& value, const JSONCPP_STRING& message) {
}
bool Reader::pushError(const Value& value,
const JSONCPP_STRING& message,
const String& message,
const Value& extra) {
ptrdiff_t const length = end_ - begin_;
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
@@ -905,7 +901,7 @@ public:
struct StructuredError {
ptrdiff_t offset_start;
ptrdiff_t offset_limit;
JSONCPP_STRING message;
String message;
};
OurReader(OurFeatures const& features);
@@ -913,12 +909,10 @@ public:
const char* endDoc,
Value& root,
bool collectComments = true);
JSONCPP_STRING getFormattedErrorMessages() const;
String getFormattedErrorMessages() const;
std::vector<StructuredError> getStructuredErrors() const;
bool pushError(const Value& value, const JSONCPP_STRING& message);
bool pushError(const Value& value,
const JSONCPP_STRING& message,
const Value& extra);
bool pushError(const Value& value, const String& message);
bool pushError(const Value& value, const String& message, const Value& extra);
bool good() const;
private:
@@ -955,7 +949,7 @@ private:
class ErrorInfo {
public:
Token token_;
JSONCPP_STRING message_;
String message_;
Location extra_;
};
@@ -976,7 +970,7 @@ private:
bool decodeNumber(Token& token);
bool decodeNumber(Token& token, Value& decoded);
bool decodeString(Token& token);
bool decodeString(Token& token, JSONCPP_STRING& decoded);
bool decodeString(Token& token, String& decoded);
bool decodeDouble(Token& token);
bool decodeDouble(Token& token, Value& decoded);
bool decodeUnicodeCodePoint(Token& token,
@@ -987,11 +981,9 @@ private:
Location& current,
Location end,
unsigned int& unicode);
bool addError(const JSONCPP_STRING& message,
Token& token,
Location extra = nullptr);
bool addError(const String& message, Token& token, Location extra = nullptr);
bool recoverFromError(TokenType skipUntilToken);
bool addErrorAndRecover(const JSONCPP_STRING& message,
bool addErrorAndRecover(const String& message,
Token& token,
TokenType skipUntilToken);
void skipUntilSpace();
@@ -999,23 +991,23 @@ private:
Char getNextChar();
void
getLocationLineAndColumn(Location location, int& line, int& column) const;
JSONCPP_STRING getLocationLineAndColumn(Location location) const;
String getLocationLineAndColumn(Location location) const;
void addComment(Location begin, Location end, CommentPlacement placement);
void skipCommentTokens(Token& token);
static JSONCPP_STRING normalizeEOL(Location begin, Location end);
static String normalizeEOL(Location begin, Location end);
static bool containsNewLine(Location begin, Location end);
typedef std::stack<Value*> Nodes;
Nodes nodes_;
Errors errors_;
JSONCPP_STRING document_;
String document_;
Location begin_;
Location end_;
Location current_;
Location lastValueEnd_;
Value* lastValue_;
JSONCPP_STRING commentsBefore_;
String commentsBefore_;
OurFeatures const features_;
bool collectComments_;
@@ -1329,9 +1321,9 @@ bool OurReader::readComment() {
return true;
}
JSONCPP_STRING OurReader::normalizeEOL(OurReader::Location begin,
OurReader::Location end) {
JSONCPP_STRING normalized;
String OurReader::normalizeEOL(OurReader::Location begin,
OurReader::Location end) {
String normalized;
normalized.reserve(static_cast<size_t>(end - begin));
OurReader::Location current = begin;
while (current != end) {
@@ -1353,7 +1345,7 @@ void OurReader::addComment(Location begin,
Location end,
CommentPlacement placement) {
assert(collectComments_);
const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
const String& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) {
assert(lastValue_ != nullptr);
lastValue_->setComment(normalized, placement);
@@ -1439,7 +1431,7 @@ bool OurReader::readStringSingleQuote() {
bool OurReader::readObject(Token& token) {
Token tokenName;
JSONCPP_STRING name;
String name;
Value init(objectValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_);
@@ -1472,7 +1464,7 @@ bool OurReader::readObject(Token& token) {
if (name.length() >= (1U << 30))
throwRuntimeError("keylength >= 2^30");
if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
JSONCPP_STRING msg = "Duplicate key: '" + name + "'";
String msg = "Duplicate key: '" + name + "'";
return addErrorAndRecover(msg, tokenName, tokenObjectEnd);
}
Value& value = currentValue()[name];
@@ -1624,20 +1616,19 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
fixNumericLocaleInput(buffer, buffer + length);
count = sscanf(buffer, format, &value);
} else {
JSONCPP_STRING buffer(token.start_, token.end_);
String buffer(token.start_, token.end_);
count = sscanf(buffer.c_str(), format, &value);
}
if (count != 1)
return addError("'" + JSONCPP_STRING(token.start_, token.end_) +
"' is not a number.",
token);
return addError(
"'" + String(token.start_, token.end_) + "' is not a number.", token);
decoded = value;
return true;
}
bool OurReader::decodeString(Token& token) {
JSONCPP_STRING decoded_string;
String decoded_string;
if (!decodeString(token, decoded_string))
return false;
Value decoded(decoded_string);
@@ -1647,7 +1638,7 @@ bool OurReader::decodeString(Token& token) {
return true;
}
bool OurReader::decodeString(Token& token, JSONCPP_STRING& decoded) {
bool OurReader::decodeString(Token& token, String& decoded) {
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
Location current = token.start_ + 1; // skip '"'
Location end = token.end_ - 1; // do not include '"'
@@ -1754,9 +1745,7 @@ bool OurReader::decodeUnicodeEscapeSequence(Token& token,
return true;
}
bool OurReader::addError(const JSONCPP_STRING& message,
Token& token,
Location extra) {
bool OurReader::addError(const String& message, Token& token, Location extra) {
ErrorInfo info;
info.token_ = token;
info.message_ = message;
@@ -1778,7 +1767,7 @@ bool OurReader::recoverFromError(TokenType skipUntilToken) {
return false;
}
bool OurReader::addErrorAndRecover(const JSONCPP_STRING& message,
bool OurReader::addErrorAndRecover(const String& message,
Token& token,
TokenType skipUntilToken) {
addError(message, token);
@@ -1816,7 +1805,7 @@ void OurReader::getLocationLineAndColumn(Location location,
++line;
}
JSONCPP_STRING OurReader::getLocationLineAndColumn(Location location) const {
String OurReader::getLocationLineAndColumn(Location location) const {
int line, column;
getLocationLineAndColumn(location, line, column);
char buffer[18 + 16 + 16 + 1];
@@ -1824,8 +1813,8 @@ JSONCPP_STRING OurReader::getLocationLineAndColumn(Location location) const {
return buffer;
}
JSONCPP_STRING OurReader::getFormattedErrorMessages() const {
JSONCPP_STRING formattedMessage;
String OurReader::getFormattedErrorMessages() const {
String formattedMessage;
for (const auto& error : errors_) {
formattedMessage +=
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
@@ -1849,7 +1838,7 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
return allErrors;
}
bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message) {
bool OurReader::pushError(const Value& value, const String& message) {
ptrdiff_t length = end_ - begin_;
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
return false;
@@ -1866,7 +1855,7 @@ bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message) {
}
bool OurReader::pushError(const Value& value,
const JSONCPP_STRING& message,
const String& message,
const Value& extra) {
ptrdiff_t length = end_ - begin_;
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
@@ -1896,7 +1885,7 @@ public:
bool parse(char const* beginDoc,
char const* endDoc,
Value* root,
JSONCPP_STRING* errs) override {
String* errs) override {
bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
if (errs) {
*errs = reader_.getFormattedErrorMessages();
@@ -1926,7 +1915,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
return new OurCharReader(collectComments, features);
}
static void getValidReaderKeys(std::set<JSONCPP_STRING>* valid_keys) {
static void getValidReaderKeys(std::set<String>* valid_keys) {
valid_keys->clear();
valid_keys->insert("collectComments");
valid_keys->insert("allowComments");
@@ -1944,19 +1933,19 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const {
if (!invalid)
invalid = &my_invalid; // so we do not need to test for NULL
Json::Value& inv = *invalid;
std::set<JSONCPP_STRING> valid_keys;
std::set<String> valid_keys;
getValidReaderKeys(&valid_keys);
Value::Members keys = settings_.getMemberNames();
size_t n = keys.size();
for (size_t i = 0; i < n; ++i) {
JSONCPP_STRING const& key = keys[i];
String const& key = keys[i];
if (valid_keys.find(key) == valid_keys.end()) {
inv[key] = settings_[key];
}
}
return inv.empty();
}
Value& CharReaderBuilder::operator[](const JSONCPP_STRING& key) {
Value& CharReaderBuilder::operator[](const String& key) {
return settings_[key];
}
// static
@@ -1993,12 +1982,12 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
// global functions
bool parseFromStream(CharReader::Factory const& fact,
JSONCPP_ISTREAM& sin,
IStream& sin,
Value* root,
JSONCPP_STRING* errs) {
JSONCPP_OSTRINGSTREAM ssin;
String* errs) {
OStringStream ssin;
ssin << sin.rdbuf();
JSONCPP_STRING doc = ssin.str();
String doc = ssin.str();
char const* begin = doc.data();
char const* end = begin + doc.size();
// Note that we do not actually need a null-terminator.
@@ -2006,9 +1995,9 @@ bool parseFromStream(CharReader::Factory const& fact,
return reader->parse(begin, end, root, errs);
}
JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM& sin, Value& root) {
IStream& operator>>(IStream& sin, Value& root) {
CharReaderBuilder b;
JSONCPP_STRING errs;
String errs;
bool ok = parseFromStream(b, sin, &root, &errs);
if (!ok) {
throwRuntimeError(errs);

View File

@@ -36,8 +36,8 @@ static inline char getDecimalPoint() {
}
/// Converts a unicode code-point to UTF-8.
static inline JSONCPP_STRING codePointToUTF8(unsigned int cp) {
JSONCPP_STRING result;
static inline String codePointToUTF8(unsigned int cp) {
String result;
// based on description from http://en.wikipedia.org/wiki/UTF-8

View File

@@ -217,15 +217,15 @@ static inline void releaseStringValue(char* value, unsigned) { free(value); }
namespace Json {
Exception::Exception(JSONCPP_STRING msg) : msg_(std::move(msg)) {}
Exception::Exception(String msg) : msg_(std::move(msg)) {}
Exception::~Exception() JSONCPP_NOEXCEPT {}
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
RuntimeError::RuntimeError(JSONCPP_STRING const& msg) : Exception(msg) {}
LogicError::LogicError(JSONCPP_STRING const& msg) : Exception(msg) {}
JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg) {
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
LogicError::LogicError(String const& msg) : Exception(msg) {}
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
throw RuntimeError(msg);
}
JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg) {
JSONCPP_NORETURN void throwLogicError(String const& msg) {
throw LogicError(msg);
}
@@ -452,7 +452,7 @@ Value::Value(const char* begin, const char* end) {
duplicateAndPrefixStringValue(begin, static_cast<unsigned>(end - begin));
}
Value::Value(const JSONCPP_STRING& value) {
Value::Value(const String& value) {
initBasic(stringValue, true);
value_.string_ = duplicateAndPrefixStringValue(
value.data(), static_cast<unsigned>(value.length()));
@@ -684,7 +684,7 @@ bool Value::getString(char const** begin, char const** end) const {
return true;
}
JSONCPP_STRING Value::asString() const {
String Value::asString() const {
switch (type_) {
case nullValue:
return "";
@@ -695,7 +695,7 @@ JSONCPP_STRING Value::asString() const {
char const* this_str;
decodePrefixedString(this->allocated_, this->value_.string_, &this_len,
&this_str);
return JSONCPP_STRING(this_str, this_len);
return String(this_str, this_len);
}
case booleanValue:
return value_.bool_ ? "true" : "false";
@@ -1172,7 +1172,7 @@ const Value& Value::operator[](const char* key) const {
return nullSingleton();
return *found;
}
Value const& Value::operator[](const JSONCPP_STRING& key) const {
Value const& Value::operator[](const String& key) const {
Value const* found = find(key.data(), key.data() + key.length());
if (!found)
return nullSingleton();
@@ -1183,7 +1183,7 @@ Value& Value::operator[](const char* key) {
return resolveReference(key, key + strlen(key));
}
Value& Value::operator[](const JSONCPP_STRING& key) {
Value& Value::operator[](const String& key) {
return resolveReference(key.data(), key.data() + key.length());
}
@@ -1220,7 +1220,7 @@ Value Value::get(char const* begin,
Value Value::get(char const* key, Value const& defaultValue) const {
return get(key, key + strlen(key), defaultValue);
}
Value Value::get(JSONCPP_STRING const& key, Value const& defaultValue) const {
Value Value::get(String const& key, Value const& defaultValue) const {
return get(key.data(), key.data() + key.length(), defaultValue);
}
@@ -1245,7 +1245,7 @@ bool Value::removeMember(const char* begin, const char* end, Value* removed) {
bool Value::removeMember(const char* key, Value* removed) {
return removeMember(key, key + strlen(key), removed);
}
bool Value::removeMember(JSONCPP_STRING const& key, Value* removed) {
bool Value::removeMember(String const& key, Value* removed) {
return removeMember(key.data(), key.data() + key.length(), removed);
}
void Value::removeMember(const char* key) {
@@ -1257,9 +1257,7 @@ void Value::removeMember(const char* key) {
CZString actualKey(key, unsigned(strlen(key)), CZString::noDuplication);
value_.map_->erase(actualKey);
}
void Value::removeMember(const JSONCPP_STRING& key) {
removeMember(key.c_str());
}
void Value::removeMember(const String& key) { removeMember(key.c_str()); }
bool Value::removeIndex(ArrayIndex index, Value* removed) {
if (type_ != arrayValue) {
@@ -1299,7 +1297,7 @@ bool Value::isMember(char const* begin, char const* end) const {
bool Value::isMember(char const* key) const {
return isMember(key, key + strlen(key));
}
bool Value::isMember(JSONCPP_STRING const& key) const {
bool Value::isMember(String const& key) const {
return isMember(key.data(), key.data() + key.length());
}
@@ -1320,7 +1318,7 @@ Value::Members Value::getMemberNames() const {
ObjectValues::const_iterator it = value_.map_->begin();
ObjectValues::const_iterator itEnd = value_.map_->end();
for (; it != itEnd; ++it) {
members.push_back(JSONCPP_STRING((*it).first.data(), (*it).first.length()));
members.push_back(String((*it).first.data(), (*it).first.length()));
}
return members;
}
@@ -1491,8 +1489,7 @@ void Value::setComment(const char* comment, CommentPlacement placement) {
setComment(comment, strlen(comment), placement);
}
void Value::setComment(const JSONCPP_STRING& comment,
CommentPlacement placement) {
void Value::setComment(const String& comment, CommentPlacement placement) {
setComment(comment.c_str(), comment.length(), placement);
}
@@ -1500,7 +1497,7 @@ bool Value::hasComment(CommentPlacement placement) const {
return comments_ != nullptr && comments_[placement].comment_ != nullptr;
}
JSONCPP_STRING Value::getComment(CommentPlacement placement) const {
String Value::getComment(CommentPlacement placement) const {
if (hasComment(placement))
return comments_[placement].comment_;
return "";
@@ -1514,10 +1511,10 @@ ptrdiff_t Value::getOffsetStart() const { return start_; }
ptrdiff_t Value::getOffsetLimit() const { return limit_; }
JSONCPP_STRING Value::toStyledString() const {
String Value::toStyledString() const {
StreamWriterBuilder builder;
JSONCPP_STRING out = this->hasComment(commentBefore) ? "\n" : "";
String out = this->hasComment(commentBefore) ? "\n" : "";
out += Json::writeString(builder, *this);
out += '\n';
@@ -1587,13 +1584,13 @@ PathArgument::PathArgument(ArrayIndex index)
PathArgument::PathArgument(const char* key)
: key_(key), index_(), kind_(kindKey) {}
PathArgument::PathArgument(const JSONCPP_STRING& key)
PathArgument::PathArgument(const String& key)
: key_(key.c_str()), index_(), kind_(kindKey) {}
// class Path
// //////////////////////////////////////////////////////////////////
Path::Path(const JSONCPP_STRING& path,
Path::Path(const String& path,
const PathArgument& a1,
const PathArgument& a2,
const PathArgument& a3,
@@ -1609,7 +1606,7 @@ Path::Path(const JSONCPP_STRING& path,
makePath(path, in);
}
void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
void Path::makePath(const String& path, const InArgs& in) {
const char* current = path.c_str();
const char* end = current + path.length();
auto itInArg = in.begin();
@@ -1635,12 +1632,12 @@ void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
const char* beginName = current;
while (current != end && !strchr("[.", *current))
++current;
args_.push_back(JSONCPP_STRING(beginName, current));
args_.push_back(String(beginName, current));
}
}
}
void Path::addPathInArg(const JSONCPP_STRING& /*path*/,
void Path::addPathInArg(const String& /*path*/,
const InArgs& in,
InArgs::const_iterator& itInArg,
PathArgument::Kind kind) {
@@ -1653,7 +1650,7 @@ void Path::addPathInArg(const JSONCPP_STRING& /*path*/,
}
}
void Path::invalidPath(const JSONCPP_STRING& /*path*/, int /*location*/) {
void Path::invalidPath(const String& /*path*/, int /*location*/) {
// Error: invalid path.
}

View File

@@ -84,13 +84,13 @@ UInt ValueIteratorBase::index() const {
return Value::UInt(-1);
}
JSONCPP_STRING ValueIteratorBase::name() const {
String ValueIteratorBase::name() const {
char const* keey;
char const* end;
keey = memberName(&end);
if (!keey)
return JSONCPP_STRING();
return JSONCPP_STRING(keey, end);
return String();
return String(keey, end);
}
char const* ValueIteratorBase::memberName() const {

View File

@@ -89,7 +89,7 @@ typedef std::unique_ptr<StreamWriter> StreamWriterPtr;
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
#endif
JSONCPP_STRING valueToString(LargestInt value) {
String valueToString(LargestInt value) {
UIntToStringBuffer buffer;
char* current = buffer + sizeof(buffer);
if (value == Value::minLargestInt) {
@@ -105,7 +105,7 @@ JSONCPP_STRING valueToString(LargestInt value) {
return current;
}
JSONCPP_STRING valueToString(LargestUInt value) {
String valueToString(LargestUInt value) {
UIntToStringBuffer buffer;
char* current = buffer + sizeof(buffer);
uintToString(value, current);
@@ -115,21 +115,17 @@ JSONCPP_STRING valueToString(LargestUInt value) {
#if defined(JSON_HAS_INT64)
JSONCPP_STRING valueToString(Int value) {
return valueToString(LargestInt(value));
}
String valueToString(Int value) { return valueToString(LargestInt(value)); }
JSONCPP_STRING valueToString(UInt value) {
return valueToString(LargestUInt(value));
}
String valueToString(UInt value) { return valueToString(LargestUInt(value)); }
#endif // # if defined(JSON_HAS_INT64)
namespace {
JSONCPP_STRING valueToString(double value,
bool useSpecialFloats,
unsigned int precision,
PrecisionType precisionType) {
String valueToString(double value,
bool useSpecialFloats,
unsigned int precision,
PrecisionType precisionType) {
// Print into the buffer. We need not request the alternative representation
// that always has a decimal point because JSON doesn't distinguish the
// concepts of reals and integers.
@@ -140,7 +136,7 @@ JSONCPP_STRING valueToString(double value,
[isnan(value) ? 0 : (value < 0) ? 1 : 2];
}
JSONCPP_STRING buffer(size_t(36), '\0');
String buffer(size_t(36), '\0');
while (true) {
int len = jsoncpp_snprintf(
&*buffer.begin(), buffer.size(),
@@ -172,13 +168,13 @@ JSONCPP_STRING valueToString(double value,
}
} // namespace
JSONCPP_STRING valueToString(double value,
unsigned int precision,
PrecisionType precisionType) {
String valueToString(double value,
unsigned int precision,
PrecisionType precisionType) {
return valueToString(value, false, precision, precisionType);
}
JSONCPP_STRING valueToString(bool value) { return value ? "true" : "false"; }
String valueToString(bool value) { return value ? "true" : "false"; }
static bool isAnyCharRequiredQuoting(char const* s, size_t n) {
assert(s || !n);
@@ -260,10 +256,10 @@ static const char hex2[] = "000102030405060708090a0b0c0d0e0f"
"e0e1e2e3e4e5e6e7e8e9eaebecedeeef"
"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
static JSONCPP_STRING toHex16Bit(unsigned int x) {
static String toHex16Bit(unsigned int x) {
const unsigned int hi = (x >> 8) & 0xff;
const unsigned int lo = x & 0xff;
JSONCPP_STRING result(4, ' ');
String result(4, ' ');
result[0] = hex2[2 * hi];
result[1] = hex2[2 * hi + 1];
result[2] = hex2[2 * lo];
@@ -271,17 +267,17 @@ static JSONCPP_STRING toHex16Bit(unsigned int x) {
return result;
}
static JSONCPP_STRING valueToQuotedStringN(const char* value, unsigned length) {
static String valueToQuotedStringN(const char* value, unsigned length) {
if (value == nullptr)
return "";
if (!isAnyCharRequiredQuoting(value, length))
return JSONCPP_STRING("\"") + value + "\"";
return String("\"") + value + "\"";
// We have to walk value and escape any special characters.
// Appending to JSONCPP_STRING is not efficient, but this should be rare.
// Appending to String is not efficient, but this should be rare.
// (Note: forward slashes are *not* rare, but I am not escaping them.)
JSONCPP_STRING::size_type maxsize = length * 2 + 3; // allescaped+quotes+NULL
JSONCPP_STRING result;
String::size_type maxsize = length * 2 + 3; // allescaped+quotes+NULL
String result;
result.reserve(maxsize); // to avoid lots of mallocs
result += "\"";
char const* end = value + length;
@@ -340,7 +336,7 @@ static JSONCPP_STRING valueToQuotedStringN(const char* value, unsigned length) {
return result;
}
JSONCPP_STRING valueToQuotedString(const char* value) {
String valueToQuotedString(const char* value) {
return valueToQuotedStringN(value, static_cast<unsigned int>(strlen(value)));
}
@@ -361,7 +357,7 @@ void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }
void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
JSONCPP_STRING FastWriter::write(const Value& root) {
String FastWriter::write(const Value& root) {
document_.clear();
writeValue(root);
if (!omitEndingLineFeed_)
@@ -410,7 +406,7 @@ void FastWriter::writeValue(const Value& value) {
Value::Members members(value.getMemberNames());
document_ += '{';
for (auto it = members.begin(); it != members.end(); ++it) {
const JSONCPP_STRING& name = *it;
const String& name = *it;
if (it != members.begin())
document_ += ',';
document_ += valueToQuotedStringN(name.data(),
@@ -428,7 +424,7 @@ void FastWriter::writeValue(const Value& value) {
StyledWriter::StyledWriter() = default;
JSONCPP_STRING StyledWriter::write(const Value& root) {
String StyledWriter::write(const Value& root) {
document_.clear();
addChildValues_ = false;
indentString_.clear();
@@ -479,7 +475,7 @@ void StyledWriter::writeValue(const Value& value) {
indent();
auto it = members.begin();
for (;;) {
const JSONCPP_STRING& name = *it;
const String& name = *it;
const Value& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedString(name.c_str()));
@@ -569,7 +565,7 @@ bool StyledWriter::isMultilineArray(const Value& value) {
return isMultiLine;
}
void StyledWriter::pushValue(const JSONCPP_STRING& value) {
void StyledWriter::pushValue(const String& value) {
if (addChildValues_)
childValues_.push_back(value);
else
@@ -587,14 +583,12 @@ void StyledWriter::writeIndent() {
document_ += indentString_;
}
void StyledWriter::writeWithIndent(const JSONCPP_STRING& value) {
void StyledWriter::writeWithIndent(const String& value) {
writeIndent();
document_ += value;
}
void StyledWriter::indent() {
indentString_ += JSONCPP_STRING(indentSize_, ' ');
}
void StyledWriter::indent() { indentString_ += String(indentSize_, ' '); }
void StyledWriter::unindent() {
assert(indentString_.size() >= indentSize_);
@@ -607,8 +601,8 @@ void StyledWriter::writeCommentBeforeValue(const Value& root) {
document_ += '\n';
writeIndent();
const JSONCPP_STRING& comment = root.getComment(commentBefore);
JSONCPP_STRING::const_iterator iter = comment.begin();
const String& comment = root.getComment(commentBefore);
String::const_iterator iter = comment.begin();
while (iter != comment.end()) {
document_ += *iter;
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
@@ -640,11 +634,11 @@ bool StyledWriter::hasCommentForValue(const Value& value) {
// Class StyledStreamWriter
// //////////////////////////////////////////////////////////////////
StyledStreamWriter::StyledStreamWriter(JSONCPP_STRING indentation)
StyledStreamWriter::StyledStreamWriter(String indentation)
: document_(nullptr), indentation_(std::move(indentation)),
addChildValues_(), indented_(false) {}
void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) {
void StyledStreamWriter::write(OStream& out, const Value& root) {
document_ = &out;
addChildValues_ = false;
indentString_.clear();
@@ -699,7 +693,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
indent();
auto it = members.begin();
for (;;) {
const JSONCPP_STRING& name = *it;
const String& name = *it;
const Value& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedString(name.c_str()));
@@ -792,7 +786,7 @@ bool StyledStreamWriter::isMultilineArray(const Value& value) {
return isMultiLine;
}
void StyledStreamWriter::pushValue(const JSONCPP_STRING& value) {
void StyledStreamWriter::pushValue(const String& value) {
if (addChildValues_)
childValues_.push_back(value);
else
@@ -807,7 +801,7 @@ void StyledStreamWriter::writeIndent() {
*document_ << '\n' << indentString_;
}
void StyledStreamWriter::writeWithIndent(const JSONCPP_STRING& value) {
void StyledStreamWriter::writeWithIndent(const String& value) {
if (!indented_)
writeIndent();
*document_ << value;
@@ -827,8 +821,8 @@ void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
if (!indented_)
writeIndent();
const JSONCPP_STRING& comment = root.getComment(commentBefore);
JSONCPP_STRING::const_iterator iter = comment.begin();
const String& comment = root.getComment(commentBefore);
String::const_iterator iter = comment.begin();
while (iter != comment.end()) {
*document_ << *iter;
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
@@ -870,61 +864,60 @@ struct CommentStyle {
};
struct BuiltStyledStreamWriter : public StreamWriter {
BuiltStyledStreamWriter(JSONCPP_STRING indentation,
BuiltStyledStreamWriter(String indentation,
CommentStyle::Enum cs,
JSONCPP_STRING colonSymbol,
JSONCPP_STRING nullSymbol,
JSONCPP_STRING endingLineFeedSymbol,
String colonSymbol,
String nullSymbol,
String endingLineFeedSymbol,
bool useSpecialFloats,
unsigned int precision,
PrecisionType precisionType);
int write(Value const& root, JSONCPP_OSTREAM* sout) override;
int write(Value const& root, OStream* sout) override;
private:
void writeValue(Value const& value);
void writeArrayValue(Value const& value);
bool isMultilineArray(Value const& value);
void pushValue(JSONCPP_STRING const& value);
void pushValue(String const& value);
void writeIndent();
void writeWithIndent(JSONCPP_STRING const& value);
void writeWithIndent(String const& value);
void indent();
void unindent();
void writeCommentBeforeValue(Value const& root);
void writeCommentAfterValueOnSameLine(Value const& root);
static bool hasCommentForValue(const Value& value);
typedef std::vector<JSONCPP_STRING> ChildValues;
typedef std::vector<String> ChildValues;
ChildValues childValues_;
JSONCPP_STRING indentString_;
String indentString_;
unsigned int rightMargin_;
JSONCPP_STRING indentation_;
String indentation_;
CommentStyle::Enum cs_;
JSONCPP_STRING colonSymbol_;
JSONCPP_STRING nullSymbol_;
JSONCPP_STRING endingLineFeedSymbol_;
String colonSymbol_;
String nullSymbol_;
String endingLineFeedSymbol_;
bool addChildValues_ : 1;
bool indented_ : 1;
bool useSpecialFloats_ : 1;
unsigned int precision_;
PrecisionType precisionType_;
};
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
JSONCPP_STRING indentation,
CommentStyle::Enum cs,
JSONCPP_STRING colonSymbol,
JSONCPP_STRING nullSymbol,
JSONCPP_STRING endingLineFeedSymbol,
bool useSpecialFloats,
unsigned int precision,
PrecisionType precisionType)
BuiltStyledStreamWriter::BuiltStyledStreamWriter(String indentation,
CommentStyle::Enum cs,
String colonSymbol,
String nullSymbol,
String endingLineFeedSymbol,
bool useSpecialFloats,
unsigned int precision,
PrecisionType precisionType)
: rightMargin_(74), indentation_(std::move(indentation)), cs_(cs),
colonSymbol_(std::move(colonSymbol)), nullSymbol_(std::move(nullSymbol)),
endingLineFeedSymbol_(std::move(endingLineFeedSymbol)),
addChildValues_(false), indented_(false),
useSpecialFloats_(useSpecialFloats), precision_(precision),
precisionType_(precisionType) {}
int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout) {
int BuiltStyledStreamWriter::write(Value const& root, OStream* sout) {
sout_ = sout;
addChildValues_ = false;
indented_ = true;
@@ -980,7 +973,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
indent();
auto it = members.begin();
for (;;) {
JSONCPP_STRING const& name = *it;
String const& name = *it;
Value const& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedStringN(
@@ -1078,7 +1071,7 @@ bool BuiltStyledStreamWriter::isMultilineArray(Value const& value) {
return isMultiLine;
}
void BuiltStyledStreamWriter::pushValue(JSONCPP_STRING const& value) {
void BuiltStyledStreamWriter::pushValue(String const& value) {
if (addChildValues_)
childValues_.push_back(value);
else
@@ -1097,7 +1090,7 @@ void BuiltStyledStreamWriter::writeIndent() {
}
}
void BuiltStyledStreamWriter::writeWithIndent(JSONCPP_STRING const& value) {
void BuiltStyledStreamWriter::writeWithIndent(String const& value) {
if (!indented_)
writeIndent();
*sout_ << value;
@@ -1119,8 +1112,8 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
if (!indented_)
writeIndent();
const JSONCPP_STRING& comment = root.getComment(commentBefore);
JSONCPP_STRING::const_iterator iter = comment.begin();
const String& comment = root.getComment(commentBefore);
String::const_iterator iter = comment.begin();
while (iter != comment.end()) {
*sout_ << *iter;
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
@@ -1160,9 +1153,9 @@ StreamWriter::Factory::~Factory() = default;
StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); }
StreamWriterBuilder::~StreamWriterBuilder() = default;
StreamWriter* StreamWriterBuilder::newStreamWriter() const {
JSONCPP_STRING indentation = settings_["indentation"].asString();
JSONCPP_STRING cs_str = settings_["commentStyle"].asString();
JSONCPP_STRING pt_str = settings_["precisionType"].asString();
String indentation = settings_["indentation"].asString();
String cs_str = settings_["commentStyle"].asString();
String pt_str = settings_["precisionType"].asString();
bool eyc = settings_["enableYAMLCompatibility"].asBool();
bool dnp = settings_["dropNullPlaceholders"].asBool();
bool usf = settings_["useSpecialFloats"].asBool();
@@ -1183,24 +1176,24 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const {
} else {
throwRuntimeError("precisionType must be 'significant' or 'decimal'");
}
JSONCPP_STRING colonSymbol = " : ";
String colonSymbol = " : ";
if (eyc) {
colonSymbol = ": ";
} else if (indentation.empty()) {
colonSymbol = ":";
}
JSONCPP_STRING nullSymbol = "null";
String nullSymbol = "null";
if (dnp) {
nullSymbol.clear();
}
if (pre > 17)
pre = 17;
JSONCPP_STRING endingLineFeedSymbol;
String endingLineFeedSymbol;
return new BuiltStyledStreamWriter(indentation, cs, colonSymbol, nullSymbol,
endingLineFeedSymbol, usf, pre,
precisionType);
}
static void getValidWriterKeys(std::set<JSONCPP_STRING>* valid_keys) {
static void getValidWriterKeys(std::set<String>* valid_keys) {
valid_keys->clear();
valid_keys->insert("indentation");
valid_keys->insert("commentStyle");
@@ -1215,19 +1208,19 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const {
if (!invalid)
invalid = &my_invalid; // so we do not need to test for NULL
Json::Value& inv = *invalid;
std::set<JSONCPP_STRING> valid_keys;
std::set<String> valid_keys;
getValidWriterKeys(&valid_keys);
Value::Members keys = settings_.getMemberNames();
size_t n = keys.size();
for (size_t i = 0; i < n; ++i) {
JSONCPP_STRING const& key = keys[i];
String const& key = keys[i];
if (valid_keys.find(key) == valid_keys.end()) {
inv[key] = settings_[key];
}
}
return inv.empty();
}
Value& StreamWriterBuilder::operator[](const JSONCPP_STRING& key) {
Value& StreamWriterBuilder::operator[](const String& key) {
return settings_[key];
}
// static
@@ -1243,15 +1236,14 @@ void StreamWriterBuilder::setDefaults(Json::Value* settings) {
//! [StreamWriterBuilderDefaults]
}
JSONCPP_STRING writeString(StreamWriter::Factory const& factory,
Value const& root) {
JSONCPP_OSTRINGSTREAM sout;
String writeString(StreamWriter::Factory const& factory, Value const& root) {
OStringStream sout;
StreamWriterPtr const writer(factory.newStreamWriter());
writer->write(root, &sout);
return sout.str();
}
JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM& sout, Value const& root) {
OStream& operator<<(OStream& sout, Value const& root) {
StreamWriterBuilder builder;
StreamWriterPtr const writer(builder.newStreamWriter());
writer->write(root, &sout);