本文整理汇总了C++中ParseResult类的典型用法代码示例。如果您正苦于以下问题:C++ ParseResult类的具体用法?C++ ParseResult怎么用?C++ ParseResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParseResult类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
static type process(const std::string & str, unsigned int & i, ParseResult & result, const CharacterValidator & validator)
{
while (i < str.size() && std::isspace(str[i])) {
++i;
}
unsigned int start = i;
if (i < str.size() && (str[i] == '-' || str[i] == '+')) {
++i;
}
while (i < str.size() && std::isdigit(str[i])) {
++i;
}
if (i < str.size() && !validator.isReserved(str[i]) && !std::isspace(str[i])) {
result.setError("Unexpected character in integer token", i);
} else if (i > start) {
std::string token = str.substr(start, i-start);
char * e = 0;
long int d = std::strtol(token.c_str(), &e, 10);
if (!(e != 0 && *e == 0)) {
result.setError("Could not convert token to integer type", start);
} else if (errno == ERANGE && d > INT_MAX) {
result.setError("Integer overflow", start);
} else if (errno == ERANGE && d < INT_MIN) {
result.setError("Integer underflow", start);
} else {
return (int)d;
}
}
return 0;
}
示例2: parse
ParseResult Pid::parse(const Line& line, Output& output, bool execute) {
auto iter = line.begin();
auto endIter = line.end();
ParseResult desc;
const auto parser = x3::with<ParseResult>(ref(desc))[command];
ast::PidCommand data;
const bool ok {x3::phrase_parse(iter, endIter, parser, x3::space, data)};
if (!ok) return desc;
const unsigned pid = data.pid ? boost::apply_visitor(PidVisitor{}, data.pid.get())
: getpid();
desc.status(Status::Ok);
if (execute) {
if (data.function) {
boost::apply_visitor(FunctionVisitor{pid, output}, data.function.get());
} else {
output << pid << "\n";
}
}
return desc;
}
示例3: TEST
TEST(Reader, IterativeParsing_Count) {
{
StringStream is("[{}, {\"k\": 1}, [1], []]");
Reader reader;
IterativeParsingReaderHandler<> handler;
ParseResult r = reader.Parse<kParseIterativeFlag>(is, handler);
EXPECT_FALSE(r.IsError());
EXPECT_FALSE(reader.HasParseError());
int e[] = {
handler.LOG_STARTARRAY,
handler.LOG_STARTOBJECT,
handler.LOG_ENDOBJECT, 0,
handler.LOG_STARTOBJECT,
handler.LOG_KEY,
handler.LOG_INT,
handler.LOG_ENDOBJECT, 1,
handler.LOG_STARTARRAY,
handler.LOG_INT,
handler.LOG_ENDARRAY, 1,
handler.LOG_STARTARRAY,
handler.LOG_ENDARRAY, 0,
handler.LOG_ENDARRAY, 4
};
EXPECT_EQ(sizeof(e) / sizeof(int), handler.LogCount);
for (size_t i = 0; i < handler.LogCount; ++i) {
EXPECT_EQ(e[i], handler.Logs[i]) << "i = " << i;
}
}
}
示例4: load_feature_list_from_json_string
bool load_feature_list_from_json_string(pfc::list_base_t<feature_handle_ptr> &p_list, const char * p_json)
{
FeatureListReaderHandler handler(p_list);
Reader reader;
StringStream stream(p_json);
ParseResult result = reader.Parse(stream, handler);
return !result.IsError();
}
示例5: matches
ParseResult BuiltIn::parse(const Line& line, Output& output, bool execute) {
auto matched = matches(line);
if (matched && execute){
_function(line, output);
}
ParseResult desc;
if (matched){
desc.status(Status::Ok);
desc.segments().emplace_back(Segment::Type::Builtin, line.begin(), line.end(), _help);
}
return desc;
}
示例6: handleExecuteCommand
ParseResult Shell::handleExecuteCommand(const LineBuffer& line){
_buffer += line.line();
const ParseResult executionResult {
_commands.parse(_buffer, _out, true)};
switch (executionResult.status()) {
case Status::Incomplete:
_buffer += '\n';
break;
default:
_buffer.clear();
break;
}
return executionResult;
}
示例7: destructStruct
bool
destructStruct(Context *ctx, ParseResult *pr, ParseResult *ret_pr,
llvm::IRBuilder<> *builder, bool value_is_ptr)
{
Struct *st = ctx->getStruct(pr->type);
std::vector<Type*> *st_types = &(st->member_types);
llvm::Value *struct_value;
if (value_is_ptr) {
struct_value = pr->value;
} else {
struct_value = llvm::cast<llvm::Value>(
builder->CreateAlloca(
ctx->toLLVMType(pr->type, NULL, false))
);
builder->CreateStore(pr->value, struct_value);
}
int i = 0;
for (std::vector<Type*>::iterator b = st_types->begin(),
e = st_types->end();
b != e;
++b) {
ParseResult element;
element.set(ret_pr->block, *b, struct_value);
std::vector<llvm::Value *> indices;
STL::push_back2(
&indices,
ctx->nt->getLLVMZero(),
llvm::cast<llvm::Value>(ctx->nt->getNativeInt(i++))
);
element.value =
builder->Insert(
llvm::GetElementPtrInst::Create(
struct_value,
llvm::ArrayRef<llvm::Value*>(indices)
),
"sp"
);
element.do_not_destruct = false;
Destruct(ctx, &element, &element, builder, true);
ret_pr->block = element.block;
}
return true;
}
示例8: 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;
}
示例9: TYPED_TEST
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());
}
示例10: CHECK
void Stream::HandleRpcResponse(butil::IOBuf* response_buffer) {
CHECK(!_remote_settings.IsInitialized());
CHECK(_host_socket != NULL);
std::unique_ptr<butil::IOBuf> buf_guard(response_buffer);
ParseResult pr = policy::ParseRpcMessage(response_buffer, NULL, true, NULL);
if (!pr.is_ok()) {
CHECK(false);
Close();
return;
}
InputMessageBase* msg = pr.message();
if (msg == NULL) {
CHECK(false);
Close();
return;
}
_host_socket->PostponeEOF();
_host_socket->ReAddress(&msg->_socket);
msg->_received_us = butil::gettimeofday_us();
msg->_base_real_us = butil::gettimeofday_us();
msg->_arg = NULL; // ProcessRpcResponse() don't need arg
policy::ProcessRpcResponse(msg);
}
示例11: TEST
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);
}
示例12: 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);
//.........这里部分代码省略.........