当前位置: 首页>>代码示例>>C++>>正文


C++ HandleLinearString类代码示例

本文整理汇总了C++中HandleLinearString的典型用法代码示例。如果您正苦于以下问题:C++ HandleLinearString类的具体用法?C++ HandleLinearString怎么用?C++ HandleLinearString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HandleLinearString类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: IsTrailSurrogateWithLeadSurrogate

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);
}
开发者ID:thangluutitan,项目名称:privafox-converted,代码行数:10,代码来源:RegExp.cpp

示例2: compile

bool
RegExpShared::compileIfNecessary(JSContext *cx, HandleLinearString input, CompilationMode mode)
{
    if (isCompiled(mode, input->hasLatin1Chars()) || canStringMatch)
        return true;
    return compile(cx, input, mode);
}
开发者ID:mlasak,项目名称:gecko-dev,代码行数:7,代码来源:RegExpObject.cpp

示例3: compile

bool
RegExpShared::compileIfNecessary(JSContext* cx, HandleLinearString input,
                                 CompilationMode mode, ForceByteCodeEnum force)
{
    if (isCompiled(mode, input->hasLatin1Chars(), force))
        return true;
    return compile(cx, input, mode, force);
}
开发者ID:lgarner,项目名称:mozilla-central,代码行数:8,代码来源:RegExpObject.cpp

示例4: IsTrailSurrogateWithLeadSurrogateImpl

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]);
}
开发者ID:thangluutitan,项目名称:privafox-converted,代码行数:10,代码来源:RegExp.cpp

示例5: options

bool
RegExpShared::compile(JSContext* cx, HandleAtom pattern, HandleLinearString input,
                      CompilationMode mode, bool sticky, ForceByteCodeEnum force)
{
    if (!ignoreCase() && !StringHasRegExpMetaChars(pattern))
        canStringMatch = true;

    CompileOptions options(cx);
    TokenStream dummyTokenStream(cx, options, nullptr, 0, nullptr);

    LifoAllocScope scope(&cx->tempLifoAlloc());

    /* Parse the pattern. */
    irregexp::RegExpCompileData data;
    if (!irregexp::ParsePattern(dummyTokenStream, cx->tempLifoAlloc(), pattern,
                                multiline(), mode == MatchOnly, unicode(), ignoreCase(), &data))
    {
        return false;
    }

    this->parenCount = data.capture_count;

    irregexp::RegExpCode code = irregexp::CompilePattern(cx, this, &data, input,
                                                         false /* global() */,
                                                         ignoreCase(),
                                                         input->hasLatin1Chars(),
                                                         mode == MatchOnly,
                                                         force == ForceByteCode,
                                                         sticky, unicode());
    if (code.empty())
        return false;

    MOZ_ASSERT(!code.jitCode || !code.byteCode);
    MOZ_ASSERT_IF(force == ForceByteCode, code.byteCode);

    RegExpCompilation& compilation = this->compilation(mode, sticky, input->hasLatin1Chars());
    if (code.jitCode)
        compilation.jitCode = code.jitCode;
    else if (code.byteCode)
        compilation.byteCode = code.byteCode;

    return true;
}
开发者ID:cbradley857,项目名称:gecko-dev,代码行数:43,代码来源:RegExpObject.cpp

示例6: 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;

//.........这里部分代码省略.........
开发者ID:lgarner,项目名称:mozilla-central,代码行数:101,代码来源:RegExpObject.cpp

示例7: 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;
            }
//.........这里部分代码省略.........
开发者ID:mlasak,项目名称:gecko-dev,代码行数:101,代码来源:RegExpObject.cpp


注:本文中的HandleLinearString类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。