本文整理汇总了C++中Document::GetErrorOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::GetErrorOffset方法的具体用法?C++ Document::GetErrorOffset怎么用?C++ Document::GetErrorOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document::GetErrorOffset方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: error
TYPED_TEST(DocumentMove, MoveAssignmentParseError) {
typedef TypeParam Allocator;
typedef GenericDocument<UTF8<>, Allocator> Document;
ParseResult noError;
Document a;
a.Parse("{ 4 = 4]");
ParseResult error(a.GetParseError(), a.GetErrorOffset());
EXPECT_TRUE(a.HasParseError());
EXPECT_NE(error.Code(), noError.Code());
EXPECT_NE(error.Offset(), noError.Offset());
Document b;
b = std::move(a);
EXPECT_FALSE(a.HasParseError());
EXPECT_TRUE(b.HasParseError());
EXPECT_EQ(a.GetParseError(), noError.Code());
EXPECT_EQ(b.GetParseError(), error.Code());
EXPECT_EQ(a.GetErrorOffset(), noError.Offset());
EXPECT_EQ(b.GetErrorOffset(), error.Offset());
Document c;
c = std::move(b);
EXPECT_FALSE(b.HasParseError());
EXPECT_TRUE(c.HasParseError());
EXPECT_EQ(b.GetParseError(), noError.Code());
EXPECT_EQ(c.GetParseError(), error.Code());
EXPECT_EQ(b.GetErrorOffset(), noError.Offset());
EXPECT_EQ(c.GetErrorOffset(), error.Offset());
}
示例2: main
int main() {
Document d;
{
AsyncDocumentParser<> parser(d);
const char json1[] = " { \"hello\" : \"world\", \"t\" : tr";
//const char json1[] = " { \"hello\" : \"world\", \"t\" : trX"; // For test parsing error
const char json2[] = "ue, \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.14";
const char json3[] = "16, \"a\":[1, 2, 3, 4] } ";
parser.ParsePart(json1, sizeof(json1) - 1);
parser.ParsePart(json2, sizeof(json2) - 1);
parser.ParsePart(json3, sizeof(json3) - 1);
}
if (d.HasParseError()) {
std::cout << "Error at offset " << d.GetErrorOffset() << ": " << GetParseError_En(d.GetParseError()) << std::endl;
return EXIT_FAILURE;
}
// Stringify the JSON to cout
OStreamWrapper os(std::cout);
Writer<OStreamWrapper> writer(os);
d.Accept(writer);
std::cout << std::endl;
return EXIT_SUCCESS;
}
示例3:
TEST(Document, UnchangedOnParseError) {
Document doc;
doc.SetArray().PushBack(0, doc.GetAllocator());
ParseResult err = doc.Parse("{]");
EXPECT_TRUE(doc.HasParseError());
EXPECT_EQ(err.Code(), doc.GetParseError());
EXPECT_EQ(err.Offset(), doc.GetErrorOffset());
EXPECT_TRUE(doc.IsArray());
EXPECT_EQ(doc.Size(), 1u);
err = doc.Parse("{}");
EXPECT_FALSE(doc.HasParseError());
EXPECT_FALSE(err.IsError());
EXPECT_EQ(err.Code(), doc.GetParseError());
EXPECT_EQ(err.Offset(), doc.GetErrorOffset());
EXPECT_TRUE(doc.IsObject());
EXPECT_EQ(doc.MemberCount(), 0u);
}
示例4: Export
bool Export(const char* data, const char* outFile)
{
Document document;
document.Parse(data);
if (document.HasParseError()) {
ParseErrorCode err = document.GetParseError();
printf("pares error! %d %d", err, document.GetErrorOffset());
return false;
}
if (!document.IsObject())
{
printf("error, not a object");
return false;
}
InitializeSdkObjects();
const Value& skel = document["Skeleton"];
if (!skel.IsNull())
{
ExportBones(skel);
}
const Value& mesh = document["Mesh"];
if (!mesh.IsNull())
{
for (uint32_t i = 0; i < mesh.Size(); i++)
{
ExportFbxMesh(mesh[i]);
}
}
const Value& anim = document["Animation"];
if (!anim.IsNull())
{
for (uint32_t i = 0; i < anim.Size(); i++)
{
ExportAnimation(anim[i]);
}
}
SaveFbxFile(outFile);
return true;
}
示例5: parseSprite
Sprites parseSprite(const std::string& image, const std::string& json) {
using namespace rapidjson;
Sprites sprites;
// Parse the sprite image.
const util::Image raster(image);
if (!raster) {
Log::Warning(Event::Sprite, "Could not parse sprite image");
return sprites;
}
Document doc;
doc.Parse<0>(json.c_str());
if (doc.HasParseError()) {
Log::Warning(Event::Sprite, std::string{ "Failed to parse JSON: " } + doc.GetParseError() +
" at offset " + std::to_string(doc.GetErrorOffset()));
return sprites;
} else if (!doc.IsObject()) {
Log::Warning(Event::Sprite, "Sprite JSON root must be an object");
return sprites;
} else {
for (Value::ConstMemberIterator itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) {
const std::string name = { itr->name.GetString(), itr->name.GetStringLength() };
const Value& value = itr->value;
if (value.IsObject()) {
const uint16_t x = getUInt16(value, "x", 0);
const uint16_t y = getUInt16(value, "y", 0);
const uint16_t width = getUInt16(value, "width", 0);
const uint16_t height = getUInt16(value, "height", 0);
const double pixelRatio = getDouble(value, "pixelRatio", 1);
const bool sdf = getBoolean(value, "sdf", false);
auto sprite = createSpriteImage(raster, x, y, width, height, pixelRatio, sdf);
if (sprite) {
sprites.emplace(name, sprite);
}
}
}
}
return sprites;
}
示例6: decode
GameState* JsonEncodeDecode::decode(const char *buffer)
{
Document doc;
// Parse and catch errors
if (doc.Parse(buffer).HasParseError())
{
printf("\n----------\nError (offset %u): %s\n----------\n",
(unsigned)doc.GetErrorOffset(),
GetParseError_En(doc.GetParseError()));
return NULL;
}
// Create new GameState
GameState* state = new GameState();
// Iterate through JSON document
for (Value::ConstMemberIterator itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr)
{
/*
* GAME OVER STATE
*/
if (strcmp(itr->name.GetString(), "GameOver") == 0)
{
int gameOver = itr->value.GetInt();
state->setGameOver(gameOver);
}
/*
* TIME TO RESTART
*/
if (strcmp(itr->name.GetString(), "SecToRestart") == 0)
{
int secToRestart = itr->value.GetInt();
state->setSecToRestart(secToRestart);
}
/*
* VEHICLES
*/
if (strcmp(itr->name.GetString(), "Vehicles") == 0)
{
// If Vehicles is not an array, something went wrong
if (!itr->value.IsArray())
{
printf("\n----------\nError: Vehicles array is not array\n----------\n");
return NULL;
}
const Value& vehicleArray = itr->value;
for (SizeType i = 0; i < vehicleArray.Size(); i++)
{
if (decodeVehicle(state, vehicleArray[i]) == -1)
{
printf("\n----------\nError decoding vehicles\n----------\n");
return NULL;
}
}
}
/*
* BULLETS
*/
if (strcmp(itr->name.GetString(), "Bullets") == 0)
{
// If Bullets is not an array, something went wrong
if (!itr->value.IsArray())
{
printf("\n----------\nError: Bullets array is not array\n----------\n");
return NULL;
}
const Value& bulletArray = itr->value;
for (SizeType i = 0; i < bulletArray.Size(); i++)
{
if (decodeBullet(state, bulletArray[i]) == -1)
{
printf("\n----------\nError decoding bullets\n----------\n");
return NULL;
}
}
}
/*
* BASES
*/
if (strcmp(itr->name.GetString(), "Bases") == 0)
{
// If Bases is not an array, something went wrong
if (!itr->value.IsArray())
{
printf("\n----------\nError: Bases array is not array\n----------\n");
return NULL;
}
const Value& basesArray = itr->value;
for (SizeType i = 0; i < basesArray.Size(); i++)
{
if (decodeBase(state, basesArray[i]) == -1)
{
//.........这里部分代码省略.........
示例7: initialiseProblemJSON
EReturn Initialiser::initialiseProblemJSON(PlanningProblem_ptr problem,
const std::string& constraints)
{
{
Document document;
if (!document.Parse<0>(constraints.c_str()).HasParseError())
{
if (ok(problem->reinitialise(document, problem)))
{
// Everythinh is fine
}
else
{
INDICATE_FAILURE
;
return FAILURE;
}
}
else
{
ERROR(
"Can't parse constraints from JSON string!\n"<<document.GetParseError() <<"\n"<<constraints.substr(document.GetErrorOffset(),50));
return FAILURE;
}
}
return SUCCESS;
}
示例8: load
bool GateConfig::load(const char* jsonConfig)
{
char *json = filetool::get_whole_file_buf(jsonConfig);
if (NULL == json) {
return false;
}
Document doc;
if (doc.ParseInsitu(json).HasParseError()) {
LOG_ERROR << "parse config<" << jsonConfig << "> failed, error code = " << doc.GetParseError() << ", error offset = " << doc.GetErrorOffset()
<< ", err text = " << json[doc.GetErrorOffset()];
delete[] json;
return false;
}
if (!doc.IsObject()) {
LOG_ERROR;
return false;
}
{
// ¶ÁÈ¡ÄÚÍøÍøÂçÅäÖÃ
const Value& wan = doc["wan"];
const Value& wanListen = wan["listen"];
m_wanListen.ip = wanListen["ip"].GetString();
m_wanListen.port = wanListen["port"].GetInt();
m_wanThreadNum = wan["threads"].GetInt();
}
{
// ¶ÁÈ¡ÍâÍøÍøÂçÅäÖÃ
const Value& lan = doc["lan"];
const Value& lanListens = lan["listen"];
const Value& lanConnects = lan["listen"];
IpPort ipport;
for (SizeType i = 0; i < lanListens.Size(); i++) {
const Value &listen = lanListens[i];
ipport.ip = listen["ip"].GetString();
ipport.port = listen["port"].GetInt();
m_lanListens.push_back(ipport);
}
for (SizeType i = 0; i < lanConnects.Size(); i++) {
const Value &connect = lanConnects[i];
ipport.ip = connect["ip"].GetString();
ipport.port = connect["port"].GetInt();
m_lanConnects.push_back(ipport);
}
m_lanThreadNum = lan["threads"].GetInt();
}
delete[] json;
return true;
}