本文整理汇总了C++中tok_ctx::expect方法的典型用法代码示例。如果您正苦于以下问题:C++ tok_ctx::expect方法的具体用法?C++ tok_ctx::expect怎么用?C++ tok_ctx::expect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tok_ctx
的用法示例。
在下文中一共展示了tok_ctx::expect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_bs_newline
/**
* Called when we hit a backslash.
* If there is nothing but whitespace until the newline, then this is a
* backslash newline
*/
static bool parse_bs_newline(tok_ctx& ctx, chunk_t& pc)
{
ctx.save();
ctx.get(); /* skip the '\' */
int ch;
while (ctx.more() && unc_isspace(ch = ctx.peek()))
{
ctx.get();
if ((ch == '\r') || (ch == '\n'))
{
if (ch == '\r')
{
ctx.expect('\n');
}
pc.str = "\\";
pc.type = CT_NL_CONT;
pc.nl_count = 1;
return(true);
}
}
ctx.restore();
return(false);
}
示例2: parse_whitespace
/**
* Count the number of whitespace characters.
*
* @param pc The structure to update, str is an input.
* @return Whether whitespace was parsed
*/
static bool parse_whitespace(tok_ctx& ctx, chunk_t& pc)
{
int nl_count = 0;
int ch = -2;
/* REVISIT: use a better whitespace detector? */
while (ctx.more() && unc_isspace(ctx.peek()))
{
ch = ctx.get(); /* throw away the whitespace char */
switch (ch)
{
case '\r':
if (ctx.expect('\n'))
{
/* CRLF ending */
cpd.le_counts[LE_CRLF]++;
}
else
{
/* CR ending */
cpd.le_counts[LE_CR]++;
}
nl_count++;
pc.orig_prev_sp = 0;
break;
case '\n':
/* LF ending */
cpd.le_counts[LE_LF]++;
nl_count++;
pc.orig_prev_sp = 0;
break;
case '\t':
pc.orig_prev_sp += calc_next_tab_column(cpd.column, cpd.settings[UO_input_tab_size].n) - cpd.column;
break;
case ' ':
pc.orig_prev_sp++;
break;
default:
break;
}
}
if (ch != -2)
{
pc.str.clear();
pc.nl_count = nl_count;
pc.type = nl_count ? CT_NEWLINE : CT_WHITESPACE;
pc.after_tab = (ctx.c.last_ch == '\t');
return(true);
}
return(false);
} // parse_whitespace
示例3: parse_newline
/**
* Parses any number of tab or space chars followed by a newline.
* Does not change pc.len if a newline isn't found.
* This is not the same as parse_whitespace() because it only consumes until
* a single newline is encountered.
*/
static bool parse_newline(tok_ctx& ctx)
{
ctx.save();
/* Eat whitespace */
while ((ctx.peek() == ' ') || (ctx.peek() == '\t'))
{
ctx.get();
}
if ((ctx.peek() == '\r') || (ctx.peek() == '\n'))
{
if (!ctx.expect('\n'))
{
ctx.get();
ctx.expect('\n');
}
return(true);
}
ctx.restore();
return(false);
}