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


C++ Poco::replace方法代码示例

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


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

示例1: parse

void AvailableTickets::parse()
{
    /* Read the contents of the current user accounts and store each user */
    FileInputStream fis(atf_file);

    if (fis.good())
    {
        string read;
        RegularExpression re("^(.{1,19}?)_+_([A-Za-z0-9_]{1,15}?)_+([0-9]{3})_([0-9]{3}\\.[0-9]{2})$");
        RegularExpression re_end("END_{33}0{3}_0{3}\\.0{2}");
        RegularExpression::MatchVec matches;

        while (getline(fis, read))
        {
            /* Stop if END of file reached */
            if (re_end.match(read))
            {
                return;
            }

            /* Add each ticket found to the list of tickets */
            if (Validate::atf_entry(read))
            {
                re.match(read, 0, matches);

                /* Replace each _ with a space character for event title */
                string event = replace(read.substr(matches[1].offset, matches[1].length), "_", " ");

                string seller = read.substr(matches[2].offset, matches[2].length);
                int volume = NumberParser::parse((read.substr(matches[3].offset, matches[3].length)));
                double price = NumberParser::parseFloat(read.substr(matches[4].offset, matches[4].length));

                /* Add the ticket to the list of tickets */
                this->tickets.push_back(Ticket(event, seller, volume, price));
            }
            /* Corrupted entry in file */
            else
            {
                throw Exception(CORRUPT_ATF);
            }
        }
    }

    /* No END of file identifier found or file corrupted */
    throw Exception(CORRUPT_ATF);
}
开发者ID:gnu-user,项目名称:qa-project,代码行数:46,代码来源:AvailableTickets.cpp

示例2: testReplace

void StringTest::testReplace()
{
    std::string s("aabbccdd");

    assert (replace(s, std::string("aa"), std::string("xx")) == "xxbbccdd");
    assert (replace(s, std::string("bb"), std::string("xx")) == "aaxxccdd");
    assert (replace(s, std::string("dd"), std::string("xx")) == "aabbccxx");
    assert (replace(s, std::string("bbcc"), std::string("xx")) == "aaxxdd");
    assert (replace(s, std::string("b"), std::string("xx")) == "aaxxxxccdd");
    assert (replace(s, std::string("bb"), std::string("")) == "aaccdd");
    assert (replace(s, std::string("b"), std::string("")) == "aaccdd");
    assert (replace(s, std::string("ee"), std::string("xx")) == "aabbccdd");
    assert (replace(s, std::string("dd"), std::string("")) == "aabbcc");

    assert (replace(s, "aa", "xx") == "xxbbccdd");
    assert (replace(s, "bb", "xx") == "aaxxccdd");
    assert (replace(s, "dd", "xx") == "aabbccxx");
    assert (replace(s, "bbcc", "xx") == "aaxxdd");
    assert (replace(s, "bb", "") == "aaccdd");
    assert (replace(s, "b", "") == "aaccdd");
    assert (replace(s, "ee", "xx") == "aabbccdd");
    assert (replace(s, "dd", "") == "aabbcc");

    s = "aabbaabb";
    assert (replace(s, std::string("aa"), std::string("")) == "bbbb");
    assert (replace(s, std::string("a"), std::string("")) == "bbbb");
    assert (replace(s, std::string("a"), std::string("x")) == "xxbbxxbb");
    assert (replace(s, std::string("a"), std::string("xx")) == "xxxxbbxxxxbb");
    assert (replace(s, std::string("aa"), std::string("xxx")) == "xxxbbxxxbb");

    assert (replace(s, std::string("aa"), std::string("xx"), 2) == "aabbxxbb");

    assert (replace(s, "aa", "") == "bbbb");
    assert (replace(s, "a", "") == "bbbb");
    assert (replace(s, "a", "x") == "xxbbxxbb");
    assert (replace(s, "a", "xx") == "xxxxbbxxxxbb");
    assert (replace(s, "aa", "xxx") == "xxxbbxxxbb");

    assert (replace(s, "aa", "xx", 2) == "aabbxxbb");
}
开发者ID:as2120,项目名称:ZPoco,代码行数:40,代码来源:StringTest.cpp


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