本文整理汇总了C++中parse_pair函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_pair函数的具体用法?C++ parse_pair怎么用?C++ parse_pair使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_pair函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parse_interface
int
parse_interface(struct tapif* tapif,char* param)
{
enum {
KEY_WAIT, KEY, VALUE_WAIT, VALUE, END
};
int state = KEY_WAIT;
char* p = param;
char* key = 0;
char* value = 0;
while (state != END) {
switch (*p) {
case '\0':
if (parse_pair(tapif,key,value) != 0)
return -1;
state = END;
break;
case ',':
if (state == KEY_WAIT) {
p++;
break;
}
state = KEY_WAIT;
*p++ = 0;
if (parse_pair(tapif,key,value) != 0)
return -1;
key = value = 0;
break;
case '=':
if (state == KEY)
state = VALUE_WAIT;
else
return -1;
*p++ = 0;
break;
case ' ':
if (state != KEY_WAIT && state != VALUE_WAIT)
return -1;
p++;
break;
default:
if (state == KEY_WAIT) {
state = KEY;
key = p;
} else if (state == VALUE_WAIT) {
state = VALUE;
value = p;
}
p++;
}
}
return 0;
}
开发者ID:huawenyu,项目名称:lwip-tap,代码行数:54,代码来源:lwip-tap.c
示例2: pgut_readopt
/*
* Get configuration from configuration file.
*/
void
pgut_readopt(const char *path, pgut_option options[], int elevel)
{
FILE *fp;
char buf[1024];
char key[1024];
char value[1024];
if (!options)
return;
if ((fp = pgut_fopen(path, "rt", true)) == NULL)
return;
while (fgets(buf, lengthof(buf), fp))
{
size_t i;
for (i = strlen(buf); i > 0 && IsSpace(buf[i - 1]); i--)
buf[i - 1] = '\0';
if (parse_pair(buf, key, value))
{
for (i = 0; options[i].type; i++)
{
pgut_option *opt = &options[i];
if (key_equals(key, opt->lname))
{
if (opt->allowed == SOURCE_DEFAULT ||
opt->allowed > SOURCE_FILE)
if (elevel >= ERROR)
{
ereport(ERROR,
(errcode(elevel),
errmsg("option %s cannot specified in file", opt->lname)));
} else {
elog(elevel, "option %s cannot specified in file", opt->lname);
}
else if (opt->source <= SOURCE_FILE)
assign_option(opt, value, SOURCE_FILE);
break;
}
}
if (!options[i].type)
{
if (elevel >= ERROR)
{
ereport(ERROR,
(errcode(elevel),
errmsg("invalid option \"%s\"", key)));
} else {
elog(elevel, "invalid option \"%s\"", key);
}
}
}
}
fclose(fp);
}
开发者ID:jamexu98918,项目名称:pg_rman,代码行数:63,代码来源:pgut.c
示例3: parse_pairs
static int
parse_pairs(void *opts, char *param, int (*parse_pair)(void *, char*, char*))
{
enum {
WAIT_KEY, KEY, WAIT_VALUE, VALUE, END
};
int state = WAIT_KEY;
char* p = param;
char* key = 0;
char* value = 0;
while (state != END) {
switch (*p) {
case '\0':
if (parse_pair(opts, key, value) != 0)
return -1;
state = END;
break;
case ',':
if (state != VALUE)
return -1;
state = WAIT_KEY;
*p++ = 0;
if (parse_pair(opts, key, value) != 0)
return -1;
key = value = 0;
break;
case '=':
if (state != KEY)
return -1;
state = WAIT_VALUE;
*p++ = 0;
break;
default:
if (state == WAIT_KEY) {
state = KEY;
key = p;
} else if (state == WAIT_VALUE) {
state = VALUE;
value = p;
}
p++;
}
}
return 0;
}
开发者ID:baruch,项目名称:lwip-dpdk,代码行数:46,代码来源:main.c
示例4: parse_dict
static heim_dict_t
parse_dict(struct parse_ctx *ctx)
{
heim_dict_t dict;
size_t count = 0;
int ret;
heim_assert(*ctx->p == '{', "string doesn't start with {");
dict = heim_dict_create(11);
if (dict == NULL) {
ctx->error = heim_error_create_enomem();
return NULL;
}
ctx->p += 1; /* safe because parse_pair() calls white_spaces() first */
while ((ret = parse_pair(dict, ctx)) > 0)
count++;
if (ret < 0) {
heim_release(dict);
return NULL;
}
if (count == 1 && !(ctx->flags & HEIM_JSON_F_NO_DATA_DICT)) {
heim_object_t v = heim_dict_copy_value(dict, heim_tid_data_uuid_key);
/*
* Binary data encoded as a dict with a single magic key with
* base64-encoded value? Decode as heim_data_t.
*/
if (v != NULL && heim_get_tid(v) == HEIM_TID_STRING) {
void *buf;
size_t len;
buf = malloc(strlen(heim_string_get_utf8(v)));
if (buf == NULL) {
heim_release(dict);
heim_release(v);
ctx->error = heim_error_create_enomem();
return NULL;
}
len = base64_decode(heim_string_get_utf8(v), buf);
heim_release(v);
if (len == -1) {
free(buf);
return dict; /* assume aliasing accident */
}
heim_release(dict);
return (heim_dict_t)heim_data_ref_create(buf, len, free);
}
}
return dict;
}
开发者ID:kaduk,项目名称:heimdal,代码行数:53,代码来源:json.c
示例5: parse_object
// object = '{' pair { ',' pair } '}'
static int parse_object(struct frozen *f) {
int ind;
TRY(test_and_skip(f, '{'));
TRY(capture_ptr(f, f->cur - 1, JSON_TYPE_OBJECT));
ind = f->num_tokens - 1;
while (cur(f) != '}') {
TRY(parse_pair(f));
if (cur(f) == ',') f->cur++;
}
TRY(test_and_skip(f, '}'));
capture_len(f, ind, f->cur);
return 0;
}
开发者ID:4gifted,项目名称:traveller,代码行数:14,代码来源:frozen.c
示例6: parse_object
/* object = '{' pair { ',' pair } '}' */
static int parse_object(struct frozen *f) {
TRY(test_and_skip(f, '{'));
{
SET_STATE(f, f->cur - 1, JSON_TYPE_OBJECT, ".", 1);
while (cur(f) != '}') {
TRY(parse_pair(f));
if (cur(f) == ',') f->cur++;
}
TRY(test_and_skip(f, '}'));
CALL_BACK(f);
}
return 0;
}
开发者ID:Henk-B,项目名称:frozen,代码行数:14,代码来源:frozen.c
示例7: parse_ranges
static void parse_ranges ( char *input, struct range_pair **list, unsigned int *length )
{
char *endp;
for ( char *token = strtok_r ( input, ",", &endp );
token != NULL;
token = strtok_r ( NULL, ",", &endp ) ) {
// Make space.
*list = g_realloc ( ( *list ), ( ( *length ) + 1 ) * sizeof ( struct range_pair ) );
// Parse a single pair.
parse_pair ( token, &( ( *list )[*length] ) );
( *length )++;
}
}
开发者ID:Tarrasch,项目名称:rofi,代码行数:14,代码来源:dmenu.c
示例8: parse_pair
// Parses a pair, assuming the opening left parenthesis has already been read.
static struct ParseResult parse_pair(const char *text) {
struct ParseResult result;
result.err_type = -1;
const char *s = text;
s += skip_whitespace(s);
if (*s == ')') {
s++;
result.expr = new_null();
goto chars_read;
}
struct ParseResult first = parse(s);
s += first.chars_read;
if (first.err_type != -1) {
result.err_type = first.err_type;
goto chars_read;
}
if (*s == '.') {
s++;
struct ParseResult second = parse(s);
s += second.chars_read;
if (second.err_type != -1) {
result.err_type = second.err_type;
release_expression(first.expr);
goto chars_read;
}
if (*s != ')') {
result.err_type = *s ? ERR_EXPECTED_RPAREN : ERR_UNEXPECTED_EOI;
release_expression(first.expr);
goto chars_read;
}
s++;
result.expr = new_pair(first.expr, second.expr);
} else {
struct ParseResult rest = parse_pair(s);
s += rest.chars_read;
if (rest.err_type != -1) {
result.err_type = rest.err_type;
release_expression(first.expr);
goto chars_read;
}
result.expr = new_pair(first.expr, rest.expr);
}
chars_read:
result.chars_read = (size_t)(s - text);
return result;
}
开发者ID:mk12,项目名称:eva,代码行数:51,代码来源:parse.c
示例9: parse_object
/* object = '{' pair { ',' pair } '}' */
static int parse_object(struct frozen *f) {
CALL_BACK(f, JSON_TYPE_OBJECT_START, NULL, 0);
TRY(test_and_skip(f, '{'));
{
SET_STATE(f, f->cur - 1, ".", 1);
while (cur(f) != '}') {
TRY(parse_pair(f));
if (cur(f) == ',') f->cur++;
}
TRY(test_and_skip(f, '}'));
truncate_path(f, fstate.path_len);
CALL_BACK(f, JSON_TYPE_OBJECT_END, fstate.ptr, f->cur - fstate.ptr);
}
return 0;
}
开发者ID:ALLTERCO,项目名称:mongoose-iot,代码行数:16,代码来源:frozen.c
示例10: get
void CameraParameters::getTouchIndexAf(int *x, int *y) const
{
*x = -1;
*y = -1;
// Get the current string, if it doesn't exist, leave the -1x-1
const char *p = get(KEY_TOUCH_INDEX_AF);
if (p == 0)
return;
int tempX, tempY;
if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
*x = tempX;
*y = tempY;
}
}
开发者ID:classicnerd,项目名称:frameworks_base,代码行数:16,代码来源:CameraParameters.cpp
示例11: pgut_readopt
/*
* Get configuration from configuration file.
*/
void
pgut_readopt(const char *path, pgut_option options[], int elevel)
{
FILE *fp;
char buf[1024];
char key[1024];
char value[1024];
if (!options)
return;
if ((fp = pgut_fopen(path, "Rt")) == NULL)
return;
while (fgets(buf, lengthof(buf), fp))
{
size_t i;
for (i = strlen(buf); i > 0 && IsSpace(buf[i - 1]); i--)
buf[i - 1] = '\0';
if (parse_pair(buf, key, value))
{
for (i = 0; options[i].type; i++)
{
pgut_option *opt = &options[i];
if (pgut_keyeq(key, opt->lname))
{
if (opt->allowed == SOURCE_DEFAULT ||
opt->allowed > SOURCE_FILE)
elog(elevel, "option %s cannot specified in file", opt->lname);
else if (opt->source <= SOURCE_FILE)
pgut_setopt(opt, value, SOURCE_FILE);
break;
}
}
if (!options[i].type)
elog(elevel, "invalid option \"%s\"", key);
}
}
fclose(fp);
}
开发者ID:bwtakacy,项目名称:pg_reorg,代码行数:47,代码来源:pgut-fe.c
示例12: parse
// Parses any expression.
struct ParseResult parse(const char *text) {
struct ParseResult result;
result.err_type = PARSE_SUCCESS;
const char *s = text;
s += skip_whitespace(s);
size_t len;
switch (*s) {
case '\0':
result.err_type = ERR_UNEXPECTED_EOI;
break;
case '(':
s++;
result = parse_pair(s);
s += result.chars_read;
break;
case ')':
result.err_type = ERR_UNEXPECTED_RPAREN;
break;
case '.':
result.err_type = ERR_INVALID_DOT;
break;
case '#':
len = skip_symbol(s + 1);
if (len == 1 && s[1] == 't') {
s += 2;
result.expr = new_boolean(true);
} else if (len == 1 && s[1] == 'f') {
s += 2;
result.expr = new_boolean(false);
} else if (len > 2 && s[1] == '\\') {
char c = parse_char_name(s + 2, len - 1);
if (c == '\0') {
s += 2;
result.err_type = ERR_UNKNOWN_CHARACTER;
} else {
s += 1 + len;
result.expr = new_character(c);
}
} else if (s[1] == '\\' && s[2] && !isspace(s[2])) {
result.expr = new_character(s[2]);
s += 3;
} else {
result.err_type = ERR_INVALID_LITERAL;
}
break;
case '\'':
s++;
result = parse(s);
s += result.chars_read;
if (result.err_type == PARSE_SUCCESS) {
result.expr = new_pair(
new_stdmacro(F_QUOTE),
new_pair(result.expr, new_null()));
}
break;
case '`':
s++;
result = parse(s);
s += result.chars_read;
if (result.err_type == PARSE_SUCCESS) {
result.expr = new_pair(
new_stdmacro(F_QUASIQUOTE),
new_pair(result.expr, new_null()));
}
break;
case ',':
s++;
enum StandardMacro stdmacro = F_UNQUOTE;
if (*s == '@') {
s++;
stdmacro = F_UNQUOTE_SPLICING;
}
result = parse(s);
s += result.chars_read;
if (result.err_type == PARSE_SUCCESS) {
result.expr = new_pair(
new_stdmacro(stdmacro),
new_pair(result.expr, new_null()));
}
break;
case '"':
s++;
len = skip_string(s);
if (!(s[len-1] == '\\' && (len < 2 || s[len-2] == '\\'))
&& s[len] == '"') {
result.expr = parse_string(s, len);
} else {
result.err_type = ERR_UNEXPECTED_EOI;
}
s += len;
s++;
break;
default:;
len = skip_symbol(s);
assert(len > 0);
Number number;
if (parse_number(s, len, &number)) {
result.expr = new_number(number);
//.........这里部分代码省略.........
开发者ID:mk12,项目名称:eva,代码行数:101,代码来源:parse.c
注:本文中的parse_pair函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论