本文整理汇总了C++中Tokenizer::SetTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Tokenizer::SetTo方法的具体用法?C++ Tokenizer::SetTo怎么用?C++ Tokenizer::SetTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer::SetTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
status_t
ExpressionParser::ParseNextCommandArgument(const char** expressionString,
char* buffer, size_t bufferSize)
{
fTokenizer.SetTo(*expressionString);
fTokenizer.SetCommandMode(true);
if (fTokenizer.NextToken().type == TOKEN_END_OF_LINE)
return B_ENTRY_NOT_FOUND;
fTokenizer.RewindToken();
char* argv[2];
int argc = 0;
if (!_ParseArgument(argc, argv))
return B_BAD_VALUE;
strlcpy(buffer, argv[0], bufferSize);
const Token& token = fTokenizer.NextToken();
if (token.type == TOKEN_END_OF_LINE)
*expressionString = NULL;
else
*expressionString += token.position;
return B_OK;
}
示例2: if
uint64
ExpressionParser::EvaluateCommand(const char* expressionString, int& returnCode)
{
fTokenizer.SetTo(expressionString);
// Allowed are command or assignment. A command always starts with an
// identifier, an assignment either with an identifier (variable name) or
// a dereferenced address.
const Token& token = fTokenizer.NextToken();
uint64 value = 0;
while (true) {
int32 startPosition = token.position;
if (token.type == TOKEN_IDENTIFIER) {
fTokenizer.NextToken();
if (token.type & TOKEN_ASSIGN_FLAG) {
// an assignment
fTokenizer.SetPosition(startPosition);
value = _ParseExpression(true);
returnCode = 0;
} else {
// no assignment, so let's assume it's a command
fTokenizer.SetPosition(startPosition);
fTokenizer.SetCommandMode(true);
value = _ParseCommandPipe(returnCode);
}
} else if (token.type == TOKEN_STAR) {
// dereferenced address -- assignment
fTokenizer.SetPosition(startPosition);
value = _ParseExpression(true);
returnCode = 0;
} else
parse_exception("expected command or assignment", token.position);
// might be chained with ";"
if (fTokenizer.NextToken().type != TOKEN_SEMICOLON)
break;
fTokenizer.SetCommandMode(false);
fTokenizer.NextToken();
}
if (token.type != TOKEN_END_OF_LINE)
parse_exception("parse error", token.position);
return value;
}