本文整理汇总了C++中Tokenizer::quotedString方法的典型用法代码示例。如果您正苦于以下问题:C++ Tokenizer::quotedString方法的具体用法?C++ Tokenizer::quotedString怎么用?C++ Tokenizer::quotedString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer::quotedString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doEmit
Token DefTokenEmitter::doEmit(Tokenizer& tokenizer) {
while (!tokenizer.eof()) {
size_t line = tokenizer.line();
size_t column = tokenizer.column();
const char* c = tokenizer.nextChar();
switch (*c) {
case '/': {
const char* begin = c;
if (tokenizer.peekChar() == '*') {
// eat all chars immediately after the '*' because it's often followed by QUAKE
while (!isWhitespace(*tokenizer.nextChar()) && !tokenizer.eof());
return Token(ODefinition, begin, c, tokenizer.offset(begin), line, column);
} else if (tokenizer.peekChar() == '/') {
// eat everything up to and including the next newline
while (*tokenizer.nextChar() != '\n');
break;
}
error(line, column, *c);
break;
}
case '*': {
const char* begin = c;
if (tokenizer.peekChar() == '/') {
tokenizer.nextChar();
return Token(ODefinition, begin, c, tokenizer.offset(begin), line, column);
}
error(line, column, *c);
break;
}
case '(':
return Token(OParenthesis, c, c + 1, tokenizer.offset(c), line, column);
case ')':
return Token(CParenthesis, c, c + 1, tokenizer.offset(c), line, column);
case '{':
return Token(OBrace, c, c + 1, tokenizer.offset(c), line, column);
case '}':
return Token(CBrace, c, c + 1, tokenizer.offset(c), line, column);
case '=':
return Token(Equality, c, c + 1, tokenizer.offset(c), line, column);
case ';':
return Token(Semicolon, c, c + 1, tokenizer.offset(c), line, column);
case '?':
return Token(Question, c, c + 1, tokenizer.offset(c), line, column);
case '\r':
if (tokenizer.peekChar() == '\n') {
tokenizer.nextChar();
}
case '\n':
return Token(Newline, c, c + 1, tokenizer.offset(c), line, column);
case ',':
return Token(Comma, c, c + 1, tokenizer.offset(c), line, column);
case ' ':
case '\t':
break;
case '"': { // quoted string
const char* begin = c;
const char* end;
tokenizer.quotedString(begin, end);
return Token(QuotedString, begin, end, tokenizer.offset(begin), line, column);
}
default: { // integer, decimal or word
const char* begin = c;
// try to read a number
if (*c == '-' || isDigit(*c)) {
while (isDigit(*(c = tokenizer.nextChar())));
if (isDelimiter(*c)) {
if (!tokenizer.eof())
tokenizer.pushChar();
return Token(Integer, begin, c, tokenizer.offset(begin), line, column);
}
}
// try to read a decimal (may start with '.')
if (*c == '.') {
while (isDigit(*(c = tokenizer.nextChar())));
if (isDelimiter(*c)) {
if (!tokenizer.eof())
tokenizer.pushChar();
return Token(Decimal, begin, c, tokenizer.offset(begin), line, column);
}
}
// read a word
while (!tokenizer.eof() && !isDelimiter(*(c = tokenizer.nextChar())));
if (!tokenizer.eof())
tokenizer.pushChar();
return Token(Word, begin, c, tokenizer.offset(begin), line, column);
}
}
}
return Token(Eof, NULL, NULL, 0, tokenizer.line(), tokenizer.column());
}
示例2: parse
//.........这里部分代码省略.........
// Check for type+name pair
string type = "";
if (next != "=" && next != "{" && next != ";" && next != ":")
{
type = name;
name = tz.getToken();
next = tz.peekToken();
}
// Assignment
if (S_CMP(next, "="))
{
// Skip =
tz.skipToken();
// Create item node
ParseTreeNode* child = (ParseTreeNode*)addChild(name);
child->type = type;
// Check type of assignment list
token = tz.getToken();
string list_end = ";";
if (token == "{")
{
list_end = "}";
token = tz.getToken();
}
// Parse until ; or }
while (1)
{
// Check for list end
if (S_CMP(token, list_end) && !tz.quotedString())
break;
// Setup value
Property value;
// Detect value type
if (tz.quotedString()) // Quoted string
value = token;
else if (S_CMPNOCASE(token, "true")) // Boolean (true)
value = true;
else if (S_CMPNOCASE(token, "false")) // Boolean (false)
value = false;
else if (re_int1.Matches(token) || // Integer
re_int2.Matches(token))
{
long val;
token.ToLong(&val);
value = (int)val;
}
else if (re_int3.Matches(token)) // Hex (0xXXXXXX)
{
long val;
token.ToLong(&val, 0);
value = (int)val;
//wxLogMessage("%s: %s is hex %d", CHR(name), CHR(token), value.getIntValue());
}
else if (re_float.Matches(token)) // Floating point
{
double val;
token.ToDouble(&val);
value = (double)val;
//LOG_MESSAGE(3, S_FMT("%s: %s is float %1.3f", CHR(name), CHR(token), val));
示例3: doEmit
Token MapTokenEmitter::doEmit(Tokenizer& tokenizer) {
while (!tokenizer.eof()) {
size_t line = tokenizer.line();
size_t column = tokenizer.column();
const char* c = tokenizer.nextChar();
switch (*c) {
case '/':
if (tokenizer.peekChar() == '/') {
tokenizer.nextChar();
if (tokenizer.peekChar() == '/') {
tokenizer.nextChar(); // it's a TB comment
} else {
// eat everything up to and including the next newline
while (*tokenizer.nextChar() != '\n');
}
}
break;
case '{':
return Token(TokenType::OBrace, c, c + 1, tokenizer.offset(c), line, column);
case '}':
return Token(TokenType::CBrace, c, c + 1, tokenizer.offset(c), line, column);
case '(':
return Token(TokenType::OParenthesis, c, c + 1, tokenizer.offset(c), line, column);
case ')':
return Token(TokenType::CParenthesis, c, c + 1, tokenizer.offset(c), line, column);
case '[':
return Token(TokenType::OBracket, c, c + 1, tokenizer.offset(c), line, column);
case ']':
return Token(TokenType::CBracket, c, c + 1, tokenizer.offset(c), line, column);
case '"': { // quoted string
const char* begin = c;
const char* end;
tokenizer.quotedString(begin, end);
return Token(TokenType::String, begin, end, tokenizer.offset(begin), line, column);
}
default: { // whitespace, integer, decimal or word
if (isWhitespace(*c))
break;
const char* begin = c;
// try to read a number
if (*c == '-' || isDigit(*c)) {
while (isDigit(*(c = tokenizer.nextChar())));
if (isDelimiter(*c)) {
if (!tokenizer.eof())
tokenizer.pushChar();
return Token(TokenType::Integer, begin, c, tokenizer.offset(begin), line, column);
}
}
// try to read a decimal (may start with '.')
if (*c == '.') {
while (isDigit(*(c = tokenizer.nextChar())));
if (isDelimiter(*c)) {
if (!tokenizer.eof())
tokenizer.pushChar();
return Token(TokenType::Decimal, begin, c, tokenizer.offset(begin), line, column);
}
}
// try to read decimal in scientific notation
if (*c == 'e') {
c = tokenizer.nextChar();
if (isDigit(*c) || *c == '+' || *c == '-') {
while (isDigit(*(c = tokenizer.nextChar())));
if (isDelimiter(*c)) {
if (!tokenizer.eof())
tokenizer.pushChar();
return Token(TokenType::Decimal, begin, c, tokenizer.offset(begin), line, column);
}
}
}
// read a word
while (!tokenizer.eof() && !isDelimiter(*(c = tokenizer.nextChar())));
if (!tokenizer.eof())
tokenizer.pushChar();
return Token(TokenType::String, begin, c, tokenizer.offset(begin), line, column);
}
}
}
return Token(TokenType::Eof, NULL, NULL, 0, tokenizer.line(), tokenizer.column());
}