本文整理汇总了C++中eat_whitespace函数的典型用法代码示例。如果您正苦于以下问题:C++ eat_whitespace函数的具体用法?C++ eat_whitespace怎么用?C++ eat_whitespace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eat_whitespace函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: eat_whitespace
//reads the format from gen_hgf.
void Player::load_hgf(Board board, Node * node, FILE * fd){
char c, buf[101];
eat_whitespace(fd);
assert(fscanf(fd, "(;%c[%100[^]]]", &c, buf) > 0);
assert(board.toplay() == (c == 'W' ? 1 : 2));
node->move = Move(buf);
board.move(node->move);
assert(fscanf(fd, "C[%100[^]]]", buf) > 0);
vecstr entry, parts = explode(string(buf), ", ");
assert(parts[0] == "mcts");
entry = explode(parts[1], ":");
assert(entry[0] == "sims");
uword sims = from_str<uword>(entry[1]);
entry = explode(parts[2], ":");
assert(entry[0] == "avg");
double avg = from_str<double>(entry[1]);
uword wins = sims*avg;
node->exp.addwins(wins);
node->exp.addlosses(sims - wins);
entry = explode(parts[3], ":");
assert(entry[0] == "outcome");
node->outcome = from_str<int>(entry[1]);
entry = explode(parts[4], ":");
assert(entry[0] == "best");
node->bestmove = Move(entry[1]);
eat_whitespace(fd);
if(fpeek(fd) != ')'){
create_children_simple(board, node);
while(fpeek(fd) != ')'){
Node child;
load_hgf(board, & child, fd);
Node * i = find_child(node, child.move);
*i = child; //copy the child experience to the tree
i->swap_tree(child); //move the child subtree to the tree
assert(child.children.empty());
eat_whitespace(fd);
}
}
eat_char(fd, ')');
return;
}
开发者ID:brthiess,项目名称:morat,代码行数:61,代码来源:player.cpp
示例2: _parse_array
static int _parse_array(char **s, struct json_result *result) {
int rc;
struct json_array *array = visit_array_start(result);
while (1) {
rc = _parse(s, result);
if (!rc) return 0;
rc = visit_array_add(result, array);
if (!rc) return 0;
eat_whitespace(s);
if (**s == ']') {
++*s;
break;
}
else if (**s == ',') {
++*s;
eat_whitespace(s);
}
else {
return 0;
}
}
visit_array_end(result, array);
return 1;
}
开发者ID:showell,项目名称:c_json,代码行数:25,代码来源:json.c
示例3: parse_section
/*
* Scan a section name and remember it in `cursec'.
*/
static void parse_section(FILE *fp)
{
int c, i, end;
/* We've already got the '['. Scan past initial white space. */
c = eat_whitespace(fp);
i = 0;
end = 0;
while (c > 0) {
if (i > (bsize-2)) {
bsize += 1024;
bufr = realloc(bufr, bsize);
if (! bufr) {
fprintf(stderr, "%s: malloc failed\n", confname);
exit(-1);
}
}
switch (c) {
case ']': /* found the closing bracked */
bufr[end] = '\0';
if (end == 0) {
fprintf(stderr, "%s: empty section name\n", confname);
exit(-1);
}
/* Register a section. */
if (cursec)
free(cursec);
cursec = strdup(bufr);
eat_comment(fp);
return;
case '\n':
i = find_continuation(bufr, i);
if (i < 0) {
bufr [end] = 0;
fprintf(stderr, "%s: invalid line: '%s'\n",
confname, bufr);
exit(-1);
}
end = ((i > 0) && (bufr[i-1] == ' ')) ? (i-1) : (i);
c = getc(fp);
break;
default:
if (isspace(c)) {
bufr[end] = ' ';
i = end + 1;
c = eat_whitespace(fp);
} else {
bufr[i++] = c;
end = i;
c = getc(fp);
}
break;
}
}
}
开发者ID:MajenkoProjects,项目名称:pic32prog,代码行数:61,代码来源:configure.c
示例4: make_command_stream
command_stream_t
make_command_stream (int (*get_next_byte) (void *),
void *get_next_byte_argument)
{
line_count = 1;
char buffer[1024] = "";
get_byte = get_next_byte;
get_byte_argument = get_next_byte_argument;
command_stream_t stream = checked_malloc(sizeof(struct command_stream));
command_node_t node = checked_malloc(sizeof(struct command_node));
command_node_t temp_node = node;
command_node_t head = NULL;
command_node_t tail = NULL;
if(!feof(get_byte_argument))
{
eat_whitespace();
if((buffer[0] = get_byte(get_byte_argument)) == EOF)
{
free(stream);
free(node);
return NULL;
}
ungetc(buffer[0], get_byte_argument);
buffer[0] = '\0';
enum command_type type = scan(buffer);
while(1)
{
if(type == SEQUENCE_COMMAND)
temp_node = make_node(buffer, SIMPLE_COMMAND);
else
temp_node = make_node(buffer, type);
if(!head)
{
head = temp_node;
}
else
{
tail->next = temp_node;
temp_node->prev = tail;
}
tail = temp_node;
if(type == SEQUENCE_COMMAND)
break;
eat_whitespace();
if((buffer[0] = get_byte(get_byte_argument)) == EOF)
{
stream->commands = &head;
return stream;
}
ungetc(buffer[0], get_byte_argument);
buffer[0] = '\0';
type = scan(buffer);
}
}
stream->commands = &head;
return stream;
}
开发者ID:aamoyg,项目名称:CS111,代码行数:58,代码来源:read-command.c
示例5: malloc
struct json_val *json_parse_object(struct read_state *state)
{
struct json_val *value;
char ch;
int i;
value = malloc(sizeof(*value));
value->type = JSON_OBJECT;
value->length = 0;
value->object = 0;
if (*state->read++ != '{') {
json_error_print(state, "Internal error parsing object\n");
goto fail;
}
if (!eat_whitespace(state)) {
json_error_print(state, "Unexpected end of file parsing object\n");
goto fail;
}
ch = *state->read++;
if (ch == '}') {
//pass
} else if(ch == '\"'){
do {
read_state_put_back(state);
value->length++;
value->object = realloc(value->object, value->length * sizeof(*value->object));
value->object[value->length-1] = json_parse_object_field(state);
if (value->object[value->length-1].key == 0 || value->object[value->length-1].value == 0)
goto fail;
if (!eat_whitespace(state)) {
json_error_print(state, "Unexpected end of file parsing object\n");
goto fail;
}
ch = *state->read++;
if (ch != '}' && ch != ',') {
json_error_print(state, "Unexpected character reading object\n");
goto fail;
}
if (!eat_whitespace(state) && ch != '}') {
json_error_print(state, "Unexpected end of file parsing object\n");
goto fail;
}
} while(ch == ',');
}
return value;
fail:
json_free_value(value);
return 0;
}
开发者ID:hilesaz,项目名称:drivle,代码行数:52,代码来源:json.c
示例6: parse_object
static int parse_object(lua_State *L, parse_state *state) {
assert(*state->ptr == '{');
state->ptr++;
eat_whitespace(state);
lua_newtable(L);
if (*state->ptr == '}') {
// empty object
state->ptr++;
return 1;
}
while (1) {
// key
if (!parse_string(L, state)) {
lua_remove(L, -2); // remove table
return 0;
}
eat_whitespace(state);
if (*state->ptr != ':') {
lua_pop(L, 2); // pop table and key
return push_parse_error(L, state, "colon expected");
}
state->ptr++;
// value
eat_whitespace(state);
if (!parse_value(L, state)) {
lua_remove(L, -2); // remove key
lua_remove(L, -2); // remove table
return 0;
}
lua_rawset(L, -3);
eat_whitespace(state);
if (*state->ptr == ',') {
state->ptr++;
eat_whitespace(state);
} else {
break;
}
}
if (*state->ptr == 0) {
lua_pop(L, 1); // pop table.
return push_parse_error(L, state, "unterminated object");
}
if (*state->ptr != '}') {
lua_pop(L, 1); // pop table
return push_parse_error(L, state, "unexpected character");
}
state->ptr++;
return 1;
}
开发者ID:JakobssonAndre,项目名称:lotech,代码行数:49,代码来源:ltjson.cpp
示例7: read_pair
static scheme_object* read_pair(vm* context, FILE* in)
{
int c;
scheme_object* car = NULL;
scheme_object* cdr = NULL;
eat_whitespace(in);
c = getc(in);
if(c ==')')
{
return the_empty_list;
}
gc_push_root((void**) &car);
gc_push_root((void**) &cdr);
ungetc(c, in);
car = read(context, in);
eat_whitespace(in);
c = getc(in);
if(c == '.')
{
if(!is_delimiter(peek(in)))
{
fprintf(stderr, "Expected a delimiter after '.'...\n");
exit(1);
}
cdr = read(context, in);
eat_whitespace(in);
c = getc(in);
if(c != ')')
{
fprintf(stderr, "Expected a ')'\n");
exit(1);
}
}
else
{
ungetc(c, in);
cdr = read_pair(context, in);
}
gc_pop_root();
gc_pop_root();
return cons(context, car, cdr);
}
开发者ID:lukesandberg,项目名称:bootstrap-scheme,代码行数:49,代码来源:read.c
示例8: ltLuaParseJSON
/*
* Expects a string as its only argument.
* Returns either the parsed value or nil and an error message.
*/
int ltLuaParseJSON(lua_State *L) {
ltLuaCheckNArgs(L, 1);
const char *input = lua_tostring(L, 1);
if (input == NULL) {
return luaL_error(L, "Argument 1 must be a string");
}
int top = lua_gettop(L);
parse_state state;
state.start = input;
state.ptr = input;
int ok = parse_value(L, &state);
if (ok) {
eat_whitespace(&state);
if (*state.ptr == 0) {
return 1; // parsed value will be at top + 1.
} else {
lua_pop(L, 1); // pop value
lua_pushnil(L);
push_parse_error(L, &state, "unexpected trailing characters");
return 2;
}
} else {
// Error message will be on top of stack.
// Insert nil before err msg.
lua_pushnil(L);
lua_insert(L, top + 1);
return 2;
}
}
开发者ID:JakobssonAndre,项目名称:lotech,代码行数:34,代码来源:ltjson.cpp
示例9: eat_whitespace
void JsonIn::skip_array()
{
char ch;
int brackets = 1;
eat_whitespace();
stream->get(ch);
if (ch != '[') {
std::stringstream err;
err << line_number(-1) << ": expected array but found '" << ch << "'";
throw err.str();
}
while (brackets && stream->good()) {
stream->get(ch);
// ignore everything inside strings
if (ch == '"') {
stream->unget();
skip_string();
// otherwise count opening and closing brackets until they all match
} else if (ch == '[') {
brackets += 1;
} else if (ch == ']') {
brackets -= 1;
}
}
if (brackets != 0) {
// something messed up!
std::stringstream err;
err << "couldn't find end of array!";
err << " " << brackets << " bracket(s) left.";
throw err.str();
}
skip_separator();
}
开发者ID:Liberman,项目名称:Cataclysm-DDA,代码行数:33,代码来源:json.cpp
示例10: get_token_arguments
/** Helper: parse space-separated arguments from the string <b>s</b> ending at
* <b>eol</b>, and store them in the args field of <b>tok</b>. Store the
* number of parsed elements into the n_args field of <b>tok</b>. Allocate
* all storage in <b>area</b>. Return the number of arguments parsed, or
* return -1 if there was an insanely high number of arguments. */
static inline int
get_token_arguments(memarea_t *area, directory_token_t *tok,
const char *s, const char *eol)
{
/** Largest number of arguments we'll accept to any token, ever. */
#define MAX_ARGS 512
char *mem = memarea_strndup(area, s, eol-s);
char *cp = mem;
int j = 0;
char *args[MAX_ARGS];
while (*cp) {
if (j == MAX_ARGS)
return -1;
args[j++] = cp;
cp = (char*)find_whitespace(cp);
if (!cp || !*cp)
break; /* End of the line. */
*cp++ = '\0';
cp = (char*)eat_whitespace(cp);
}
tok->n_args = j;
tok->args = memarea_memdup(area, args, j*sizeof(char*));
return j;
#undef MAX_ARGS
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:30,代码来源:parsecommon.c
示例11: eat_whitespace
bool JsonIn::skip_value()
{
char ch;
bool foundsep;
eat_whitespace();
ch = peek();
// it's either a string '"'
if (ch == '"') {
foundsep = skip_string();
// or an object '{'
} else if (ch == '{') {
foundsep = skip_object();
// or an array '['
} else if (ch == '[') {
foundsep = skip_array();
// or a number (-0123456789)
} else if (ch == '-' || (ch >= '0' && ch <= '9')) {
foundsep = skip_number();
// or "true", "false" or "null"
} else if (ch == 't') {
foundsep = skip_true();
} else if (ch == 'f') {
foundsep = skip_false();
} else if (ch == 'n') {
foundsep = skip_null();
// or an error.
} else {
std::stringstream err;
err << line_number() << ": expected JSON value but got '" << ch << "'";
throw err.str();
}
return foundsep;//b( foundsep || skip_separator() );
}
开发者ID:CepheidVar,项目名称:Cataclysm-DDA,代码行数:33,代码来源:json.cpp
示例12: extract_value
err_t extract_value(chunk_t *value, chunk_t *line)
{
char delimiter = ' ';
if (!eat_whitespace(line))
{
*value = chunk_empty;
return NULL;
}
if (*line->ptr == '\'' || *line->ptr == '"')
{
delimiter = *line->ptr;
line->ptr++; line->len--;
}
if (!extract_token(value, delimiter, line))
{
if (delimiter == ' ')
{
*value = *line;
line->len = 0;
}
else
{
return "missing second delimiter";
}
}
return NULL;
}
开发者ID:21superman,项目名称:strongswan,代码行数:28,代码来源:lexparser.c
示例13: eat_whitespace
void JsonIn::skip_separator()
{
char ch;
eat_whitespace();
ch = peek();
if (ch == ',') {
if (strict && ate_separator) {
error("duplicate separator");
}
stream->get();
ate_separator = true;
} else if (ch == ']' || ch == '}' || ch == ':') {
// okay
if (strict && ate_separator) {
std::stringstream err;
err << "separator should not be found before '" << ch << "'";
uneat_whitespace();
error(err.str());
}
ate_separator = false;
} else if (ch == EOF) {
// that's okay too... probably
if (strict && ate_separator) {
uneat_whitespace();
error("separator at end of file not strictly allowed");
}
ate_separator = false;
} else if (strict) {
// not okay >:(
uneat_whitespace();
error("missing separator", 1);
}
}
开发者ID:Doffeh,项目名称:Cataclysm-DDA,代码行数:33,代码来源:json.cpp
示例14: next_token
/*
* Read the next token into the 'token' argument. If there is a
* newline after the token then 'newline' is set to 1. The return
* value is the number of characters added to 'token' or EOF if the
* end of file is reached.
*/
static int next_token(FILE * f, char token[], int size, int *newline)
{
unsigned int i = 0;
int c = eat_whitespace(f);
if (c == EOF)
return EOF;
if (c == '\n')
goto out;
for (i = 0; i < size - 1; i += 1) {
token[i] = c;
c = fgetc(f);
if (isspace(c) || c == EOF) {
i += 1;
break;
}
}
if (!isspace(c) && c != EOF) {
fprintf(stderr, "Warning: token is too long. Truncating!\n");
c = eat_non_whitespace(f);
}
out:
token[i] = '\0';
*newline = c == '\n';
debug_printf(DEBUG_SPAM, "token: [%s], newline=%s\n", token,
*newline ? "true" : "false");
return i;
}
开发者ID:hitchiker42,项目名称:my-code,代码行数:38,代码来源:depfile.c
示例15: parse_expr
pointer parse_expr(parser* parse)
{
eat_whitespace(parse);
pointer ret_car;
pointer ret_cdr;
switch(*parse->curr)
{
case '(':
parse->curr++;
ret_car = parse_expr(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case '"':
ret_car = parse_string(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case '\'':
parse->curr++;
ret_car = parse_quote(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case ')':
parse->curr++;
return NIL;
case '+': case '-': case 'b':
ret_car = parse_number_or_symbol(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case '.':
return parse_number_or_pair(parse);
case '\\':
parse->curr++;
ret_car = create_char(*(parse->curr++));
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
case ';':
while(!is_newline(*parse->curr) && *parse->curr != '\0')
parse->curr++;
return parse_expr(parse);
case 0:
return NIL;
default:
if(is_number_char(*parse->curr))
{
ret_car = parse_number(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
}
else if(is_symbol_char(*parse->curr))
{
ret_car = parse_symbol(parse);
ret_cdr = parse_expr(parse);
return create_pair(ret_car, ret_cdr);
}
else
return parser_error(parse, "Unexpected char in expression.");
}
parse->curr++;
}
开发者ID:Arelius,项目名称:ploy,代码行数:60,代码来源:parser.cpp
示例16: while
struct conf_entry *conf_parse(FILE *f)
{
struct conf_entry *head = NULL;
struct conf_entry *tail = NULL;
char buf[CONF_MAX_LINE];
while (fgets(buf, sizeof(buf), f)) {
struct conf_entry *e;
char *start = buf;
char *key;
char *val;
strip_newlines(start);
start = eat_whitespace(start);
if (is_ignored_line(start))
continue;
key = strtok(start, " \t");
val = strtok(NULL, "");
if (val)
val = eat_whitespace(val);
e = (struct conf_entry *) malloc(sizeof *e);
if (!e)
goto fail;
e->next = NULL;
e->key = strdup(key);
e->value = val ? strdup(val) : NULL;
if (!e->key || (val && !e->value)) {
free(e->key);
free(e->value);
free(e);
goto fail;
}
if (!head) {
head = e;
tail = e;
} else {
tail->next = e;
tail = e;
}
}
return head;
fail:
conf_free(head);
return NULL;
}
开发者ID:BrianAker,项目名称:tlsdate,代码行数:47,代码来源:conf.c
示例17: while
SvgAttributeReader::SvgAttributeReader(clan::DomElement e, const std::string &attr_name, bool inherit)
{
while (!e.is_null() && !e.has_attribute_ns(Svg::svg_ns, attr_name))
e = e.get_parent_node().to_element();
attr = e.get_attribute_ns(Svg::svg_ns, attr_name);
eat_whitespace();
}
开发者ID:ArtHome12,项目名称:ClanLib,代码行数:8,代码来源:svg_attribute_reader.cpp
示例18: TEST
TEST(Parser, EatWhitespace)
{
std::stringstream read_in(" \r\n\t abc");
eat_whitespace(read_in);
std::string abc;
read_in >> abc;
EXPECT_EQ("abc", abc);
}
开发者ID:achimkrause,项目名称:akss_cpp,代码行数:8,代码来源:parser_test.cpp
示例19: process_block_decl
void process_block_decl(char **decl, int nlines) {
char *name,*cur,*region_name,operand_name[40];
struct memory_region *bytes, *operands;
initialize();
sprintf(operand_name,"ops%i",operand_region_counter++);
cur = decl[0]+1;
eat_whitespace(&cur);
name=grab_identifier(&cur);
region_name = bytecode_malloc(strlen(name)+2);
strcpy(region_name,"#");
strcat(region_name,name);
bytes = mr_new(region_name,3 + (nlines+17)/8);
operands = mr_new(operand_name,nlines*2);
mr_mark_ptr(bytes,1,operands);
bytes->data[0] = 0;
int current_operand = 0;
int current_byte = 0;
int current_word = 2;
int i;
uint64_t word = 0;
char *byte = (char *)&word;
for(i=1;i<nlines;i++) {
char *cur_line = decl[i];
*byte++ = get_bytecode(&cur_line);
cur_line++;
eat_whitespace(&cur_line);
while(*cur_line != '\0') {
process_argument(operands,¤t_operand,&cur_line);
eat_whitespace(&cur_line);
}
if(++current_byte==8) {
current_byte = 0;
bytes->data[current_word] = word;
byte = (char *)&word;
current_word++;
word = 0;
}
}
bytes->data[current_word] = word;
bytes->data[current_word+1] = 0;
*byte = 0;
}
开发者ID:jhartzell42,项目名称:compass,代码行数:44,代码来源:block.c
注:本文中的eat_whitespace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论