示例#1
0
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;
}
示例#2
0
文件: json.cpp 项目: soramimi/twicpps
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;
}
示例#3
0
文件: json.c 项目: sqlparser/postgres
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);
}
示例#4
0
// 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;
}
示例#5
0
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();
}
示例#6
0
文件: json.c 项目: sqlparser/postgres
/*
 * 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);

}
示例#7
0
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;
  }
}
示例#8
0
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);
    }
  }
}
示例#9
0
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;
}
示例#10
0
文件: JSON.cpp 项目: w3c/wot-arduino
// 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;
}
示例#11
0
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;
}
示例#12
0
/* 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. */
}
示例#13
0
/* 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. */
}
示例#14
0
文件: json.c 项目: martinpetrus/1101
/* 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. */
}
示例#15
0
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;
    }
}
示例#16
0
文件: json.c 项目: kaduk/heimdal
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;
}
示例#17
0
文件: load.c 项目: JDGBOLT/impact
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;
}
示例#18
0
// 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.
}
示例#19
0
文件: mma.c 项目: stanleyhon/grind
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;
}
示例#20
0
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;
    }
}
示例#21
0
文件: frozen.c 项目: moodyking/frozen
static int doit(struct frozen *f) {
  int ret = 0;

  if (f->cur == 0 || f->end < f->cur) return JSON_STRING_INVALID;
  if (f->end == f->cur) return JSON_STRING_INCOMPLETE;

  if (0 == (ret = test_no_skip(f, '{'))) {
    TRY(parse_object(f));
  } else if (0 == (ret = test_no_skip(f, '['))) {
    TRY(parse_array(f));
  } else {
    return ret;
  }

  return 0;
}
示例#22
0
文件: json.c 项目: sqlparser/postgres
static void
parse_object_field(JsonLexContext *lex, JsonSemAction *sem)
{
	/*
	 * an object field is "fieldname" : value where value can be a scalar,
	 * object or array
	 */

	char	   *fname = NULL;	/* keep compiler quiet */
	json_ofield_action ostart = sem->object_field_start;
	json_ofield_action oend = sem->object_field_end;
	bool		isnull;
	char	  **fnameaddr = NULL;
	JsonTokenType tok;

	if (ostart != NULL || oend != NULL)
		fnameaddr = &fname;

	if (!lex_accept(lex, JSON_TOKEN_STRING, fnameaddr))
		report_parse_error(JSON_PARSE_STRING, lex);

	lex_expect(JSON_PARSE_OBJECT_LABEL, lex, JSON_TOKEN_COLON);

	tok = lex_peek(lex);
	isnull = tok == JSON_TOKEN_NULL;

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

	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 (oend != NULL)
		(*oend) (sem->semstate, fname, isnull);

	if (fname != NULL)
		pfree(fname);
}
示例#23
0
文件: cJSON.c 项目: FSMaxB/cJSON
/* Parser core - when encountering text, process appropriately. */
static const char *parse_value(cJSON *item, const char *value, const char **ep)
{
    if (!value)
    {
        /* Fail on null. */
        return NULL;
    }

    /* parse the different types of values */
    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, ep);
    }
    if ((*value == '-') || ((*value >= '0') && (*value <= '9')))
    {
        return parse_number(item, value);
    }
    if (*value == '[')
    {
        return parse_array(item, value, ep);
    }
    if (*value == '{')
    {
        return parse_object(item, value, ep);
    }

    /* failure. */
    *ep = value;
    return NULL;
}
示例#24
0
int isPrinter(char *model1, char *model2)
{
	char tmparray[MAXARRAY][MAXARRSIZE];
	int tmpidx;
	unsigned long size=0;
	int i;

	tmpidx=parse_array("/tmp/diskstatus", "printer_models", tmparray);
	if (tmpidx<=0) return 0;

	if (tmpidx>=1)
		strcpy(model1, &tmparray[0][0]);
	if (tmpidx>=2)
		strcpy(model2, &tmparray[1][0]);
	
	return tmpidx;
}
示例#25
0
int parse_value(const char** input, JzonValue* output, JzonAllocator* allocator)
{
	skip_whitespace(input);
	char ch = current(input);

	switch (ch)
	{
		case '{': return parse_object(input, output, false, allocator);
		case '[': return parse_array(input, output, allocator);
		case '"': return parse_string(input, output, allocator);
		case '-': return parse_number(input, output);
		case 'f': return parse_false(input, output);
		case 't': return parse_true(input, output);
		case 'n': return parse_null(input, output);
		default: return ch >= '0' && ch <= '9' ? parse_number(input, output) : -1;
	}
}
示例#26
0
    std::pair< bool, bool > parser::parse(const char* begin, const char* end)
    {
        assert( !state_.empty() );

        for ( ; begin != end && !state_.empty(); )
        {
            switch ( main_state( state_.top() ) )
            {
            case idle_parsing:
                begin = eat_white_space(begin, end);

                if ( begin != end )
                {
                    state_.top() = parse_idle(*begin);
                }
                break;
            case start_number_parsing:
                begin = parse_number(begin, end);
                break;
            case start_array_parsing:
                begin = parse_array(begin, end);
                break;
            case start_object_parsing:
                begin = parse_object(begin, end);
                break;
            case start_string_parsing:
                begin = parse_string(begin, end);
                break;
            case start_true_parsing:
            case start_false_parsing:
            case start_null_parsing:
                begin = parse_literal(begin, end);
                break;
            default:
                assert(!"should not happen");
            }
        }

        // consume trailing whitespaces
        if ( state_.empty() )
            begin = eat_white_space(begin, end);

        return std::make_pair( begin == end, state_.empty() );
    }
