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


C++ parse_array函数代码示例

本文整理汇总了C++中parse_array函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_array函数的具体用法?C++ parse_array怎么用?C++ parse_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: isClaimedIDE

int isClaimedIDE(char *model)
{
	char tmparray[MAXARRAY][MAXARRSIZE];
	int tmpidx;
	unsigned long size=0;
	int i;

	tmpidx=parse_array("/tmp/diskstatus", "claimed_disk_interface_names", tmparray);

	for (i=0;i<tmpidx;i++)
	{
		printf("%d:%s\n", i, &tmparray[i][0]);
		if (strstr(&tmparray[i][0], "IDE")) break;
	}

	if (i==tmpidx) return 0;

	tmpidx=parse_array("/tmp/diskstatus", "claimed_disk_total_size", tmparray);
	if (i>=tmpidx) return 0;
	size = atoi(&tmparray[i][0]);
	
	tmpidx=parse_array("/tmp/diskstatus", "claimed_disk_model_info", tmparray);
	if (i>=tmpidx) return 0;
	strcpy(model, &tmparray[i][0]);
	return size;
}
开发者ID:morpheu,项目名称:asuswrt-merlin,代码行数:26,代码来源:storage.c

示例2: scan_space

int JSON::parse_value(const char *begin, const char *end, JSON::Node *node)
{
	char const *ptr = begin;
	int n;
	ptr += scan_space(ptr, end);
	if (ptr < end) {
		if (*ptr == '[') {
			ptr++;
			node->type = Type::Array;
			n = parse_array(ptr, end, false, &node->children);
			ptr += n;
			if (ptr < end && *ptr == ']') {
				ptr++;
				return ptr - begin;
			}
		} else if (*ptr == '{') {
			ptr++;
			node->type = Type::Object;
			n = parse_array(ptr, end, true, &node->children);
			ptr += n;
			if (ptr < end && *ptr == '}') {
				ptr++;
				return ptr - begin;
			}
		} else if (*ptr == '\"') {
			n = parse_string(ptr, end, &node->value);
			if (n > 0) {
				ptr += n;
				node->type = Type::String;
				return ptr - begin;
			}
		} else {
			char const *left = ptr;
			while (ptr < end) {
				int c = *ptr & 0xff;
				if (isspace(c)) break;
				if (strchr("[]{},:\"", c)) break;
				ptr++;
			}
			if (left < ptr) {
				std::string value(left, ptr);
				if (value == "null") {
					node->type = Type::Null;
				} else if (value == "false") {
					node->type = Type::Boolean;
					node->value = "0";
				} else if (value == "true") {
					node->type = Type::Boolean;
					node->value = "1";
				} else {
					node->type = Type::Number;
					node->value = value;
				}
				return ptr - begin;
			}
		}
	}
	return 0;
}
开发者ID:soramimi,项目名称:twicpps,代码行数:59,代码来源:json.cpp

示例3: parse_array_element

static void
parse_array_element(JsonLexContext *lex, JsonSemAction *sem)
{
	json_aelem_action astart = sem->array_element_start;
	json_aelem_action aend = sem->array_element_end;
	JsonTokenType tok = lex_peek(lex);

	bool		isnull;

	isnull = tok == JSON_TOKEN_NULL;

	if (astart != NULL)
		(*astart) (sem->semstate, isnull);

	/* an array element is any object, array or scalar */
	switch (tok)
	{
		case JSON_TOKEN_OBJECT_START:
			parse_object(lex, sem);
			break;
		case JSON_TOKEN_ARRAY_START:
			parse_array(lex, sem);
			break;
		default:
			parse_scalar(lex, sem);
	}

	if (aend != NULL)
		(*aend) (sem->semstate, isnull);
}
开发者ID:sqlparser,项目名称:postgres,代码行数:30,代码来源:json.c

示例4: parse_value

