⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsregexp.c

📁 Swfdec still is development software, but has also followed a rigid no-crashes-allowed policy. I b
💻 C
📖 第 1 页 / 共 5 页
字号:
    uintN value = JS7_UNDEC(c);    JSBool overflow = (value > max && (!findMax || value > findMax(state)));    /* The following restriction allows simpler overflow checks. */    JS_ASSERT(max <= ((uintN)-1 - 9) / 10);    while (state->cp < state->cpend) {        c = *state->cp;        if (!JS7_ISDEC(c))            break;        value = 10 * value + JS7_UNDEC(c);        if (!overflow && value > max && (!findMax || value > findMax(state)))            overflow = JS_TRUE;        ++state->cp;    }    return overflow ? OVERFLOW_VALUE : value;}/* * Calculate the total size of the bitmap required for a class expression. */static JSBoolCalculateBitmapSize(CompilerState *state, RENode *target, const jschar *src,                    const jschar *end){    uintN max = 0;    JSBool inRange = JS_FALSE;    jschar c, rangeStart = 0;    uintN n, digit, nDigits, i;    target->u.ucclass.bmsize = 0;    target->u.ucclass.sense = JS_TRUE;    if (src == end)        return JS_TRUE;    if (*src == '^') {        ++src;        target->u.ucclass.sense = JS_FALSE;    }    while (src != end) {        uintN localMax = 0;        switch (*src) {        case '\\':            ++src;            c = *src++;            switch (c) {            case 'b':                localMax = 0x8;                break;            case 'f':                localMax = 0xC;                break;            case 'n':                localMax = 0xA;                break;            case 'r':                localMax = 0xD;                break;            case 't':                localMax = 0x9;                break;            case 'v':                localMax = 0xB;                break;            case 'c':                if (src + 1 < end && RE_IS_LETTER(src[1]))                    localMax = (jschar) (*src++ & 0x1F);                else                    localMax = '\\';                break;            case 'x':                nDigits = 2;                goto lexHex;            case 'u':                nDigits = 4;lexHex:                n = 0;                for (i = 0; (i < nDigits) && (src < end); i++) {                    c = *src++;                    if (!isASCIIHexDigit(c, &digit)) {                        /*                         * Back off to accepting the original                         *'\' as a literal.                         */                        src -= i + 1;                        n = '\\';                        break;                    }                    n = (n << 4) | digit;                }                localMax = n;                break;            case 'd':                if (inRange) {                    JS_ReportErrorNumber(state->context,                                         js_GetErrorMessage, NULL,                                         JSMSG_BAD_CLASS_RANGE);                    return JS_FALSE;                }                localMax = '9';                break;            case 'D':            case 's':            case 'S':            case 'w':            case 'W':                if (inRange) {                    JS_ReportErrorNumber(state->context,                                         js_GetErrorMessage, NULL,                                         JSMSG_BAD_CLASS_RANGE);                    return JS_FALSE;                }                target->u.ucclass.bmsize = 65535;                return JS_TRUE;            case '0':            case '1':            case '2':            case '3':            case '4':            case '5':            case '6':            case '7':                /*                 *  This is a non-ECMA extension - decimal escapes (in this                 *  case, octal!) are supposed to be an error inside class                 *  ranges, but supported here for backwards compatibility.                 *                 */                n = JS7_UNDEC(c);                c = *src;                if ('0' <= c && c <= '7') {                    src++;                    n = 8 * n + JS7_UNDEC(c);                    c = *src;                    if ('0' <= c && c <= '7') {                        src++;                        i = 8 * n + JS7_UNDEC(c);                        if (i <= 0377)                            n = i;                        else                            src--;                    }                }                localMax = n;                break;            default:                localMax = c;                break;            }            break;        default:            localMax = *src++;            break;        }        if (inRange) {            if (rangeStart > localMax) {                JS_ReportErrorNumber(state->context,                                     js_GetErrorMessage, NULL,                                     JSMSG_BAD_CLASS_RANGE);                return JS_FALSE;            }            inRange = JS_FALSE;        } else {            if (src < end - 1) {                if (*src == '-') {                    ++src;                    inRange = JS_TRUE;                    rangeStart = (jschar)localMax;                    continue;                }            }        }        if (state->flags & JSREG_FOLD) {            c = JS_MAX(upcase((jschar)localMax), downcase((jschar)localMax));            if (c > localMax)                localMax = c;        }        if (localMax > max)            max = localMax;    }    target->u.ucclass.bmsize = max;    return JS_TRUE;}/* *  item:       assertion               An item is either an assertion or *              quantatom               a quantified atom. * *  assertion:  '^'                     Assertions match beginning of string *                                      (or line if the class static property *                                      RegExp.multiline is true). *              '$'                     End of string (or line if the class *                                      static property RegExp.multiline is *                                      true). *              '\b'                    Word boundary (between \w and \W). *              '\B'                    Word non-boundary. * *  quantatom:  atom                    An unquantified atom. *              quantatom '{' n ',' m '}' *                                      Atom must occur between n and m times. *              quantatom '{' n ',' '}' Atom must occur at least n times. *              quantatom '{' n '}'     Atom must occur exactly n times. *              quantatom '*'           Zero or more times (same as {0,}). *              quantatom '+'           One or more times (same as {1,}). *              quantatom '?'           Zero or one time (same as {0,1}). * *              any of which can be optionally followed by '?' for ungreedy * *  atom:       '(' regexp ')'          A parenthesized regexp (what matched *                                      can be addressed using a backreference, *                                      see '\' n below). *              '.'                     Matches any char except '\n'. *              '[' classlist ']'       A character class. *              '[' '^' classlist ']'   A negated character class. *              '\f'                    Form Feed. *              '\n'                    Newline (Line Feed). *              '\r'                    Carriage Return. *              '\t'                    Horizontal Tab. *              '\v'                    Vertical Tab. *              '\d'                    A digit (same as [0-9]). *              '\D'                    A non-digit. *              '\w'                    A word character, [0-9a-z_A-Z]. *              '\W'                    A non-word character. *              '\s'                    A whitespace character, [ \b\f\n\r\t\v]. *              '\S'                    A non-whitespace character. *              '\' n                   A backreference to the nth (n decimal *                                      and positive) parenthesized expression. *              '\' octal               An octal escape sequence (octal must be *                                      two or three digits long, unless it is *                                      0 for the null character). *              '\x' hex                A hex escape (hex must be two digits). *              '\u' unicode            A unicode escape (must be four digits). *              '\c' ctrl               A control character, ctrl is a letter. *              '\' literalatomchar     Any character except one of the above *                                      that follow '\' in an atom. *              otheratomchar           Any character not first among the other *                                      atom right-hand sides. */static JSBoolParseTerm(CompilerState *state){    jschar c = *state->cp++;    uintN nDigits;    uintN num, tmp, n, i;    const jschar *termStart;    switch (c) {    /* assertions and atoms */    case '^':        state->result = NewRENode(state, REOP_BOL);        if (!state->result)            return JS_FALSE;        state->progLength++;        return JS_TRUE;    case '$':        state->result = NewRENode(state, REOP_EOL);        if (!state->result)            return JS_FALSE;        state->progLength++;        return JS_TRUE;    case '\\':        if (state->cp >= state->cpend) {            /* a trailing '\' is an error */            js_ReportCompileErrorNumber(state->context, state->tokenStream,                                        NULL, JSREPORT_ERROR,                                        JSMSG_TRAILING_SLASH);            return JS_FALSE;        }        c = *state->cp++;        switch (c) {        /* assertion escapes */        case 'b' :            state->result = NewRENode(state, REOP_WBDRY);            if (!state->result)                return JS_FALSE;            state->progLength++;            return JS_TRUE;        case 'B':            state->result = NewRENode(state, REOP_WNONBDRY);            if (!state->result)                return JS_FALSE;            state->progLength++;            return JS_TRUE;        /* Decimal escape */        case '0':            if (JS_HAS_STRICT_OPTION(state->context)) {                if (!js_ReportCompileErrorNumber(state->context,                                                 state->tokenStream,                                                 NULL,                                                 JSREPORT_WARNING |                                                 JSREPORT_STRICT,                                                 JSMSG_INVALID_BACKREF)) {                    return JS_FALSE;                }                c = 0;            } else {     doOctal:                num = 0;                while (state->cp < state->cpend) {                    c = *state->cp;                    if (c < '0' || '7' < c)                        break;                    state->cp++;                    tmp = 8 * num + (uintN)JS7_UNDEC(c);                    if (tmp > 0377)                        break;                    num = tmp;                }                c = (jschar)num;            }    doFlat:            state->result = NewRENode(state, REOP_FLAT);            if (!state->result)                return JS_FALSE;            state->result->u.flat.chr = c;            state->result->u.flat.length = 1;            state->progLength += 3;            break;        case '1':        case '2':        case '3':        case '4':        case '5':        case '6':        case '7':        case '8':        case '9':            termStart = state->cp - 1;            num = GetDecimalValue(c, state->parenCount, FindParenCount, state);            if (state->flags & JSREG_FIND_PAREN_ERROR)                return JS_FALSE;            if (num == OVERFLOW_VALUE) {                if (!JS_HAS_STRICT_OPTION(state->context)) {                    state->cp = termStart;                    goto doOctal;                }                if (!js_ReportCompileErrorNumber(state->context,                                                 state->tokenStream,                                                 NULL,                                                 JSREPORT_WARNING |                                                 JSREPORT_STRICT,                                                 (c >= '8')                                                 ? JSMSG_INVALID_BACKREF                                                 : JSMSG_BAD_BACKREF)) {                    return JS_FALSE;                }                num = 0x10000;            }            JS_ASSERT(1 <= num && num <= 0x10000);            state->result = NewRENode(state, REOP_BACKREF);            if (!state->result)                return JS_FALSE;            state->result->u.parenIndex = num - 1;            state->progLength += 3;            break;        /* Control escape */        case 'f':            c = 0xC;            goto doFlat;        case 'n':            c = 0xA;            goto doFlat;        case 'r':            c = 0xD;            goto doFlat;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -