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


C++ StringView类代码示例

本文整理汇总了C++中StringView的典型用法代码示例。如果您正苦于以下问题:C++ StringView类的具体用法?C++ StringView怎么用?C++ StringView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: findGrammaticalErrors

static void findGrammaticalErrors(TextCheckerClient& client, StringView text, Vector<TextCheckingResult>& results)
{
    for (unsigned checkLocation = 0; checkLocation < text.length(); ) {
        int badGrammarLocation = -1;
        int badGrammarLength = 0;
        Vector<GrammarDetail> badGrammarDetails;
        client.checkGrammarOfString(text.substring(checkLocation), badGrammarDetails, &badGrammarLocation, &badGrammarLength);
        if (!badGrammarLength)
            break;

        ASSERT(badGrammarLocation >= 0);
        ASSERT(static_cast<unsigned>(badGrammarLocation) <= text.length() - checkLocation);
        ASSERT(badGrammarLength > 0);
        ASSERT(static_cast<unsigned>(badGrammarLength) <= text.length() - checkLocation - badGrammarLocation);

        TextCheckingResult badGrammar;
        badGrammar.type = TextCheckingTypeGrammar;
        badGrammar.location = checkLocation + badGrammarLocation;
        badGrammar.length = badGrammarLength;
        badGrammar.details = std::move(badGrammarDetails);
        results.append(badGrammar);

        checkLocation += badGrammarLocation + badGrammarLength;
    }
}
开发者ID:boska,项目名称:webkit,代码行数:25,代码来源:TextCheckingHelper.cpp

示例2: checkTextOfParagraph

void checkTextOfParagraph(TextCheckerClient& client, StringView text, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
{
#if USE(UNIFIED_TEXT_CHECKING)
    results = client.checkTextOfParagraph(text, checkingTypes);
#else
    Vector<TextCheckingResult> mispellings;
    if (checkingTypes & TextCheckingTypeSpelling)
        findMisspellings(client, text, mispellings);

#if USE(GRAMMAR_CHECKING)
    // Look for grammatical errors that occur before the first misspelling.
    Vector<TextCheckingResult> grammaticalErrors;
    if (checkingTypes & TextCheckingTypeGrammar) {
        unsigned grammarCheckLength = text.length();
        for (auto& mispelling : mispellings)
            grammarCheckLength = std::min<unsigned>(grammarCheckLength, mispelling.location);
        findGrammaticalErrors(client, text.substring(0, grammarCheckLength), grammaticalErrors);
    }

    results = std::move(grammaticalErrors);
#endif

    if (results.isEmpty())
        results = std::move(mispellings);
    else
        results.appendVector(mispellings);
#endif // USE(UNIFIED_TEXT_CHECKING)
}
开发者ID:boska,项目名称:webkit,代码行数:28,代码来源:TextCheckingHelper.cpp

示例3: INI_T

void Settings::remove(const StringView& _name) const
{
	ini_t* ini = INI_T(m_ini);

	FilePath uri(_name);
	const StringView  path     = strTrim(uri.getPath(), "/");
	const StringView& fileName = uri.getFileName();

	int32_t section = INI_GLOBAL_SECTION;

	if (!path.isEmpty() )
	{
		section = ini_find_section(ini, path.getPtr(), path.getLength() );
		if (INI_NOT_FOUND == section)
		{
			section = INI_GLOBAL_SECTION;
		}
	}

	int32_t property = ini_find_property(ini, section, fileName.getPtr(), fileName.getLength() );
	if (INI_NOT_FOUND == property)
	{
		return;
	}

	ini_property_remove(ini, section, property);

	if (INI_GLOBAL_SECTION != section
	&&  0 == ini_property_count(ini, section) )
	{
		ini_section_remove(ini, section);
	}
}
开发者ID:Dagarman,项目名称:mame,代码行数:33,代码来源:settings.cpp

示例4: StringToUTF32

		std::u32string StringToUTF32(const StringView str)
		{
			if (str.empty())
			{
				return std::u32string();
			}

			const wchar* begin = &str[0];
			const wchar* end = begin + str.length();

			if (const auto length = detail::CountCodePoints(begin, end))
			{
				std::u32string result(length.value(), L'\0');

				while (begin != end)
				{
					const auto ch = *begin++;

					if (!IsUTF16Surrogate(ch))
					{
						result.push_back(ch);
					}
					else
					{
						result.push_back(SurrogateToUTF32(ch, *begin++));
					}
				}

				return result;
			}
			else
			{
				return std::u32string();
			}
		}
开发者ID:raykudo,项目名称:OpenSiv3D,代码行数:35,代码来源:SivCharacterSet.cpp

示例5: processFeaturesString

void processFeaturesString(StringView features, std::function<void(StringView type, StringView value)> callback)
{
    unsigned length = features.length();
    for (unsigned i = 0; i < length; ) {
        // skip to first non-separator
        while (i < length && isSeparator(features[i]))
            ++i;
        unsigned keyBegin = i;

        // skip to first separator
        while (i < length && !isSeparator(features[i]))
            i++;
        unsigned keyEnd = i;

        // skip to first '=', but don't skip past a ','
        while (i < length && features[i] != '=' && features[i] != ',')
            ++i;

        // skip to first non-separator, but don't skip past a ','
        while (i < length && isSeparator(features[i]) && features[i] != ',')
            ++i;
        unsigned valueBegin = i;

        // skip to first separator
        while (i < length && !isSeparator(features[i]))
            ++i;
        unsigned valueEnd = i;

        callback(features.substring(keyBegin, keyEnd - keyBegin), features.substring(valueBegin, valueEnd - valueBegin));
    }
}
开发者ID:edcwconan,项目名称:webkit,代码行数:31,代码来源:WindowFeatures.cpp

示例6: setWindowFeature

static void setWindowFeature(WindowFeatures& features, StringView key, StringView value)
{
    // Listing a key with no value is shorthand for key=yes
    int numericValue;
    if (value.isEmpty() || equalLettersIgnoringASCIICase(value, "yes"))
        numericValue = 1;
    else
        numericValue = value.toInt();

    // We treat key of "resizable" here as an additional feature rather than setting resizeable to true.
    // This is consistent with Firefox, but could also be handled at another level.

    if (equalLettersIgnoringASCIICase(key, "left") || equalLettersIgnoringASCIICase(key, "screenx"))
        features.x = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "top") || equalLettersIgnoringASCIICase(key, "screeny"))
        features.y = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "width") || equalLettersIgnoringASCIICase(key, "innerwidth"))
        features.width = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "height") || equalLettersIgnoringASCIICase(key, "innerheight"))
        features.height = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "menubar"))
        features.menuBarVisible = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "toolbar"))
        features.toolBarVisible = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "location"))
        features.locationBarVisible = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "status"))
        features.statusBarVisible = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "fullscreen"))
        features.fullscreen = numericValue;
    else if (equalLettersIgnoringASCIICase(key, "scrollbars"))
        features.scrollbarsVisible = numericValue;
    else if (numericValue == 1)
        features.additionalFeatures.append(key.toString());
}
开发者ID:edcwconan,项目名称:webkit,代码行数:35,代码来源:WindowFeatures.cpp

示例7: main

int main() {
    constexpr StringView sv{"123456"};
    static_assert(sv.IsNumber(), "sv isn't a number? WTF?");
    
    constexpr StringView sv2{"123a456"};
    static_assert(!sv2.IsNumber(), "sv2 is a number? WTF?");
}
开发者ID:CCJY,项目名称:coliru,代码行数:7,代码来源:main.cpp

示例8: parseImageCandidatesFromSrcsetAttribute

static void parseImageCandidatesFromSrcsetAttribute(StringView attribute, Vector<ImageCandidate>& imageCandidates)
{
    // FIXME: We should consider replacing the direct pointers in the parsing process with StringView and positions.
    if (attribute.is8Bit())
        parseImageCandidatesFromSrcsetAttribute<LChar>(attribute.characters8(), attribute.length(), imageCandidates);
    else
        parseImageCandidatesFromSrcsetAttribute<UChar>(attribute.characters16(), attribute.length(), imageCandidates);
}
开发者ID:CannedFish,项目名称:webkit,代码行数:8,代码来源:HTMLSrcsetParser.cpp

示例9: createIterator

UCharIterator createIterator(StringView string)
{
    if (string.is8Bit())
        return createLatin1Iterator(string.characters8(), string.length());
    UCharIterator iterator;
    uiter_setString(&iterator, string.characters16(), string.length());
    return iterator;
}
开发者ID:wolfviking0,项目名称:webcl-webkit,代码行数:8,代码来源:CollatorICU.cpp

示例10: write_string

	bool write_string(Slice<char>& buffer, StringView v)
	{
		if (buffer.size() < v.length()) return false;
		
		memcpy(buffer.ptr(), v.c_str(), v.length());
		buffer.trim_front(v.length());
		return true;
	}