// value = 'null' | 'true' | 'false' | number | string | array | object
static int parse_value(struct frozen *f) {
  int ch = cur(f);
  if (ch == '"') {
    TRY(parse_string(f));
  } else if (ch == '{') {
    TRY(parse_object(f));
  } else if (ch == '[') {
    TRY(parse_array(f));
  } else if (ch == 'n' && left(f) > 4 && compare(f->cur, "null", 4)) {
    TRY(capture_ptr(f, f->cur, JSON_TYPE_NULL));
    f->cur += 4;
    capture_len(f, f->num_tokens - 1, f->cur);
  } else if (ch == 't' && left(f) > 4 && compare(f->cur, "true", 4)) {
    TRY(capture_ptr(f, f->cur, JSON_TYPE_TRUE));
    f->cur += 4;
    capture_len(f, f->num_tokens - 1, f->cur);
  } else if (ch == 'f' && left(f) > 5 && compare(f->cur, "false", 5)) {
    TRY(capture_ptr(f, f->cur, JSON_TYPE_FALSE));
    f->cur += 5;
    capture_len(f, f->num_tokens - 1, f->cur);
  } else if (is_digit(ch) ||
             (ch == '-' && f->cur + 1 < f->end && is_digit(f->cur[1]))) {
    TRY(parse_number(f));
  } else {
    return ch == END_OF_STRING ? JSON_STRING_INCOMPLETE : JSON_STRING_INVALID;
  }
  return 0;
}
开发者ID:4gifted,项目名称:traveller,代码行数:29,代码来源:frozen.c

示例5: consume_white_space

json parser::parse_next(
    const std::string& input, size_t& offset, std::error_code& error)
{
    char value;
    consume_white_space(input, offset, error);
    value = input[offset];
    switch (value)
    {
    case '[': return parse_array(input, offset, error);
    case '{': return parse_object(input, offset, error);
    case '\"': return parse_string(input, offset, error);
    case 't':
    case 'f': return parse_bool(input, offset, error);
    case 'n': return parse_null(input, offset, error);
    default:
    {
        if ((value <= '9' && value >= '0') || value == '-')
        {
            return parse_number(input, offset, error);
        }
    }
    }
    // Error: Unknown starting character
    error = std::make_error_code(std::errc::invalid_argument);
    return json();
}
开发者ID:steinwurf,项目名称:bourne,代码行数:26,代码来源:parser.cpp

示例6: pg_parse_json

/*
 * pg_parse_json
 *
 * Publicly visible entry point for the JSON parser.
 *
 * lex is a lexing context, set up for the json to be processed by calling
 * makeJsonLexContext(). sem is a strucure of function pointers to semantic
 * action routines to be called at appropriate spots during parsing, and a
 * pointer to a state object to be passed to those routines.
 */
void
pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
{
	JsonTokenType tok;

	/* get the initial token */
	json_lex(lex);

	tok = lex_peek(lex);

	/* parse by recursive descent */
	switch (tok)
	{
		case JSON_TOKEN_OBJECT_START:
			parse_object(lex, sem);
			break;
		case JSON_TOKEN_ARRAY_START:
			parse_array(lex, sem);
			break;
		default:
			parse_scalar(lex, sem);		/* json can be a bare scalar */
	}

	lex_expect(JSON_PARSE_END, lex, JSON_TOKEN_END);

}
开发者ID:sqlparser,项目名称:postgres,代码行数:36,代码来源:json.c

示例7: parse_key_value

static void parse_key_value(int indent, json_obj_t * kv){
  if(kv->type != JSON_KEY_VALUE_PAIR){
    printf("%d: unexpected type %d\n", __LINE__, kv->type);
    return;
  }
  json_obj_t * key = kv->children;
  json_obj_t * value = kv->children->next_sibling;

  printf("%*s%.*s",IDENT(indent), "",  key->length, key->str);

  switch(value->type){
    case JSON_STRING:
      printf(" -> %.*s\n", value->length, value->str);
      break;
    case JSON_PRIMITIVE:
      printf(" -> %.*s\n", value->length, value->str);
      break;
    case JSON_OBJECT:
      printf("\n");
      parse_object(indent + 1, value);
      printf("\n");
      break;
    case JSON_ARRAY:
      printf("\n");
      parse_array(indent + 1, value);
      printf("\n");
      break;
    default:
      printf("%d: unexpected type %d in array\n", __LINE__, value->type);
      return;
  }
}
开发者ID:petter-petersson,项目名称:pettson,代码行数:32,代码来源:sample.c

示例8: if

