本文整理汇总了C++中JSLinearString::hasTwoByteChars方法的典型用法代码示例。如果您正苦于以下问题:C++ JSLinearString::hasTwoByteChars方法的具体用法?C++ JSLinearString::hasTwoByteChars怎么用?C++ JSLinearString::hasTwoByteChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSLinearString
的用法示例。
在下文中一共展示了JSLinearString::hasTwoByteChars方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: new_
JSLinearString*
js::NewDependentString(JSContext* cx, JSString* baseArg, size_t start, size_t length)
{
if (length == 0)
return cx->emptyString();
JSLinearString* base = baseArg->ensureLinear(cx);
if (!base)
return nullptr;
if (start == 0 && length == base->length())
return base;
if (base->hasTwoByteChars()) {
AutoCheckCannotGC nogc;
const char16_t* chars = base->twoByteChars(nogc) + start;
if (JSLinearString* staticStr = cx->staticStrings().lookup(chars, length))
return staticStr;
} else {
AutoCheckCannotGC nogc;
const Latin1Char* chars = base->latin1Chars(nogc) + start;
if (JSLinearString* staticStr = cx->staticStrings().lookup(chars, length))
return staticStr;
}
return JSDependentString::new_(cx, base, start, length);
}
示例2: PodCopy
JSString*
js::ConcatStrings(ExclusiveContext* cx,
typename MaybeRooted<JSString*, allowGC>::HandleType left,
typename MaybeRooted<JSString*, allowGC>::HandleType right)
{
MOZ_ASSERT_IF(!left->isAtom(), cx->isInsideCurrentZone(left));
MOZ_ASSERT_IF(!right->isAtom(), cx->isInsideCurrentZone(right));
size_t leftLen = left->length();
if (leftLen == 0)
return right;
size_t rightLen = right->length();
if (rightLen == 0)
return left;
size_t wholeLength = leftLen + rightLen;
if (!JSString::validateLength(cx, wholeLength))
return nullptr;
bool isLatin1 = left->hasLatin1Chars() && right->hasLatin1Chars();
bool canUseInline = isLatin1
? JSInlineString::lengthFits<Latin1Char>(wholeLength)
: JSInlineString::lengthFits<char16_t>(wholeLength);
if (canUseInline && cx->isJSContext()) {
Latin1Char* latin1Buf = nullptr; // initialize to silence GCC warning
char16_t* twoByteBuf = nullptr; // initialize to silence GCC warning
JSInlineString* str = isLatin1
? AllocateInlineString<allowGC>(cx, wholeLength, &latin1Buf)
: AllocateInlineString<allowGC>(cx, wholeLength, &twoByteBuf);
if (!str)
return nullptr;
AutoCheckCannotGC nogc;
JSLinearString* leftLinear = left->ensureLinear(cx);
if (!leftLinear)
return nullptr;
JSLinearString* rightLinear = right->ensureLinear(cx);
if (!rightLinear)
return nullptr;
if (isLatin1) {
PodCopy(latin1Buf, leftLinear->latin1Chars(nogc), leftLen);
PodCopy(latin1Buf + leftLen, rightLinear->latin1Chars(nogc), rightLen);
latin1Buf[wholeLength] = 0;
} else {
if (leftLinear->hasTwoByteChars())
PodCopy(twoByteBuf, leftLinear->twoByteChars(nogc), leftLen);
else
CopyAndInflateChars(twoByteBuf, leftLinear->latin1Chars(nogc), leftLen);
if (rightLinear->hasTwoByteChars())
PodCopy(twoByteBuf + leftLen, rightLinear->twoByteChars(nogc), rightLen);
else
CopyAndInflateChars(twoByteBuf + leftLen, rightLinear->latin1Chars(nogc), rightLen);
twoByteBuf[wholeLength] = 0;
}
return str;
}
return JSRope::new_<allowGC>(cx, left, right, wholeLength);
}