mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-14 23:07:55 +02:00
Enabled PointerBindsToType in clang-format options.
This commit is contained in:
@@ -42,15 +42,15 @@ static std::string normalizeFloatingPointStr(double value) {
|
||||
return s;
|
||||
}
|
||||
|
||||
static std::string readInputTestFile(const char *path) {
|
||||
FILE *file = fopen(path, "rb");
|
||||
static std::string readInputTestFile(const char* path) {
|
||||
FILE* file = fopen(path, "rb");
|
||||
if (!file)
|
||||
return std::string("");
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
std::string text;
|
||||
char *buffer = new char[size + 1];
|
||||
char* buffer = new char[size + 1];
|
||||
buffer[size] = 0;
|
||||
if (fread(buffer, 1, size, file) == (unsigned long)size)
|
||||
text = buffer;
|
||||
@@ -60,7 +60,7 @@ static std::string readInputTestFile(const char *path) {
|
||||
}
|
||||
|
||||
static void
|
||||
printValueTree(FILE *fout, Json::Value &value, const std::string &path = ".") {
|
||||
printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
|
||||
switch (value.type()) {
|
||||
case Json::nullValue:
|
||||
fprintf(fout, "%s=null\n", path.c_str());
|
||||
@@ -110,7 +110,7 @@ printValueTree(FILE *fout, Json::Value &value, const std::string &path = ".") {
|
||||
for (Json::Value::Members::iterator it = members.begin();
|
||||
it != members.end();
|
||||
++it) {
|
||||
const std::string &name = *it;
|
||||
const std::string& name = *it;
|
||||
printValueTree(fout, value[name], path + suffix + name);
|
||||
}
|
||||
} break;
|
||||
@@ -119,11 +119,11 @@ printValueTree(FILE *fout, Json::Value &value, const std::string &path = ".") {
|
||||
}
|
||||
}
|
||||
|
||||
static int parseAndSaveValueTree(const std::string &input,
|
||||
const std::string &actual,
|
||||
const std::string &kind,
|
||||
Json::Value &root,
|
||||
const Json::Features &features,
|
||||
static int parseAndSaveValueTree(const std::string& input,
|
||||
const std::string& actual,
|
||||
const std::string& kind,
|
||||
Json::Value& root,
|
||||
const Json::Features& features,
|
||||
bool parseOnly) {
|
||||
Json::Reader reader(features);
|
||||
bool parsingSuccessful = reader.parse(input, root);
|
||||
@@ -135,7 +135,7 @@ static int parseAndSaveValueTree(const std::string &input,
|
||||
}
|
||||
|
||||
if (!parseOnly) {
|
||||
FILE *factual = fopen(actual.c_str(), "wt");
|
||||
FILE* factual = fopen(actual.c_str(), "wt");
|
||||
if (!factual) {
|
||||
printf("Failed to create %s actual file.\n", kind.c_str());
|
||||
return 2;
|
||||
@@ -146,14 +146,14 @@ static int parseAndSaveValueTree(const std::string &input,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rewriteValueTree(const std::string &rewritePath,
|
||||
const Json::Value &root,
|
||||
std::string &rewrite) {
|
||||
static int rewriteValueTree(const std::string& rewritePath,
|
||||
const Json::Value& root,
|
||||
std::string& rewrite) {
|
||||
// Json::FastWriter writer;
|
||||
// writer.enableYAMLCompatibility();
|
||||
Json::StyledWriter writer;
|
||||
rewrite = writer.write(root);
|
||||
FILE *fout = fopen(rewritePath.c_str(), "wt");
|
||||
FILE* fout = fopen(rewritePath.c_str(), "wt");
|
||||
if (!fout) {
|
||||
printf("Failed to create rewrite file: %s\n", rewritePath.c_str());
|
||||
return 2;
|
||||
@@ -163,8 +163,8 @@ static int rewriteValueTree(const std::string &rewritePath,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::string removeSuffix(const std::string &path,
|
||||
const std::string &extension) {
|
||||
static std::string removeSuffix(const std::string& path,
|
||||
const std::string& extension) {
|
||||
if (extension.length() >= path.length())
|
||||
return std::string("");
|
||||
std::string suffix = path.substr(path.length() - extension.length());
|
||||
@@ -182,16 +182,16 @@ static void printConfig() {
|
||||
#endif
|
||||
}
|
||||
|
||||
static int printUsage(const char *argv[]) {
|
||||
static int printUsage(const char* argv[]) {
|
||||
printf("Usage: %s [--strict] input-json-file", argv[0]);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int parseCommandLine(int argc,
|
||||
const char *argv[],
|
||||
Json::Features &features,
|
||||
std::string &path,
|
||||
bool &parseOnly) {
|
||||
const char* argv[],
|
||||
Json::Features& features,
|
||||
std::string& path,
|
||||
bool& parseOnly) {
|
||||
parseOnly = false;
|
||||
if (argc < 2) {
|
||||
return printUsage(argv);
|
||||
@@ -217,7 +217,7 @@ int parseCommandLine(int argc,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
std::string path;
|
||||
Json::Features features;
|
||||
bool parseOnly;
|
||||
@@ -261,7 +261,7 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
catch (const std::exception& e) {
|
||||
printf("Unhandled exception:\n%s\n", e.what());
|
||||
exitCode = 1;
|
||||
}
|
||||
|
@@ -33,16 +33,16 @@ public:
|
||||
// printf( "Size: %d => %s\n", sizeof(AllocatedType),
|
||||
// typeid(AllocatedType).name() );
|
||||
assert(sizeof(AllocatedType) * objectPerAllocation >=
|
||||
sizeof(AllocatedType *)); // We must be able to store a slist in the
|
||||
// object free space.
|
||||
sizeof(AllocatedType*)); // We must be able to store a slist in the
|
||||
// object free space.
|
||||
assert(objectsPerPage >= 16);
|
||||
batches_ = allocateBatch(0); // allocated a dummy page
|
||||
currentBatch_ = batches_;
|
||||
}
|
||||
|
||||
~BatchAllocator() {
|
||||
for (BatchInfo *batch = batches_; batch;) {
|
||||
BatchInfo *nextBatch = batch->next_;
|
||||
for (BatchInfo* batch = batches_; batch;) {
|
||||
BatchInfo* nextBatch = batch->next_;
|
||||
free(batch);
|
||||
batch = nextBatch;
|
||||
}
|
||||
@@ -51,11 +51,11 @@ public:
|
||||
/// allocate space for an array of objectPerAllocation object.
|
||||
/// @warning it is the responsability of the caller to call objects
|
||||
/// constructors.
|
||||
AllocatedType *allocate() {
|
||||
AllocatedType* allocate() {
|
||||
if (freeHead_) // returns node from free list.
|
||||
{
|
||||
AllocatedType *object = freeHead_;
|
||||
freeHead_ = *(AllocatedType **)object;
|
||||
AllocatedType* object = freeHead_;
|
||||
freeHead_ = *(AllocatedType**)object;
|
||||
return object;
|
||||
}
|
||||
if (currentBatch_->used_ == currentBatch_->end_) {
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
batches_ = currentBatch_;
|
||||
}
|
||||
}
|
||||
AllocatedType *allocated = currentBatch_->used_;
|
||||
AllocatedType* allocated = currentBatch_->used_;
|
||||
currentBatch_->used_ += objectPerAllocation;
|
||||
return allocated;
|
||||
}
|
||||
@@ -78,39 +78,39 @@ public:
|
||||
/// Release the object.
|
||||
/// @warning it is the responsability of the caller to actually destruct the
|
||||
/// object.
|
||||
void release(AllocatedType *object) {
|
||||
void release(AllocatedType* object) {
|
||||
assert(object != 0);
|
||||
*(AllocatedType **)object = freeHead_;
|
||||
*(AllocatedType**)object = freeHead_;
|
||||
freeHead_ = object;
|
||||
}
|
||||
|
||||
private:
|
||||
struct BatchInfo {
|
||||
BatchInfo *next_;
|
||||
AllocatedType *used_;
|
||||
AllocatedType *end_;
|
||||
BatchInfo* next_;
|
||||
AllocatedType* used_;
|
||||
AllocatedType* end_;
|
||||
AllocatedType buffer_[objectPerAllocation];
|
||||
};
|
||||
|
||||
// disabled copy constructor and assignement operator.
|
||||
BatchAllocator(const BatchAllocator &);
|
||||
void operator=(const BatchAllocator &);
|
||||
BatchAllocator(const BatchAllocator&);
|
||||
void operator=(const BatchAllocator&);
|
||||
|
||||
static BatchInfo *allocateBatch(unsigned int objectsPerPage) {
|
||||
static BatchInfo* allocateBatch(unsigned int objectsPerPage) {
|
||||
const unsigned int mallocSize =
|
||||
sizeof(BatchInfo) - sizeof(AllocatedType) * objectPerAllocation +
|
||||
sizeof(AllocatedType) * objectPerAllocation * objectsPerPage;
|
||||
BatchInfo *batch = static_cast<BatchInfo *>(malloc(mallocSize));
|
||||
BatchInfo* batch = static_cast<BatchInfo*>(malloc(mallocSize));
|
||||
batch->next_ = 0;
|
||||
batch->used_ = batch->buffer_;
|
||||
batch->end_ = batch->buffer_ + objectsPerPage;
|
||||
return batch;
|
||||
}
|
||||
|
||||
BatchInfo *batches_;
|
||||
BatchInfo *currentBatch_;
|
||||
BatchInfo* batches_;
|
||||
BatchInfo* currentBatch_;
|
||||
/// Head of a single linked list within the allocated space of freeed object
|
||||
AllocatedType *freeHead_;
|
||||
AllocatedType* freeHead_;
|
||||
unsigned int objectsPerPage_;
|
||||
};
|
||||
|
||||
|
@@ -75,20 +75,20 @@ Reader::Reader()
|
||||
lastValue_(), commentsBefore_(), features_(Features::all()),
|
||||
collectComments_() {}
|
||||
|
||||
Reader::Reader(const Features &features)
|
||||
Reader::Reader(const Features& features)
|
||||
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
|
||||
lastValue_(), commentsBefore_(), features_(features), collectComments_() {
|
||||
}
|
||||
|
||||
bool
|
||||
Reader::parse(const std::string &document, Value &root, bool collectComments) {
|
||||
Reader::parse(const std::string& document, Value& root, bool collectComments) {
|
||||
document_ = document;
|
||||
const char *begin = document_.c_str();
|
||||
const char *end = begin + document_.length();
|
||||
const char* begin = document_.c_str();
|
||||
const char* end = begin + document_.length();
|
||||
return parse(begin, end, root, collectComments);
|
||||
}
|
||||
|
||||
bool Reader::parse(std::istream &sin, Value &root, bool collectComments) {
|
||||
bool Reader::parse(std::istream& sin, Value& root, bool collectComments) {
|
||||
// std::istream_iterator<char> begin(sin);
|
||||
// std::istream_iterator<char> end;
|
||||
// Those would allow streamed input from a file, if parse() were a
|
||||
@@ -101,9 +101,9 @@ bool Reader::parse(std::istream &sin, Value &root, bool collectComments) {
|
||||
return parse(doc, root, collectComments);
|
||||
}
|
||||
|
||||
bool Reader::parse(const char *beginDoc,
|
||||
const char *endDoc,
|
||||
Value &root,
|
||||
bool Reader::parse(const char* beginDoc,
|
||||
const char* endDoc,
|
||||
Value& root,
|
||||
bool collectComments) {
|
||||
if (!features_.allowComments_) {
|
||||
collectComments = false;
|
||||
@@ -215,7 +215,7 @@ bool Reader::readValue() {
|
||||
return successful;
|
||||
}
|
||||
|
||||
void Reader::skipCommentTokens(Token &token) {
|
||||
void Reader::skipCommentTokens(Token& token) {
|
||||
if (features_.allowComments_) {
|
||||
do {
|
||||
readToken(token);
|
||||
@@ -225,14 +225,14 @@ void Reader::skipCommentTokens(Token &token) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Reader::expectToken(TokenType type, Token &token, const char *message) {
|
||||
bool Reader::expectToken(TokenType type, Token& token, const char* message) {
|
||||
readToken(token);
|
||||
if (token.type_ != type)
|
||||
return addError(message, token);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::readToken(Token &token) {
|
||||
bool Reader::readToken(Token& token) {
|
||||
skipSpaces();
|
||||
token.start_ = current_;
|
||||
Char c = getNextChar();
|
||||
@@ -399,7 +399,7 @@ bool Reader::readString() {
|
||||
return c == '"';
|
||||
}
|
||||
|
||||
bool Reader::readObject(Token &tokenStart) {
|
||||
bool Reader::readObject(Token& tokenStart) {
|
||||
Token tokenName;
|
||||
std::string name;
|
||||
currentValue() = Value(objectValue);
|
||||
@@ -430,7 +430,7 @@ bool Reader::readObject(Token &tokenStart) {
|
||||
return addErrorAndRecover(
|
||||
"Missing ':' after object member name", colon, tokenObjectEnd);
|
||||
}
|
||||
Value &value = currentValue()[name];
|
||||
Value& value = currentValue()[name];
|
||||
nodes_.push(&value);
|
||||
bool ok = readValue();
|
||||
nodes_.pop();
|
||||
@@ -454,7 +454,7 @@ bool Reader::readObject(Token &tokenStart) {
|
||||
"Missing '}' or object member name", tokenName, tokenObjectEnd);
|
||||
}
|
||||
|
||||
bool Reader::readArray(Token &tokenStart) {
|
||||
bool Reader::readArray(Token& tokenStart) {
|
||||
currentValue() = Value(arrayValue);
|
||||
currentValue().setOffsetStart(tokenStart.start_ - begin_);
|
||||
skipSpaces();
|
||||
@@ -466,7 +466,7 @@ bool Reader::readArray(Token &tokenStart) {
|
||||
}
|
||||
int index = 0;
|
||||
for (;;) {
|
||||
Value &value = currentValue()[index++];
|
||||
Value& value = currentValue()[index++];
|
||||
nodes_.push(&value);
|
||||
bool ok = readValue();
|
||||
nodes_.pop();
|
||||
@@ -491,7 +491,7 @@ bool Reader::readArray(Token &tokenStart) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeNumber(Token &token) {
|
||||
bool Reader::decodeNumber(Token& token) {
|
||||
Value decoded;
|
||||
if (!decodeNumber(token, decoded))
|
||||
return false;
|
||||
@@ -501,7 +501,7 @@ bool Reader::decodeNumber(Token &token) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeNumber(Token &token, Value &decoded) {
|
||||
bool Reader::decodeNumber(Token& token, Value& decoded) {
|
||||
bool isDouble = false;
|
||||
for (Location inspect = token.start_; inspect != token.end_; ++inspect) {
|
||||
isDouble = isDouble || in(*inspect, '.', 'e', 'E', '+') ||
|
||||
@@ -549,7 +549,7 @@ bool Reader::decodeNumber(Token &token, Value &decoded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeDouble(Token &token) {
|
||||
bool Reader::decodeDouble(Token& token) {
|
||||
Value decoded;
|
||||
if (!decodeDouble(token, decoded))
|
||||
return false;
|
||||
@@ -559,7 +559,7 @@ bool Reader::decodeDouble(Token &token) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeDouble(Token &token, Value &decoded) {
|
||||
bool Reader::decodeDouble(Token& token, Value& decoded) {
|
||||
double value = 0;
|
||||
const int bufferSize = 32;
|
||||
int count;
|
||||
@@ -595,7 +595,7 @@ bool Reader::decodeDouble(Token &token, Value &decoded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeString(Token &token) {
|
||||
bool Reader::decodeString(Token& token) {
|
||||
std::string decoded;
|
||||
if (!decodeString(token, decoded))
|
||||
return false;
|
||||
@@ -605,7 +605,7 @@ bool Reader::decodeString(Token &token) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeString(Token &token, std::string &decoded) {
|
||||
bool Reader::decodeString(Token& token, std::string& decoded) {
|
||||
decoded.reserve(token.end_ - token.start_ - 2);
|
||||
Location current = token.start_ + 1; // skip '"'
|
||||
Location end = token.end_ - 1; // do not include '"'
|
||||
@@ -658,10 +658,10 @@ bool Reader::decodeString(Token &token, std::string &decoded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeUnicodeCodePoint(Token &token,
|
||||
Location ¤t,
|
||||
bool Reader::decodeUnicodeCodePoint(Token& token,
|
||||
Location& current,
|
||||
Location end,
|
||||
unsigned int &unicode) {
|
||||
unsigned int& unicode) {
|
||||
|
||||
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
|
||||
return false;
|
||||
@@ -687,10 +687,10 @@ bool Reader::decodeUnicodeCodePoint(Token &token,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeUnicodeEscapeSequence(Token &token,
|
||||
Location ¤t,
|
||||
bool Reader::decodeUnicodeEscapeSequence(Token& token,
|
||||
Location& current,
|
||||
Location end,
|
||||
unsigned int &unicode) {
|
||||
unsigned int& unicode) {
|
||||
if (end - current < 4)
|
||||
return addError(
|
||||
"Bad unicode escape sequence in string: four digits expected.",
|
||||
@@ -716,7 +716,7 @@ bool Reader::decodeUnicodeEscapeSequence(Token &token,
|
||||
}
|
||||
|
||||
bool
|
||||
Reader::addError(const std::string &message, Token &token, Location extra) {
|
||||
Reader::addError(const std::string& message, Token& token, Location extra) {
|
||||
ErrorInfo info;
|
||||
info.token_ = token;
|
||||
info.message_ = message;
|
||||
@@ -738,14 +738,14 @@ bool Reader::recoverFromError(TokenType skipUntilToken) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Reader::addErrorAndRecover(const std::string &message,
|
||||
Token &token,
|
||||
bool Reader::addErrorAndRecover(const std::string& message,
|
||||
Token& token,
|
||||
TokenType skipUntilToken) {
|
||||
addError(message, token);
|
||||
return recoverFromError(skipUntilToken);
|
||||
}
|
||||
|
||||
Value &Reader::currentValue() { return *(nodes_.top()); }
|
||||
Value& Reader::currentValue() { return *(nodes_.top()); }
|
||||
|
||||
Reader::Char Reader::getNextChar() {
|
||||
if (current_ == end_)
|
||||
@@ -754,8 +754,8 @@ Reader::Char Reader::getNextChar() {
|
||||
}
|
||||
|
||||
void Reader::getLocationLineAndColumn(Location location,
|
||||
int &line,
|
||||
int &column) const {
|
||||
int& line,
|
||||
int& column) const {
|
||||
Location current = begin_;
|
||||
Location lastLineStart = current;
|
||||
line = 0;
|
||||
@@ -802,7 +802,7 @@ std::string Reader::getFormattedErrorMessages() const {
|
||||
for (Errors::const_iterator itError = errors_.begin();
|
||||
itError != errors_.end();
|
||||
++itError) {
|
||||
const ErrorInfo &error = *itError;
|
||||
const ErrorInfo& error = *itError;
|
||||
formattedMessage +=
|
||||
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
||||
formattedMessage += " " + error.message_ + "\n";
|
||||
@@ -818,7 +818,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
|
||||
for (Errors::const_iterator itError = errors_.begin();
|
||||
itError != errors_.end();
|
||||
++itError) {
|
||||
const ErrorInfo &error = *itError;
|
||||
const ErrorInfo& error = *itError;
|
||||
Reader::StructuredError structured;
|
||||
structured.offset_start = error.token_.start_ - begin_;
|
||||
structured.offset_limit = error.token_.end_ - begin_;
|
||||
@@ -828,7 +828,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
|
||||
return allErrors;
|
||||
}
|
||||
|
||||
std::istream &operator>>(std::istream &sin, Value &root) {
|
||||
std::istream& operator>>(std::istream& sin, Value& root) {
|
||||
Json::Reader reader;
|
||||
bool ok = reader.parse(sin, root, true);
|
||||
if (!ok) {
|
||||
|
@@ -60,7 +60,7 @@ typedef char UIntToStringBuffer[uintToStringBufferSize];
|
||||
* @param current Input/Output string buffer.
|
||||
* Must have at least uintToStringBufferSize chars free.
|
||||
*/
|
||||
static inline void uintToString(LargestUInt value, char *¤t) {
|
||||
static inline void uintToString(LargestUInt value, char*& current) {
|
||||
*--current = 0;
|
||||
do {
|
||||
*--current = char(value % 10) + '0';
|
||||
@@ -73,7 +73,7 @@ static inline void uintToString(LargestUInt value, char *¤t) {
|
||||
* We had a sophisticated way, but it did not work in WinCE.
|
||||
* @see https://github.com/open-source-parsers/jsoncpp/pull/9
|
||||
*/
|
||||
static inline void fixNumericLocale(char *begin, char *end) {
|
||||
static inline void fixNumericLocale(char* begin, char* end) {
|
||||
while (begin < end) {
|
||||
if (*begin == ',') {
|
||||
*begin = '.';
|
||||
|
@@ -34,8 +34,8 @@ namespace Json {
|
||||
#define ALIGNAS(byte_alignment)
|
||||
#endif
|
||||
static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
|
||||
const unsigned char &kNullRef = kNull[0];
|
||||
const Value &Value::null = reinterpret_cast<const Value &>(kNullRef);
|
||||
const unsigned char& kNullRef = kNull[0];
|
||||
const Value& Value::null = reinterpret_cast<const Value&>(kNullRef);
|
||||
|
||||
const Int Value::minInt = Int(~(UInt(-1) / 2));
|
||||
const Int Value::maxInt = Int(UInt(-1) / 2);
|
||||
@@ -83,7 +83,7 @@ static inline bool InRange(double d, T min, U max) {
|
||||
* computed using strlen(value).
|
||||
* @return Pointer on the duplicate instance of string.
|
||||
*/
|
||||
static inline char *duplicateStringValue(const char *value,
|
||||
static inline char* duplicateStringValue(const char* value,
|
||||
unsigned int length = unknown) {
|
||||
if (length == unknown)
|
||||
length = (unsigned int)strlen(value);
|
||||
@@ -93,7 +93,7 @@ static inline char *duplicateStringValue(const char *value,
|
||||
if (length >= (unsigned)Value::maxInt)
|
||||
length = Value::maxInt - 1;
|
||||
|
||||
char *newString = static_cast<char *>(malloc(length + 1));
|
||||
char* newString = static_cast<char*>(malloc(length + 1));
|
||||
JSON_ASSERT_MESSAGE(newString != 0,
|
||||
"in Json::Value::duplicateStringValue(): "
|
||||
"Failed to allocate string value buffer");
|
||||
@@ -104,7 +104,7 @@ static inline char *duplicateStringValue(const char *value,
|
||||
|
||||
/** Free the string duplicated by duplicateStringValue().
|
||||
*/
|
||||
static inline void releaseStringValue(char *value) { free(value); }
|
||||
static inline void releaseStringValue(char* value) { free(value); }
|
||||
|
||||
} // namespace Json
|
||||
|
||||
@@ -141,7 +141,7 @@ Value::CommentInfo::~CommentInfo() {
|
||||
releaseStringValue(comment_);
|
||||
}
|
||||
|
||||
void Value::CommentInfo::setComment(const char *text) {
|
||||
void Value::CommentInfo::setComment(const char* text) {
|
||||
if (comment_)
|
||||
releaseStringValue(comment_);
|
||||
JSON_ASSERT(text != 0);
|
||||
@@ -166,11 +166,11 @@ void Value::CommentInfo::setComment(const char *text) {
|
||||
|
||||
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
|
||||
|
||||
Value::CZString::CZString(const char *cstr, DuplicationPolicy allocate)
|
||||
Value::CZString::CZString(const char* cstr, DuplicationPolicy allocate)
|
||||
: cstr_(allocate == duplicate ? duplicateStringValue(cstr) : cstr),
|
||||
index_(allocate) {}
|
||||
|
||||
Value::CZString::CZString(const CZString &other)
|
||||
Value::CZString::CZString(const CZString& other)
|
||||
: cstr_(other.index_ != noDuplication && other.cstr_ != 0
|
||||
? duplicateStringValue(other.cstr_)
|
||||
: other.cstr_),
|
||||
@@ -180,26 +180,26 @@ Value::CZString::CZString(const CZString &other)
|
||||
|
||||
Value::CZString::~CZString() {
|
||||
if (cstr_ && index_ == duplicate)
|
||||
releaseStringValue(const_cast<char *>(cstr_));
|
||||
releaseStringValue(const_cast<char*>(cstr_));
|
||||
}
|
||||
|
||||
void Value::CZString::swap(CZString &other) {
|
||||
void Value::CZString::swap(CZString& other) {
|
||||
std::swap(cstr_, other.cstr_);
|
||||
std::swap(index_, other.index_);
|
||||
}
|
||||
|
||||
Value::CZString &Value::CZString::operator=(CZString other) {
|
||||
Value::CZString& Value::CZString::operator=(CZString other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Value::CZString::operator<(const CZString &other) const {
|
||||
bool Value::CZString::operator<(const CZString& other) const {
|
||||
if (cstr_)
|
||||
return strcmp(cstr_, other.cstr_) < 0;
|
||||
return index_ < other.index_;
|
||||
}
|
||||
|
||||
bool Value::CZString::operator==(const CZString &other) const {
|
||||
bool Value::CZString::operator==(const CZString& other) const {
|
||||
if (cstr_)
|
||||
return strcmp(cstr_, other.cstr_) == 0;
|
||||
return index_ == other.index_;
|
||||
@@ -207,7 +207,7 @@ bool Value::CZString::operator==(const CZString &other) const {
|
||||
|
||||
ArrayIndex Value::CZString::index() const { return index_; }
|
||||
|
||||
const char *Value::CZString::c_str() const { return cstr_; }
|
||||
const char* Value::CZString::c_str() const { return cstr_; }
|
||||
|
||||
bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
|
||||
|
||||
@@ -324,7 +324,7 @@ Value::Value(double value)
|
||||
value_.real_ = value;
|
||||
}
|
||||
|
||||
Value::Value(const char *value)
|
||||
Value::Value(const char* value)
|
||||
: type_(stringValue), allocated_(true)
|
||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||
,
|
||||
@@ -335,7 +335,7 @@ Value::Value(const char *value)
|
||||
value_.string_ = duplicateStringValue(value);
|
||||
}
|
||||
|
||||
Value::Value(const char *beginValue, const char *endValue)
|
||||
Value::Value(const char* beginValue, const char* endValue)
|
||||
: type_(stringValue), allocated_(true)
|
||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||
,
|
||||
@@ -347,7 +347,7 @@ Value::Value(const char *beginValue, const char *endValue)
|
||||
duplicateStringValue(beginValue, (unsigned int)(endValue - beginValue));
|
||||
}
|
||||
|
||||
Value::Value(const std::string &value)
|
||||
Value::Value(const std::string& value)
|
||||
: type_(stringValue), allocated_(true)
|
||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||
,
|
||||
@@ -359,7 +359,7 @@ Value::Value(const std::string &value)
|
||||
duplicateStringValue(value.c_str(), (unsigned int)value.length());
|
||||
}
|
||||
|
||||
Value::Value(const StaticString &value)
|
||||
Value::Value(const StaticString& value)
|
||||
: type_(stringValue), allocated_(false)
|
||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||
,
|
||||
@@ -367,11 +367,11 @@ Value::Value(const StaticString &value)
|
||||
#endif
|
||||
,
|
||||
comments_(0), start_(0), limit_(0) {
|
||||
value_.string_ = const_cast<char *>(value.c_str());
|
||||
value_.string_ = const_cast<char*>(value.c_str());
|
||||
}
|
||||
|
||||
#ifdef JSON_USE_CPPTL
|
||||
Value::Value(const CppTL::ConstString &value)
|
||||
Value::Value(const CppTL::ConstString& value)
|
||||
: type_(stringValue), allocated_(true)
|
||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||
,
|
||||
@@ -394,7 +394,7 @@ Value::Value(bool value)
|
||||
value_.bool_ = value;
|
||||
}
|
||||
|
||||
Value::Value(const Value &other)
|
||||
Value::Value(const Value& other)
|
||||
: type_(other.type_), allocated_(false)
|
||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||
,
|
||||
@@ -438,7 +438,7 @@ Value::Value(const Value &other)
|
||||
if (other.comments_) {
|
||||
comments_ = new CommentInfo[numberOfCommentPlacement];
|
||||
for (int comment = 0; comment < numberOfCommentPlacement; ++comment) {
|
||||
const CommentInfo &otherComment = other.comments_[comment];
|
||||
const CommentInfo& otherComment = other.comments_[comment];
|
||||
if (otherComment.comment_)
|
||||
comments_[comment].setComment(otherComment.comment_);
|
||||
}
|
||||
@@ -478,12 +478,12 @@ Value::~Value() {
|
||||
delete[] comments_;
|
||||
}
|
||||
|
||||
Value &Value::operator=(Value other) {
|
||||
Value& Value::operator=(Value other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Value::swap(Value &other) {
|
||||
void Value::swap(Value& other) {
|
||||
ValueType temp = type_;
|
||||
type_ = other.type_;
|
||||
other.type_ = temp;
|
||||
@@ -497,7 +497,7 @@ void Value::swap(Value &other) {
|
||||
|
||||
ValueType Value::type() const { return type_; }
|
||||
|
||||
int Value::compare(const Value &other) const {
|
||||
int Value::compare(const Value& other) const {
|
||||
if (*this < other)
|
||||
return -1;
|
||||
if (*this > other)
|
||||
@@ -505,7 +505,7 @@ int Value::compare(const Value &other) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Value::operator<(const Value &other) const {
|
||||
bool Value::operator<(const Value& other) const {
|
||||
int typeDelta = type_ - other.type_;
|
||||
if (typeDelta)
|
||||
return typeDelta < 0 ? true : false;
|
||||
@@ -544,13 +544,13 @@ bool Value::operator<(const Value &other) const {
|
||||
return false; // unreachable
|
||||
}
|
||||
|
||||
bool Value::operator<=(const Value &other) const { return !(other < *this); }
|
||||
bool Value::operator<=(const Value& other) const { return !(other < *this); }
|
||||
|
||||
bool Value::operator>=(const Value &other) const { return !(*this < other); }
|
||||
bool Value::operator>=(const Value& other) const { return !(*this < other); }
|
||||
|
||||
bool Value::operator>(const Value &other) const { return other < *this; }
|
||||
bool Value::operator>(const Value& other) const { return other < *this; }
|
||||
|
||||
bool Value::operator==(const Value &other) const {
|
||||
bool Value::operator==(const Value& other) const {
|
||||
// if ( type_ != other.type_ )
|
||||
// GCC 2.95.3 says:
|
||||
// attempt to take address of bit-field structure member `Json::Value::type_'
|
||||
@@ -590,9 +590,9 @@ bool Value::operator==(const Value &other) const {
|
||||
return false; // unreachable
|
||||
}
|
||||
|
||||
bool Value::operator!=(const Value &other) const { return !(*this == other); }
|
||||
bool Value::operator!=(const Value& other) const { return !(*this == other); }
|
||||
|
||||
const char *Value::asCString() const {
|
||||
const char* Value::asCString() const {
|
||||
JSON_ASSERT_MESSAGE(type_ == stringValue,
|
||||
"in Json::Value::asCString(): requires stringValue");
|
||||
return value_.string_;
|
||||
@@ -910,7 +910,7 @@ void Value::resize(ArrayIndex newSize) {
|
||||
#endif
|
||||
}
|
||||
|
||||
Value &Value::operator[](ArrayIndex index) {
|
||||
Value& Value::operator[](ArrayIndex index) {
|
||||
JSON_ASSERT_MESSAGE(
|
||||
type_ == nullValue || type_ == arrayValue,
|
||||
"in Json::Value::operator[](ArrayIndex): requires arrayValue");
|
||||
@@ -930,14 +930,14 @@ Value &Value::operator[](ArrayIndex index) {
|
||||
#endif
|
||||
}
|
||||
|
||||
Value &Value::operator[](int index) {
|
||||
Value& Value::operator[](int index) {
|
||||
JSON_ASSERT_MESSAGE(
|
||||
index >= 0,
|
||||
"in Json::Value::operator[](int index): index cannot be negative");
|
||||
return (*this)[ArrayIndex(index)];
|
||||
}
|
||||
|
||||
const Value &Value::operator[](ArrayIndex index) const {
|
||||
const Value& Value::operator[](ArrayIndex index) const {
|
||||
JSON_ASSERT_MESSAGE(
|
||||
type_ == nullValue || type_ == arrayValue,
|
||||
"in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
|
||||
@@ -950,23 +950,23 @@ const Value &Value::operator[](ArrayIndex index) const {
|
||||
return null;
|
||||
return (*it).second;
|
||||
#else
|
||||
Value *value = value_.array_->find(index);
|
||||
Value* value = value_.array_->find(index);
|
||||
return value ? *value : null;
|
||||
#endif
|
||||
}
|
||||
|
||||
const Value &Value::operator[](int index) const {
|
||||
const Value& Value::operator[](int index) const {
|
||||
JSON_ASSERT_MESSAGE(
|
||||
index >= 0,
|
||||
"in Json::Value::operator[](int index) const: index cannot be negative");
|
||||
return (*this)[ArrayIndex(index)];
|
||||
}
|
||||
|
||||
Value &Value::operator[](const char *key) {
|
||||
Value& Value::operator[](const char* key) {
|
||||
return resolveReference(key, false);
|
||||
}
|
||||
|
||||
Value &Value::resolveReference(const char *key, bool isStatic) {
|
||||
Value& Value::resolveReference(const char* key, bool isStatic) {
|
||||
JSON_ASSERT_MESSAGE(
|
||||
type_ == nullValue || type_ == objectValue,
|
||||
"in Json::Value::resolveReference(): requires objectValue");
|
||||
@@ -981,21 +981,21 @@ Value &Value::resolveReference(const char *key, bool isStatic) {
|
||||
|
||||
ObjectValues::value_type defaultValue(actualKey, null);
|
||||
it = value_.map_->insert(it, defaultValue);
|
||||
Value &value = (*it).second;
|
||||
Value& value = (*it).second;
|
||||
return value;
|
||||
#else
|
||||
return value_.map_->resolveReference(key, isStatic);
|
||||
#endif
|
||||
}
|
||||
|
||||
Value Value::get(ArrayIndex index, const Value &defaultValue) const {
|
||||
const Value *value = &((*this)[index]);
|
||||
Value Value::get(ArrayIndex index, const Value& defaultValue) const {
|
||||
const Value* value = &((*this)[index]);
|
||||
return value == &null ? defaultValue : *value;
|
||||
}
|
||||
|
||||
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
|
||||
|
||||
const Value &Value::operator[](const char *key) const {
|
||||
const Value& Value::operator[](const char* key) const {
|
||||
JSON_ASSERT_MESSAGE(
|
||||
type_ == nullValue || type_ == objectValue,
|
||||
"in Json::Value::operator[](char const*)const: requires objectValue");
|
||||
@@ -1008,45 +1008,45 @@ const Value &Value::operator[](const char *key) const {
|
||||
return null;
|
||||
return (*it).second;
|
||||
#else
|
||||
const Value *value = value_.map_->find(key);
|
||||
const Value* value = value_.map_->find(key);
|
||||
return value ? *value : null;
|
||||
#endif
|
||||
}
|
||||
|
||||
Value &Value::operator[](const std::string &key) {
|
||||
Value& Value::operator[](const std::string& key) {
|
||||
return (*this)[key.c_str()];
|
||||
}
|
||||
|
||||
const Value &Value::operator[](const std::string &key) const {
|
||||
const Value& Value::operator[](const std::string& key) const {
|
||||
return (*this)[key.c_str()];
|
||||
}
|
||||
|
||||
Value &Value::operator[](const StaticString &key) {
|
||||
Value& Value::operator[](const StaticString& key) {
|
||||
return resolveReference(key, true);
|
||||
}
|
||||
|
||||
#ifdef JSON_USE_CPPTL
|
||||
Value &Value::operator[](const CppTL::ConstString &key) {
|
||||
Value& Value::operator[](const CppTL::ConstString& key) {
|
||||
return (*this)[key.c_str()];
|
||||
}
|
||||
|
||||
const Value &Value::operator[](const CppTL::ConstString &key) const {
|
||||
const Value& Value::operator[](const CppTL::ConstString& key) const {
|
||||
return (*this)[key.c_str()];
|
||||
}
|
||||
#endif
|
||||
|
||||
Value &Value::append(const Value &value) { return (*this)[size()] = value; }
|
||||
Value& Value::append(const Value& value) { return (*this)[size()] = value; }
|
||||
|
||||
Value Value::get(const char *key, const Value &defaultValue) const {
|
||||
const Value *value = &((*this)[key]);
|
||||
Value Value::get(const char* key, const Value& defaultValue) const {
|
||||
const Value* value = &((*this)[key]);
|
||||
return value == &null ? defaultValue : *value;
|
||||
}
|
||||
|
||||
Value Value::get(const std::string &key, const Value &defaultValue) const {
|
||||
Value Value::get(const std::string& key, const Value& defaultValue) const {
|
||||
return get(key.c_str(), defaultValue);
|
||||
}
|
||||
|
||||
Value Value::removeMember(const char *key) {
|
||||
Value Value::removeMember(const char* key) {
|
||||
JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue,
|
||||
"in Json::Value::removeMember(): requires objectValue");
|
||||
if (type_ == nullValue)
|
||||
@@ -1060,7 +1060,7 @@ Value Value::removeMember(const char *key) {
|
||||
value_.map_->erase(it);
|
||||
return old;
|
||||
#else
|
||||
Value *value = value_.map_->find(key);
|
||||
Value* value = value_.map_->find(key);
|
||||
if (value) {
|
||||
Value old(*value);
|
||||
value_.map_.remove(key);
|
||||
@@ -1071,28 +1071,28 @@ Value Value::removeMember(const char *key) {
|
||||
#endif
|
||||
}
|
||||
|
||||
Value Value::removeMember(const std::string &key) {
|
||||
Value Value::removeMember(const std::string& key) {
|
||||
return removeMember(key.c_str());
|
||||
}
|
||||
|
||||
#ifdef JSON_USE_CPPTL
|
||||
Value Value::get(const CppTL::ConstString &key,
|
||||
const Value &defaultValue) const {
|
||||
Value Value::get(const CppTL::ConstString& key,
|
||||
const Value& defaultValue) const {
|
||||
return get(key.c_str(), defaultValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Value::isMember(const char *key) const {
|
||||
const Value *value = &((*this)[key]);
|
||||
bool Value::isMember(const char* key) const {
|
||||
const Value* value = &((*this)[key]);
|
||||
return value != &null;
|
||||
}
|
||||
|
||||
bool Value::isMember(const std::string &key) const {
|
||||
bool Value::isMember(const std::string& key) const {
|
||||
return isMember(key.c_str());
|
||||
}
|
||||
|
||||
#ifdef JSON_USE_CPPTL
|
||||
bool Value::isMember(const CppTL::ConstString &key) const {
|
||||
bool Value::isMember(const CppTL::ConstString& key) const {
|
||||
return isMember(key.c_str());
|
||||
}
|
||||
#endif
|
||||
@@ -1243,13 +1243,13 @@ bool Value::isArray() const { return type_ == arrayValue; }
|
||||
|
||||
bool Value::isObject() const { return type_ == objectValue; }
|
||||
|
||||
void Value::setComment(const char *comment, CommentPlacement placement) {
|
||||
void Value::setComment(const char* comment, CommentPlacement placement) {
|
||||
if (!comments_)
|
||||
comments_ = new CommentInfo[numberOfCommentPlacement];
|
||||
comments_[placement].setComment(comment);
|
||||
}
|
||||
|
||||
void Value::setComment(const std::string &comment, CommentPlacement placement) {
|
||||
void Value::setComment(const std::string& comment, CommentPlacement placement) {
|
||||
setComment(comment.c_str(), placement);
|
||||
}
|
||||
|
||||
@@ -1404,21 +1404,21 @@ PathArgument::PathArgument() : key_(), index_(), kind_(kindNone) {}
|
||||
PathArgument::PathArgument(ArrayIndex index)
|
||||
: key_(), index_(index), kind_(kindIndex) {}
|
||||
|
||||
PathArgument::PathArgument(const char *key)
|
||||
PathArgument::PathArgument(const char* key)
|
||||
: key_(key), index_(), kind_(kindKey) {}
|
||||
|
||||
PathArgument::PathArgument(const std::string &key)
|
||||
PathArgument::PathArgument(const std::string& key)
|
||||
: key_(key.c_str()), index_(), kind_(kindKey) {}
|
||||
|
||||
// class Path
|
||||
// //////////////////////////////////////////////////////////////////
|
||||
|
||||
Path::Path(const std::string &path,
|
||||
const PathArgument &a1,
|
||||
const PathArgument &a2,
|
||||
const PathArgument &a3,
|
||||
const PathArgument &a4,
|
||||
const PathArgument &a5) {
|
||||
Path::Path(const std::string& path,
|
||||
const PathArgument& a1,
|
||||
const PathArgument& a2,
|
||||
const PathArgument& a3,
|
||||
const PathArgument& a4,
|
||||
const PathArgument& a5) {
|
||||
InArgs in;
|
||||
in.push_back(&a1);
|
||||
in.push_back(&a2);
|
||||
@@ -1428,9 +1428,9 @@ Path::Path(const std::string &path,
|
||||
makePath(path, in);
|
||||
}
|
||||
|
||||
void Path::makePath(const std::string &path, const InArgs &in) {
|
||||
const char *current = path.c_str();
|
||||
const char *end = current + path.length();
|
||||
void Path::makePath(const std::string& path, const InArgs& in) {
|
||||
const char* current = path.c_str();
|
||||
const char* end = current + path.length();
|
||||
InArgs::const_iterator itInArg = in.begin();
|
||||
while (current != end) {
|
||||
if (*current == '[') {
|
||||
@@ -1451,7 +1451,7 @@ void Path::makePath(const std::string &path, const InArgs &in) {
|
||||
} else if (*current == '.') {
|
||||
++current;
|
||||
} else {
|
||||
const char *beginName = current;
|
||||
const char* beginName = current;
|
||||
while (current != end && !strchr("[.", *current))
|
||||
++current;
|
||||
args_.push_back(std::string(beginName, current));
|
||||
@@ -1459,9 +1459,9 @@ void Path::makePath(const std::string &path, const InArgs &in) {
|
||||
}
|
||||
}
|
||||
|
||||
void Path::addPathInArg(const std::string & /*path*/,
|
||||
const InArgs &in,
|
||||
InArgs::const_iterator &itInArg,
|
||||
void Path::addPathInArg(const std::string& /*path*/,
|
||||
const InArgs& in,
|
||||
InArgs::const_iterator& itInArg,
|
||||
PathArgument::Kind kind) {
|
||||
if (itInArg == in.end()) {
|
||||
// Error: missing argument %d
|
||||
@@ -1472,14 +1472,14 @@ void Path::addPathInArg(const std::string & /*path*/,
|
||||
}
|
||||
}
|
||||
|
||||
void Path::invalidPath(const std::string & /*path*/, int /*location*/) {
|
||||
void Path::invalidPath(const std::string& /*path*/, int /*location*/) {
|
||||
// Error: invalid path.
|
||||
}
|
||||
|
||||
const Value &Path::resolve(const Value &root) const {
|
||||
const Value *node = &root;
|
||||
const Value& Path::resolve(const Value& root) const {
|
||||
const Value* node = &root;
|
||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
||||
const PathArgument &arg = *it;
|
||||
const PathArgument& arg = *it;
|
||||
if (arg.kind_ == PathArgument::kindIndex) {
|
||||
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
|
||||
// Error: unable to resolve path (array value expected at position...
|
||||
@@ -1499,10 +1499,10 @@ const Value &Path::resolve(const Value &root) const {
|
||||
return *node;
|
||||
}
|
||||
|
||||
Value Path::resolve(const Value &root, const Value &defaultValue) const {
|
||||
const Value *node = &root;
|
||||
Value Path::resolve(const Value& root, const Value& defaultValue) const {
|
||||
const Value* node = &root;
|
||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
||||
const PathArgument &arg = *it;
|
||||
const PathArgument& arg = *it;
|
||||
if (arg.kind_ == PathArgument::kindIndex) {
|
||||
if (!node->isArray() || !node->isValidIndex(arg.index_))
|
||||
return defaultValue;
|
||||
@@ -1518,10 +1518,10 @@ Value Path::resolve(const Value &root, const Value &defaultValue) const {
|
||||
return *node;
|
||||
}
|
||||
|
||||
Value &Path::make(Value &root) const {
|
||||
Value *node = &root;
|
||||
Value& Path::make(Value& root) const {
|
||||
Value* node = &root;
|
||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
||||
const PathArgument &arg = *it;
|
||||
const PathArgument& arg = *it;
|
||||
if (arg.kind_ == PathArgument::kindIndex) {
|
||||
if (!node->isArray()) {
|
||||
// Error: node is not an array at position ...
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
namespace Json {
|
||||
|
||||
static bool containsControlCharacter(const char *str) {
|
||||
static bool containsControlCharacter(const char* str) {
|
||||
while (*str) {
|
||||
if (isControlCharacter(*(str++)))
|
||||
return true;
|
||||
@@ -32,7 +32,7 @@ static bool containsControlCharacter(const char *str) {
|
||||
|
||||
std::string valueToString(LargestInt value) {
|
||||
UIntToStringBuffer buffer;
|
||||
char *current = buffer + sizeof(buffer);
|
||||
char* current = buffer + sizeof(buffer);
|
||||
bool isNegative = value < 0;
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
@@ -45,7 +45,7 @@ std::string valueToString(LargestInt value) {
|
||||
|
||||
std::string valueToString(LargestUInt value) {
|
||||
UIntToStringBuffer buffer;
|
||||
char *current = buffer + sizeof(buffer);
|
||||
char* current = buffer + sizeof(buffer);
|
||||
uintToString(value, current);
|
||||
assert(current >= buffer);
|
||||
return current;
|
||||
@@ -102,7 +102,7 @@ std::string valueToString(double value) {
|
||||
|
||||
std::string valueToString(bool value) { return value ? "true" : "false"; }
|
||||
|
||||
std::string valueToQuotedString(const char *value) {
|
||||
std::string valueToQuotedString(const char* value) {
|
||||
if (value == NULL)
|
||||
return "";
|
||||
// Not sure how to handle unicode...
|
||||
@@ -117,7 +117,7 @@ std::string valueToQuotedString(const char *value) {
|
||||
std::string result;
|
||||
result.reserve(maxsize); // to avoid lots of mallocs
|
||||
result += "\"";
|
||||
for (const char *c = value; *c != 0; ++c) {
|
||||
for (const char* c = value; *c != 0; ++c) {
|
||||
switch (*c) {
|
||||
case '\"':
|
||||
result += "\\\"";
|
||||
@@ -181,7 +181,7 @@ void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }
|
||||
|
||||
void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
|
||||
|
||||
std::string FastWriter::write(const Value &root) {
|
||||
std::string FastWriter::write(const Value& root) {
|
||||
document_ = "";
|
||||
writeValue(root);
|
||||
if (!omitEndingLineFeed_)
|
||||
@@ -189,7 +189,7 @@ std::string FastWriter::write(const Value &root) {
|
||||
return document_;
|
||||
}
|
||||
|
||||
void FastWriter::writeValue(const Value &value) {
|
||||
void FastWriter::writeValue(const Value& value) {
|
||||
switch (value.type()) {
|
||||
case nullValue:
|
||||
if (!dropNullPlaceholders_)
|
||||
@@ -225,7 +225,7 @@ void FastWriter::writeValue(const Value &value) {
|
||||
document_ += "{";
|
||||
for (Value::Members::iterator it = members.begin(); it != members.end();
|
||||
++it) {
|
||||
const std::string &name = *it;
|
||||
const std::string& name = *it;
|
||||
if (it != members.begin())
|
||||
document_ += ",";
|
||||
document_ += valueToQuotedString(name.c_str());
|
||||
@@ -243,7 +243,7 @@ void FastWriter::writeValue(const Value &value) {
|
||||
StyledWriter::StyledWriter()
|
||||
: rightMargin_(74), indentSize_(3), addChildValues_() {}
|
||||
|
||||
std::string StyledWriter::write(const Value &root) {
|
||||
std::string StyledWriter::write(const Value& root) {
|
||||
document_ = "";
|
||||
addChildValues_ = false;
|
||||
indentString_ = "";
|
||||
@@ -254,7 +254,7 @@ std::string StyledWriter::write(const Value &root) {
|
||||
return document_;
|
||||
}
|
||||
|
||||
void StyledWriter::writeValue(const Value &value) {
|
||||
void StyledWriter::writeValue(const Value& value) {
|
||||
switch (value.type()) {
|
||||
case nullValue:
|
||||
pushValue("null");
|
||||
@@ -286,8 +286,8 @@ void StyledWriter::writeValue(const Value &value) {
|
||||
indent();
|
||||
Value::Members::iterator it = members.begin();
|
||||
for (;;) {
|
||||
const std::string &name = *it;
|
||||
const Value &childValue = value[name];
|
||||
const std::string& name = *it;
|
||||
const Value& childValue = value[name];
|
||||
writeCommentBeforeValue(childValue);
|
||||
writeWithIndent(valueToQuotedString(name.c_str()));
|
||||
document_ += " : ";
|
||||
@@ -306,7 +306,7 @@ void StyledWriter::writeValue(const Value &value) {
|
||||
}
|
||||
}
|
||||
|
||||
void StyledWriter::writeArrayValue(const Value &value) {
|
||||
void StyledWriter::writeArrayValue(const Value& value) {
|
||||
unsigned size = value.size();
|
||||
if (size == 0)
|
||||
pushValue("[]");
|
||||
@@ -318,7 +318,7 @@ void StyledWriter::writeArrayValue(const Value &value) {
|
||||
bool hasChildValue = !childValues_.empty();
|
||||
unsigned index = 0;
|
||||
for (;;) {
|
||||
const Value &childValue = value[index];
|
||||
const Value& childValue = value[index];
|
||||
writeCommentBeforeValue(childValue);
|
||||
if (hasChildValue)
|
||||
writeWithIndent(childValues_[index]);
|
||||
@@ -349,12 +349,12 @@ void StyledWriter::writeArrayValue(const Value &value) {
|
||||
}
|
||||
}
|
||||
|
||||
bool StyledWriter::isMultineArray(const Value &value) {
|
||||
bool StyledWriter::isMultineArray(const Value& value) {
|
||||
int size = value.size();
|
||||
bool isMultiLine = size * 3 >= rightMargin_;
|
||||
childValues_.clear();
|
||||
for (int index = 0; index < size && !isMultiLine; ++index) {
|
||||
const Value &childValue = value[index];
|
||||
const Value& childValue = value[index];
|
||||
isMultiLine =
|
||||
isMultiLine || ((childValue.isArray() || childValue.isObject()) &&
|
||||
childValue.size() > 0);
|
||||
@@ -374,7 +374,7 @@ bool StyledWriter::isMultineArray(const Value &value) {
|
||||
return isMultiLine;
|
||||
}
|
||||
|
||||
void StyledWriter::pushValue(const std::string &value) {
|
||||
void StyledWriter::pushValue(const std::string& value) {
|
||||
if (addChildValues_)
|
||||
childValues_.push_back(value);
|
||||
else
|
||||
@@ -392,7 +392,7 @@ void StyledWriter::writeIndent() {
|
||||
document_ += indentString_;
|
||||
}
|
||||
|
||||
void StyledWriter::writeWithIndent(const std::string &value) {
|
||||
void StyledWriter::writeWithIndent(const std::string& value) {
|
||||
writeIndent();
|
||||
document_ += value;
|
||||
}
|
||||
@@ -404,7 +404,7 @@ void StyledWriter::unindent() {
|
||||
indentString_.resize(indentString_.size() - indentSize_);
|
||||
}
|
||||
|
||||
void StyledWriter::writeCommentBeforeValue(const Value &root) {
|
||||
void StyledWriter::writeCommentBeforeValue(const Value& root) {
|
||||
if (!root.hasComment(commentBefore))
|
||||
return;
|
||||
|
||||
@@ -423,7 +423,7 @@ void StyledWriter::writeCommentBeforeValue(const Value &root) {
|
||||
document_ += "\n";
|
||||
}
|
||||
|
||||
void StyledWriter::writeCommentAfterValueOnSameLine(const Value &root) {
|
||||
void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) {
|
||||
if (root.hasComment(commentAfterOnSameLine))
|
||||
document_ += " " + normalizeEOL(root.getComment(commentAfterOnSameLine));
|
||||
|
||||
@@ -434,18 +434,18 @@ void StyledWriter::writeCommentAfterValueOnSameLine(const Value &root) {
|
||||
}
|
||||
}
|
||||
|
||||
bool StyledWriter::hasCommentForValue(const Value &value) {
|
||||
bool StyledWriter::hasCommentForValue(const Value& value) {
|
||||
return value.hasComment(commentBefore) ||
|
||||
value.hasComment(commentAfterOnSameLine) ||
|
||||
value.hasComment(commentAfter);
|
||||
}
|
||||
|
||||
std::string StyledWriter::normalizeEOL(const std::string &text) {
|
||||
std::string StyledWriter::normalizeEOL(const std::string& text) {
|
||||
std::string normalized;
|
||||
normalized.reserve(text.length());
|
||||
const char *begin = text.c_str();
|
||||
const char *end = begin + text.length();
|
||||
const char *current = begin;
|
||||
const char* begin = text.c_str();
|
||||
const char* end = begin + text.length();
|
||||
const char* current = begin;
|
||||
while (current != end) {
|
||||
char c = *current++;
|
||||
if (c == '\r') // mac or dos EOL
|
||||
@@ -466,7 +466,7 @@ StyledStreamWriter::StyledStreamWriter(std::string indentation)
|
||||
: document_(NULL), rightMargin_(74), indentation_(indentation),
|
||||
addChildValues_() {}
|
||||
|
||||
void StyledStreamWriter::write(std::ostream &out, const Value &root) {
|
||||
void StyledStreamWriter::write(std::ostream& out, const Value& root) {
|
||||
document_ = &out;
|
||||
addChildValues_ = false;
|
||||
indentString_ = "";
|
||||
@@ -477,7 +477,7 @@ void StyledStreamWriter::write(std::ostream &out, const Value &root) {
|
||||
document_ = NULL; // Forget the stream, for safety.
|
||||
}
|
||||
|
||||
void StyledStreamWriter::writeValue(const Value &value) {
|
||||
void StyledStreamWriter::writeValue(const Value& value) {
|
||||
switch (value.type()) {
|
||||
case nullValue:
|
||||
pushValue("null");
|
||||
@@ -509,8 +509,8 @@ void StyledStreamWriter::writeValue(const Value &value) {
|
||||
indent();
|
||||
Value::Members::iterator it = members.begin();
|
||||
for (;;) {
|
||||
const std::string &name = *it;
|
||||
const Value &childValue = value[name];
|
||||
const std::string& name = *it;
|
||||
const Value& childValue = value[name];
|
||||
writeCommentBeforeValue(childValue);
|
||||
writeWithIndent(valueToQuotedString(name.c_str()));
|
||||
*document_ << " : ";
|
||||
@@ -529,7 +529,7 @@ void StyledStreamWriter::writeValue(const Value &value) {
|
||||
}
|
||||
}
|
||||
|
||||
void StyledStreamWriter::writeArrayValue(const Value &value) {
|
||||
void StyledStreamWriter::writeArrayValue(const Value& value) {
|
||||
unsigned size = value.size();
|
||||
if (size == 0)
|
||||
pushValue("[]");
|
||||
@@ -541,7 +541,7 @@ void StyledStreamWriter::writeArrayValue(const Value &value) {
|
||||
bool hasChildValue = !childValues_.empty();
|
||||
unsigned index = 0;
|
||||
for (;;) {
|
||||
const Value &childValue = value[index];
|
||||
const Value& childValue = value[index];
|
||||
writeCommentBeforeValue(childValue);
|
||||
if (hasChildValue)
|
||||
writeWithIndent(childValues_[index]);
|
||||
@@ -572,12 +572,12 @@ void StyledStreamWriter::writeArrayValue(const Value &value) {
|
||||
}
|
||||
}
|
||||
|
||||
bool StyledStreamWriter::isMultineArray(const Value &value) {
|
||||
bool StyledStreamWriter::isMultineArray(const Value& value) {
|
||||
int size = value.size();
|
||||
bool isMultiLine = size * 3 >= rightMargin_;
|
||||
childValues_.clear();
|
||||
for (int index = 0; index < size && !isMultiLine; ++index) {
|
||||
const Value &childValue = value[index];
|
||||
const Value& childValue = value[index];
|
||||
isMultiLine =
|
||||
isMultiLine || ((childValue.isArray() || childValue.isObject()) &&
|
||||
childValue.size() > 0);
|
||||
@@ -597,7 +597,7 @@ bool StyledStreamWriter::isMultineArray(const Value &value) {
|
||||
return isMultiLine;
|
||||
}
|
||||
|
||||
void StyledStreamWriter::pushValue(const std::string &value) {
|
||||
void StyledStreamWriter::pushValue(const std::string& value) {
|
||||
if (addChildValues_)
|
||||
childValues_.push_back(value);
|
||||
else
|
||||
@@ -620,7 +620,7 @@ void StyledStreamWriter::writeIndent() {
|
||||
*document_ << '\n' << indentString_;
|
||||
}
|
||||
|
||||
void StyledStreamWriter::writeWithIndent(const std::string &value) {
|
||||
void StyledStreamWriter::writeWithIndent(const std::string& value) {
|
||||
writeIndent();
|
||||
*document_ << value;
|
||||
}
|
||||
@@ -632,14 +632,14 @@ void StyledStreamWriter::unindent() {
|
||||
indentString_.resize(indentString_.size() - indentation_.size());
|
||||
}
|
||||
|
||||
void StyledStreamWriter::writeCommentBeforeValue(const Value &root) {
|
||||
void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
|
||||
if (!root.hasComment(commentBefore))
|
||||
return;
|
||||
*document_ << normalizeEOL(root.getComment(commentBefore));
|
||||
*document_ << "\n";
|
||||
}
|
||||
|
||||
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value &root) {
|
||||
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) {
|
||||
if (root.hasComment(commentAfterOnSameLine))
|
||||
*document_ << " " + normalizeEOL(root.getComment(commentAfterOnSameLine));
|
||||
|
||||
@@ -650,18 +650,18 @@ void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value &root) {
|
||||
}
|
||||
}
|
||||
|
||||
bool StyledStreamWriter::hasCommentForValue(const Value &value) {
|
||||
bool StyledStreamWriter::hasCommentForValue(const Value& value) {
|
||||
return value.hasComment(commentBefore) ||
|
||||
value.hasComment(commentAfterOnSameLine) ||
|
||||
value.hasComment(commentAfter);
|
||||
}
|
||||
|
||||
std::string StyledStreamWriter::normalizeEOL(const std::string &text) {
|
||||
std::string StyledStreamWriter::normalizeEOL(const std::string& text) {
|
||||
std::string normalized;
|
||||
normalized.reserve(text.length());
|
||||
const char *begin = text.c_str();
|
||||
const char *end = begin + text.length();
|
||||
const char *current = begin;
|
||||
const char* begin = text.c_str();
|
||||
const char* end = begin + text.length();
|
||||
const char* current = begin;
|
||||
while (current != end) {
|
||||
char c = *current++;
|
||||
if (c == '\r') // mac or dos EOL
|
||||
@@ -675,7 +675,7 @@ std::string StyledStreamWriter::normalizeEOL(const std::string &text) {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &sout, const Value &root) {
|
||||
std::ostream& operator<<(std::ostream& sout, const Value& root) {
|
||||
Json::StyledStreamWriter writer;
|
||||
writer.write(sout, root);
|
||||
return sout;
|
||||
|
@@ -81,14 +81,14 @@ TestResult::TestResult()
|
||||
predicateStackTail_ = &rootPredicateNode_;
|
||||
}
|
||||
|
||||
void TestResult::setTestName(const std::string &name) { name_ = name; }
|
||||
void TestResult::setTestName(const std::string& name) { name_ = name; }
|
||||
|
||||
TestResult &
|
||||
TestResult::addFailure(const char *file, unsigned int line, const char *expr) {
|
||||
TestResult&
|
||||
TestResult::addFailure(const char* file, unsigned int line, const char* expr) {
|
||||
/// Walks the PredicateContext stack adding them to failures_ if not already
|
||||
/// added.
|
||||
unsigned int nestingLevel = 0;
|
||||
PredicateContext *lastNode = rootPredicateNode_.next_;
|
||||
PredicateContext* lastNode = rootPredicateNode_.next_;
|
||||
for (; lastNode != 0; lastNode = lastNode->next_) {
|
||||
if (lastNode->id_ > lastUsedPredicateId_) // new PredicateContext
|
||||
{
|
||||
@@ -108,9 +108,9 @@ TestResult::addFailure(const char *file, unsigned int line, const char *expr) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void TestResult::addFailureInfo(const char *file,
|
||||
void TestResult::addFailureInfo(const char* file,
|
||||
unsigned int line,
|
||||
const char *expr,
|
||||
const char* expr,
|
||||
unsigned int nestingLevel) {
|
||||
Failure failure;
|
||||
failure.file_ = file;
|
||||
@@ -122,13 +122,13 @@ void TestResult::addFailureInfo(const char *file,
|
||||
failures_.push_back(failure);
|
||||
}
|
||||
|
||||
TestResult &TestResult::popPredicateContext() {
|
||||
PredicateContext *lastNode = &rootPredicateNode_;
|
||||
TestResult& TestResult::popPredicateContext() {
|
||||
PredicateContext* lastNode = &rootPredicateNode_;
|
||||
while (lastNode->next_ != 0 && lastNode->next_->next_ != 0) {
|
||||
lastNode = lastNode->next_;
|
||||
}
|
||||
// Set message target to popped failure
|
||||
PredicateContext *tail = lastNode->next_;
|
||||
PredicateContext* tail = lastNode->next_;
|
||||
if (tail != 0 && tail->failure_ != 0) {
|
||||
messageTarget_ = tail->failure_;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ bool TestResult::failed() const { return !failures_.empty(); }
|
||||
|
||||
unsigned int TestResult::getAssertionNestingLevel() const {
|
||||
unsigned int level = 0;
|
||||
const PredicateContext *lastNode = &rootPredicateNode_;
|
||||
const PredicateContext* lastNode = &rootPredicateNode_;
|
||||
while (lastNode->next_ != 0) {
|
||||
lastNode = lastNode->next_;
|
||||
++level;
|
||||
@@ -162,7 +162,7 @@ void TestResult::printFailure(bool printTestName) const {
|
||||
// Print in reverse to display the callstack in the right order
|
||||
Failures::const_iterator itEnd = failures_.end();
|
||||
for (Failures::const_iterator it = failures_.begin(); it != itEnd; ++it) {
|
||||
const Failure &failure = *it;
|
||||
const Failure& failure = *it;
|
||||
std::string indent(failure.nestingLevel_ * 2, ' ');
|
||||
if (failure.file_) {
|
||||
printf("%s%s(%d): ", indent.c_str(), failure.file_, failure.line_);
|
||||
@@ -179,8 +179,8 @@ void TestResult::printFailure(bool printTestName) const {
|
||||
}
|
||||
}
|
||||
|
||||
std::string TestResult::indentText(const std::string &text,
|
||||
const std::string &indent) {
|
||||
std::string TestResult::indentText(const std::string& text,
|
||||
const std::string& indent) {
|
||||
std::string reindented;
|
||||
std::string::size_type lastIndex = 0;
|
||||
while (lastIndex < text.size()) {
|
||||
@@ -195,22 +195,22 @@ std::string TestResult::indentText(const std::string &text,
|
||||
return reindented;
|
||||
}
|
||||
|
||||
TestResult &TestResult::addToLastFailure(const std::string &message) {
|
||||
TestResult& TestResult::addToLastFailure(const std::string& message) {
|
||||
if (messageTarget_ != 0) {
|
||||
messageTarget_->message_ += message;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
TestResult &TestResult::operator<<(Json::Int64 value) {
|
||||
TestResult& TestResult::operator<<(Json::Int64 value) {
|
||||
return addToLastFailure(Json::valueToString(value));
|
||||
}
|
||||
|
||||
TestResult &TestResult::operator<<(Json::UInt64 value) {
|
||||
TestResult& TestResult::operator<<(Json::UInt64 value) {
|
||||
return addToLastFailure(Json::valueToString(value));
|
||||
}
|
||||
|
||||
TestResult &TestResult::operator<<(bool value) {
|
||||
TestResult& TestResult::operator<<(bool value) {
|
||||
return addToLastFailure(value ? "true" : "false");
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ TestCase::TestCase() : result_(0) {}
|
||||
|
||||
TestCase::~TestCase() {}
|
||||
|
||||
void TestCase::run(TestResult &result) {
|
||||
void TestCase::run(TestResult& result) {
|
||||
result_ = &result;
|
||||
runTestCase();
|
||||
}
|
||||
@@ -231,7 +231,7 @@ void TestCase::run(TestResult &result) {
|
||||
|
||||
Runner::Runner() {}
|
||||
|
||||
Runner &Runner::add(TestCaseFactory factory) {
|
||||
Runner& Runner::add(TestCaseFactory factory) {
|
||||
tests_.push_back(factory);
|
||||
return *this;
|
||||
}
|
||||
@@ -241,14 +241,14 @@ unsigned int Runner::testCount() const {
|
||||
}
|
||||
|
||||
std::string Runner::testNameAt(unsigned int index) const {
|
||||
TestCase *test = tests_[index]();
|
||||
TestCase* test = tests_[index]();
|
||||
std::string name = test->testName();
|
||||
delete test;
|
||||
return name;
|
||||
}
|
||||
|
||||
void Runner::runTestAt(unsigned int index, TestResult &result) const {
|
||||
TestCase *test = tests_[index]();
|
||||
void Runner::runTestAt(unsigned int index, TestResult& result) const {
|
||||
TestCase* test = tests_[index]();
|
||||
result.setTestName(test->testName());
|
||||
printf("Testing %s: ", test->testName());
|
||||
fflush(stdout);
|
||||
@@ -258,13 +258,13 @@ void Runner::runTestAt(unsigned int index, TestResult &result) const {
|
||||
test->run(result);
|
||||
#if JSON_USE_EXCEPTION
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
catch (const std::exception& e) {
|
||||
result.addFailure(__FILE__, __LINE__, "Unexpected exception caught:")
|
||||
<< e.what();
|
||||
}
|
||||
#endif // if JSON_USE_EXCEPTION
|
||||
delete test;
|
||||
const char *status = result.failed() ? "FAILED" : "OK";
|
||||
const char* status = result.failed() ? "FAILED" : "OK";
|
||||
printf("%s\n", status);
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -287,7 +287,7 @@ bool Runner::runAllTest(bool printSummary) const {
|
||||
return true;
|
||||
} else {
|
||||
for (unsigned int index = 0; index < failures.size(); ++index) {
|
||||
TestResult &result = failures[index];
|
||||
TestResult& result = failures[index];
|
||||
result.printFailure(count > 1);
|
||||
}
|
||||
|
||||
@@ -303,8 +303,8 @@ bool Runner::runAllTest(bool printSummary) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool Runner::testIndex(const std::string &testName,
|
||||
unsigned int &indexOut) const {
|
||||
bool Runner::testIndex(const std::string& testName,
|
||||
unsigned int& indexOut) const {
|
||||
unsigned int count = testCount();
|
||||
for (unsigned int index = 0; index < count; ++index) {
|
||||
if (testNameAt(index) == testName) {
|
||||
@@ -322,7 +322,7 @@ void Runner::listTests() const {
|
||||
}
|
||||
}
|
||||
|
||||
int Runner::runCommandLine(int argc, const char *argv[]) const {
|
||||
int Runner::runCommandLine(int argc, const char* argv[]) const {
|
||||
typedef std::deque<std::string> TestNames;
|
||||
Runner subrunner;
|
||||
for (int index = 1; index < argc; ++index) {
|
||||
@@ -363,7 +363,7 @@ int Runner::runCommandLine(int argc, const char *argv[]) const {
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
// Hook MSVCRT assertions to prevent dialog from appearing
|
||||
static int
|
||||
msvcrtSilentReportHook(int reportType, char *message, int * /*returnValue*/) {
|
||||
msvcrtSilentReportHook(int reportType, char* message, int* /*returnValue*/) {
|
||||
// The default CRT handling of error and assertion is to display
|
||||
// an error dialog to the user.
|
||||
// Instead, when an error or an assertion occurs, we force the
|
||||
@@ -409,7 +409,7 @@ void Runner::preventDialogOnCrash() {
|
||||
#endif // if defined(_WIN32)
|
||||
}
|
||||
|
||||
void Runner::printUsage(const char *appName) {
|
||||
void Runner::printUsage(const char* appName) {
|
||||
printf("Usage: %s [options]\n"
|
||||
"\n"
|
||||
"If --test is not specified, then all the test cases be run.\n"
|
||||
@@ -426,12 +426,12 @@ void Runner::printUsage(const char *appName) {
|
||||
// Assertion functions
|
||||
// //////////////////////////////////////////////////////////////////
|
||||
|
||||
TestResult &checkStringEqual(TestResult &result,
|
||||
const std::string &expected,
|
||||
const std::string &actual,
|
||||
const char *file,
|
||||
TestResult& checkStringEqual(TestResult& result,
|
||||
const std::string& expected,
|
||||
const std::string& actual,
|
||||
const char* file,
|
||||
unsigned int line,
|
||||
const char *expr) {
|
||||
const char* expr) {
|
||||
if (expected != actual) {
|
||||
result.addFailure(file, line, expr);
|
||||
result << "Expected: '" << expected << "'\n";
|
||||
|
@@ -30,7 +30,7 @@ namespace JsonTest {
|
||||
|
||||
class Failure {
|
||||
public:
|
||||
const char *file_;
|
||||
const char* file_;
|
||||
unsigned int line_;
|
||||
std::string expr_;
|
||||
std::string message_;
|
||||
@@ -43,13 +43,13 @@ public:
|
||||
struct PredicateContext {
|
||||
typedef unsigned int Id;
|
||||
Id id_;
|
||||
const char *file_;
|
||||
const char* file_;
|
||||
unsigned int line_;
|
||||
const char *expr_;
|
||||
PredicateContext *next_;
|
||||
const char* expr_;
|
||||
PredicateContext* next_;
|
||||
/// Related Failure, set when the PredicateContext is converted
|
||||
/// into a Failure.
|
||||
Failure *failure_;
|
||||
Failure* failure_;
|
||||
};
|
||||
|
||||
class TestResult {
|
||||
@@ -63,25 +63,25 @@ public:
|
||||
PredicateContext::Id predicateId_;
|
||||
|
||||
/// \internal Implementation detail for predicate macros
|
||||
PredicateContext *predicateStackTail_;
|
||||
PredicateContext* predicateStackTail_;
|
||||
|
||||
void setTestName(const std::string &name);
|
||||
void setTestName(const std::string& name);
|
||||
|
||||
/// Adds an assertion failure.
|
||||
TestResult &
|
||||
addFailure(const char *file, unsigned int line, const char *expr = 0);
|
||||
TestResult&
|
||||
addFailure(const char* file, unsigned int line, const char* expr = 0);
|
||||
|
||||
/// Removes the last PredicateContext added to the predicate stack
|
||||
/// chained list.
|
||||
/// Next messages will be targed at the PredicateContext that was removed.
|
||||
TestResult &popPredicateContext();
|
||||
TestResult& popPredicateContext();
|
||||
|
||||
bool failed() const;
|
||||
|
||||
void printFailure(bool printTestName) const;
|
||||
|
||||
// Generic operator that will work with anything ostream can deal with.
|
||||
template <typename T> TestResult &operator<<(const T &value) {
|
||||
template <typename T> TestResult& operator<<(const T& value) {
|
||||
std::ostringstream oss;
|
||||
oss.precision(16);
|
||||
oss.setf(std::ios_base::floatfield);
|
||||
@@ -90,21 +90,21 @@ public:
|
||||
}
|
||||
|
||||
// Specialized versions.
|
||||
TestResult &operator<<(bool value);
|
||||
TestResult& operator<<(bool value);
|
||||
// std:ostream does not support 64bits integers on all STL implementation
|
||||
TestResult &operator<<(Json::Int64 value);
|
||||
TestResult &operator<<(Json::UInt64 value);
|
||||
TestResult& operator<<(Json::Int64 value);
|
||||
TestResult& operator<<(Json::UInt64 value);
|
||||
|
||||
private:
|
||||
TestResult &addToLastFailure(const std::string &message);
|
||||
TestResult& addToLastFailure(const std::string& message);
|
||||
unsigned int getAssertionNestingLevel() const;
|
||||
/// Adds a failure or a predicate context
|
||||
void addFailureInfo(const char *file,
|
||||
void addFailureInfo(const char* file,
|
||||
unsigned int line,
|
||||
const char *expr,
|
||||
const char* expr,
|
||||
unsigned int nestingLevel);
|
||||
static std::string indentText(const std::string &text,
|
||||
const std::string &indent);
|
||||
static std::string indentText(const std::string& text,
|
||||
const std::string& indent);
|
||||
|
||||
typedef std::deque<Failure> Failures;
|
||||
Failures failures_;
|
||||
@@ -112,7 +112,7 @@ private:
|
||||
PredicateContext rootPredicateNode_;
|
||||
PredicateContext::Id lastUsedPredicateId_;
|
||||
/// Failure which is the target of the messages added using operator <<
|
||||
Failure *messageTarget_;
|
||||
Failure* messageTarget_;
|
||||
};
|
||||
|
||||
class TestCase {
|
||||
@@ -121,32 +121,32 @@ public:
|
||||
|
||||
virtual ~TestCase();
|
||||
|
||||
void run(TestResult &result);
|
||||
void run(TestResult& result);
|
||||
|
||||
virtual const char *testName() const = 0;
|
||||
virtual const char* testName() const = 0;
|
||||
|
||||
protected:
|
||||
TestResult *result_;
|
||||
TestResult* result_;
|
||||
|
||||
private:
|
||||
virtual void runTestCase() = 0;
|
||||
};
|
||||
|
||||
/// Function pointer type for TestCase factory
|
||||
typedef TestCase *(*TestCaseFactory)();
|
||||
typedef TestCase* (*TestCaseFactory)();
|
||||
|
||||
class Runner {
|
||||
public:
|
||||
Runner();
|
||||
|
||||
/// Adds a test to the suite
|
||||
Runner &add(TestCaseFactory factory);
|
||||
Runner& add(TestCaseFactory factory);
|
||||
|
||||
/// Runs test as specified on the command-line
|
||||
/// If no command-line arguments are provided, run all tests.
|
||||
/// If --list-tests is provided, then print the list of all test cases
|
||||
/// If --test <testname> is provided, then run test testname.
|
||||
int runCommandLine(int argc, const char *argv[]) const;
|
||||
int runCommandLine(int argc, const char* argv[]) const;
|
||||
|
||||
/// Runs all the test cases
|
||||
bool runAllTest(bool printSummary) const;
|
||||
@@ -158,17 +158,17 @@ public:
|
||||
std::string testNameAt(unsigned int index) const;
|
||||
|
||||
/// Runs the test case at the specified index using the specified TestResult
|
||||
void runTestAt(unsigned int index, TestResult &result) const;
|
||||
void runTestAt(unsigned int index, TestResult& result) const;
|
||||
|
||||
static void printUsage(const char *appName);
|
||||
static void printUsage(const char* appName);
|
||||
|
||||
private: // prevents copy construction and assignment
|
||||
Runner(const Runner &other);
|
||||
Runner &operator=(const Runner &other);
|
||||
Runner(const Runner& other);
|
||||
Runner& operator=(const Runner& other);
|
||||
|
||||
private:
|
||||
void listTests() const;
|
||||
bool testIndex(const std::string &testName, unsigned int &index) const;
|
||||
bool testIndex(const std::string& testName, unsigned int& index) const;
|
||||
static void preventDialogOnCrash();
|
||||
|
||||
private:
|
||||
@@ -177,12 +177,12 @@ private:
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
TestResult &checkEqual(TestResult &result,
|
||||
const T &expected,
|
||||
const U &actual,
|
||||
const char *file,
|
||||
TestResult& checkEqual(TestResult& result,
|
||||
const T& expected,
|
||||
const U& actual,
|
||||
const char* file,
|
||||
unsigned int line,
|
||||
const char *expr) {
|
||||
const char* expr) {
|
||||
if (static_cast<U>(expected) != actual) {
|
||||
result.addFailure(file, line, expr);
|
||||
result << "Expected: " << static_cast<U>(expected) << "\n";
|
||||
@@ -191,12 +191,12 @@ TestResult &checkEqual(TestResult &result,
|
||||
return result;
|
||||
}
|
||||
|
||||
TestResult &checkStringEqual(TestResult &result,
|
||||
const std::string &expected,
|
||||
const std::string &actual,
|
||||
const char *file,
|
||||
TestResult& checkStringEqual(TestResult& result,
|
||||
const std::string& expected,
|
||||
const std::string& actual,
|
||||
const char* file,
|
||||
unsigned int line,
|
||||
const char *expr);
|
||||
const char* expr);
|
||||
|
||||
} // namespace JsonTest
|
||||
|
||||
@@ -260,12 +260,12 @@ TestResult &checkStringEqual(TestResult &result,
|
||||
#define JSONTEST_FIXTURE(FixtureType, name) \
|
||||
class Test##FixtureType##name : public FixtureType { \
|
||||
public: \
|
||||
static JsonTest::TestCase *factory() { \
|
||||
static JsonTest::TestCase* factory() { \
|
||||
return new Test##FixtureType##name(); \
|
||||
} \
|
||||
\
|
||||
public: /* overidden from TestCase */ \
|
||||
virtual const char *testName() const { return #FixtureType "/" #name; } \
|
||||
virtual const char* testName() const { return #FixtureType "/" #name; } \
|
||||
virtual void runTestCase(); \
|
||||
}; \
|
||||
\
|
||||
|
@@ -85,23 +85,23 @@ struct ValueTest : JsonTest::TestCase {
|
||||
bool isNumeric_;
|
||||
};
|
||||
|
||||
void checkConstMemberCount(const Json::Value &value,
|
||||
void checkConstMemberCount(const Json::Value& value,
|
||||
unsigned int expectedCount);
|
||||
|
||||
void checkMemberCount(Json::Value &value, unsigned int expectedCount);
|
||||
void checkMemberCount(Json::Value& value, unsigned int expectedCount);
|
||||
|
||||
void checkIs(const Json::Value &value, const IsCheck &check);
|
||||
void checkIs(const Json::Value& value, const IsCheck& check);
|
||||
|
||||
void checkIsLess(const Json::Value &x, const Json::Value &y);
|
||||
void checkIsLess(const Json::Value& x, const Json::Value& y);
|
||||
|
||||
void checkIsEqual(const Json::Value &x, const Json::Value &y);
|
||||
void checkIsEqual(const Json::Value& x, const Json::Value& y);
|
||||
|
||||
/// Normalize the representation of floating-point number by stripped leading
|
||||
/// 0 in exponent.
|
||||
static std::string normalizeFloatingPointStr(const std::string &s);
|
||||
static std::string normalizeFloatingPointStr(const std::string& s);
|
||||
};
|
||||
|
||||
std::string ValueTest::normalizeFloatingPointStr(const std::string &s) {
|
||||
std::string ValueTest::normalizeFloatingPointStr(const std::string& s) {
|
||||
std::string::size_type index = s.find_last_of("eE");
|
||||
if (index != std::string::npos) {
|
||||
std::string::size_type hasSign =
|
||||
@@ -187,7 +187,7 @@ JSONTEST_FIXTURE(ValueTest, objects) {
|
||||
JSONTEST_ASSERT(!emptyObject_.isConvertibleTo(Json::stringValue));
|
||||
|
||||
// Access through const reference
|
||||
const Json::Value &constObject = object1_;
|
||||
const Json::Value& constObject = object1_;
|
||||
|
||||
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constObject["id"]);
|
||||
JSONTEST_ASSERT_EQUAL(Json::Value(), constObject["unknown id"]);
|
||||
@@ -229,7 +229,7 @@ JSONTEST_FIXTURE(ValueTest, arrays) {
|
||||
JSONTEST_ASSERT(!emptyArray_.isConvertibleTo(Json::stringValue));
|
||||
|
||||
// Access through const reference
|
||||
const Json::Value &constArray = array1_;
|
||||
const Json::Value& constArray = array1_;
|
||||
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constArray[index0]);
|
||||
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constArray[0]);
|
||||
|
||||
@@ -1239,7 +1239,7 @@ JSONTEST_FIXTURE(ValueTest, nonIntegers) {
|
||||
normalizeFloatingPointStr(val.asString()));
|
||||
}
|
||||
|
||||
void ValueTest::checkConstMemberCount(const Json::Value &value,
|
||||
void ValueTest::checkConstMemberCount(const Json::Value& value,
|
||||
unsigned int expectedCount) {
|
||||
unsigned int count = 0;
|
||||
Json::Value::const_iterator itEnd = value.end();
|
||||
@@ -1249,7 +1249,7 @@ void ValueTest::checkConstMemberCount(const Json::Value &value,
|
||||
JSONTEST_ASSERT_EQUAL(expectedCount, count) << "Json::Value::const_iterator";
|
||||
}
|
||||
|
||||
void ValueTest::checkMemberCount(Json::Value &value,
|
||||
void ValueTest::checkMemberCount(Json::Value& value,
|
||||
unsigned int expectedCount) {
|
||||
JSONTEST_ASSERT_EQUAL(expectedCount, value.size());
|
||||
|
||||
@@ -1269,7 +1269,7 @@ ValueTest::IsCheck::IsCheck()
|
||||
isUInt64_(false), isIntegral_(false), isDouble_(false),
|
||||
isNumeric_(false) {}
|
||||
|
||||
void ValueTest::checkIs(const Json::Value &value, const IsCheck &check) {
|
||||
void ValueTest::checkIs(const Json::Value& value, const IsCheck& check) {
|
||||
JSONTEST_ASSERT_EQUAL(check.isObject_, value.isObject());
|
||||
JSONTEST_ASSERT_EQUAL(check.isArray_, value.isArray());
|
||||
JSONTEST_ASSERT_EQUAL(check.isBool_, value.isBool());
|
||||
@@ -1384,7 +1384,7 @@ JSONTEST_FIXTURE(ValueTest, compareType) {
|
||||
Json::Value(Json::objectValue)));
|
||||
}
|
||||
|
||||
void ValueTest::checkIsLess(const Json::Value &x, const Json::Value &y) {
|
||||
void ValueTest::checkIsLess(const Json::Value& x, const Json::Value& y) {
|
||||
JSONTEST_ASSERT(x < y);
|
||||
JSONTEST_ASSERT(y > x);
|
||||
JSONTEST_ASSERT(x <= y);
|
||||
@@ -1399,7 +1399,7 @@ void ValueTest::checkIsLess(const Json::Value &x, const Json::Value &y) {
|
||||
JSONTEST_ASSERT(y.compare(x) >= 0);
|
||||
}
|
||||
|
||||
void ValueTest::checkIsEqual(const Json::Value &x, const Json::Value &y) {
|
||||
void ValueTest::checkIsEqual(const Json::Value& x, const Json::Value& y) {
|
||||
JSONTEST_ASSERT(x == y);
|
||||
JSONTEST_ASSERT(y == x);
|
||||
JSONTEST_ASSERT(x <= y);
|
||||
@@ -1601,7 +1601,7 @@ JSONTEST_FIXTURE(ReaderTest, parseWithDetailError) {
|
||||
JSONTEST_ASSERT(errors.at(0).message == "Bad escape sequence in string");
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
JsonTest::Runner runner;
|
||||
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, checkNormalizeFloatingPointStr);
|
||||
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, memberCount);
|
||||
|
Reference in New Issue
Block a user