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


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

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


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

示例1: retrieveKeyValuePairs

static KeyValueMap retrieveKeyValuePairs(WebCore::SharedBufferChunkReader* buffer)
{
    KeyValueMap keyValuePairs;
    String line;
    String key;
    StringBuilder value;
    while (!(line = buffer->nextChunkAsUTF8StringWithLatin1Fallback()).isNull()) {
        if (line.isEmpty())
            break; // Empty line means end of key/value section.
        if (line[0] == '\t') {
            ASSERT(!key.isEmpty());
            value.append(line.substring(1));
            continue;
        }
        // New key/value, store the previous one if any.
        if (!key.isEmpty()) {
            if (keyValuePairs.find(key) != keyValuePairs.end())
                LOG_ERROR("Key duplicate found in MIME header. Key is '%s', previous value replaced.", key.ascii().data());
            keyValuePairs.add(key, value.toString().stripWhiteSpace());
            key = String();
            value.clear();
        }
        size_t semiColonIndex = line.find(':');
        if (semiColonIndex == notFound) {
            // This is not a key value pair, ignore.
            continue;
        }
        key = line.substring(0, semiColonIndex).lower().stripWhiteSpace();
        value.append(line.substring(semiColonIndex + 1));
    }
    // Store the last property if there is one.
    if (!key.isEmpty())
        keyValuePairs.set(key, value.toString().stripWhiteSpace());
    return keyValuePairs;
}
开发者ID:Channely,项目名称:know-your-chrome,代码行数:35,代码来源:MIMEHeader.cpp

示例2:

TEST_F(SecurityOriginTest, SuboriginsParsing)
{
    RuntimeEnabledFeatures::setSuboriginsEnabled(true);
    String host, realHost, suborigin;
    host = "test.com";
    EXPECT_FALSE(SecurityOrigin::deserializeSuboriginAndHost(host, suborigin, realHost));

    host = "foobar_test.com";
    EXPECT_TRUE(SecurityOrigin::deserializeSuboriginAndHost(host, suborigin, realHost));
    EXPECT_EQ("test.com", realHost);
    EXPECT_EQ("foobar", suborigin);

    RefPtr<SecurityOrigin> origin;
    StringBuilder builder;

    origin = SecurityOrigin::createFromString("https://foobar_test.com");
    origin->buildRawString(builder);
    EXPECT_EQ("https://foobar_test.com", builder.toString());

    builder.clear();
    origin = SecurityOrigin::createFromString("https://test.com");
    origin->addSuborigin("foobar");
    origin->buildRawString(builder);
    EXPECT_EQ("https://foobar_test.com", builder.toString());
}
开发者ID:howardroark2018,项目名称:chromium,代码行数:25,代码来源:SecurityOriginTest.cpp

示例3: getAndResetAccumulatedLogs

String WTFLoggingAccumulator::getAndResetAccumulatedLogs()
{
    Locker<Lock> locker(accumulatorLock);
    String result = loggingAccumulator.toString();
    loggingAccumulator.clear();
    return result;
}
开发者ID:Comcast,项目名称:WebKitForWayland,代码行数:7,代码来源:Assertions.cpp

示例4: expectEmpty

TEST(StringBuilderTest, Clear)
{
    StringBuilder builder;
    builder.append("0123456789");
    builder.clear();
    expectEmpty(builder);
}
开发者ID:sysrqb,项目名称:chromium-src,代码行数:7,代码来源:StringBuilder.cpp

示例5: flush

 void XmlContext::flush() {
     if (text.length() > 0) {
         exprs.addAtEnd(ALLOC(LiteralString, (text.str(), text_start)));
         /*
         char buf[500];
         getn(buf, text.str(), 500);
         puts(buf);
          */
         text.clear();
     }
 }
开发者ID:AdiKo,项目名称:avmplus,代码行数:11,代码来源:eval-parse-xml.cpp

示例6:

TEST_F(SecurityOriginTest, SuboriginsParsing) {
  RuntimeEnabledFeatures::setSuboriginsEnabled(true);
  String protocol, realProtocol, host, realHost, suborigin;
  protocol = "https";
  host = "test.com";
  EXPECT_FALSE(SecurityOrigin::deserializeSuboriginAndProtocolAndHost(
      protocol, host, suborigin, realProtocol, realHost));

  protocol = "https-so";
  host = "foobar.test.com";
  EXPECT_TRUE(SecurityOrigin::deserializeSuboriginAndProtocolAndHost(
      protocol, host, suborigin, realProtocol, realHost));
  EXPECT_EQ("https", realProtocol);
  EXPECT_EQ("test.com", realHost);
  EXPECT_EQ("foobar", suborigin);

  RefPtr<SecurityOrigin> origin;
  StringBuilder builder;

  origin = SecurityOrigin::createFromString("https-so://foobar.test.com");
  origin->buildRawString(builder, true);
  EXPECT_EQ("https-so://foobar.test.com", builder.toString());
  EXPECT_EQ("https-so://foobar.test.com", origin->toString());
  builder.clear();
  origin->buildRawString(builder, false);
  EXPECT_EQ("https://test.com", builder.toString());
  EXPECT_EQ("https://test.com", origin->toPhysicalOriginString());

  Suborigin suboriginObj;
  suboriginObj.setName("foobar");
  builder.clear();
  origin = SecurityOrigin::createFromString("https://test.com");
  origin->addSuborigin(suboriginObj);
  origin->buildRawString(builder, true);
  EXPECT_EQ("https-so://foobar.test.com", builder.toString());
  EXPECT_EQ("https-so://foobar.test.com", origin->toString());
  builder.clear();
  origin->buildRawString(builder, false);
  EXPECT_EQ("https://test.com", builder.toString());
  EXPECT_EQ("https://test.com", origin->toPhysicalOriginString());
}
开发者ID:ollie314,项目名称:chromium,代码行数:41,代码来源:SecurityOriginTest.cpp

示例7: consumeNamedEntity

 static bool consumeNamedEntity(SegmentedString& source, StringBuilder& decodedEntity, bool& notEnoughCharacters, UChar additionalAllowedCharacter, UChar& cc)
 {
     StringBuilder consumedCharacters;
     HTMLEntitySearch entitySearch;
     while (!source.isEmpty()) {
         cc = source.currentChar();
         entitySearch.advance(cc);
         if (!entitySearch.isEntityPrefix())
             break;
         consumedCharacters.append(cc);
         source.advance();
     }
     notEnoughCharacters = source.isEmpty();
     if (notEnoughCharacters) {
         // We can't an entity because there might be a longer entity
         // that we could match if we had more data.
         unconsumeCharacters(source, consumedCharacters);
         return false;
     }
     if (!entitySearch.mostRecentMatch()) {
         unconsumeCharacters(source, consumedCharacters);
         return false;
     }
     if (entitySearch.mostRecentMatch()->length != entitySearch.currentLength()) {
         // We've consumed too many characters. We need to walk the
         // source back to the point at which we had consumed an
         // actual entity.
         unconsumeCharacters(source, consumedCharacters);
         consumedCharacters.clear();
         const int length = entitySearch.mostRecentMatch()->length;
         const LChar* reference = entitySearch.mostRecentMatch()->entity;
         for (int i = 0; i < length; ++i) {
             cc = source.currentChar();
             ASSERT_UNUSED(reference, cc == *reference++);
             consumedCharacters.append(cc);
             source.advance();
             ASSERT(!source.isEmpty());
         }
         cc = source.currentChar();
     }
     if (entitySearch.mostRecentMatch()->lastCharacter() == ';'
         || !additionalAllowedCharacter
         || !(isASCIIAlphanumeric(cc) || cc == '=')) {
         decodedEntity.append(entitySearch.mostRecentMatch()->firstValue);
         if (entitySearch.mostRecentMatch()->secondValue)
             decodedEntity.append(entitySearch.mostRecentMatch()->secondValue);
         return true;
     }
     unconsumeCharacters(source, consumedCharacters);
     return false;
 }