开发者ID:karhu,项目名称:arc-project,代码行数:8,代码来源:StringView.cpp

示例11: functionProtoFuncToString

EncodedJSValue JSC_HOST_CALL functionProtoFuncToString(ExecState* exec)
{
    VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    JSValue thisValue = exec->thisValue();
    if (thisValue.inherits(JSFunction::info())) {
        JSFunction* function = jsCast<JSFunction*>(thisValue);
        if (function->isHostOrBuiltinFunction()) {
            scope.release();
            return JSValue::encode(jsMakeNontrivialString(exec, "function ", function->name(vm), "() {\n    [native code]\n}"));
        }

        FunctionExecutable* executable = function->jsExecutable();
        if (executable->isClass()) {
            StringView classSource = executable->classSource().view();
            return JSValue::encode(jsString(exec, classSource.toStringWithoutCopying()));
        }

        if (thisValue.inherits(JSAsyncFunction::info())) {
            String functionHeader = executable->isArrowFunction() ? "async " : "async function ";

            StringView source = executable->source().provider()->getRange(
                executable->parametersStartOffset(),
                executable->parametersStartOffset() + executable->source().length());
            return JSValue::encode(jsMakeNontrivialString(exec, functionHeader, function->name(vm), source));
        }

        String functionHeader = executable->isArrowFunction() ? "" : "function ";
        
        StringView source = executable->source().provider()->getRange(
            executable->parametersStartOffset(),
            executable->parametersStartOffset() + executable->source().length());
        scope.release();
        return JSValue::encode(jsMakeNontrivialString(exec, functionHeader, function->name(vm), source));
    }

    if (thisValue.inherits(InternalFunction::info())) {
        InternalFunction* function = asInternalFunction(thisValue);
        scope.release();
        return JSValue::encode(jsMakeNontrivialString(exec, "function ", function->name(), "() {\n    [native code]\n}"));
    }

    if (thisValue.isObject()) {
        JSObject* object = asObject(thisValue);
        if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
            CallData callData;
            if (object->methodTable(vm)->getCallData(object, callData) != CallType::None) {
                if (auto* classInfo = object->classInfo()) {
                    scope.release();
                    return JSValue::encode(jsMakeNontrivialString(exec, "function ", classInfo->className, "() {\n    [native code]\n}"));
                }
            }
        }
    }

    return throwVMTypeError(exec, scope);
}
开发者ID:eocanha,项目名称:webkit,代码行数:58,代码来源:FunctionPrototype.cpp

示例12: parseGroupTell

void AbstractParser::parseGroupTell(const StringView &view)
{
    if (view.isEmpty())
        sendToUser("What do you want to tell the group?\r\n");
    else {
        emit sendGroupTellEvent(view.toQByteArray());
        sendToUser("OK.\r\n");
    }
}
开发者ID:nschimme,项目名称:MMapper,代码行数:9,代码来源:AbstractParser-Commands.cpp

示例13: hostIsInDomain

static inline bool hostIsInDomain(StringView host, StringView domain)
{
    if (!host.endsWithIgnoringASCIICase(domain))
        return false;

    ASSERT(host.length() >= domain.length());
    unsigned suffixOffset = host.length() - domain.length();
    return suffixOffset == 0 || host[suffixOffset - 1] == '.';
}
开发者ID:Comcast,项目名称:WebKitForWayland,代码行数:9,代码来源:NetworkStorageSessionCFNet.cpp

示例14: double_from_string

		inline double double_from_string(StringView & i_source)
		{
			char temp[256];
			i_source.copy_to_cstr(temp);
			char * end = nullptr;
			const double result = strtod(temp, &end);
			REFLECTIVE_INTERNAL_ASSERT(end != nullptr && end >= temp);
			i_source.remove_prefix(end - temp);
			return result;
		}
开发者ID:giucamp,项目名称:rreflective,代码行数:10,代码来源:primitive_types.cpp

示例15: add_string

	size_t add_string(const size_t vertex, const StringView& s, const bool add_substrings = false)
		// extend Trie by one string
		// REQUIRE: all chars in interval [0..alphabet_size]
	{
		size_t v = vertex;
		for (size_t i = 0; i < s.length(); ++i) {
			v = add_char(v, s[i], add_substrings || i == s.length() - 1);
		}
		return v;
	}
开发者ID:agul,项目名称:algolib,代码行数:10,代码来源:trie.hpp


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