本文整理汇总了C++中TextNode::setText方法的典型用法代码示例。如果您正苦于以下问题:C++ TextNode::setText方法的具体用法?C++ TextNode::setText怎么用?C++ TextNode::setText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextNode
的用法示例。
在下文中一共展示了TextNode::setText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
// FIXME: Most of the assertions below should be turn into parse errors and be
// reported in a cleaner way to the client side.
TemplateNode* Parser::parse()
{
TemplateNode* root = new TemplateNode();
Node* current = root;
m_insideClause = false;
Tokenizer::Token token;
do {
assert(m_lastTokenType != Tokenizer::Token::EndOfInput);
m_tokenizer->nextToken(token);
assert(token.type != Tokenizer::Token::None);
switch (token.type) {
case Tokenizer::Token::Text:
assert(m_lastTokenType != Tokenizer::Token::Text);
switch (m_lastTokenType) {
case Tokenizer::Token::OpenComment: {
assert(m_insideClause);
CommentNode* commentNode = new CommentNode(current);
commentNode->setText(token.contents);
break;
}
case Tokenizer::Token::OpenVariable: {
assert(m_insideClause);
std::string variable;
assert(splitVariableExpression(token.contents, variable));
VariableNode* variableNode = new VariableNode(current);
variableNode->setExpression(VariableExpression::parse(variable));
break;
}
case Tokenizer::Token::OpenTag: {
assert(m_insideClause);
std::string tagName;
std::vector<std::string> parameters;
assert(splitTagExpression(token.contents, tagName, parameters));
if (tagName.size() > 3 && tagName.substr(0, 3) == "end") {
std::string tagBaseName = tagName.substr(3);
if (TagNodeFactory::self()->isTagRegistered(tagBaseName.c_str())) {
assert(current->type() == Node::Tag);
TagNode* tagNode = static_cast<TagNode*>(current);
assert(tagNode->name() == tagBaseName);
assert(!tagNode->isSelfClosing());
current = current->parent();
} else {
TagNode* tagNode = new NullTagNode(current);
assert(tagNode->isSelfClosing());
}
} else {
if (TagNodeFactory::self()->isTagRegistered(tagName.c_str())) {
TagNode* tagNode = TagNodeFactory::self()->create(tagName.c_str(), current);
assert(tagNode);
tagNode->setName(tagName);
tagNode->setParameters(parameters);
if (!tagNode->isSelfClosing())
current = tagNode;
} else {
TagNode* tagNode = new NullTagNode(current);
assert(tagNode->isSelfClosing());
}
}
break;
}
default: {
TextNode* textNode = new TextNode(current);
textNode->setText(token.contents);
break;
}
}
break;
case Tokenizer::Token::OpenComment:
case Tokenizer::Token::OpenVariable:
case Tokenizer::Token::OpenTag:
assert(!m_insideClause);
m_insideClause = true;
break;
case Tokenizer::Token::CloseComment:
case Tokenizer::Token::CloseVariable:
case Tokenizer::Token::CloseTag:
assert(m_insideClause);
m_insideClause = false;
break;
case Tokenizer::Token::EndOfInput:
// Make sure all opening tags have their corresponding closing tags.
assert(current == root);
break;
}
m_lastTokenType = token.type;
assert(current);
} while (token.type != Tokenizer::Token::EndOfInput);
return root;
}