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


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

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


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

示例1: serialized

String Color::serialized() const
{
    if (!hasAlpha()) {
        StringBuilder builder;
        builder.reserveCapacity(7);
        builder.append('#');
        appendByteAsHex(red(), builder, Lowercase);
        appendByteAsHex(green(), builder, Lowercase);
        appendByteAsHex(blue(), builder, Lowercase);
        return builder.toString();
    }

    StringBuilder result;
    result.reserveCapacity(28);

    result.appendLiteral("rgba(");
    result.appendNumber(red());
    result.appendLiteral(", ");
    result.appendNumber(green());
    result.appendLiteral(", ");
    result.appendNumber(blue());
    result.appendLiteral(", ");

    if (!alpha())
        result.append('0');
    else {
        result.append(Decimal::fromDouble(alpha() / 255.0).toString());
    }

    result.append(')');
    return result.toString();
}
开发者ID:335969568,项目名称:Blink-1,代码行数:32,代码来源:Color.cpp

示例2: convertFromLocalizedNumber

String Locale::convertFromLocalizedNumber(const String& localized)
{
    initializeLocaleData();
    String input = localized.removeCharacters(isASCIISpace);
    if (!m_hasLocaleData || input.isEmpty())
        return input;

    bool isNegative;
    unsigned startIndex;
    unsigned endIndex;
    if (!detectSignAndGetDigitRange(input, isNegative, startIndex, endIndex))
        return input;

    StringBuilder builder;
    builder.reserveCapacity(input.length());
    if (isNegative)
        builder.append('-');
    for (unsigned i = startIndex; i < endIndex;) {
        unsigned symbolIndex = matchedDecimalSymbolIndex(input, i);
        if (symbolIndex >= DecimalSymbolsSize)
            return input;
        if (symbolIndex == DecimalSeparatorIndex)
            builder.append('.');
        else if (symbolIndex == GroupSeparatorIndex)
            return input;
        else
            builder.append(static_cast<UChar>('0' + symbolIndex));
    }
    return builder.toString();
}
开发者ID:smilusingjavascript,项目名称:blink,代码行数:30,代码来源:PlatformLocale.cpp

示例3: wholeText

String Text::wholeText() const
{
    const Text* startText = earliestLogicallyAdjacentTextNode(this);
    const Text* endText = latestLogicallyAdjacentTextNode(this);

    Node* onePastEndText = endText->nextSibling();
    unsigned resultLength = 0;
    for (const Node* n = startText; n != onePastEndText; n = n->nextSibling()) {
        if (!n->isTextNode())
            continue;
        const String& data = toText(n)->data();
        if (std::numeric_limits<unsigned>::max() - data.length() < resultLength)
            CRASH();
        resultLength += data.length();
    }
    StringBuilder result;
    result.reserveCapacity(resultLength);
    for (const Node* n = startText; n != onePastEndText; n = n->nextSibling()) {
        if (!n->isTextNode())
            continue;
        result.append(toText(n)->data());
    }
    ASSERT(result.length() == resultLength);

    return result.toString();
}
开发者ID:glenkim-dev,项目名称:blink-crosswalk,代码行数:26,代码来源:Text.cpp

示例4: addJavaScriptString

void PagePopupClient::addJavaScriptString(const String& str, SharedBuffer* data)
{
    addLiteral("\"", data);
    StringBuilder builder;
    builder.reserveCapacity(str.length());
    for (unsigned i = 0; i < str.length(); ++i) {
        if (str[i] == '\r') {
            builder.append("\\r");
        } else if (str[i] == '\n') {
            builder.append("\\n");
        } else if (str[i] == '\\' || str[i] == '"') {
            builder.append('\\');
            builder.append(str[i]);
        } else if (str[i] == '<') {
            // Need to avoid to add "</script>" because the resultant string is
            // typically embedded in <script>.
            builder.append("\\x3C");
        } else if (str[i] < 0x20 || str[i] == lineSeparator || str[i] == paragraphSeparator) {
            builder.append(String::format("\\u%04X", str[i]));
        } else {
            builder.append(str[i]);
        }
    }
    addString(builder.toString(), data);
    addLiteral("\"", data);
}
开发者ID:joone,项目名称:blink-crosswalk,代码行数:26,代码来源:PagePopupClient.cpp

示例5: extractMIMETypeFromMediaType