开发者ID:caiolima,项目名称:webkit,代码行数:51,代码来源:HTMLEntityParser.cpp

示例8: generateUniquePrefix

void MarkupAccumulator::generateUniquePrefix(QualifiedName& prefixedName, const Namespaces& namespaces)
{
    // http://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#normalizeDocumentAlgo
    // Find a prefix following the pattern "NS" + index (starting at 1) and make sure this
    // prefix is not declared in the current scope.
    StringBuilder builder;
    do {
        builder.clear();
        builder.append("NS");
        builder.appendNumber(++m_prefixLevel);
        const AtomicString& name = builder.toAtomicString();
        if (!namespaces.get(name.impl())) {
            prefixedName.setPrefix(name);
            return;
        }
    } while (true);
}
开发者ID:Happy-Ferret,项目名称:webkit.js,代码行数:17,代码来源:MarkupAccumulator.cpp

示例9:

TEST(StringBuilderTest, ToAtomicStringOnEmpty)
{
    { // Default constructed.
        StringBuilder builder;
        AtomicString atomicString = builder.toAtomicString();
        EXPECT_EQ(emptyAtom, atomicString);
    }
    { // With capacity.
        StringBuilder builder;
        builder.reserveCapacity(64);
        AtomicString atomicString = builder.toAtomicString();
        EXPECT_EQ(emptyAtom, atomicString);
    }
    { // AtomicString constructed from a null string.
        StringBuilder builder;
        builder.append(String());
        AtomicString atomicString = builder.toAtomicString();
        EXPECT_EQ(emptyAtom, atomicString);
    }
    { // AtomicString constructed from an empty string.
        StringBuilder builder;
        builder.append(emptyString());
        AtomicString atomicString = builder.toAtomicString();
        EXPECT_EQ(emptyAtom, atomicString);
    }
    { // AtomicString constructed from an empty StringBuilder.
        StringBuilder builder;
        StringBuilder emptyBuilder;
        builder.append(emptyBuilder);
        AtomicString atomicString = builder.toAtomicString();
        EXPECT_EQ(emptyAtom, atomicString);
    }
    { // AtomicString constructed from an empty char* string.
        StringBuilder builder;
        builder.append("", 0);
        AtomicString atomicString = builder.toAtomicString();
        EXPECT_EQ(emptyAtom, atomicString);
    }
    { // Cleared StringBuilder.
        StringBuilder builder;
        builder.appendLiteral("WebKit");
        builder.clear();
        AtomicString atomicString = builder.toAtomicString();
        EXPECT_EQ(emptyAtom, atomicString);
    }
}
开发者ID:aobzhirov,项目名称:ChromiumGStreamerBackend,代码行数:46,代码来源:StringBuilderTest.cpp

示例10:

/**
* Destructor
*/
STM32F7USB::~STM32F7USB() {
  _accumulator.clear();
}
开发者ID:Manuvr,项目名称:Digitabulum-Firmware,代码行数:6,代码来源:STM32F7USB.cpp

示例11: ProcessDiskInfo

