本文整理汇总了C++中HandleLinearString::length方法的典型用法代码示例。如果您正苦于以下问题:C++ HandleLinearString::length方法的具体用法?C++ HandleLinearString::length怎么用?C++ HandleLinearString::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HandleLinearString
的用法示例。
在下文中一共展示了HandleLinearString::length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsTrailSurrogate
static bool
IsTrailSurrogateWithLeadSurrogateImpl(JSContext* cx, HandleLinearString input, size_t index)
{
JS::AutoCheckCannotGC nogc;
MOZ_ASSERT(index > 0 && index < input->length());
const CharT* inputChars = input->chars<CharT>(nogc);
return unicode::IsTrailSurrogate(inputChars[index]) &&
unicode::IsLeadSurrogate(inputChars[index - 1]);
}
示例2:
static bool
IsTrailSurrogateWithLeadSurrogate(JSContext* cx, HandleLinearString input, int32_t index)
{
if (index <= 0 || size_t(index) >= input->length())
return false;
return input->hasLatin1Chars()
? IsTrailSurrogateWithLeadSurrogateImpl<Latin1Char>(cx, input, index)
: IsTrailSurrogateWithLeadSurrogateImpl<char16_t>(cx, input, index);
}
示例3: stackScope
RegExpRunStatus
RegExpShared::execute(JSContext* cx, HandleLinearString input, size_t start,
MatchPairs* matches)
{
TraceLoggerThread* logger = TraceLoggerForMainThread(cx->runtime());
CompilationMode mode = matches ? Normal : MatchOnly;
/* Compile the code at point-of-use. */
if (!compileIfNecessary(cx, input, mode, DontForceByteCode))
return RegExpRunStatus_Error;
/*
* Ensure sufficient memory for output vector.
* No need to initialize it. The RegExp engine fills them in on a match.
*/
if (matches && !matches->allocOrExpandArray(pairCount())) {
ReportOutOfMemory(cx);
return RegExpRunStatus_Error;
}
/*
* |displacement| emulates sticky mode by matching from this offset
* into the char buffer and subtracting the delta off at the end.
*/
size_t charsOffset = 0;
size_t length = input->length();
size_t origLength = length;
size_t displacement = 0;
if (sticky()) {
displacement = start;
charsOffset += displacement;
length -= displacement;
start = 0;
}
// Reset the Irregexp backtrack stack if it grows during execution.
irregexp::RegExpStackScope stackScope(cx->runtime());
if (canStringMatch) {
MOZ_ASSERT(pairCount() == 1);
int res = StringFindPattern(input, source, start + charsOffset);
if (res == -1)
return RegExpRunStatus_Success_NotFound;
if (matches) {
(*matches)[0].start = res;
(*matches)[0].limit = res + source->length();
matches->checkAgainst(origLength);
}
return RegExpRunStatus_Success;
}
do {
jit::JitCode* code = compilation(mode, input->hasLatin1Chars()).jitCode;
if (!code)
break;
RegExpRunStatus result;
{
AutoTraceLog logJIT(logger, TraceLogger_IrregexpExecute);
AutoCheckCannotGC nogc;
if (input->hasLatin1Chars()) {
const Latin1Char* chars = input->latin1Chars(nogc) + charsOffset;
result = irregexp::ExecuteCode(cx, code, chars, start, length, matches);
} else {
const char16_t* chars = input->twoByteChars(nogc) + charsOffset;
result = irregexp::ExecuteCode(cx, code, chars, start, length, matches);
}
}
if (result == RegExpRunStatus_Error) {
// An 'Error' result is returned if a stack overflow guard or
// interrupt guard failed. If CheckOverRecursed doesn't throw, break
// out and retry the regexp in the bytecode interpreter, which can
// execute while tolerating future interrupts. Otherwise, if we keep
// getting interrupted we will never finish executing the regexp.
if (!jit::CheckOverRecursed(cx))
return RegExpRunStatus_Error;
break;
}
if (result == RegExpRunStatus_Success_NotFound)
return RegExpRunStatus_Success_NotFound;
MOZ_ASSERT(result == RegExpRunStatus_Success);
if (matches) {
matches->displace(displacement);
matches->checkAgainst(origLength);
}
return RegExpRunStatus_Success;
} while (false);
// Compile bytecode for the RegExp if necessary.
if (!compileIfNecessary(cx, input, mode, ForceByteCode))
return RegExpRunStatus_Error;
//.........这里部分代码省略.........
示例4: stackScope
RegExpRunStatus
RegExpShared::execute(JSContext *cx, HandleLinearString input, size_t start,
MatchPairs *matches)
{
TraceLogger *logger = TraceLoggerForMainThread(cx->runtime());
CompilationMode mode = matches ? Normal : MatchOnly;
/* Compile the code at point-of-use. */
if (!compileIfNecessary(cx, input, mode))
return RegExpRunStatus_Error;
/*
* Ensure sufficient memory for output vector.
* No need to initialize it. The RegExp engine fills them in on a match.
*/
if (matches && !matches->allocOrExpandArray(pairCount()))
return RegExpRunStatus_Error;
/*
* |displacement| emulates sticky mode by matching from this offset
* into the char buffer and subtracting the delta off at the end.
*/
size_t charsOffset = 0;
size_t length = input->length();
size_t origLength = length;
size_t displacement = 0;
if (sticky()) {
displacement = start;
charsOffset += displacement;
length -= displacement;
start = 0;
}
// Reset the Irregexp backtrack stack if it grows during execution.
irregexp::RegExpStackScope stackScope(cx->runtime());
if (canStringMatch) {
JS_ASSERT(pairCount() == 1);
int res = StringFindPattern(input, source, start + charsOffset);
if (res == -1)
return RegExpRunStatus_Success_NotFound;
if (matches) {
(*matches)[0].start = res;
(*matches)[0].limit = res + source->length();
matches->checkAgainst(origLength);
}
return RegExpRunStatus_Success;
}
if (uint8_t *byteCode = compilation(mode, input->hasLatin1Chars()).byteCode) {
AutoTraceLog logInterpreter(logger, TraceLogger::IrregexpExecute);
AutoStableStringChars inputChars(cx);
if (!inputChars.init(cx, input))
return RegExpRunStatus_Error;
RegExpRunStatus result;
if (inputChars.isLatin1()) {
const Latin1Char *chars = inputChars.latin1Range().start().get() + charsOffset;
result = irregexp::InterpretCode(cx, byteCode, chars, start, length, matches);
} else {
const char16_t *chars = inputChars.twoByteRange().start().get() + charsOffset;
result = irregexp::InterpretCode(cx, byteCode, chars, start, length, matches);
}
if (result == RegExpRunStatus_Success && matches) {
matches->displace(displacement);
matches->checkAgainst(origLength);
}
return result;
}
while (true) {
RegExpRunStatus result;
{
AutoTraceLog logJIT(logger, TraceLogger::IrregexpExecute);
AutoCheckCannotGC nogc;
jit::JitCode *code = compilation(mode, input->hasLatin1Chars()).jitCode;
if (input->hasLatin1Chars()) {
const Latin1Char *chars = input->latin1Chars(nogc) + charsOffset;
result = irregexp::ExecuteCode(cx, code, chars, start, length, matches);
} else {
const char16_t *chars = input->twoByteChars(nogc) + charsOffset;
result = irregexp::ExecuteCode(cx, code, chars, start, length, matches);
}
}
if (result == RegExpRunStatus_Error) {
// The RegExp engine might exit with an exception if an interrupt
// was requested. Check this case and retry until a clean result is
// obtained.
bool interrupted;
{
JSRuntime::AutoLockForInterrupt lock(cx->runtime());
interrupted = cx->runtime()->interrupt;
}
//.........这里部分代码省略.........