当前位置: 首页>>代码示例>>C++>>正文


C++ ParseResult::Offset方法代码示例

本文整理汇总了C++中ParseResult::Offset方法的典型用法代码示例。如果您正苦于以下问题:C++ ParseResult::Offset方法的具体用法?C++ ParseResult::Offset怎么用?C++ ParseResult::Offset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParseResult的用法示例。


在下文中一共展示了ParseResult::Offset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
开发者ID:Longhui,项目名称:mysql-5.7.9-readcode,代码行数:30,代码来源:documenttest.cpp

示例2: is

TEST(Reader, IterativeParsing_ShortCircuit) {
    {
        HandlerTerminateAtStartObject handler;
        Reader reader;
        StringStream is("[1, {}]");

        ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);

        EXPECT_TRUE(reader.HasParseError());
        EXPECT_EQ(kParseErrorTermination, r.Code());
        EXPECT_EQ(4u, r.Offset());
    }

    {
        HandlerTerminateAtStartArray handler;
        Reader reader;
        StringStream is("{\"a\": []}");

        ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);

        EXPECT_TRUE(reader.HasParseError());
        EXPECT_EQ(kParseErrorTermination, r.Code());
        EXPECT_EQ(6u, r.Offset());
    }

    {
        HandlerTerminateAtEndObject handler;
        Reader reader;
        StringStream is("[1, {}]");

        ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);

        EXPECT_TRUE(reader.HasParseError());
        EXPECT_EQ(kParseErrorTermination, r.Code());
        EXPECT_EQ(5u, r.Offset());
    }

    {
        HandlerTerminateAtEndArray handler;
        Reader reader;
        StringStream is("{\"a\": []}");

        ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);

        EXPECT_TRUE(reader.HasParseError());
        EXPECT_EQ(kParseErrorTermination, r.Code());
        EXPECT_EQ(7u, r.Offset());
    }
}
开发者ID:ALEXGUOQ,项目名称:rapidjson,代码行数:49,代码来源:readertest.cpp

示例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);
}
开发者ID:amandatta16,项目名称:rapidjson,代码行数:19,代码来源:documenttest.cpp

示例4: decode

int decode(lua_State* L, Stream* s)
{
    auto top = lua_gettop(L);
    values::ToLuaHandler handler(L);
    Reader reader;

    ParseResult r = reader.Parse(*s, handler);
    if (!r)
    {
        lua_settop(L, top);
        lua_pushnil(L);
        lua_pushfstring(L, "%s (%d)", GetParseError_En(r.Code()), r.Offset());
        return 2;
    }

    return 1;
}
开发者ID:wtfbbqhax,项目名称:tremulous,代码行数:17,代码来源:rapidjson.cpp

示例5: evaluate

	virtual ReturnValue evaluate()
	{
		char valueBuffer[MAX_JSON_DOCUMENT_LENGTH];
		char parseBuffer[MAX_JSON_STRING_LENGTH];
		MemoryPoolAllocator<> valueAllocator(valueBuffer, sizeof(valueBuffer));
		MemoryPoolAllocator<> parseAllocator(parseBuffer, sizeof(parseBuffer));

		// input: JSON document, JSON pointer
		DocumentNZ document(&valueAllocator, sizeof(parseBuffer), &parseAllocator);
		Pointer pointer;

		// JSON input document in argument[0]
		StringArg *arg0;
		arg0 = stringArg(0);
		char *input = arg0->data;
		int inputLen = arg0->length;
		if (inputLen > MAX_JSON_DOCUMENT_LENGTH) {
			throwUdxException("JSON input too long");
		}
		logMsg(LOG_DEBUG, "INPUT: %.*s\n", inputLen, input);

		// parse JSON input
		ParseResult ok = document.Parse(input);
		if (!ok) {
			char msg[1024];
			sprintf(msg, "JSON parse error (offset %u): %s\n",
		        ok.Offset(), GetParseError_En(ok.Code()));
			throwUdxException(msg);
		}

		// JSON input pointer in argument[1]
		StringArg *arg1;
		arg1 = stringArg(1);
		char *ptr = arg1->data;
		int ptrLen = arg1->length;
		logMsg(LOG_DEBUG, "POINTER: %.*s\n", ptrLen, ptr);
		pointer = Pointer(ptr);
		if (!pointer.IsValid()) {
			char msg[1024];
			sprintf(msg, "JSON pointer error (offset %u): %d\n",
		        pointer.GetParseErrorOffset(), pointer.GetParseErrorCode());
			throwUdxException(msg);
		}

		// retrieve value
		Value* result = pointer.Get(document);
		if (!result || result->IsNull()) {
			logMsg(LOG_DEBUG, "RESULT: NULL\n");
			NZ_UDX_RETURN_NULL();
		}

		// handle results
		if (result->IsBool()) {
			if (STRING_TYPE(returnType())) {
				StringReturn* ret = stringReturnInfo();
				const char* retval = result->GetBool() ? "true" : "false";
				ret->size = strlen(retval);
				memcpy(ret->data, retval, ret->size);
				NZ_UDX_RETURN_STRING(ret);
			}
			logMsg(LOG_DEBUG, "RESULT: %s\n", result->GetBool() ? "true" : "false");
			NZ_UDX_RETURN_BOOL(result->GetBool());
		}
		if (result->IsInt()) {		// check for Int first to do the 'smallest' ones early
			if (STRING_TYPE(returnType())) {
				StringReturn* ret = stringReturnInfo();
				sprintf(ret->data, "%ld", result->GetInt());
				ret->size = strlen(ret->data);
				NZ_UDX_RETURN_STRING(ret);
			}
			logMsg(LOG_DEBUG, "RESULT: %ld\n", result->GetInt());
			NZ_UDX_RETURN_INT32(result->GetInt());
		}
		if (result->IsInt64()) {	// then for Int64 to handle left over big ints
			if (STRING_TYPE(returnType())) {
				StringReturn* ret = stringReturnInfo();
				sprintf(ret->data, "%lld", result->GetInt64());
				ret->size = strlen(ret->data);
				NZ_UDX_RETURN_STRING(ret);
			}
			logMsg(LOG_DEBUG, "RESULT: %lld\n", result->GetInt64());
			NZ_UDX_RETURN_INT64(result->GetInt64());
		}
		if (result->IsDouble()) {
			if (STRING_TYPE(returnType())) {
				StringReturn* ret = stringReturnInfo();
				sprintf(ret->data, "%g", result->GetDouble());
				ret->size = strlen(ret->data);
				NZ_UDX_RETURN_STRING(ret);
			}
			logMsg(LOG_DEBUG, "RESULT: %g\n", result->GetDouble());
			NZ_UDX_RETURN_DOUBLE(result->GetDouble());
		}
		if (result->IsString()) {
			// output: JSON string value at pointer
			StringReturn* ret = stringReturnInfo();
			logMsg(LOG_DEBUG, "RESULT: %.*s\n", result->GetStringLength(), result->GetString());
			ret->size = result->GetStringLength();
			memcpy(ret->data, result->GetString(), ret->size);
			NZ_UDX_RETURN_STRING(ret);
//.........这里部分代码省略.........
开发者ID:Bartman0,项目名称:NZJSON,代码行数:101,代码来源:GetValueByPointer.cpp


注:本文中的ParseResult::Offset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。