本文整理汇总了C++中StringBuilder::length方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuilder::length方法的具体用法?C++ StringBuilder::length怎么用?C++ StringBuilder::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2:
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());
}
示例3: isValid
public boolean isValid(String s) {
StringBuilder sb = new StringBuilder();
boolean valid = true;
for (int i = 0; valid && i < s.length(); i++) {
int lastIdx = sb.length() - 1;
char c = s.charAt(i);
switch (c) {
case '{':
case '(':
case '[':
sb.append(c);
break;
case '}':
case ')':
case ']':
char lchar = (c == ']' ? '[' : (c == ')' ? '(' : '{'));
if (lastIdx >= 0 && sb.charAt(lastIdx) == lchar)
sb.setLength(lastIdx);
else
valid = false;
break;
}
}
return valid && sb.length() == 0;
}
示例4: formatForDebugger
void Element::formatForDebugger(char* buffer, unsigned length) const
{
StringBuilder result;
String s;
result.append(nodeName());
s = getIdAttribute();
if (s.length() > 0) {
if (result.length() > 0)
result.appendLiteral("; ");
result.appendLiteral("id=");
result.append(s);
}
s = getAttribute(HTMLNames::classAttr);
if (s.length() > 0) {
if (result.length() > 0)
result.appendLiteral("; ");
result.appendLiteral("class=");
result.append(s);
}
strncpy(buffer, result.toString().utf8().data(), length - 1);
}
示例5: findBreakIndexBetween
// This is only needed for TextDocuments where we might have text nodes
// approaching the default length limit (~64k) and we don't want to
// break a text node in the middle of a combining character.
static unsigned findBreakIndexBetween(const StringBuilder& string, unsigned currentPosition, unsigned proposedBreakIndex)
{
ASSERT(currentPosition < proposedBreakIndex);
ASSERT(proposedBreakIndex <= string.length());
// The end of the string is always a valid break.
if (proposedBreakIndex == string.length())
return proposedBreakIndex;
// Latin-1 does not have breakable boundaries. If we ever moved to a differnet 8-bit encoding this could be wrong.
if (string.is8Bit())
return proposedBreakIndex;
const UChar* breakSearchCharacters = string.characters16() + currentPosition;
// We need at least two characters look-ahead to account for UTF-16 surrogates, but can't search off the end of the buffer!
unsigned breakSearchLength = std::min(proposedBreakIndex - currentPosition + 2, string.length() - currentPosition);
NonSharedCharacterBreakIterator it(breakSearchCharacters, breakSearchLength);
if (it.isBreak(proposedBreakIndex - currentPosition))
return proposedBreakIndex;
int adjustedBreakIndexInSubstring = it.preceding(proposedBreakIndex - currentPosition);
if (adjustedBreakIndexInSubstring > 0)
return currentPosition + adjustedBreakIndexInSubstring;
// We failed to find a breakable point, let the caller figure out what to do.
return 0;
}
示例6: frameContentAsPlainText
static void frameContentAsPlainText(size_t maxChars, LocalFrame* frame, StringBuilder& output)
{
Document* document = frame->document();
if (!document)
return;
if (!frame->view())
return;
// Select the document body.
RefPtr<Range> range(document->createRange());
TrackExceptionState exceptionState;
range->selectNodeContents(document, exceptionState);
if (!exceptionState.had_exception()) {
// The text iterator will walk nodes giving us text. This is similar to
// the plainText() function in core/editing/TextIterator.h, but we implement the maximum
// size and also copy the results directly into a wstring, avoiding the
// string conversion.
for (TextIterator it(range.get()); !it.atEnd(); it.advance()) {
it.appendTextToStringBuilder(output, 0, maxChars - output.length());
if (output.length() >= maxChars)
return; // Filled up the buffer.
}
}
}
示例7: frameContentAsPlainText
static void frameContentAsPlainText(size_t maxChars, LocalFrame* frame, StringBuilder& output)
{
Document* document = frame->document();
if (!document)
return;
if (!frame->view())
return;
// Select the document body.
if (document->body()) {
const EphemeralRange range = EphemeralRange::rangeOfContents(*document->body());
// The text iterator will walk nodes giving us text. This is similar to
// the plainText() function in core/editing/TextIterator.h, but we implement the maximum
// size and also copy the results directly into a wstring, avoiding the
// string conversion.
for (TextIterator it(range.startPosition(), range.endPosition()); !it.atEnd(); it.advance()) {
it.text().appendTextToStringBuilder(output, 0, maxChars - output.length());
if (output.length() >= maxChars)
return; // Filled up the buffer.
}
}
// The separator between frames when the frames are converted to plain text.
const LChar frameSeparator[] = { '\n', '\n' };
const size_t frameSeparatorLength = WTF_ARRAY_LENGTH(frameSeparator);
// Recursively walk the children.
const FrameTree& frameTree = frame->tree();
for (Frame* curChild = frameTree.firstChild(); curChild; curChild = curChild->tree().nextSibling()) {
if (!curChild->isLocalFrame())
continue;
LocalFrame* curLocalChild = toLocalFrame(curChild);
// Ignore the text of non-visible frames.
LayoutView* contentLayoutObject = curLocalChild->contentLayoutObject();
LayoutPart* ownerLayoutObject = curLocalChild->ownerLayoutObject();
if (!contentLayoutObject || !contentLayoutObject->size().width() || !contentLayoutObject->size().height()
|| (contentLayoutObject->location().x() + contentLayoutObject->size().width() <= 0) || (contentLayoutObject->location().y() + contentLayoutObject->size().height() <= 0)
|| (ownerLayoutObject && ownerLayoutObject->style() && ownerLayoutObject->style()->visibility() != VISIBLE)) {
continue;
}
// Make sure the frame separator won't fill up the buffer, and give up if
// it will. The danger is if the separator will make the buffer longer than
// maxChars. This will cause the computation above:
// maxChars - output->size()
// to be a negative number which will crash when the subframe is added.
if (output.length() >= maxChars - frameSeparatorLength)
return;
output.append(frameSeparator, frameSeparatorLength);
frameContentAsPlainText(maxChars, curLocalChild, output);
if (output.length() >= maxChars)
return; // Filled up the buffer.
}
}
示例8: toString
public String toString() {
StringBuilder result = new StringBuilder(8 * getDegree());
for (int degree = getDegree(); degree >= 0; degree--) {
int coefficient = getCoefficient(degree);
if (coefficient != 0) {
if (coefficient < 0) {
result.append(" - ");
coefficient = -coefficient;
} else {
if (result.length() > 0) {
result.append(" + ");
}
}
if (degree == 0 || coefficient != 1) {
result.append(coefficient);
}
if (degree != 0) {
if (degree == 1) {
result.append('x');
} else {
result.append("x^");
result.append(degree);
}
}
}
}
return result.toString();
}
示例9: 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();
}
示例10: generateHTMLContent
String generateHTMLContent(unsigned contentLength)
{
String baseString("abcdefghijklmnopqrstuvwxyz0123457890");
unsigned baseLength = baseString.length();
StringBuilder builder;
builder.append("<html><body>");
if (contentLength <= baseLength)
builder.append(baseString, 0, contentLength);
else {
unsigned currentLength = 0;
while (currentLength < contentLength) {
if ((currentLength + baseLength) <= contentLength)
builder.append(baseString);
else
builder.append(baseString, 0, contentLength - currentLength);
// Account for the 12 characters of the '<html><body>' prefix.
currentLength = builder.length() - 12;
}
}
builder.append("</body></html>");
return builder.toString();
}
示例11: 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);
}
示例12: toString
const String WebMediaConstraintsPrivate::toString() const
{
StringBuilder builder;
if (!isEmpty()) {
builder.append('{');
builder.append(basic().toString());
if (!advanced().isEmpty()) {
if (builder.length() > 1)
builder.appendLiteral(", ");
builder.appendLiteral("advanced: [");
bool first = true;
for (const auto& constraintSet : advanced()) {
if (!first)
builder.appendLiteral(", ");
builder.append('{');
builder.append(constraintSet.toString());
builder.append('}');
first = false;
}
builder.append(']');
}
builder.append('}');
}
return builder.toString();
}
示例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: appendText
void StyledMarkupAccumulator::appendText(StringBuilder& out, Text* text)
{
const bool parentIsTextarea = text->parentElement() && text->parentElement()->tagQName() == textareaTag;
const bool wrappingSpan = shouldApplyWrappingStyle(text) && !parentIsTextarea;
if (wrappingSpan) {
RefPtr<EditingStyle> wrappingStyle = m_wrappingStyle->copy();
// FIXME: <rdar://problem/5371536> Style rules that match pasted content can change it's appearance
// Make sure spans are inline style in paste side e.g. span { display: block }.
wrappingStyle->forceInline();
// FIXME: Should this be included in forceInline?
wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone);
StringBuilder openTag;
appendStyleNodeOpenTag(openTag, wrappingStyle->style(), text->document());
out.append(openTag.characters(), openTag.length());
}
if (!shouldAnnotate() || parentIsTextarea)
MarkupAccumulator::appendText(out, text);
else {
const bool useRenderedText = !enclosingNodeWithTag(firstPositionInNode(text), selectTag);
String content = useRenderedText ? renderedText(text, m_range) : stringValueForRange(text, m_range);
StringBuilder buffer;
appendCharactersReplacingEntities(buffer, content.characters(), content.length(), EntityMaskInPCDATA);
out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text));
}
if (wrappingSpan)
out.append(styleNodeCloseTag());
}
示例15: read
std::string ParagraphStream::read() throw(IOException)
{
StringBuilder *paragraph = new StringBuilder();
while (true)
{
std::string line = samples->read();
// The last paragraph in the input might not
// be terminated well with a new line at the end.
if (line == "" || line == "")
{
if (paragraph->length() > 0)
{
//JAVA TO C++ CONVERTER TODO TASK: There is no native C++ equivalent to 'toString':
return paragraph->toString();
}
}
else
{
paragraph->append(line)->append('\n');
}
if (line == "")
return 0;
}
}