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


C++ String::stripWhiteSpace方法代码示例

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


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

示例1: parseIntegrityAttribute

SubresourceIntegrity::IntegrityParseResult SubresourceIntegrity::parseIntegrityAttribute(const WTF::String& attribute, IntegrityMetadataSet& metadataSet, Document* document)
{
    Vector<UChar> characters;
    attribute.stripWhiteSpace().appendTo(characters);
    const UChar* position = characters.data();
    const UChar* end = characters.end();
    const UChar* currentIntegrityEnd;

    metadataSet.clear();
    bool error = false;

    // The integrity attribute takes the form:
    //    *WSP hash-with-options *( 1*WSP hash-with-options ) *WSP / *WSP
    // To parse this, break on whitespace, parsing each algorithm/digest/option
    // in order.
    while (position < end) {
        WTF::String digest;
        HashAlgorithm algorithm;

        skipWhile<UChar, isASCIISpace>(position, end);
        currentIntegrityEnd = position;
        skipUntil<UChar, isASCIISpace>(currentIntegrityEnd, end);

        // Algorithm parsing errors are non-fatal (the subresource should
        // still be loaded) because strong hash algorithms should be used
        // without fear of breaking older user agents that don't support
        // them.
        AlgorithmParseResult parseResult = parseAlgorithm(position, currentIntegrityEnd, algorithm);
        if (parseResult == AlgorithmUnknown) {
            // Unknown hash algorithms are treated as if they're not present,
            // and thus are not marked as an error, they're just skipped.
            skipUntil<UChar, isASCIISpace>(position, end);
            if (document) {
                logErrorToConsole("Error parsing 'integrity' attribute ('" + attribute + "'). The specified hash algorithm must be one of 'sha256', 'sha384', or 'sha512'.", *document);
                UseCounter::count(*document, UseCounter::SRIElementWithUnparsableIntegrityAttribute);
            }
            continue;
        }

        if (parseResult == AlgorithmUnparsable) {
            error = true;
            skipUntil<UChar, isASCIISpace>(position, end);
            if (document) {
                logErrorToConsole("Error parsing 'integrity' attribute ('" + attribute + "'). The hash algorithm must be one of 'sha256', 'sha384', or 'sha512', followed by a '-' character.", *document);
                UseCounter::count(*document, UseCounter::SRIElementWithUnparsableIntegrityAttribute);
            }
            continue;
        }

        ASSERT(parseResult == AlgorithmValid);

        if (!parseDigest(position, currentIntegrityEnd, digest)) {
            error = true;
            skipUntil<UChar, isASCIISpace>(position, end);
            if (document) {
                logErrorToConsole("Error parsing 'integrity' attribute ('" + attribute + "'). The digest must be a valid, base64-encoded value.", *document);
                UseCounter::count(*document, UseCounter::SRIElementWithUnparsableIntegrityAttribute);
            }
            continue;
        }

        // The spec defines a space in the syntax for options, separated by a
        // '?' character followed by unbounded VCHARs, but no actual options
        // have been defined yet. Thus, for forward compatibility, ignore any
        // options specified.
        if (skipExactly<UChar>(position, end, '?')) {
            const UChar* begin = position;
            skipWhile<UChar, isValueCharacter>(position, end);
            if (begin != position && document)
                logErrorToConsole("Ignoring unrecogized 'integrity' attribute option '" + String(begin, position - begin) + "'.", *document);
        }

        IntegrityMetadata integrityMetadata(digest, algorithm);
        metadataSet.add(integrityMetadata.toPair());
    }

    if (metadataSet.size() == 0 && error)
        return IntegrityParseNoValidResult;

    return IntegrityParseValidResult;
}
开发者ID:endlessm,项目名称:chromium-browser,代码行数:81,代码来源:SubresourceIntegrity.cpp


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