本文整理汇总了C++中parse_array函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_array函数的具体用法?C++ parse_array怎么用?C++ parse_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_array函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: parse_value
static heim_object_t
parse_value(struct parse_ctx *ctx)
{
size_t len;
heim_object_t o;
if (white_spaces(ctx))
return NULL;
if (*ctx->p == '"') {
return parse_string(ctx);
} else if (*ctx->p == '{') {
if (ctx->depth-- == 1) {
ctx->error = heim_error_create(EINVAL, "JSON object too deep");
return NULL;
}
o = parse_dict(ctx);
ctx->depth++;
return o;
} else if (*ctx->p == '[') {
if (ctx->depth-- == 1) {
ctx->error = heim_error_create(EINVAL, "JSON object too deep");
return NULL;
}
o = parse_array(ctx);
ctx->depth++;
return o;
} else if (is_number(*ctx->p) || *ctx->p == '-') {
return parse_number(ctx);
}
len = ctx->pend - ctx->p;
if ((ctx->flags & HEIM_JSON_F_NO_C_NULL) == 0 &&
len >= 6 && memcmp(ctx->p, "<NULL>", 6) == 0) {
ctx->p += 6;
return heim_null_create();
} else if (len >= 4 && memcmp(ctx->p, "null", 4) == 0) {
ctx->p += 4;
return heim_null_create();
} else if (len >= 4 && strncasecmp((char *)ctx->p, "true", 4) == 0) {
ctx->p += 4;
return heim_bool_create(1);
} else if (len >= 5 && strncasecmp((char *)ctx->p, "false", 5) == 0) {
ctx->p += 5;
return heim_bool_create(0);
}
ctx->error = heim_error_create(EINVAL, "unknown char %c at %lu line %lu",
(char)*ctx->p,
(unsigned long)(ctx->p - ctx->pstart),
ctx->lineno);
return NULL;
}
开发者ID:kaduk,项目名称:heimdal,代码行数:54,代码来源:json.c
示例17: switch
static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error)
{
json_t *json;
switch(lex->token) {
case TOKEN_STRING: {
json = json_string_nocheck(lex->value.string);
break;
}
case TOKEN_INTEGER: {
json = json_integer(lex->value.integer);
break;
}
case TOKEN_REAL: {
json = json_real(lex->value.real);
break;
}
case TOKEN_TRUE:
json = json_true();
break;
case TOKEN_FALSE:
json = json_false();
break;
case TOKEN_NULL:
json = json_null();
break;
case '{':
json = parse_object(lex, flags, error);
break;
case '[':
json = parse_array(lex, flags, error);
break;
case TOKEN_INVALID:
error_set(error, lex, "invalid token");
return NULL;
default:
error_set(error, lex, "unexpected token");
return NULL;
}
if(!json)
return NULL;
return json;
}
开发者ID:JDGBOLT,项目名称:impact,代码行数:54,代码来源:load.c
示例18:
// Parser core - when encountering text, process appropriately.
const char *parse_value(JSON *item,const char *value)
{
if (!value) return 0; // Fail on null.
if (!strncmp(value,"null",4)) { item->type=JSON_NULL; return value+4; }
if (!strncmp(value,"false",5)) { item->type=JSON_FALSE; return value+5; }
if (!strncmp(value,"true",4)) { item->type=JSON_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); }
return 0; // failure.
}
开发者ID:inhedron,项目名称:libtr50,代码行数:14,代码来源:tr50.json.c
示例19: main
int main (void) {
// Read the array in first
int ** matrix = malloc (sizeof (int*) * DIMENSIONS);
int index = 0;
while (index < DIMENSIONS) {
matrix[index] = malloc (sizeof (int) * DIMENSIONS);
index++;
}
srand (time(NULL));
int col = 0;
while (col < DIMENSIONS) {
int row = 0;
while (row < DIMENSIONS) {
int value = rand() % 100;
if (value < 100-FREQUENCY) {
matrix[col][row] = 0;
} else {
matrix[col][row] = 1;
}
row++;
}
col++;
}
// Show the matrix
show_array (matrix);
// Keep track of values in an array
int nextFree = 0;
int * areas = malloc (sizeof (int) * DIMENSIONS * DIMENSIONS);
// Parse matrix
parse_array (matrix, areas, &nextFree);
// See what values we come up with
index = 0;
printf ("AREAS: ");
while (index < nextFree) {
printf ("%d ", areas[index]);
index++;
}
printf("\n");
// Perform quick select for median.
printf ("Median Area: %d\n", quickselect (areas, nextFree - 1));
return EXIT_SUCCESS;
}
开发者ID:stanleyhon,项目名称:grind,代码行数:51,代码来源:mma.c
示例20: IndirectObjectImpl
ShadingImpl::ShadingImpl(DocWriterImpl& doc,
Char const* pattern,
ColorSpaceHandle cs,
FunctionHandle const* fns,
UInt num_functions)
: IndirectObjectImpl(doc)
, m_cs(cs)
{
// Indexed is not allowed for dictionaries with Function field. Shading
// types supported now require Function field so indexed color space is
// forbidden.
if (is_pattern_color_space(cs) || (CS_INDEXED == color_space_type(cs)))
throw exception_invalid_value(msg_shading_invalid_space()) << JAGLOC;
m_function_handles.resize(num_functions);
std::copy(fns, fns + num_functions, m_function_handles.begin());
try
{
ParsedResult const& p =
parse_options(pattern, ParseArgs(&g_shading_keywords, &g_shading_values));
// common options matrix
parse_array(p, SH_BBOX, m_bbox, true, 4);
parse_array(p, SH_BACKGROUND, m_background);
// shading type specific
m_shading_type = p.explicit_value();
switch(m_shading_type)
{
case SHV_AXIAL:
case SHV_RADIAL:
parse_array(p, SH_COORDS, m_coords, false, m_shading_type==SHV_AXIAL ? 4 : 6);
parse_array(p, SH_DOMAIN, m_domain, true, 2);
if (parse_array(p, SH_EXTEND, m_extend, true, 2)) m_keys.set(BIT_EXTEND);
break;
case SHV_FUNCTION:
parse_array(p, SH_MATRIX_FUN, m_matrix_fun, true, 6);
parse_array(p, SH_DOMAIN, m_domain, true, 4);
break;
default:
throw exception_invalid_value(msg_unknown_shading_type()) << JAGLOC;
}
}
catch(exception const& exc)
{
throw exception_invalid_value(msg_invalid_shading_spec(), &exc) << JAGLOC;
}
}
开发者ID:Rogaven,项目名称:jagpdf,代码行数:51,代码来源:patternimpl.cpp
注:本文中的parse_array函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论