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

@@ -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.
}