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


C++ OTMLNodePtr::setValue方法代码示例

本文整理汇总了C++中OTMLNodePtr::setValue方法的典型用法代码示例。如果您正苦于以下问题:C++ OTMLNodePtr::setValue方法的具体用法?C++ OTMLNodePtr::setValue怎么用?C++ OTMLNodePtr::setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OTMLNodePtr的用法示例。


在下文中一共展示了OTMLNodePtr::setValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parseNode

void OTMLParser::parseNode(const std::string& data)
{
    std::string tag;
    std::string value;
    std::size_t dotsPos = data.find_first_of(':');
    int nodeLine = currentLine;

    // node that has no tag and may have a value
    if(!data.empty() && data[0] == '-') {
        value = data.substr(1);
        boost::trim(value);
    // node that has tag and possible a value
    } else if(dotsPos != std::string::npos) {
        tag = data.substr(0, dotsPos);
        if(data.size() > dotsPos+1)
            value = data.substr(dotsPos+1);
    // node that has only a tag
    } else {
        tag = data;
    }

    boost::trim(tag);
    boost::trim(value);

    // process multitine values
    if(value == "|" || value == "|-" || value == "|+") {
        // reads next lines until we can a value below the same depth
        std::string multiLineData;
        do {
            size_t lastPos = in.tellg();
            std::string line = getNextLine();
            int depth = getLineDepth(line, true);

            // depth above current depth, add the text to the multiline
            if(depth > currentDepth) {
                multiLineData += line.substr((currentDepth+1)*2);
            // it has contents below the current depth
            } else {
                // if not empty, its a node
                boost::trim(line);
                if(!line.empty()) {
                    // rewind and break
                    in.seekg(lastPos, std::ios::beg);
                    currentLine--;
                    break;
                }
            }
            multiLineData += "\n";
        } while(!in.eof());

        /* determine how to treat new lines at the end
         * | strip all new lines at the end and add just a new one
         * |- strip all new lines at the end
         * |+ keep all the new lines at the end (the new lines until next node)
         */
        if(value == "|" || value == "|-") {
            // remove all new lines at the end
            int lastPos = multiLineData.length();
            while(multiLineData[--lastPos] == '\n')
                multiLineData.erase(lastPos, 1);

            if(value == "|")
                multiLineData.append("\n");
        } // else it's |+

        value = multiLineData;
    }

    // create the node
    OTMLNodePtr node = OTMLNode::create(tag);

    node->setUnique(dotsPos != std::string::npos);
    node->setTag(tag);
    node->setSource(doc->source() + ":" + Fw::unsafeCast<std::string>(nodeLine));

    // ~ is considered the null value
    if(value == "~")
        node->setNull(true);
    else
        node->setValue(value);

    currentParent->addChild(node);
    previousNode = node;
}
开发者ID:brun123,项目名称:otclient,代码行数:84,代码来源:otmlparser.cpp


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