String extractMIMETypeFromMediaType(const String& mediaType)
{
    StringBuilder mimeType;
    unsigned length = mediaType.length();
    mimeType.reserveCapacity(length);
    for (unsigned i = 0; i < length; i++) {
        UChar c = mediaType[i];

        if (c == ';')
            break;

        // While RFC 2616 does not allow it, other browsers allow multiple values in the HTTP media
        // type header field, Content-Type. In such cases, the media type string passed here may contain
        // the multiple values separated by commas. For now, this code ignores text after the first comma,
        // which prevents it from simply failing to parse such types altogether. Later for better
        // compatibility we could consider using the first or last valid MIME type instead.
        // See https://bugs.webkit.org/show_bug.cgi?id=25352 for more discussion.
        if (c == ',')
            break;

        // FIXME: The following is not correct. RFC 2616 allows linear white space before and
        // after the MIME type, but not within the MIME type itself. And linear white space
        // includes only a few specific ASCII characters; a small subset of isSpaceOrNewline.
        // See https://bugs.webkit.org/show_bug.cgi?id=8644 for a bug tracking part of this.
        if (isSpaceOrNewline(c))
            continue;

        mimeType.append(c);
    }

    if (mimeType.length() == length)
        return mediaType;
    return mimeType.toString();
}
开发者ID:Channely,项目名称:know-your-chrome,代码行数:34,代码来源:HTTPParsers.cpp

示例6: serializedAsCSSComponentValue

String Color::serializedAsCSSComponentValue() const
{
    StringBuilder result;
    result.reserveCapacity(32);
    bool colorHasAlpha = hasAlpha();
    if (colorHasAlpha)
        result.appendLiteral("rgba(");
    else
        result.appendLiteral("rgb(");

    result.appendNumber(static_cast<unsigned char>(red()));
    result.appendLiteral(", ");

    result.appendNumber(static_cast<unsigned char>(green()));
    result.appendLiteral(", ");

    result.appendNumber(static_cast<unsigned char>(blue()));
    if (colorHasAlpha) {
        result.appendLiteral(", ");

        NumberToStringBuffer buffer;
        const char* alphaString = numberToFixedPrecisionString(alpha() / 255.0f, 6, buffer, true);
        result.append(alphaString, strlen(alphaString));
    }

    result.append(')');
    return result.toString();
}
开发者ID:335969568,项目名称:Blink-1,代码行数:28,代码来源:Color.cpp

示例7: convertFromLocalizedNumber

String ICULocale::convertFromLocalizedNumber(const String& localized)
{
    initializeDecimalFormat();
    String input = localized.stripWhiteSpace();
    if (!m_numberFormat || input.isEmpty())
        return input;

    bool isNegative;
    unsigned startIndex;
    unsigned endIndex;
    if (!detectSignAndGetDigitRange(input, isNegative, startIndex, endIndex)) {
        // Input is broken. Returning an invalid number string.
        return "*";
    }

    StringBuilder builder;
    builder.reserveCapacity(input.length());
    if (isNegative)
        builder.append("-");
    for (unsigned i = startIndex; i < endIndex;) {
        unsigned symbolIndex = matchedDecimalSymbolIndex(input, i);
        if (symbolIndex >= DecimalSymbolsSize)
            return "*";
        if (symbolIndex == DecimalSeparatorIndex)
            builder.append('.');
        else if (symbolIndex == GroupSeparatorIndex) {
            // Ignore group separators.

        } else
            builder.append(static_cast<UChar>('0' + symbolIndex));
    }
    return builder.toString();
}
开发者ID:kanongil,项目名称:webkit,代码行数:33,代码来源:ICULocale.cpp

示例8: stringValue

String stringValue(Node* node)
{
    switch (node->nodeType()) {
        case Node::ATTRIBUTE_NODE:
        case Node::PROCESSING_INSTRUCTION_NODE:
        case Node::COMMENT_NODE:
        case Node::TEXT_NODE:
        case Node::CDATA_SECTION_NODE:
        case Node::XPATH_NAMESPACE_NODE:
            return node->nodeValue();
        default:
            if (isRootDomNode(node) || node->nodeType() == Node::ELEMENT_NODE) {
                StringBuilder result;
                result.reserveCapacity(1024);

                for (Node* n = node->firstChild(); n; n = n->traverseNextNode(node)) {
                    if (n->isTextNode()) {
                        const String& nodeValue = n->nodeValue();
                        result.append(nodeValue);
                    }
                }

                return result.toString();
            }
    }
    
    return String();
}
开发者ID:sysrqb,项目名称:chromium-src,代码行数:28,代码来源:XPathUtil.cpp

示例9: toJSONString

String InspectorValue::toJSONString() const
{
    StringBuilder result;
    result.reserveCapacity(512);
    writeJSON(&result);
    return result.toString();
}
开发者ID:MYSHLIFE,项目名称:webkit,代码行数:7,代码来源:InspectorValues.cpp

示例10: getCookie

String CookieManager::getCookie(const KURL& url, CookieFilter filter) const
{
    // If the database hasn't been sync-ed at this point, force a sync load
    if (!m_syncedWithDatabase && !m_privateMode)
        m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar());

    Vector<RefPtr<ParsedCookie> > rawCookies;
    rawCookies.reserveInitialCapacity(s_maxCookieCountPerHost);

    // Retrieve cookies related to this url
    getRawCookies(rawCookies, url, filter);

    CookieLog("CookieManager - there are %d cookies in raw cookies\n", rawCookies.size());

    // Generate the cookie header string using the retrieved cookies
    StringBuilder cookieStringBuilder;
    cookieStringBuilder.reserveCapacity(512);
    size_t cookieSize = rawCookies.size();
    for (size_t i = 0; i < cookieSize; i++) {
        cookieStringBuilder.append(rawCookies[i]->toNameValuePair());
        if (i != cookieSize-1)
            cookieStringBuilder.append("; ");
    }

    CookieLog("CookieManager - cookieString is - %s\n", cookieStringBuilder.toString().utf8().data());

    return cookieStringBuilder.toString();
}
开发者ID:3163504123,项目名称:phantomjs,代码行数:28,代码来源:CookieManager.cpp

