本文整理汇总了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;
}
}
示例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)
}
示例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);
}
}
示例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();
}
}
示例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));
}
}
示例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());
}
示例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?");
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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");
}
}
示例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] == '.';
}
示例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;
}
示例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;
}