本文整理汇总了C++中parse_string函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_string函数的具体用法?C++ parse_string怎么用?C++ parse_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_format
static int
parse_format (GLogItem * glog, const char *fmt, const char *date_format,
char *str)
{
const char *p;
double serve_secs;
int special = 0;
struct tm tm;
unsigned long long bandw, serve_time;
if (str == NULL || *str == '\0')
return 1;
memset (&tm, 0, sizeof (tm));
/* iterate over the log format */
for (p = fmt; *p; p++) {
if (*p == '%') {
special++;
continue;
}
if (special && *p != '\0') {
char *pch, *sEnd, *bEnd, *tkn = NULL, *end = NULL;
errno = 0;
bandw = 0;
serve_time = 0;
serve_secs = 0;
switch (*p) {
/* date */
case 'd':
if (glog->date)
return 1;
/* parse date format including dates containing spaces,
* i.e., syslog date format (Jul 15 20:10:56) */
tkn = parse_string (&str, p[1], count_matches (date_format, ' ') + 1);
if (tkn == NULL)
return 1;
end = strptime (tkn, date_format, &tm);
if (end == NULL || *end != '\0') {
free (tkn);
return 1;
}
glog->date = tkn;
break;
/* remote hostname (IP only) */
case 'h':
if (glog->host)
return 1;
tkn = parse_string (&str, p[1], 1);
if (tkn == NULL)
return 1;
if (invalid_ipaddr (tkn)) {
free (tkn);
return 1;
}
glog->host = tkn;
break;
/* request method */
case 'm':
if (glog->method)
return 1;
tkn = parse_string (&str, p[1], 1);
if (tkn == NULL)
return 1;
if (!extract_method (tkn)) {
free (tkn);
return 1;
}
glog->method = tkn;
break;
/* request not including method or protocol */
case 'U':
if (glog->req)
return 1;
tkn = parse_string (&str, p[1], 1);
if (tkn == NULL || *tkn == '\0')
return 1;
if ((glog->req = decode_url (tkn)) == NULL)
return 1;
free (tkn);
break;
/* request protocol */
case 'H':
if (glog->protocol)
return 1;
tkn = parse_string (&str, p[1], 1);
if (tkn == NULL)
return 1;
if (invalid_protocol (tkn)) {
free (tkn);
return 1;
}
glog->protocol = tkn;
break;
/* request, including method + protocol */
case 'r':
if (glog->req)
return 1;
tkn = parse_string (&str, p[1], 1);
//.........这里部分代码省略.........
示例2: spec_describe
char *test_multi_operator_method() {
spec_describe("multi operator method chain: 1 + (n * 3) - 5");
FxP_ParserContext *context = parse_string("1 + (n * 3) - 5\n");
char *inspection = fxp_parser_inspect(context);
char *expected = "{\n"
" \"expressions\": [\n"
" {\n"
" \"method_call\": {\n"
" \"receiver\": {\n"
" \"literal\": {\n"
" \"bit\": {\n"
" \"INTEGER\": 1\n"
" },\n"
" \"class\": \"Integer\"\n"
" }\n"
" },\n"
" \"message\": {\n"
" \"lookup\": {\n"
" \"type\": \"Identifier\",\n"
" \"bit\": {\n"
" \"STRING\": \"+\"\n"
" }\n"
" }\n"
" },\n"
" \"arguments\": [\n"
" {\n"
" \"method_call\": {\n"
" \"receiver\": {\n"
" \"grouped_expression\": {\n"
" \"method_call\": {\n"
" \"receiver\": {\n"
" \"lookup\": {\n"
" \"type\": \"Identifier\",\n"
" \"bit\": {\n"
" \"STRING\": \"n\"\n"
" }\n"
" }\n"
" },\n"
" \"message\": {\n"
" \"lookup\": {\n"
" \"type\": \"Identifier\",\n"
" \"bit\": {\n"
" \"STRING\": \"*\"\n"
" }\n"
" }\n"
" },\n"
" \"arguments\": [\n"
" {\n"
" \"literal\": {\n"
" \"bit\": {\n"
" \"INTEGER\": 3\n"
" },\n"
" \"class\": \"Integer\"\n"
" }\n"
" }\n"
" ]\n"
" }\n"
" }\n"
" },\n"
" \"message\": {\n"
" \"lookup\": {\n"
" \"type\": \"Identifier\",\n"
" \"bit\": {\n"
" \"STRING\": \"-\"\n"
" }\n"
" }\n"
" },\n"
" \"arguments\": [\n"
" {\n"
" \"literal\": {\n"
" \"bit\": {\n"
" \"INTEGER\": 5\n"
" },\n"
" \"class\": \"Integer\"\n"
" }\n"
" }\n"
" ]\n"
" }\n"
" }\n"
" ]\n"
" }\n"
" }\n"
" ]\n"
"}";
assert_strings_equal(inspection, expected, "ast");
fxp_parser_context_free(context);
free(inspection);
return NULL;
}
示例3: parse_entry
static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
t_blocka *block, char ***gn,
atom_id *nr, atom_id *index, char *gname)
{
static char **names, *ostring;
static gmx_bool bFirst = TRUE;
int j, n_names, sel_nr1;
atom_id i, nr1, *index1;
char c;
gmx_bool bRet, bCompl;
if (bFirst)
{
bFirst = FALSE;
snew(names, MAXNAMES);
for (i = 0; i < MAXNAMES; i++)
{
snew(names[i], NAME_LEN+1);
}
}
bRet = FALSE;
sel_nr1 = NOTSET;
while (*string[0] == ' ')
{
(*string)++;
}
if ((*string)[0] == '!')
{
bCompl = TRUE;
(*string)++;
while (*string[0] == ' ')
{
(*string)++;
}
}
else
{
bCompl = FALSE;
}
ostring = *string;
if (parse_int(string, &sel_nr1) ||
parse_string(string, &sel_nr1, block->nr, *gn))
{
if ((sel_nr1 >= 0) && (sel_nr1 < block->nr))
{
copy_group(sel_nr1, block, nr, index);
strcpy(gname, (*gn)[sel_nr1]);
printf("Copied index group %d '%s'\n", sel_nr1, (*gn)[sel_nr1]);
bRet = TRUE;
}
else
{
printf("Group %d does not exist\n", sel_nr1);
}
}
else if ((*string)[0] == 'a')
{
(*string)++;
if (check_have_atoms(atoms, ostring))
{
if (parse_int(string, &sel_nr1))
{
bRet = select_atomnumbers(string, atoms, sel_nr1, nr, index, gname);
}
else if (parse_names(string, &n_names, names))
{
bRet = select_atomnames(atoms, n_names, names, nr, index, FALSE);
make_gname(n_names, names, gname);
}
}
}
else if ((*string)[0] == 't')
{
(*string)++;
if (check_have_atoms(atoms, ostring) &&
parse_names(string, &n_names, names))
{
if (atoms->atomtype == NULL)
{
printf("Need a run input file to select atom types\n");
}
else
{
bRet = select_atomnames(atoms, n_names, names, nr, index, TRUE);
make_gname(n_names, names, gname);
}
}
}
else if (strncmp(*string, "res", 3) == 0)
{
(*string) += 3;
if (check_have_atoms(atoms, ostring) &&
parse_int(string, &sel_nr1) &&
(sel_nr1 >= 0) && (sel_nr1 < block->nr) )
{
//.........这里部分代码省略.........
示例4: eval_string
/**
Evaluate the source code in a given string
*/
value_t eval_string(const char* cstr, const char* src_name)
{
ast_fun_t* unit_fun = parse_check_error(parse_string(cstr, src_name));
return eval_unit(unit_fun);
}
示例5: parse_host
static IteratorT parse_host(IteratorT begin, IteratorT end) {
// For convenience we shortcut this parsing for now.
return parse_string(parse_host_character, begin, end);
}
示例6: precondition
void parser::parse_code( std::istream &in )
{
precondition( in.get() == '%', "missing '%' to start code" );
// find the first word
std::string word;
while ( std::isspace( in.peek() ) )
in.get();
while ( std::isalpha( in.peek() ) )
word.push_back( static_cast<char>( in.get() ) );
while ( std::isspace( in.peek() ) )
in.get();
if ( word == "for" )
{
_func.add( "for " );
}
else if ( word == "if" )
{
_func.add( "if " );
}
else if ( word == "else" )
{
_func.unindent();
_func.add( "}\nelse" );
_func.push_code();
}
else if ( word == "code" || word == "endfor" || word == "endif" )
{
}
else
throw_runtime( "unknown template keyword '{0}'", word );
int count = 0;
while ( !in.eof() && in )
{
int c = in.get();
if ( std::char_traits<char>::not_eof( c ) )
{
if ( c == ']' )
{
if ( count == 0 )
{
_func.push_code();
break;
}
_func.add( static_cast<char>( c ) );
--count;
}
else if ( c == '[' )
{
_func.add( static_cast<char>( c ) );
++count;
}
else if ( c == '"' )
{
_func.add( static_cast<char>( c ) );
parse_string( in );
}
else
_func.add( static_cast<char>( c ) );
}
}
if ( word == "for" || word == "if" || word == "else" )
{
_func.add( "\n{" );
_func.indent();
}
else if ( word == "endfor" || word == "endif" )
{
_func.unindent();
_func.add( '}' );
_func.push_code();
}
}
示例7: exec_file
int
exec_file(const char *fn, const char *script, const char *tmpdir,
char *logbuf, unsigned loglen)
{
unsigned old_err;
char *p;
FILE *f;
struct extmacro *m;
signal(SIGPIPE, SIG_IGN);
vtc_loginit(logbuf, loglen);
vltop = vtc_logopen("top");
AN(vltop);
init_macro();
init_sema();
/* Apply extmacro definitions */
VTAILQ_FOREACH(m, &extmacro_list, list)
macro_def(vltop, NULL, m->name, "%s", m->val);
/*
* We need an IP number which will not repond, ever, and that is a
* lot harder than it sounds. This IP# is from RFC5737 and a
* C-class broadcast at that.
* If tests involving ${bad_ip} fails and you run linux, you should
* check your /proc/sys/net/ipv4/ip_nonlocal_bind setting.
*/
macro_def(vltop, NULL, "bad_ip", "192.0.2.255");
/* Move into our tmpdir */
AZ(chdir(tmpdir));
macro_def(vltop, NULL, "tmpdir", "%s", tmpdir);
/* Drop file to tell what was going on here */
f = fopen("INFO", "w");
AN(f);
fprintf(f, "Test case: %s\n", fn);
AZ(fclose(f));
vtc_stop = 0;
vtc_desc = NULL;
vtc_log(vltop, 1, "TEST %s starting", fn);
p = strdup(script);
AN(p);
vtc_thread = pthread_self();
parse_string(p, cmds, NULL, vltop);
old_err = vtc_error;
vtc_stop = 1;
vtc_log(vltop, 1, "RESETTING after %s", fn);
reset_cmds(cmds);
vtc_error = old_err;
if (vtc_error)
vtc_log(vltop, 1, "TEST %s FAILED", fn);
else
vtc_log(vltop, 1, "TEST %s completed", fn);
free(vtc_desc);
return (vtc_error);
}
示例8: parse_string
ehval_p EHI::execute_string(const char *cmd) {
parse_string(cmd);
return execute_code();
}
示例9: options_map
explicit options_map(std::string &s) {
parse_string(s);
};
示例10: gfire_sq_ase_parse
static gboolean gfire_sq_ase_parse(gfire_game_server *p_server, guint16 p_ping, gboolean p_full,
const unsigned char *p_data, guint p_len)
{
if(memcmp(p_data, "EYE1", 4) != 0)
return FALSE;
gfire_sq_ase_data *data = g_new0(gfire_sq_ase_data, 1);
guint offset = 4;
gchar *tempstr;
// General server data
data->game_name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!data->game_name)
goto error;
tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!tempstr)
goto error;
data->game_port = atoi(tempstr);
g_free(tempstr);
data->server_name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!data->server_name)
goto error;
data->game_type = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!data->game_type)
goto error;
data->map = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!data->map)
goto error;
data->version = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!data->version)
goto error;
tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!tempstr)
goto error;
data->password = (*tempstr == '1');
g_free(tempstr);
tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!tempstr)
goto error;
data->num_players = atoi(tempstr);
g_free(tempstr);
tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!tempstr)
goto error;
data->max_players = atoi(tempstr);
g_free(tempstr);
// Server rules
g_datalist_init(&data->rules);
while(1)
{
gchar *key = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!key)
break;
gchar *value = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
if(!value)
{
g_free(key);
goto error;
}
g_datalist_set_data_full(&data->rules, key, value, g_free);
g_free(key);
}
// Players
while(p_len > offset)
{
gfire_sq_ase_player *player = g_new0(gfire_sq_ase_player, 1);
guint8 flags = *(p_data + offset++);
if(flags & 1)
{
player->name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE));
if(!player->name)
{
free_ase_player(player);
break;
}
}
if(flags & 2)
{
player->team = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE));
if(!player->team)
{
free_ase_player(player);
break;
}
}
if(flags & 4)
{
//.........这里部分代码省略.........
示例11: amort_opt
amort_sched_ptr amort_opt(
amort_sched_ptr amortsched,
void *parse_env)
{
char buffer[200], *errp;
unsigned long ii;
unsigned prec = amortsched->prec;
var_store value;
numeric_ptr nval;
struct tm *times_E,
*times_I;
/* print amortization options */
times_E = (struct tm *)calloc(1, sizeof(struct tm));
ii = amortsched->Eff_Date_jdn;
times_E->tm_mday = amortsched->day_E;
times_E->tm_mon = amortsched->month_E - 1;
times_E->tm_year = amortsched->year_E - 1900;
times_E->tm_wday = (ii + 1) % 7;
times_E->tm_yday = amortsched->yday_E;
times_I = (struct tm *)calloc(1, sizeof(struct tm));
ii = amortsched->Init_Date_jdn;
times_I->tm_mday = amortsched->day_I;
times_I->tm_mon = amortsched->month_I - 1;
times_I->tm_year = amortsched->year_I - 1900;
times_I->tm_wday = (ii + 1) % 7;
times_I->tm_yday = amortsched->yday_I;
printf("\n******************************");
qof_strftime(buffer, (size_t)50, "%c", times_E);
printf("\nEffective Date: %s\n", buffer);
qof_strftime(buffer, (size_t)50, "%c", times_I);
printf("Initial Payment Date: %s\n", buffer);
free(times_E);
free(times_I);
printf("The Original Present Value (pv) is: %.*f\n", (int)prec, amortsched->pv);
printf("The Original Periodic Payment (pmt) is: %.*f\n", (int)prec, amortsched->pmt);
printf("The Original Future Value (fv) is: %.*f\n", (int)prec, amortsched->fv);
printf("The Delayed Present Value (pve) is: %.*f\n", (int)prec, amortsched->pve);
printf("The New Periodic Payment (pmt) for pve is: %.*f\n\n", (int)prec, amortsched->new_pmt);
printf("The amortization options are:\n");
printf("1 -- Amortize with Original Amount and Constant Payment to Principal: %.*f\n", (int) prec, amortsched->cpmt1);
printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_1);
printf("2 -- Amortize with Delayed Amount and Constant Payment to Principal: %.*f\n", (int)prec, amortsched->cpmt2);
printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_2);
printf("3 -- Amortize with Original Transaction Values\n");
printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_3);
printf("4 -- Amortize with Delayed Amount, Original Periodic Payment\n");
printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_4);
printf("5 -- Amortize with Delayed Amount, New Periodic Payment\n");
printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_5);
if ( amortsched->new_n )
{
printf("6 -- Amortize with Original Amount, Original Periodic Payment,\n");
printf(" new number of total payments (n): %u\n", amortsched->new_n);
printf(" and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_6);
} /* endif */
printf("Enter choice 1, 2, 3, 4, 5 or 6: ");
fgets(buffer, 190, stdin);
amortsched->option = buffer[0] - '0';
printf("Amortization Schedule:\n");
printf("y -- Yearly Summary\n");
printf("p -- Periodic Payment\n");
if ( amortsched->option < 3 )
{
printf("Enter Choice y or p: ");
}
else
{
printf("f -- Fixed Advanced Payment\n");
printf("a -- Variable Advanced Payment\n");
printf("Enter Choice y, p, f or a: ");
} /* endif */
fgets(buffer, 190, stdin);
amortsched->summary = buffer[0];
if ( amortsched->summary == 'f' )
{
if ( amortsched->fixed_pmt != 0.0 )
{
printf("Current Fixed Prepayment: %.*f\nChange Fixed Prepayment? (y/n): ", (int)prec, amortsched->fixed_pmt);
fgets(buffer, 190, stdin);
}
else
{
buffer[0] = 'y';
} /* endif */
if ( buffer[0] == 'y' )
{
printf("Enter Fixed Prepayment Amount: ");
fgets(buffer, 190, stdin);
if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
{
nval = (numeric_ptr)(value.value);
switch ( nval->type )
//.........这里部分代码省略.........
示例12: main
int main(int argc, const char *argv[])
{
rtc_time_t tm;
reg_data_t regv;
reg_temp_mode_t mode;
int ret = -1;
int fd = -1;
const char *dev_name = "/dev/hi_rtc";
char string[50] = {0};
memset(&tm, 0, sizeof(tm));
if (argc < 2){
usage();
return 0;
}
fd = open(dev_name, O_RDWR);
if (fd < 0) {
printf("open %s failed\n", dev_name);
return -1;
}
if (!strcmp(argv[1],"-s")) {
if (argc < 4) {
usage();
goto err1;
}
if (!strcmp(argv[2], "time")) {
strncpy(string, argv[3], sizeof(string)-1);
ret = parse_string(string, &tm);
if (ret < 0)
{
printf("parse time param failed\n");
goto err1;
}
printf("set time\n");
#if 1
/* code */
printf("year:%d\n", tm.year);
printf("month:%d\n",tm.month);
printf("date:%d\n", tm.date);
printf("hour:%d\n", tm.hour);
printf("minute:%d\n", tm.minute);
printf("second:%d\n", tm.second);
#endif
ret = ioctl(fd, HI_RTC_SET_TIME, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_SET_TIME failed\n");
goto err1;
}
} else if (!strcmp(argv[2], "alarm")) {
strncpy(string, argv[3], sizeof(string)-1);
ret = parse_string(string, &tm);
if (ret < 0) {
printf("parse alarm param failed\n");
goto err1;
}
printf("set alarm\n");
#if 1
printf("year:%d\n", tm.year);
printf("month:%d\n",tm.month);
printf("date:%d\n", tm.date);
printf("hour:%d\n", tm.hour);
printf("minute:%d\n", tm.minute);
printf("second:%d\n", tm.second);
#endif
ret = ioctl(fd, HI_RTC_ALM_SET, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_ALM_SET failed\n");
goto err1;
}
} else {
printf("unknown options %s\n", argv[2]);
goto err1;
}
} else if (!strcmp(argv[1],"-g")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "time")) {
printf("[RTC_RD_TIME]\n");
ret = ioctl(fd, HI_RTC_RD_TIME, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_RD_TIME failed\n");
goto err1;
}
printf("Current time value: \n");
} else if (!strcmp(argv[2], "alarm")) {
//.........这里部分代码省略.........
示例13: SKIPWS
static ZZJSON *parse_object(ZZJSON_CONFIG *config) {
ZZJSON *retval = NULL;
int c;
ZZJSON **next = &retval;
SKIPWS();
c = GETC();
if (c != '{') {
ERROR("object: expected '{'");
return NULL;
}
SKIPWS();
c = GETC();
while (c > 0 && c != '}') {
ZZJSON *zzjson = NULL, *val = NULL;
char *str;
UNGETC(c);
str = parse_string(config);
if (!str) {
ERROR("object: expected string");
errout_with_str:
config->free(str);
goto errout;
}
SKIPWS();
c = GETC();
if (c != ':') {
ERROR("object: expected ':'");
goto errout_with_str;
}
SKIPWS();
val = parse_value(config);
if (!val) {
ERROR("object: value expected");
goto errout_with_str;
}
SKIPWS();
c = GETC();
if (c != ',' && c != '}') {
ERROR("object: expected ',' or '}'");
errout_with_str_and_val:
zzjson_free(config, val);
goto errout_with_str;
}
if (c == ',') {
SKIPWS();
c = GETC();
if (c == '}' && !ALLOW_EXTRA_COMMA) {
ERROR("object: expected pair after ','");
goto errout_with_str_and_val;
}
}
UNGETC(c);
zzjson = config->calloc(1, sizeof(ZZJSON));
if (!zzjson) {
MEMERROR();
goto errout_with_str_and_val;
}
zzjson->type = ZZJSON_OBJECT;
zzjson->value.object.label = str;
zzjson->value.object.val = val;
*next = zzjson;
next = &zzjson->next;
c = GETC();
}
if (c != '}') {
ERROR("object: expected '}'");
goto errout;
}
if (!retval) { /* empty object, { } */
retval = config->calloc(1, sizeof(ZZJSON));
if (!retval) {
MEMERROR();
return NULL;
}
retval->type = ZZJSON_OBJECT;
}
return retval;
errout:
zzjson_free(config, retval);
return NULL;
}
示例14: parse_table
static struct buffer parse_table(struct buffer buff,
struct invocation *invocation, const char **error)
{
unsigned i;
size_t ident_len;
struct argument args[QUERY_MAX_ARGS];
const char *ident_name = NULL;
unsigned argi = 0;
buff = chomp(buff);
buff = expect_char(buff, '{', error);
if (*error)
goto clean;
buff = chomp(buff);
while (!peek(buff, "}"))
{
if (argi >= QUERY_MAX_ARGS)
{
raise_too_many_arguments(error);
goto clean;
}
if (isalpha((int)buff.data[buff.offset]))
{
buff = get_ident(buff, &ident_name, &ident_len, error);
if (!*error)
{
args[argi].a.value.type = RDT_STRING;
args[argi].a.value.val.string.len = ident_len;
args[argi].a.value.val.string.buff = (char*)calloc(
ident_len + 1,
sizeof(char)
);
if (!args[argi].a.value.val.string.buff)
goto clean;
strncpy(
args[argi].a.value.val.string.buff,
ident_name,
ident_len
);
}
}
else
buff = parse_string(buff, &args[argi].a.value, error);
if (*error)
goto clean;
args[argi].type = AT_VALUE;
buff = chomp(buff);
argi++;
buff = expect_char(buff, ':', error);
if (*error)
goto clean;
buff = chomp(buff);
if (argi >= QUERY_MAX_ARGS)
{
raise_too_many_arguments(error);
goto clean;
}
buff = parse_argument(buff, &args[argi], error);
if (*error)
goto clean;
argi++;
buff = chomp(buff);
buff = expect_char(buff, ',', error);
if (*error)
{
*error = NULL;
break;
}
buff = chomp(buff);
}
buff = expect_char(buff, '}', error);
if (*error)
goto clean;
invocation->func = all_map;
invocation->argc = argi;
invocation->argv = (struct argument*)
malloc(sizeof(struct argument) * argi);
if (!invocation->argv)
{
raise_enomem(error);
goto clean;
//.........这里部分代码省略.........
示例15: parse_pair
static int
parse_pair(heim_dict_t dict, struct parse_ctx *ctx)
{
heim_string_t key;
heim_object_t value;
if (white_spaces(ctx))
return -1;
if (*ctx->p == '}') {
ctx->p++;
return 0;
}
if (ctx->flags & HEIM_JSON_F_STRICT_DICT)
/* JSON allows only string keys */
key = parse_string(ctx);
else
/* heim_dict_t allows any heim_object_t as key */
key = parse_value(ctx);
if (key == NULL)
/* Even heim_dict_t does not allow C NULLs as keys though! */
return -1;
if (white_spaces(ctx)) {
heim_release(key);
return -1;
}
if (*ctx->p != ':') {
heim_release(key);
return -1;
}
ctx->p += 1; /* safe because we call white_spaces() next */
if (white_spaces(ctx)) {
heim_release(key);
return -1;
}
value = parse_value(ctx);
if (value == NULL &&
(ctx->error != NULL || (ctx->flags & HEIM_JSON_F_NO_C_NULL))) {
if (ctx->error == NULL)
ctx->error = heim_error_create(EINVAL, "Invalid JSON encoding");
heim_release(key);
return -1;
}
heim_dict_set_value(dict, key, value);
heim_release(key);
heim_release(value);
if (white_spaces(ctx))
return -1;
if (*ctx->p == '}') {
/*
* Return 1 but don't consume the '}' so we can count the one
* pair in a one-pair dict
*/
return 1;
} else if (*ctx->p == ',') {
ctx->p++;
return 1;
}
return -1;
}