本文整理汇总了C++中Token::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ Token::ToString方法的具体用法?C++ Token::ToString怎么用?C++ Token::ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PushBack
void Lexer::PushBack(Token& t)
{
DEBUG("Pushback: %s", t.ToString().c_str() );
pushback_tokens.push_back(t);
}
示例2: ParseTokens
void ParseTokens(vector<Token>& tokens, XMLDocument& outDoc){
Stack<Token> tokenStack;
Stack<XMLElement> elementStack;
bool inTag = false;
for(auto iter = tokens.begin(); iter != tokens.end(); iter++){
Token token = *iter;
//cout << "Parsing token: |" << token << "|" << endl;
if(token == "<"){
inTag = true;
tokenStack.Push(token);
}
else if(token == "/"){
if(tokenStack.Top() == "<"){
//Add the element to the doc
XMLElement elem = elementStack.Pop();
if(elementStack.count == 0){
outDoc.contents.push_back(elem);
}
else{
elementStack.Top().children.push_back(elem);
}
iter++;
iter++;
}
else{
tokenStack.Push(token);
}
}
else if(token == ">"){
inTag = false;
bool startList = true;
if(tokenStack.Top() == "/"){
startList = false;
tokenStack.Pop();
}
Token currToken = tokenStack.Pop();
XMLAttribute attr;
attr.data = attr.name = "";
bool gotData = false;
while(currToken != "<"){
if(currToken == "="){
//do nothing
}
else if(!gotData){
attr.data = currToken.ToString();
gotData = true;
}
else{
attr.name = currToken.ToString();
elementStack.Top().AddAttribute(attr.name, attr.data);
attr.data = attr.name = "";
gotData = false;
}
currToken = tokenStack.Pop();
}
if(!startList){
XMLElement elem = elementStack.Pop();
if(elementStack.count == 0){
outDoc.contents.push_back(elem);
}
else{
elementStack.Top().children.push_back(elem);
}
}
}
else{
if(!inTag){
XMLElement elem;
elem.name = "__plaintext__";
elem.AddAttribute("val", token.ToString());
if(elementStack.count == 0){
outDoc.contents.push_back(elem);
}
else{
elementStack.Top().children.push_back(elem);
}
continue;
}
else if(tokenStack.Top() == "<"){
XMLElement elem;
elem.name = token.ToString();
//cout << "Pushing to element stack: " << token << endl;
elementStack.Push(elem);
}
//cout << "Pushing token: "<< token << endl;
tokenStack.Push(token);
}
}
}