示例11: customCSSText

String CSSQuadValue::customCSSText() const {
  String top = m_top->cssText();
  String right = m_right->cssText();
  String bottom = m_bottom->cssText();
  String left = m_left->cssText();

  if (m_serializationType == TypeForSerialization::SerializeAsRect)
    return "rect(" + top + ' ' + right + ' ' + bottom + ' ' + left + ')';

  StringBuilder result;
  // reserve space for the four strings, plus three space separator characters.
  result.reserveCapacity(top.length() + right.length() + bottom.length() +
                         left.length() + 3);
  result.append(top);
  if (right != top || bottom != top || left != top) {
    result.append(' ');
    result.append(right);
    if (bottom != top || right != left) {
      result.append(' ');
      result.append(bottom);
      if (left != right) {
        result.append(' ');
        result.append(left);
      }
    }
  }
  return result.toString();
}
开发者ID:mirror,项目名称:chromium,代码行数:28,代码来源:CSSQuadValue.cpp

示例12:

TEST(StringBuilderTest, ToAtomicString)
{
    StringBuilder builder;
    builder.append("123");
    AtomicString atomicString = builder.toAtomicString();
    EXPECT_EQ(String("123"), atomicString);

    builder.reserveCapacity(256);
    EXPECT_TRUE(builder.canShrink());
    for (int i = builder.length(); i < 128; i++)
        builder.append('x');
    AtomicString atomicString1 = builder.toAtomicString();
    EXPECT_EQ(128u, atomicString1.length());
    EXPECT_EQ('x', atomicString1[127]);

    // Later change of builder should not affect the atomic string.
    for (int i = builder.length(); i < 256; i++)
        builder.append('x');
    EXPECT_EQ(128u, atomicString1.length());

    EXPECT_FALSE(builder.canShrink());
    String string = builder.toString();
    AtomicString atomicString2 = builder.toAtomicString();
    // They should share the same StringImpl.
    EXPECT_EQ(atomicString2.impl(), string.impl());
}
开发者ID:aobzhirov,项目名称:ChromiumGStreamerBackend,代码行数:26,代码来源:StringBuilderTest.cpp

示例13: process

void StyleElement::process(Element* e)
{
    if (!e || !e->inDocument())
        return;

    unsigned resultLength = 0;
    for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
        if (isValidStyleChild(c)) {
            unsigned length = c->nodeValue().length();
            if (length > std::numeric_limits<unsigned>::max() - resultLength) {
                createSheet(e, m_startLineNumber, "");
                return;
            }
            resultLength += length;
        }
    }
    StringBuilder sheetText;
    sheetText.reserveCapacity(resultLength);

    for (Node* c = e->firstChild(); c; c = c->nextSibling()) {
        if (isValidStyleChild(c)) {
            sheetText.append(c->nodeValue());
        }
    }
    ASSERT(sheetText.length() == resultLength);

    createSheet(e, m_startLineNumber, sheetText.toString());
}
开发者ID:Moondee,项目名称:Artemis,代码行数:28,代码来源:StyleElement.cpp

示例14: toPrettyJSONString

String JSONValue::toPrettyJSONString() const
{
    StringBuilder result;
    result.reserveCapacity(512);
    prettyWriteJSON(&result);
    return result.toString();
}
开发者ID:smishenk,项目名称:chromium-crosswalk,代码行数:7,代码来源:JSONValues.cpp

示例15: sourceForToken

String HTMLSourceTracker::sourceForToken(const HTMLToken& token)
{
    if (!m_cachedSourceForToken.isEmpty())
        return m_cachedSourceForToken;

    size_t length;
    if (token.type() == HTMLToken::EndOfFile) {
        // Consume the remainder of the input, omitting the null character we use to mark the end of the file.
        length = m_previousSource.length() + m_currentSource.length() - 1;
    } else {
        ASSERT(!token.startIndex());
        length = static_cast<size_t>(token.endIndex() - token.startIndex());
    }

    StringBuilder source;
    source.reserveCapacity(length);

    size_t i = 0;
    for ( ; i < length && !m_previousSource.isEmpty(); ++i) {
        source.append(m_previousSource.currentChar());
        m_previousSource.advance();
    }
    for ( ; i < length; ++i) {
        ASSERT(!m_currentSource.isEmpty());
        source.append(m_currentSource.currentChar());
        m_currentSource.advance();
    }

    m_cachedSourceForToken = source.toString();
    return m_cachedSourceForToken;
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:31,代码来源:HTMLSourceTracker.cpp


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