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


C++ StringBuilder::resize方法代码示例

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


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

示例1:

TEST(StringBuilderTest, ToString)
{
    StringBuilder builder;
    builder.append("0123456789");
    String string = builder.toString();
    ASSERT_EQ(String("0123456789"), string);
    ASSERT_EQ(string.impl(), builder.toString().impl());

    // Changing the StringBuilder should not affect the original result of toString().
    builder.append("abcdefghijklmnopqrstuvwxyz");
    ASSERT_EQ(String("0123456789"), string);

    // Changing the StringBuilder should not affect the original result of toString() in case the capacity is not changed.
    builder.reserveCapacity(200);
    string = builder.toString();
    ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);
    builder.append("ABC");
    ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyz"), string);

    // Changing the original result of toString() should not affect the content of the StringBuilder.
    String string1 = builder.toString();
    ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
    string1.append("DEF");
    ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), builder.toString());
    ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABCDEF"), string1);

    // Resizing the StringBuilder should not affect the original result of toString().
    string1 = builder.toString();
    builder.resize(10);
    builder.append("###");
    ASSERT_EQ(String("0123456789abcdefghijklmnopqrstuvwxyzABC"), string1);
}
开发者ID:sysrqb,项目名称:chromium-src,代码行数:32,代码来源:StringBuilder.cpp

示例2: leastUpperBound

String StructureShape::leastUpperBound(Vector<RefPtr<StructureShape>>* shapes)
{
    if (!shapes->size())
        return "";

    StringBuilder lub;
    RefPtr<StructureShape> origin = shapes->at(0);
    lub.append("{");
    for (auto iter = origin->m_fields.begin(), end = origin->m_fields.end(); iter != end; ++iter) {
        bool shouldAdd = true;
        for (size_t i = 1, size = shapes->size(); i < size; i++) {
            // If all other Shapes have the same field as origin, add it to the least upper bound.
            if (!shapes->at(i)->m_fields.contains(iter->key)) {
                shouldAdd = false;
                break;
            }
        }
        if (shouldAdd)
            lub.append(String(iter->key.get()) + String(", "));
    }

    if (lub.length() >= 3)
        lub.resize(lub.length() - 2); // Remove the trailing ', '

    lub.append("}");
    
    return lub.toString();
}
开发者ID:sdujq,项目名称:webkit,代码行数:28,代码来源:TypeSet.cpp

示例3: stripTrailingNewline

static void stripTrailingNewline(StringBuilder& result)
{
    // Remove one trailing newline; there's always one that's collapsed out by rendering.
    size_t size = result.length();
    if (size && result[size - 1] == newlineCharacter)
        result.resize(size - 1);
}
开发者ID:clbr,项目名称:webkitfltk,代码行数:7,代码来源:HTMLTextFormControlElement.cpp

示例4: finishText

static String finishText(StringBuilder& result)
{
    // Remove one trailing newline; there's always one that's collapsed out by rendering.
    size_t size = result.length();
    if (size && result[size - 1] == '\n')
        result.resize(--size);
    return result.toString();
}
开发者ID:awong-chromium,项目名称:webkit,代码行数:8,代码来源:HTMLTextFormControlElement.cpp

示例5: expectBuilderContent

TEST(StringBuilderTest, Resize)
{
    StringBuilder builder;
    builder.append("0123456789");
    builder.resize(10);
    EXPECT_EQ(10U, builder.length());
    expectBuilderContent("0123456789", builder);
    builder.resize(8);
    EXPECT_EQ(8U, builder.length());
    expectBuilderContent("01234567", builder);

    builder.toString();
    builder.resize(7);
    EXPECT_EQ(7U, builder.length());
    expectBuilderContent("0123456", builder);
    builder.resize(0);
    expectEmpty(builder);
}
开发者ID:sysrqb,项目名称:chromium-src,代码行数:18,代码来源:StringBuilder.cpp

示例6: toString

String WebMediaSessionManager::toString(ConfigurationTasks tasks)
{
    StringBuilder string;
    if (tasks & InitialConfigurationTask)
        string.append("InitialConfigurationTask + ");
    if (tasks & TargetClientsConfigurationTask)
        string.append("TargetClientsConfigurationTask + ");
    if (tasks & TargetMonitoringConfigurationTask)
        string.append("TargetMonitoringConfigurationTask + ");
    if (string.isEmpty())
        string.append("NoTask");
    else
        string.resize(string.length() - 2);
    
    return string.toString();
}
开发者ID:shushanbj,项目名称:webkit,代码行数:16,代码来源:WebMediaSessionManager.cpp

示例7: stringRepresentation

String StructureShape::stringRepresentation()
{
    StringBuilder representation;
    representation.append("{");
    for (auto iter = m_fields.begin(), end = m_fields.end(); iter != end; ++iter) {
        String prop(iter->key.get());
        representation.append(prop);
        representation.append(", ");
    }

    if (representation.length() >= 3)
        representation.resize(representation.length() - 2);

    representation.append("}");

    return representation.toString();
}
开发者ID:sdujq,项目名称:webkit,代码行数:17,代码来源:TypeSet.cpp

示例8: synchronousScrollingReasonsAsText

String ScrollingCoordinator::synchronousScrollingReasonsAsText(SynchronousScrollingReasons reasons)
{
    StringBuilder stringBuilder;

    if (reasons & ScrollingCoordinator::ForcedOnMainThread)
        stringBuilder.append("Forced on main thread, ");
    if (reasons & ScrollingCoordinator::HasSlowRepaintObjects)
        stringBuilder.append("Has slow repaint objects, ");
    if (reasons & ScrollingCoordinator::HasViewportConstrainedObjectsWithoutSupportingFixedLayers)
        stringBuilder.append("Has viewport constrained objects without supporting fixed layers, ");
    if (reasons & ScrollingCoordinator::HasNonLayerViewportConstrainedObjects)
        stringBuilder.append("Has non-layer viewport-constrained objects, ");
    if (reasons & ScrollingCoordinator::IsImageDocument)
        stringBuilder.append("Is image document, ");

    if (stringBuilder.length())
        stringBuilder.resize(stringBuilder.length() - 2);
    return stringBuilder.toString();
}
开发者ID:highweb-project,项目名称:qplusweb,代码行数:19,代码来源:ScrollingCoordinator.cpp

示例9: removeToken

String DOMTokenList::removeToken(const AtomicString& input, const AtomicString& token)
{
    // Algorithm defined at http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#remove-a-token-from-a-string

    unsigned inputLength = input.length();
    StringBuilder output; // 3
    output.reserveCapacity(inputLength);
    unsigned position = 0; // 4

    // Step 5
    while (position < inputLength) {
        if (isHTMLSpace(input[position])) { // 6
            output.append(input[position++]); // 6.1, 6.2
            continue; // 6.3
        }

        // Step 7
        StringBuilder s;
        while (position < inputLength && isNotHTMLSpace(input[position]))
            s.append(input[position++]);

        // Step 8
        if (s.toStringPreserveCapacity() == token) {
            // Step 8.1
            while (position < inputLength && isHTMLSpace(input[position]))
                ++position;

            // Step 8.2
            size_t j = output.length();
            while (j > 0 && isHTMLSpace(output[j - 1]))
                --j;
            output.resize(j);

            // Step 8.3
            if (position < inputLength && !output.isEmpty())
                output.append(' ');
        } else
            output.append(s.toStringPreserveCapacity()); // Step 9
    }

    return output.toString();
}
开发者ID:CannedFish,项目名称:deepin-webkit,代码行数:42,代码来源:DOMTokenList.cpp

示例10: mediaProducerStateString

static String mediaProducerStateString(MediaProducer::MediaStateFlags flags)
{
    StringBuilder string;
    if (flags & MediaProducer::IsPlayingAudio)
        string.append("IsPlayingAudio + ");
    if (flags & MediaProducer::IsPlayingVideo)
        string.append("IsPlayingVideo + ");
    if (flags & MediaProducer::IsPlayingToExternalDevice)
        string.append("IsPlayingToExternalDevice + ");
    if (flags & MediaProducer::RequiresPlaybackTargetMonitoring)
        string.append("RequiresPlaybackTargetMonitoring + ");
    if (flags & MediaProducer::ExternalDeviceAutoPlayCandidate)
        string.append("ExternalDeviceAutoPlayCandidate + ");
    if (string.isEmpty())
        string.append("IsNotPlaying");
    else
        string.resize(string.length() - 2);

    return string.toString();
}
开发者ID:shushanbj,项目名称:webkit,代码行数:20,代码来源:WebMediaSessionManager.cpp

示例11: saveResultToString

static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, String& resultString)
{
    xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0);
    if (!outputBuf)
        return false;

    StringBuilder resultBuilder;
    outputBuf->context = &resultBuilder;
    outputBuf->writecallback = writeToStringBuilder;

    int retval = xsltSaveResultTo(outputBuf, resultDoc, sheet);
    xmlOutputBufferClose(outputBuf);
    if (retval < 0)
        return false;

    // Workaround for <http://bugzilla.gnome.org/show_bug.cgi?id=495668>: libxslt appends an extra line feed to the result.
    if (resultBuilder.length() > 0 && resultBuilder[resultBuilder.length() - 1] == '\n')
        resultBuilder.resize(resultBuilder.length() - 1);

    resultString = resultBuilder.toString();

    return true;
}
开发者ID:iArnaud,项目名称:webkitnix,代码行数:23,代码来源:XSLTProcessorLibxslt.cpp


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