本文整理汇总了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();
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例9: toJSONString
String InspectorValue::toJSONString() const
{
StringBuilder result;
result.reserveCapacity(512);
writeJSON(&result);
return result.toString();
}
示例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();
}
示例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();
}
示例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());
}
示例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());
}
示例14: toPrettyJSONString
String JSONValue::toPrettyJSONString() const
{
StringBuilder result;
result.reserveCapacity(512);
prettyWriteJSON(&result);
return result.toString();
}
示例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;
}