本文整理汇总了C++中StringView::is8Bit方法的典型用法代码示例。如果您正苦于以下问题:C++ StringView::is8Bit方法的具体用法?C++ StringView::is8Bit怎么用?C++ StringView::is8Bit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringView
的用法示例。
在下文中一共展示了StringView::is8Bit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: numCodeUnitsInGraphemeClusters
unsigned numCodeUnitsInGraphemeClusters(StringView string, unsigned numGraphemeClusters)
{
unsigned stringLength = string.length();
if (stringLength <= numGraphemeClusters)
return stringLength;
// The only Latin-1 Extended Grapheme Cluster is CRLF.
if (string.is8Bit()) {
auto* characters = string.characters8();
unsigned i, j;
for (i = 0, j = 0; i < numGraphemeClusters && j + 1 < stringLength; ++i, ++j)
j += characters[j] == '\r' && characters[j + 1] == '\n';
return j + (i < numGraphemeClusters);
}
NonSharedCharacterBreakIterator iterator { string };
if (!iterator) {
ASSERT_NOT_REACHED();
return stringLength;
}
for (unsigned i = 0; i < numGraphemeClusters; ++i) {
if (ubrk_next(iterator) == UBRK_DONE)
return stringLength;
}
return ubrk_current(iterator);
}
示例2: numGraphemeClusters
unsigned numGraphemeClusters(StringView string)
{
unsigned stringLength = string.length();
if (!stringLength)
return 0;
// The only Latin-1 Extended Grapheme Cluster is CRLF.
if (string.is8Bit()) {
auto* characters = string.characters8();
unsigned numCRLF = 0;
for (unsigned i = 1; i < stringLength; ++i)
numCRLF += characters[i - 1] == '\r' && characters[i] == '\n';
return stringLength - numCRLF;
}
NonSharedCharacterBreakIterator iterator { string };
if (!iterator) {
ASSERT_NOT_REACHED();
return stringLength;
}
unsigned numGraphemeClusters = 0;
while (ubrk_next(iterator) != UBRK_DONE)
++numGraphemeClusters;
return numGraphemeClusters;
}
示例3: 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);
}
示例4: 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;
}
示例5:
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());
}
示例6: numCharactersInGraphemeClusters
unsigned numCharactersInGraphemeClusters(const StringView& s, unsigned numGraphemeClusters)
{
unsigned stringLength = s.length();
if (!stringLength)
return 0;
// The only Latin-1 Extended Grapheme Cluster is CR LF
if (s.is8Bit() && !s.contains('\r'))
return std::min(stringLength, numGraphemeClusters);
NonSharedCharacterBreakIterator it(s);
if (!it)
return std::min(stringLength, numGraphemeClusters);
for (unsigned i = 0; i < numGraphemeClusters; ++i) {
if (textBreakNext(it) == TextBreakDone)
return stringLength;
}
return textBreakCurrent(it);
}