本文整理汇总了C++中StringView::length方法的典型用法代码示例。如果您正苦于以下问题:C++ StringView::length方法的具体用法?C++ StringView::length怎么用?C++ StringView::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringView
的用法示例。
在下文中一共展示了StringView::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: httpVersionStaticPreamble
// https://tools.ietf.org/html/rfc6455#section-4.1
// "The HTTP version MUST be at least 1.1."
static inline bool headerHasValidHTTPVersion(StringView httpStatusLine)
{
const char* httpVersionStaticPreambleLiteral = "HTTP/";
StringView httpVersionStaticPreamble(reinterpret_cast<const LChar*>(httpVersionStaticPreambleLiteral), strlen(httpVersionStaticPreambleLiteral));
if (!httpStatusLine.startsWith(httpVersionStaticPreamble))
return false;
// Check that there is a version number which should be at least three characters after "HTTP/"
unsigned preambleLength = httpVersionStaticPreamble.length();
if (httpStatusLine.length() < preambleLength + 3)
return false;
auto dotPosition = httpStatusLine.find('.', preambleLength);
if (dotPosition == notFound)
return false;
StringView majorVersionView = httpStatusLine.substring(preambleLength, dotPosition - preambleLength);
bool isValid;
int majorVersion = majorVersionView.toIntStrict(isValid);
if (!isValid)
return false;
unsigned minorVersionLength;
unsigned charactersLeftAfterDotPosition = httpStatusLine.length() - dotPosition;
for (minorVersionLength = 1; minorVersionLength < charactersLeftAfterDotPosition; minorVersionLength++) {
if (!isASCIIDigit(httpStatusLine[dotPosition + minorVersionLength]))
break;
}
int minorVersion = (httpStatusLine.substring(dotPosition + 1, minorVersionLength)).toIntStrict(isValid);
if (!isValid)
return false;
return (majorVersion >= 1 && minorVersion >= 1) || majorVersion >= 2;
}
示例2: 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;
}
}
示例3: appendSourceToError
static void appendSourceToError(CallFrame* callFrame, ErrorInstance* exception, unsigned bytecodeOffset)
{
ErrorInstance::SourceAppender appender = exception->sourceAppender();
exception->clearSourceAppender();
RuntimeType type = exception->runtimeTypeForCause();
exception->clearRuntimeTypeForCause();
if (!callFrame->codeBlock()->hasExpressionInfo())
return;
int startOffset = 0;
int endOffset = 0;
int divotPoint = 0;
unsigned line = 0;
unsigned column = 0;
CodeBlock* codeBlock;
CodeOrigin codeOrigin = callFrame->codeOrigin();
if (codeOrigin && codeOrigin.inlineCallFrame)
codeBlock = baselineCodeBlockForInlineCallFrame(codeOrigin.inlineCallFrame);
else
codeBlock = callFrame->codeBlock();
codeBlock->expressionRangeForBytecodeOffset(bytecodeOffset, divotPoint, startOffset, endOffset, line, column);
int expressionStart = divotPoint - startOffset;
int expressionStop = divotPoint + endOffset;
StringView sourceString = codeBlock->source()->source();
if (!expressionStop || expressionStart > static_cast<int>(sourceString.length()))
return;
VM* vm = &callFrame->vm();
JSValue jsMessage = exception->getDirect(*vm, vm->propertyNames->message);
if (!jsMessage || !jsMessage.isString())
return;
String message = asString(jsMessage)->value(callFrame);
if (expressionStart < expressionStop)
message = appender(message, codeBlock->source()->getRange(expressionStart, expressionStop).toString(), type, ErrorInstance::FoundExactSource);
else {
// No range information, so give a few characters of context.
int dataLength = sourceString.length();
int start = expressionStart;
int stop = expressionStart;
// Get up to 20 characters of context to the left and right of the divot, clamping to the line.
// Then strip whitespace.
while (start > 0 && (expressionStart - start < 20) && sourceString[start - 1] != '\n')
start--;
while (start < (expressionStart - 1) && isStrWhiteSpace(sourceString[start]))
start++;
while (stop < dataLength && (stop - expressionStart < 20) && sourceString[stop] != '\n')
stop++;
while (stop > expressionStart && isStrWhiteSpace(sourceString[stop - 1]))
stop--;
message = appender(message, codeBlock->source()->getRange(start, stop).toString(), type, ErrorInstance::FoundApproximateSource);
}
exception->putDirect(*vm, vm->propertyNames->message, jsString(vm, message));
}
示例4: findNextWordFromIndex
int findNextWordFromIndex(StringView text, int position, bool forward)
{
TextBreakIterator* it = wordBreakIterator(text);
if (forward) {
position = textBreakFollowing(it, position);
while (position != TextBreakDone) {
// We stop searching when the character preceeding the break is alphanumeric.
if (static_cast<unsigned>(position) < text.length() && u_isalnum(text[position - 1]))
return position;
position = textBreakFollowing(it, position);
}
return text.length();
} else {
position = textBreakPreceding(it, position);
while (position != TextBreakDone) {
// We stop searching when the character following the break is alphanumeric.
if (position && u_isalnum(text[position]))
return position;
position = textBreakPreceding(it, position);
}
return 0;
}
}
示例5:
StringView::StringView(const StringView &str, uint32 begin, uint32 end)
: _str(str.c_str()+begin)
, _length(end-begin)
{
ARC_ASSERT(begin <= str.length(),"Invalid StringView begin.");
ARC_ASSERT(end <= str.length(), "Invalid StringView end");
}
示例6: 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;
}
示例7: 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);
}
示例8: 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;
}
示例9: 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] == '.';
}
示例10: 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;
}
示例11: Write
void Write(StringView data)
{
NEPTOOLS_CHECK(SinkOverflow, offset+buf_put+data.length() <= size,
"Sink overflow during write");
auto cp = std::min(data.length(), size_t(buf_size - buf_put));
memcpy(buf+buf_put, data.data(), cp);
data.remove_prefix(cp);
buf_put += cp;
if (!data.empty()) Write_(data);
}
示例12:
v8_inspector::StringView toV8InspectorStringView(const StringView& string) {
if (string.isNull())
return v8_inspector::StringView();
if (string.is8Bit())
return v8_inspector::StringView(
reinterpret_cast<const uint8_t*>(string.characters8()),
string.length());
return v8_inspector::StringView(
reinterpret_cast<const uint16_t*>(string.characters16()),
string.length());
}
示例13: lexIdentifier
IDBKeyPathLexer::TokenType IDBKeyPathLexer::lexIdentifier(String& element)
{
StringView start = m_remainingText;
if (!m_remainingText.isEmpty() && isIdentifierStartCharacter(m_remainingText[0]))
m_remainingText = m_remainingText.substring(1);
else
return TokenError;
while (!m_remainingText.isEmpty() && isIdentifierCharacter(m_remainingText[0]))
m_remainingText = m_remainingText.substring(1);
element = start.substring(0, start.length() - m_remainingText.length()).toString();
return TokenIdentifier;
}
示例14: resolveRelativeVirtualPath
// https://wicg.github.io/entries-api/#resolve-a-relative-path
static String resolveRelativeVirtualPath(StringView baseVirtualPath, StringView relativeVirtualPath)
{
ASSERT(baseVirtualPath[0] == '/');
if (!relativeVirtualPath.isEmpty() && relativeVirtualPath[0] == '/')
return relativeVirtualPath.length() == 1 ? relativeVirtualPath.toString() : resolveRelativeVirtualPath("/", relativeVirtualPath.substring(1));
Vector<StringView> virtualPathSegments;
for (auto segment : baseVirtualPath.split('/'))
virtualPathSegments.append(segment);
for (auto segment : relativeVirtualPath.split('/')) {
ASSERT(!segment.isEmpty());
if (segment == ".")
continue;
if (segment == "..") {
if (!virtualPathSegments.isEmpty())
virtualPathSegments.removeLast();
continue;
}
virtualPathSegments.append(segment);
}
if (virtualPathSegments.isEmpty())
return "/"_s;
StringBuilder builder;
for (auto& segment : virtualPathSegments) {
builder.append('/');
builder.append(segment);
}
return builder.toString();
}
示例15: encodingFromMetaAttributes
TextEncoding HTMLMetaCharsetParser::encodingFromMetaAttributes(const AttributeList& attributes)
{
bool gotPragma = false;
enum { None, Charset, Pragma } mode = None;
StringView charset;
for (auto& attribute : attributes) {
const String& attributeName = attribute.first;
const String& attributeValue = attribute.second;
if (attributeName == http_equivAttr) {
if (equalIgnoringCase(attributeValue, "content-type"))
gotPragma = true;
} else if (charset.isEmpty()) {
if (attributeName == charsetAttr) {
charset = attributeValue;
mode = Charset;
} else if (attributeName == contentAttr) {
charset = extractCharset(attributeValue);
if (charset.length())
mode = Pragma;
}
}
}
if (mode == Charset || (mode == Pragma && gotPragma))
return TextEncoding(stripLeadingAndTrailingHTMLSpaces(charset.toStringWithoutCopying()));
return TextEncoding();
}