当前位置: 首页>>代码示例>>C++>>正文


C++ TextNode::setText方法代码示例

本文整理汇总了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;
}
开发者ID:vietlq,项目名称:cjango,代码行数:100,代码来源:Parser.cpp


注:本文中的TextNode::setText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。