void config_file::parse_key(config_file::value& value, std::string& key, const std::string& strvalue)
{
  value::value_type keytype = config_file::parse_keytype(key);
  value.type_ = keytype;
  
  if(keytype == value::RAW_VALUE){
    value.raw_value_ = strvalue;
  }
  else if(keytype == value::ARRAY){
    size_t index;
    bool ret_val = parse_array(key, index);
    if(index>=value.array_.size())
    {
      value.array_.resize(index + 1);
    }
    parse_key(value.array_[index], key, strvalue);
  }
  else if(keytype == value::RECORD){
    std::string recordname = parse_record_name(key);
    mapi it = value.record_.find(recordname);
    if(it == value.record_.end()){
      config_file::value new_value;
      parse_key(new_value, key, strvalue);
      value.record_.insert(mapt::value_type(recordname, new_value));
    }
    else{
      parse_key(it->second, key, strvalue);
    }
  }
}
开发者ID:ShiningDrops,项目名称:switchflow,代码行数:30,代码来源:config_file.cpp

示例9: main

int main(int argc, char **argv) {

  char *buf;
  if(read_json_file(&buf, JSON_FILE)!=0){
    printf("failed to read fixture\n");
    if(buf != NULL){
      free(buf);
    }
    return 1;
  }

  json_context_t ctx;
  json_init_context(&ctx, buf);

  json_obj_t * res = NULL;
  res = json_read_array(NULL, &ctx);

  parse_array(1, res);


  json_object_destroy(res, &ctx);

  if(buf != NULL){
    free(buf);
  }
  return 0;
}
开发者ID:petter-petersson,项目名称:pettson,代码行数:27,代码来源:sample.c

示例10: switch

// build JSON object hierarchy
JSON * JSON::parse_private(Lexer *lexer)
{
    // check token to determine what JSON type to construct
    Json_Token token = lexer->get_token();
    
    switch (token)
    {
        case Object_start_token:
            return parse_object(lexer);
        case Array_start_token:
            return parse_array(lexer);
        case String_token:
            return new_string(lexer->token_src, lexer->token_len);
        case Null_token:
            return new_null();
        case True_token:
            return new_boolean(true);
        case False_token:
            return new_boolean(false);
        case Float_token:
            return new_float(lexer->float_num);
        case Unsigned_token:
            return new_unsigned(lexer->unsigned_num);
        case Signed_token:
            return new_signed(lexer->signed_num);
        default:
            Serial.println(F("JSON syntax error"));
    }

    return null;
}
开发者ID:w3c,项目名称:wot-arduino,代码行数:32,代码来源:JSON.cpp

示例11: SKIPWS

static ZZJSON *parse_value(ZZJSON_CONFIG *config) {
    ZZJSON *retval = NULL;
    int c;

    SKIPWS();
    c = GETC();
    UNGETC(c);
    switch (c) {
        case '"':   retval = parse_string2(config); break;
        case '0': case '1': case '2': case '3': case '4': case '5':
        case '6': case '7': case '8': case '9': case '-':
                    retval = parse_number(config); break;
        case '{':   retval = parse_object(config); break;
        case '[':   retval = parse_array(config); break;
        case 't':   retval = parse_true(config); break;
        case 'f':   retval = parse_false(config); break;
        case 'n':   retval = parse_null(config); break;
    }

    if (!retval) {
        ERROR("value: invalid value");
        return retval;
    }

    return retval;
}
开发者ID:1stMaster,项目名称:syslinux,代码行数:26,代码来源:zzjson_parse.c

示例12: parse_string

/* Parser core - when encountering text, process appropriately. */
static const char *parse_value(srjson_doc_t *doc, srjson_t *item, const char *value)
{
	if (!value)
		return 0;	/* Fail on null. */
	if (!strncmp(value, "null", 4)) {
		item->type = srjson_NULL;
		item->valuedouble = 0;
		return value + 4;
	}
	if (!strncmp(value, "false", 5)) {
		item->type = srjson_False;
		item->valuedouble = 0;
		return value + 5;
	}
	if (!strncmp(value, "true", 4)) {
		item->type = srjson_True;
		item->valuedouble = 1;
		return value + 4;
	}
	if (*value == '\"') {
		return parse_string(doc, item, value);
	}
	if (*value == '-' || (*value >= '0' && *value <= '9')) {
		return parse_number(doc, item, value);
	}
	if (*value == '[') {
		return parse_array(doc, item, value);
	}
	if (*value == '{') {
		return parse_object(doc, item, value);
	}
	ep = value;
	return 0;		/* failure. */
}
开发者ID:GreenfieldTech,项目名称:kamailio,代码行数:35,代码来源:srjson.c

示例13: parse_string

