本文整理汇总了C++中StringBuilder::characters16方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuilder::characters16方法的具体用法?C++ StringBuilder::characters16怎么用?C++ StringBuilder::characters16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder::characters16方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findBreakIndexBetween
// This is only needed for TextDocuments where we might have text nodes
// approaching the default length limit (~64k) and we don't want to
// break a text node in the middle of a combining character.
static unsigned findBreakIndexBetween(const StringBuilder& string, unsigned currentPosition, unsigned proposedBreakIndex)
{
ASSERT(currentPosition < proposedBreakIndex);
ASSERT(proposedBreakIndex <= string.length());
// The end of the string is always a valid break.
if (proposedBreakIndex == string.length())
return proposedBreakIndex;
// Latin-1 does not have breakable boundaries. If we ever moved to a differnet 8-bit encoding this could be wrong.
if (string.is8Bit())
return proposedBreakIndex;
const UChar* breakSearchCharacters = string.characters16() + currentPosition;
// We need at least two characters look-ahead to account for UTF-16 surrogates, but can't search off the end of the buffer!
unsigned breakSearchLength = std::min(proposedBreakIndex - currentPosition + 2, string.length() - currentPosition);
NonSharedCharacterBreakIterator it(breakSearchCharacters, breakSearchLength);
if (it.isBreak(proposedBreakIndex - currentPosition))
return proposedBreakIndex;
int adjustedBreakIndexInSubstring = it.preceding(proposedBreakIndex - currentPosition);
if (adjustedBreakIndexInSubstring > 0)
return currentPosition + adjustedBreakIndexInSubstring;
// We failed to find a breakable point, let the caller figure out what to do.
return 0;
}
示例2: parseHTMLIntegerInternal
static bool parseHTMLIntegerInternal(const CharacterType* position, const CharacterType* end, int& value)
{
// Step 3
int sign = 1;
// Step 4
while (position < end) {
if (!isHTMLSpace<CharacterType>(*position))
break;
++position;
}
// Step 5
if (position == end)
return false;
ASSERT(position < end);
// Step 6
if (*position == '-') {
sign = -1;
++position;
} else if (*position == '+')
++position;
if (position == end)
return false;
ASSERT(position < end);
// Step 7
if (!isASCIIDigit(*position))
return false;
// Step 8
StringBuilder digits;
while (position < end) {
if (!isASCIIDigit(*position))
break;
digits.append(*position++);
}
// Step 9
bool ok;
if (digits.is8Bit())
value = sign * charactersToIntStrict(digits.characters8(), digits.length(), &ok);
else
value = sign * charactersToIntStrict(digits.characters16(), digits.length(), &ok);
return ok;
}
示例3: parseHTMLNonNegativeIntegerInternal
static bool parseHTMLNonNegativeIntegerInternal(const CharacterType* position, const CharacterType* end, unsigned& value)
{
// Step 3
while (position < end) {
if (!isHTMLSpace(*position))
break;
++position;
}
// Step 4
if (position == end)
return false;
ASSERT(position < end);
// Step 5
if (*position == '+')
++position;
// Step 6
if (position == end)
return false;
ASSERT(position < end);
// Step 7
if (!isASCIIDigit(*position))
return false;
// Step 8
StringBuilder digits;
while (position < end) {
if (!isASCIIDigit(*position))
break;
digits.append(*position++);
}
// Step 9
bool ok;
if (digits.is8Bit())
value = charactersToUIntStrict(digits.characters8(), digits.length(), &ok);
else
value = charactersToUIntStrict(digits.characters16(), digits.length(), &ok);
return ok;
}
示例4: parseFontSize
static bool parseFontSize(const CharacterType* characters, unsigned length, int& size)
{
// Step 1
// Step 2
const CharacterType* position = characters;
const CharacterType* end = characters + length;
// Step 3
while (position < end) {
if (!isHTMLSpace(*position))
break;
++position;
}
// Step 4
if (position == end)
return false;
ASSERT_WITH_SECURITY_IMPLICATION(position < end);
// Step 5
enum {
RelativePlus,
RelativeMinus,
Absolute
} mode;
switch (*position) {
case '+':
mode = RelativePlus;
++position;
break;
case '-':
mode = RelativeMinus;
++position;
break;
default:
mode = Absolute;
break;
}
// Step 6
StringBuilder digits;
digits.reserveCapacity(16);
while (position < end) {
if (!isASCIIDigit(*position))
break;
digits.append(*position++);
}
// Step 7
if (digits.isEmpty())
return false;
// Step 8
int value;
if (digits.is8Bit())
value = charactersToIntStrict(digits.characters8(), digits.length());
else
value = charactersToIntStrict(digits.characters16(), digits.length());
// Step 9
if (mode == RelativePlus)
value += 3;
else if (mode == RelativeMinus)
value = 3 - value;
// Step 10
if (value > 7)
value = 7;
// Step 11
if (value < 1)
value = 1;
size = value;
return true;
}