Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
198 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# - Find YAJL | ||
# This module finds an installed YAJL package. | ||
# | ||
# It sets the following variables: | ||
# YAJL_FOUND - Set to false, or undefined, if YAJL isn't found. | ||
# YAJL_INCLUDE_DIR - The YAJL include directory. | ||
# YAJL_LIBRARY - The YAJL library to link against. | ||
|
||
FIND_PATH(YAJL_INCLUDE_DIR yajl/yajl_gen.h) | ||
FIND_LIBRARY(YAJL_LIBRARY NAMES yajl) | ||
|
||
IF (YAJL_INCLUDE_DIR AND YAJL_LIBRARY) | ||
SET(YAJL_FOUND TRUE) | ||
ENDIF (YAJL_INCLUDE_DIR AND YAJL_LIBRARY) | ||
|
||
IF (YAJL_FOUND) | ||
|
||
# show which YAJL was found only if not quiet | ||
IF (NOT YAJL_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found YAJL: ${YAJL_LIBRARY}") | ||
ENDIF (NOT YAJL_FIND_QUIETLY) | ||
|
||
ELSE (YAJL_FOUND) | ||
|
||
# fatal error if YAJL is required but not found | ||
IF (YAJL_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find YAJL") | ||
ENDIF (YAJL_FIND_REQUIRED) | ||
|
||
ENDIF (YAJL_FOUND) | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
yajl https://github.com/lloyd/yajl/archive/2.1.0.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "JsonParser.h" | ||
|
||
#define DEBUG | ||
|
||
#ifdef DEBUG | ||
#define D(x) x | ||
#else | ||
#define D(x) | ||
#endif | ||
|
||
using namespace std; | ||
|
||
yajl_val JsonParser::parse(string jsonString) { | ||
char errbuf[1024]; | ||
yajl_val json = yajl_tree_parse(jsonString.c_str(), errbuf, sizeof(errbuf)); | ||
if (json == NULL) { | ||
D(cout << "Error parsing json:\n" << jsonString << "\nMessage:\n" << errbuf << "\n"); | ||
} | ||
return json; | ||
} | ||
|
||
const char** JsonParser::getPath(int path_len, va_list args) { | ||
char** path = new char*[path_len + 1]; | ||
for (int i = 0; i < path_len; i++) { | ||
path[i] = va_arg(args, char*); | ||
} | ||
path[path_len] = (char*)0; | ||
return (const char**)path; | ||
} | ||
|
||
bool JsonParser::getBoolean(yajl_val json, int path_len, ...) { | ||
va_list args; | ||
va_start(args, path_len); | ||
const char **path = getPath(path_len, args); | ||
bool ret = YAJL_IS_TRUE(yajl_tree_get(json, path, yajl_t_true)); | ||
va_end(args); | ||
delete [] path; | ||
return ret; | ||
} | ||
|
||
string JsonParser::getString(yajl_val json, int path_len, ...) { | ||
va_list args; | ||
va_start(args, path_len); | ||
const char **path = getPath(path_len, args); | ||
char *str = YAJL_GET_STRING(yajl_tree_get(json, path, yajl_t_string)); | ||
va_end(args); | ||
delete [] path; | ||
if (str == NULL) { | ||
return ""; | ||
} | ||
return str; | ||
} | ||
|
||
int JsonParser::getInt(yajl_val json, int path_len, ...) { | ||
va_list args; | ||
va_start(args, path_len); | ||
const char **path = getPath(path_len, args); | ||
int ret = YAJL_GET_INTEGER(yajl_tree_get(json, path, yajl_t_number)); | ||
va_end(args); | ||
delete [] path; | ||
return ret; | ||
} | ||
|
||
yajl_val JsonParser::getArray(yajl_val json, int path_len, ...) { | ||
va_list args; | ||
va_start(args, path_len); | ||
const char **path = getPath(path_len, args); | ||
yajl_val ret = yajl_tree_get(json, path, yajl_t_array); | ||
va_end(args); | ||
delete [] path; | ||
return ret; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "yajl/yajl_tree.h" | ||
#include <iostream> | ||
#include <stdarg.h> | ||
|
||
using namespace std; | ||
|
||
class JsonParser | ||
{ | ||
public: | ||
static yajl_val parse(string jsonString); | ||
static bool getBoolean(yajl_val json, int path_len, ...); | ||
static string getString(yajl_val json, int path_len, ...); | ||
static int getInt(yajl_val json, int path_len, ...); | ||
static yajl_val getArray(yajl_val json, int path_len, ...); | ||
private: | ||
static const char** getPath(int path_len, va_list args); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.