/* Parser core - when encountering text, process appropriately. */
static const char *parse_value(cJSON *item,const char *value) {
    if (!value) {
        return 0;    /* Fail on null. */
    }
    if (!strncmp(value,"null",4))	{
        item->type=cJSON_NULL;
        return value+4;
    }
    if (!strncmp(value,"false",5))	{
        item->type=cJSON_False;
        return value+5;
    }
    if (!strncmp(value,"true",4))	{
        item->type=cJSON_True;
        item->valueint=1;
        return value+4;
    }
    if (*value=='\"')				{
        return parse_string(item,value);
    }
    if (*value=='-' || (*value>='0' && *value<='9'))	{
        return parse_number(item,value);
    }
    if (*value=='[')				{
        return parse_array(item,value);
    }
    if (*value=='{')				{
        return parse_object(item,value);
    }

    ep=value;
    return 0;	/* failure. */
}
开发者ID:JasonYSU,项目名称:VETH3000Switch,代码行数:34,代码来源:cJSON.c

示例14: parse_value

/* Parser core - when encountering text, process appropriately. */
static const char* parse_value (json *item, const char* value) {
    /* Referenced by json_create(), parse_array(), and parse_object(). */
    /* Always called with the result of skip(). */
#if SPINE_JSON_DEBUG /* Checked at entry to graph, json_create, and after every parse_ call. */
	if (!value) return 0; /* Fail on null. */
#endif

    switch (*value) {
        case 'n': {
            if (!strncmp(value + 1, "ull", 3)) {
                item->type = json_NULL;
                return value + 4;
            }
            break;
        }
        case 'f': {
            if (!strncmp(value + 1, "alse", 4)) {
                item->type = json_False;
                /* calloc prevents us needing item->type = json_False or valueInt = 0 here */
                return value + 5;
            }
            break;
        }
        case 't': {
            if (!strncmp(value + 1, "rue", 3)) {
                item->type = json_True;
                item->valueInt = 1;
                return value + 4;
            }
            break;
        }
        case '\"':
            return parse_string(item, value);
        case '[':
            return parse_array(item, value);
        case '{':
            return parse_object(item, value);
        case '-': /* fallthrough */
        case '0': /* fallthrough */
        case '1': /* fallthrough */
        case '2': /* fallthrough */
        case '3': /* fallthrough */
        case '4': /* fallthrough */
        case '5': /* fallthrough */
        case '6': /* fallthrough */
        case '7': /* fallthrough */
        case '8': /* fallthrough */
        case '9':
            return parse_number(item, value);
        default:
            break;
    }

    ep = value;
    return 0; /* failure. */
}
开发者ID:martinpetrus,项目名称:1101,代码行数:57,代码来源:json.c

示例15: PatternBase

TilingPatternImpl::TilingPatternImpl(DocWriterImpl& doc,
                                     Char const* pattern_str,
                                     ICanvas* canvas)
    : PatternBase(pattern_str)
    , m_doc(doc)
    , m_canvas(checked_static_cast<CanvasImpl*>(canvas))
{
    if (m_canvas->content_stream().is_empty())
        throw exception_invalid_value(msg_pattern_no_canvas()) << JAGLOC;

    IProfileInternal const& profile = m_doc.exec_context().config();
    m_tiling_type = static_cast<PatternTilingType>(
        profile.get_int("patterns.tiling_type"));

    reset_indirect_object_worker(m_canvas);

    // parse the string spec
    try
    {
        ParsedResult const& p =
            parse_options(pattern_str,
                          ParseArgs(&g_tiling_keywords));


        parse_array(p, TIP_MATRIX, m_matrix, true, 6);
        parse_array(p, TIP_STEP, m_step, false, 2);
        if (!parse_array(p, TIP_BBOX, m_bbox, true, 4))
        {
            // if bbox not set, set it to [0, 0, stepx, stepy]
            m_bbox[0] = m_bbox[1] = 0;
            m_bbox[2] = m_step[0];
            m_bbox[3] = m_step[1];
        }
        m_tiling_type = static_cast<PatternTilingType>(
            p.to_<int>(TIP_TYPE, m_tiling_type));
    }
    catch(exception const& exc)
    {
        throw exception_invalid_value(
            msg_invalid_shading_spec(), &exc) << JAGLOC;
    }
}
开发者ID:Rogaven,项目名称:jagpdf,代码行数:42,代码来源:patternimpl.cpp


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