void ProcessDiskInfo(wstring apiKey, wstring envKey, SOCKET socketHandle, sockaddr_in remoteServAddr, int interval)
{
    StringBuilder sb;

    int sleepTime = interval * 1000;
    wchar_t driveLetter[_MAX_PATH + 1];
    HRESULT hr;
    ULARGE_INTEGER freeBytesAvailable;
    ULARGE_INTEGER totalNumberOfBytes;
    ULARGE_INTEGER totalNumberOfFreeBytes;
    
    while (true)
    {
        if (g_servicePaused == FALSE)
        {
            sb.clear();

            sb.push_back(L"{");

            sb.push_back(L"\"" + StorageInfo::Members::disk + L"\":");
            sb.push_back(L"[");

            DWORD dwNeedLength = ::GetLogicalDriveStrings(0, NULL);

            wchar_t *pWchBuf = nullptr;
            wchar_t *pHead = nullptr;

            do
            {
                if (dwNeedLength != 0)
                {
                    pWchBuf = new wchar_t[dwNeedLength + 1];
                    if (pWchBuf == nullptr)
                    {
                        break;
                    }

                    pHead = pWchBuf;

                    DWORD dwResult = ::GetLogicalDriveStrings(dwNeedLength, pWchBuf);

                    while (dwResult > 0)
                    {
                        hr = StringCchPrintf(driveLetter, _MAX_PATH, L"%s", pWchBuf);
                        if (FAILED(hr) == TRUE)
                        {
                            break;
                        }

                        int length = wcslen(driveLetter) + 1;
                        if (length < 2)
                        {
                            break;
                        }

                        dwResult -= length;
                        pWchBuf += length;

                        if (::GetDiskFreeSpaceEx(driveLetter, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes) == FALSE)
                        {
                            break;
                        }

                        driveLetter[1] = '\0';

                        sb.push_back(L"{ \"" + DiskInfo::Members::name + L"\": \"");
                        sb.push_back(driveLetter);
                        sb.push_back(L"\", ");

                        sb.push_back(L"\"" + DiskInfo::Members::size + L"\": ");
                        sb.push_back((__int64)totalNumberOfBytes.QuadPart);
                        sb.push_back(L", ");

                        sb.push_back(L"\"" + DiskInfo::Members::current + L"\": ");
                        sb.push_back((__int64)(totalNumberOfBytes.QuadPart - totalNumberOfFreeBytes.QuadPart));
                        sb.push_back(L"}");

                        if (dwResult > 0)
                        {
                            sb.push_back(L",");
                        }
                    }
                }
            } while (false);

            if (pHead != nullptr)
            {
                delete[] pHead;
            }

            sb.push_back(L"],");

            sb.push_back(L"\"" + PacketBase::Members::groupKey + L"\":");
            sb.push_back(L"\"");
            sb.push_back(apiKey);
            sb.push_back(L"\",");

            sb.push_back(L"\"" + PacketBase::Members::machineId + L"\":");
            sb.push_back(L"\"");
            sb.push_back(envKey);
//.........这里部分代码省略.........
开发者ID:stjeong,项目名称:Straw,代码行数:101,代码来源:InfoCollector.cpp

示例12: ProcessCpuMemInfo

void ProcessCpuMemInfo(wstring apiKey, wstring envKey, SOCKET socketHandle, sockaddr_in remoteServAddr, int interval)
{
    StringBuilder sb;
    int sleepTime = interval * 1000;

    while (true)
    {
        if (g_servicePaused == FALSE)
        {
            sb.clear();

            sb.push_back(L"{");
            {
                sb.push_back(L"\"" + SystemInfo::Members::cpuUsage + L"\":");
                sb.push_back(L"{");
                {
                    float totalUsage = 0.0f;
                    sb.push_back(L"\"" + CpuInfo::Members::unit + L"\":[");
                    if (RetrieveCpuInfo(sb, &totalUsage) == false)
                    {
                        Sleep(1000);
                        continue;
                    }

                    sb.push_back(L"]");

                    wchar_t buf[40];
                    StringCchPrintf(buf, 40, L", \"%s\": %.2f", CpuInfo::Members::total.c_str(), totalUsage / 100);
                    sb.push_back(buf);
                }
                sb.push_back(L"},");

                __int64 maxMemory;
                __int64 currentUsage;
                GetMemoryInfo(&maxMemory, &currentUsage);

                sb.push_back(L"\"" + SystemInfo::Members::memoryUsage + L"\":");
                {
                    sb.push_back(L"{\"" + MemoryInfo::Members::max + L"\":");
                    sb.push_back(maxMemory);

                    sb.push_back(L", \"" + MemoryInfo::Members::current + L"\":");
                    sb.push_back(currentUsage);
                    sb.push_back(L"},");
                }

                sb.push_back(L"\"" + PacketBase::Members::groupKey + L"\":");
                sb.push_back(L"\"");
                sb.push_back(apiKey);
                sb.push_back(L"\",");

                sb.push_back(L"\"" + PacketBase::Members::machineId + L"\":");
                sb.push_back(L"\"");
                sb.push_back(envKey);
                sb.push_back(L"\"");
            }

            sb.push_back(L"}");

            SendToServer(socketHandle, remoteServAddr, sb);

            if (g_isConsoleApp == TRUE)
            {
                printf(".");
            }
        }

        if (::WaitForSingleObject(g_killServiceEvent, sleepTime) == WAIT_TIMEOUT)
        {
            continue;
        }

#if defined(_DEBUG)
        ::OutputDebugString(L"ProcessCpuMemInfo-thread exited.");
#endif

        break;
    }
}
开发者ID:stjeong,项目名称:Straw,代码行数:79,代码来源:InfoCollector.cpp

示例13: resetAccumulatedLogs

void WTFLoggingAccumulator::resetAccumulatedLogs()
{
    Locker<Lock> locker(accumulatorLock);
    loggingAccumulator.clear();
}
开发者ID:Comcast,项目名称:WebKitForWayland,代码行数:5,代码来源:Assertions.cpp

示例14: parse

bool DateTimeFormat::parse(const String& source, TokenHandler& tokenHandler)
{
    enum State {
        StateInQuote,
        StateInQuoteQuote,
        StateLiteral,
        StateQuote,
        StateSymbol,
    } state = StateLiteral;

    FieldType fieldType = FieldTypeLiteral;
    StringBuilder literalBuffer;
    int fieldCounter = 0;

    for (unsigned index = 0; index < source.length(); ++index) {
        const UChar ch = source[index];
        switch (state) {
        case StateInQuote:
            if (ch == '\'') {
                state = StateInQuoteQuote;
                break;
            }

            literalBuffer.append(ch);
            break;

        case StateInQuoteQuote:
            if (ch == '\'') {
                literalBuffer.append('\'');
                state = StateInQuote;
                break;
            }

            fieldType = mapCharacterToFieldType(ch);
            if (fieldType == FieldTypeInvalid)
                return false;

            if (fieldType == FieldTypeLiteral) {
                literalBuffer.append(ch);
                state = StateLiteral;
                break;
            }

            if (literalBuffer.length()) {
                tokenHandler.visitLiteral(literalBuffer.toString());
                literalBuffer.clear();
            }

            fieldCounter = 1;
            state = StateSymbol;
            break;

        case StateLiteral:
            if (ch == '\'') {
                state = StateQuote;
                break;
            }

            fieldType = mapCharacterToFieldType(ch);
            if (fieldType == FieldTypeInvalid)
                return false;

            if (fieldType == FieldTypeLiteral) {
                literalBuffer.append(ch);
                break;
            }

            if (literalBuffer.length()) {
                tokenHandler.visitLiteral(literalBuffer.toString());
                literalBuffer.clear();
            }

            fieldCounter = 1;
            state = StateSymbol;
            break;

        case StateQuote:
            literalBuffer.append(ch);
            state = ch == '\'' ? StateLiteral : StateInQuote;
            break;

        case StateSymbol: {
            ASSERT(fieldType != FieldTypeInvalid);
            ASSERT(fieldType != FieldTypeLiteral);
            ASSERT(literalBuffer.isEmpty());

            FieldType fieldType2 = mapCharacterToFieldType(ch);
            if (fieldType2 == FieldTypeInvalid)
                return false;

            if (fieldType == fieldType2) {
                ++fieldCounter;
                break;
            }

            tokenHandler.visitField(fieldType, fieldCounter);

            if (fieldType2 == FieldTypeLiteral) {
                if (ch == '\'') {
                    state = StateQuote;
//.........这里部分代码省略.........
开发者ID:rmacnak-google,项目名称:engine,代码行数:101,代码来源:DateTimeFormat.cpp

示例15: pageSerializer

PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLData(Page* page, bool useBinaryEncoding)
{
    Vector<PageSerializer::Resource> resources;
    PageSerializer pageSerializer(&resources);
    pageSerializer.serialize(page);

    String boundary = generateRandomBoundary();
    String endOfResourceBoundary = makeString("--", boundary, "\r\n");

    tm localTM;
    getCurrentLocalTime(&localTM);
    String dateString = makeRFC2822DateString(localTM.tm_wday, localTM.tm_mday, localTM.tm_mon, 1900 + localTM.tm_year, localTM.tm_hour, localTM.tm_min, localTM.tm_sec, calculateUTCOffset() / (1000 * 60));

    StringBuilder stringBuilder;
    stringBuilder.append("From: <Saved by WebKit>\r\n");
    stringBuilder.append("Subject: ");
    // We replace non ASCII characters with '?' characters to match IE's behavior.
    stringBuilder.append(replaceNonPrintableCharacters(page->mainFrame()->document()->title()));
    stringBuilder.append("\r\nDate: ");
    stringBuilder.append(dateString);
    stringBuilder.append("\r\nMIME-Version: 1.0\r\n");
    stringBuilder.append("Content-Type: multipart/related;\r\n");
    stringBuilder.append("\ttype=\"");
    stringBuilder.append(page->mainFrame()->document()->suggestedMIMEType());
    stringBuilder.append("\";\r\n");
    stringBuilder.append("\tboundary=\"");
    stringBuilder.append(boundary);
    stringBuilder.append("\"\r\n\r\n");

    // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ?? (we still only have put ASCII characters in it).
    ASSERT(stringBuilder.toString().containsOnlyASCII());
    CString asciiString = stringBuilder.toString().utf8();
    RefPtr<SharedBuffer> mhtmlData = SharedBuffer::create();
    mhtmlData->append(asciiString.data(), asciiString.length());

    for (size_t i = 0; i < resources.size(); ++i) {
        const PageSerializer::Resource& resource = resources[i];

        stringBuilder.clear();
        stringBuilder.append(endOfResourceBoundary);
        stringBuilder.append("Content-Type: ");
        stringBuilder.append(resource.mimeType);

        const char* contentEncoding = 0;
        if (useBinaryEncoding)
            contentEncoding = binary;
        else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType))
            contentEncoding = quotedPrintable;
        else
            contentEncoding = base64;

        stringBuilder.append("\r\nContent-Transfer-Encoding: ");
        stringBuilder.append(contentEncoding);
        stringBuilder.append("\r\nContent-Location: ");
        stringBuilder.append(resource.url);
        stringBuilder.append("\r\n\r\n");

        asciiString = stringBuilder.toString().utf8();
        mhtmlData->append(asciiString.data(), asciiString.length());

        if (!strcmp(contentEncoding, binary)) {
            const char* data;
            size_t position = 0;
            while (size_t length = resource.data->getSomeData(data, position)) {
                mhtmlData->append(data, length);
                position += length;
            }
        } else {
            // FIXME: ideally we would encode the content as a stream without having to fetch it all.
            const char* data = resource.data->data();
            size_t dataLength = resource.data->size();
            Vector<char> encodedData;
            if (!strcmp(contentEncoding, quotedPrintable)) {
                quotedPrintableEncode(data, dataLength, encodedData);
                mhtmlData->append(encodedData.data(), encodedData.size());
                mhtmlData->append("\r\n", 2);
            } else {
                ASSERT(!strcmp(contentEncoding, base64));
                // We are not specifying insertLFs = true below as it would cut the lines with LFs and MHTML requires CRLFs.
                base64Encode(data, dataLength, encodedData);
                const size_t maximumLineLength = 76;
                size_t index = 0;
                size_t encodedDataLength = encodedData.size();
                do {
                    size_t lineLength = std::min(encodedDataLength - index, maximumLineLength);
                    mhtmlData->append(encodedData.data() + index, lineLength);
                    mhtmlData->append("\r\n", 2);
                    index += maximumLineLength;
                } while (index < encodedDataLength);
            }
        }
    }

    asciiString = makeString("--", boundary, "--\r\n").utf8();
    mhtmlData->append(asciiString.data(), asciiString.length());

    return mhtmlData.release();
}
开发者ID:Moondee,项目名称:Artemis,代码行数:98,代码来源:MHTMLArchive.cpp


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