示例#27
0
ShadingPatternImpl::ShadingPatternImpl(DocWriterImpl& doc,
                                       Char const* pattern,
                                       ShadingHandle shading)
    : IndirectObjectImpl(doc)
    , PatternBase(pattern)
    , m_shading(shading)
{
    try
    {
        ParsedResult const& p =
            parse_options(pattern, ParseArgs(&g_shading_keywords, &g_shading_values));

        parse_array(p, SH_MATRIX, m_matrix, true, 6);
    }
    catch(exception const& exc)
    {
        throw exception_invalid_value(msg_invalid_shading_spec(), &exc) << JAGLOC;
    }
}
示例#28
0
文件: frozen.c 项目: Henk-B/frozen
/* value = 'null' | 'true' | 'false' | number | string | array | object */
static int parse_value(struct frozen *f) {
  int ch = cur(f);

  switch (ch) {
    case '"':
      TRY(parse_string(f));
      break;
    case '{':
      TRY(parse_object(f));
      break;
    case '[':
      TRY(parse_array(f));
      break;
    case 'n':
      TRY(expect(f, "null", 4, JSON_TYPE_NULL));
      break;
    case 't':
      TRY(expect(f, "true", 4, JSON_TYPE_TRUE));
      break;
    case 'f':
      TRY(expect(f, "false", 5, JSON_TYPE_FALSE));
      break;
    case '-':
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      TRY(parse_number(f));
      break;
    default:
      return ch == END_OF_STRING ? JSON_STRING_INCOMPLETE : JSON_STRING_INVALID;
  }

  return 0;
}
	Variant JSONReader::parse_value()
	{
		skip_space();

		if (at('{'))
			return parse_object();
		if (at('['))
			return parse_array();
		if (at('"'))
			return parse_string();
		if (at_digit() || at('-'))
			return parse_number();
		if (skip_string("true"))
			return Variant(true);
		if (skip_string("false"))
			return Variant(false);
		if (skip_string("null"))
			return Variant();

		throw Exception(position(), "invalid value");
	}
示例#30
0
void json::parse_value( std::istream_iterator<char> &it, std::istream_iterator<char> &end, int &line )
{
	skip_whitespace( it, end, line );

	if ( it == end )
	{
		clear();
		return;
	}

	switch ( *it )
	{
		case '[':
			parse_array( it, end, line );
			break;

		case '{':
			parse_object( it, end, line );
			break;

		case '"':
			parse_string( it, end, line );
			break;

		case 't':
			parse_true( it, end, line );
			break;

		case 'f':
			parse_false( it, end, line );
			break;

		case 'n':
			parse_null( it, end, line );
			break;

		default:
			parse_number( it, end, line );
	}
}