本文整理汇总了C++中StringBuilder::characters8方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuilder::characters8方法的具体用法?C++ StringBuilder::characters8怎么用?C++ StringBuilder::characters8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder::characters8方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: expectBuilderContent
TEST(StringBuilderTest, Append)
{
StringBuilder builder;
builder.append(String("0123456789"));
expectBuilderContent("0123456789", builder);
builder.append("abcd");
expectBuilderContent("0123456789abcd", builder);
builder.append("efgh", 3);
expectBuilderContent("0123456789abcdefg", builder);
builder.append("");
expectBuilderContent("0123456789abcdefg", builder);
builder.append('#');
expectBuilderContent("0123456789abcdefg#", builder);
builder.toString(); // Test after reifyString().
StringBuilder builder1;
builder.append("", 0);
expectBuilderContent("0123456789abcdefg#", builder);
builder1.append(builder.characters8(), builder.length());
builder1.append("XYZ");
builder.append(builder1.characters8(), builder1.length());
expectBuilderContent("0123456789abcdefg#0123456789abcdefg#XYZ", builder);
StringBuilder builder2;
builder2.reserveCapacity(100);
builder2.append("xyz");
const LChar* characters = builder2.characters8();
builder2.append("0123456789");
EXPECT_EQ(characters, builder2.characters8());
// Test appending UChar32 characters to StringBuilder.
StringBuilder builderForUChar32Append;
UChar32 frakturAChar = 0x1D504;
builderForUChar32Append.append(frakturAChar); // The fraktur A is not in the BMP, so it's two UTF-16 code units long.
EXPECT_EQ(2U, builderForUChar32Append.length());
builderForUChar32Append.append(static_cast<UChar32>('A'));
EXPECT_EQ(3U, builderForUChar32Append.length());
const UChar resultArray[] = { U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), 'A' };
expectBuilderContent(String(resultArray, WTF_ARRAY_LENGTH(resultArray)), builderForUChar32Append);
}
示例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;
}