Ignore:
Timestamp:
Dec 16, 2007, 8:19:25 PM (17 years ago)
Author:
Darin Adler
Message:

Reviewed by Maciej.

  • pcre/dftables.cpp: (main): Added the kjs prefix a normal way in lieu of using macros.
  • pcre/pcre_compile.cpp: Moved some definitions here from pcre_internal.h. (errorText): Name changes, fewer typedefs. (checkEscape): Ditto. Changed uppercase conversion to use toASCIIUpper. (isCountedRepeat): Name change. (readRepeatCounts): Name change. (firstSignificantOpcode): Got rid of the use of OP_lengths, which is very lightly used here. Hard-coded the length of OP_BRANUMBER. (firstSignificantOpcodeSkippingAssertions): Ditto. Also changed to use the advanceToEndOfBracket function. (getOthercaseRange): Name changes. (encodeUTF8): Ditto. (compileBranch): Name changes. Removed unused after_manual_callout and the code to handle it. Removed code to handle OP_ONCE since we never emit this opcode. Changed to use advanceToEndOfBracket in more places. (compileBracket): Name changes. (branchIsAnchored): Removed code to handle OP_ONCE since we never emit this opcode. (bracketIsAnchored): Name changes. (branchNeedsLineStart): More fo the same. (bracketNeedsLineStart): Ditto. (branchFindFirstAssertedCharacter): Removed OP_ONCE code. (bracketFindFirstAssertedCharacter): More of the same. (calculateCompiledPatternLengthAndFlags): Ditto. (returnError): Name changes. (jsRegExpCompile): Ditto.
  • pcre/pcre_exec.cpp: Moved some definitions here from pcre_internal.h. (matchRef): Updated names. Improved macros to use the do { } while(0) idiom so they expand to single statements rather than to blocks or multiple statements. And refeactored the recursive match macros. (MatchStack::pushNewFrame): Name changes. (getUTF8CharAndIncrementLength): Name changes. (match): Name changes. Removed the ONCE opcode. (jsRegExpExecute): Name changes.
  • pcre/pcre_internal.h: Removed quite a few unneeded includes. Rewrote quite a few comments. Removed the macros that add kjs prefixes to the functions with external linkage; instead renamed the functions. Removed the unneeded typedefs pcre_uint16, pcre_uint32, and uschar. Removed the dead and not-all-working code for LINK_SIZE values other than 2, although we aim to keep the abstraction working. Removed the OP_LENGTHS macro. (put2ByteValue): Replaces put2ByteOpcodeValueAtOffset. (get2ByteValue): Replaces get2ByteOpcodeValueAtOffset. (put2ByteValueAndAdvance): Replaces put2ByteOpcodeValueAtOffsetAndAdvance. (putLinkValueAllowZero): Replaces putOpcodeValueAtOffset; doesn't do the addition, since a comma is really no better than a plus sign. Added an assertion to catch out of range values and changed the parameter type to int rather than unsigned. (getLinkValueAllowZero): Replaces getOpcodeValueAtOffset. (putLinkValue): New function that most former callers of the putOpcodeValueAtOffset function can use; asserts the value that is being stored is non-zero and then calls putLinkValueAllowZero. (getLinkValue): Ditto. (putLinkValueAndAdvance): Replaces putOpcodeValueAtOffsetAndAdvance. No caller was using an offset, which makes sense given the advancing behavior. (putLinkValueAllowZeroAndAdvance): Ditto. (isBracketOpcode): Added. For use in an assertion. (advanceToEndOfBracket): Renamed from moveOpcodePtrPastAnyAlternateBranches, and removed comments about how it's not well designed. This function takes a pointer to the beginning of a bracket and advances to the end of the bracket.
  • pcre/pcre_tables.cpp: Updated names.
  • pcre/pcre_ucp_searchfuncs.cpp: (kjs_pcre_ucp_othercase): Ditto.
  • pcre/pcre_xclass.cpp: (getUTF8CharAndAdvancePointer): Ditto. (kjs_pcre_xclass): Ditto.
  • pcre/ucpinternal.h: Ditto.
  • wtf/ASCIICType.h: (WTF::isASCIIAlpha): Added an int overload, like the one we already have for isASCIIDigit. (WTF::isASCIIAlphanumeric): Ditto. (WTF::isASCIIHexDigit): Ditto. (WTF::isASCIILower): Ditto. (WTF::isASCIISpace): Ditto. (WTF::toASCIILower): Ditto. (WTF::toASCIIUpper): Ditto.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/pcre/pcre_compile.cpp

    r28785 r28793  
    5151using namespace WTF;
    5252
     53/* Negative values for the firstchar and reqchar variables */
     54
     55#define REQ_UNSET (-2)
     56#define REQ_NONE  (-1)
     57
    5358/*************************************************
    5459*      Code parameters and static tables         *
     
    8994};
    9095
    91 /* Table of sizes for the fixed-length opcodes. It's defined in a macro so that
    92 the definition is next to the definition of the opcodes in pcre_internal.h. */
    93 
    94 static const uschar OP_lengths[] = { OP_LENGTHS };
    95 
    9696/* The texts of compile-time error messages. These are "char *" because they
    9797are passed to the outside world. */
    9898
    99 static const char* error_text(ErrorCode code)
     99static const char* errorText(ErrorCode code)
    100100{
    101     static const char error_texts[] =
     101    static const char errorTexts[] =
    102102      /* 1 */
    103103      "\\ at end of pattern\0"
     
    124124
    125125    int i = code;
    126     const char* text = error_texts;
     126    const char* text = errorTexts;
    127127    while (i > 1)
    128128        i -= !*text++;
     
    142142        needOuterBracket = false;
    143143    }
    144     const uschar* start_code;   /* The start of the compiled code */
     144    const unsigned char* start_code;   /* The start of the compiled code */
    145145    const UChar* start_pattern; /* The start of the pattern */
    146146    int top_backref;            /* Maximum back reference */
     
    152152/* Definitions to allow mutual recursion */
    153153
    154 static bool compileBracket(int, int*, uschar**, const UChar**, const UChar*, ErrorCode*, int, int*, int*, CompileData&);
    155 static bool bracketIsAnchored(const uschar* code);
    156 static bool bracketNeedsLineStart(const uschar* code, unsigned captureMap, unsigned backrefMap);
    157 static int bracketFindFirstAssertedCharacter(const uschar* code, bool inassert);
     154static bool compileBracket(int, int*, unsigned char**, const UChar**, const UChar*, ErrorCode*, int, int*, int*, CompileData&);
     155static bool bracketIsAnchored(const unsigned char* code);
     156static bool bracketNeedsLineStart(const unsigned char* code, unsigned captureMap, unsigned backrefMap);
     157static int bracketFindFirstAssertedCharacter(const unsigned char* code, bool inassert);
    158158
    159159/*************************************************
     
    179179*/
    180180
    181 static int check_escape(const UChar** ptrptr, const UChar* patternEnd, ErrorCode* errorcodeptr, int bracount, bool isclass)
     181static int checkEscape(const UChar** ptrptr, const UChar* patternEnd, ErrorCode* errorcodeptr, int bracount, bool isclass)
    182182{
    183183    const UChar* ptr = *ptrptr + 1;
     
    209209    } else {
    210210        switch (c) {
    211         case '1':
    212         case '2':
    213         case '3':
    214         case '4':
    215         case '5':
    216         case '6':
    217         case '7':
    218         case '8':
    219         case '9':
    220             /* Escape sequences starting with a non-zero digit are backreferences,
    221              unless there are insufficient brackets, in which case they are octal
    222              escape sequences. Those sequences end on the first non-octal character
    223              or when we overflow 0-255, whichever comes first. */
    224            
    225             if (!isclass) {
    226                 const UChar* oldptr = ptr;
    227                 c -= '0';
    228                 while ((ptr + 1 < patternEnd) && isASCIIDigit(ptr[1]) && c <= bracount)
    229                     c = c * 10 + *(++ptr) - '0';
    230                 if (c <= bracount) {
    231                     c = -(ESC_REF + c);
     211            case '1':
     212            case '2':
     213            case '3':
     214            case '4':
     215            case '5':
     216            case '6':
     217            case '7':
     218            case '8':
     219            case '9':
     220                /* Escape sequences starting with a non-zero digit are backreferences,
     221                 unless there are insufficient brackets, in which case they are octal
     222                 escape sequences. Those sequences end on the first non-octal character
     223                 or when we overflow 0-255, whichever comes first. */
     224               
     225                if (!isclass) {
     226                    const UChar* oldptr = ptr;
     227                    c -= '0';
     228                    while ((ptr + 1 < patternEnd) && isASCIIDigit(ptr[1]) && c <= bracount)
     229                        c = c * 10 + *(++ptr) - '0';
     230                    if (c <= bracount) {
     231                        c = -(ESC_REF + c);
     232                        break;
     233                    }
     234                    ptr = oldptr;      /* Put the pointer back and fall through */
     235                }
     236               
     237                /* Handle an octal number following \. If the first digit is 8 or 9,
     238                 this is not octal. */
     239               
     240                if ((c = *ptr) >= '8')
    232241                    break;
    233                 }
    234                 ptr = oldptr;      /* Put the pointer back and fall through */
    235             }
    236            
    237             /* Handle an octal number following \. If the first digit is 8 or 9,
    238              this is not octal. */
    239            
    240             if ((c = *ptr) >= '8')
    241                 break;
    242            
     242
    243243            /* \0 always starts an octal number, but we may drop through to here with a
    244244             larger first octal digit. */
    245        
    246         case '0': {
    247             c -= '0';
    248             int i;
    249             for (i = 1; i <= 2; ++i) {
    250                 if (ptr + i >= patternEnd || ptr[i] < '0' || ptr[i] > '7')
    251                     break;
    252                 int cc = c * 8 + ptr[i] - '0';
    253                 if (cc > 255)
    254                     break;
    255                 c = cc;
     245
     246            case '0': {
     247                c -= '0';
     248                int i;
     249                for (i = 1; i <= 2; ++i) {
     250                    if (ptr + i >= patternEnd || ptr[i] < '0' || ptr[i] > '7')
     251                        break;
     252                    int cc = c * 8 + ptr[i] - '0';
     253                    if (cc > 255)
     254                        break;
     255                    c = cc;
     256                }
     257                ptr += i - 1;
     258                break;
    256259            }
    257             ptr += i - 1;
    258             break;
    259         }
    260         case 'x': {
    261             c = 0;
    262             int i;
    263             for (i = 1; i <= 2; ++i) {
    264                 if (ptr + i >= patternEnd || !isASCIIHexDigit(ptr[i])) {
    265                     c = 'x';
    266                     i = 1;
    267                     break;
    268                 }
    269                 int cc = ptr[i];
    270                 if (cc >= 'a')
    271                     cc -= 32;             /* Convert to upper case */
    272                 c = c * 16 + cc - ((cc < 'A') ? '0' : ('A' - 10));
     260
     261            case 'x': {
     262                c = 0;
     263                int i;
     264                for (i = 1; i <= 2; ++i) {
     265                    if (ptr + i >= patternEnd || !isASCIIHexDigit(ptr[i])) {
     266                        c = 'x';
     267                        i = 1;
     268                        break;
     269                    }
     270                    int cc = ptr[i];
     271                    if (cc >= 'a')
     272                        cc -= 32;             /* Convert to upper case */
     273                    c = c * 16 + cc - ((cc < 'A') ? '0' : ('A' - 10));
     274                }
     275                ptr += i - 1;
     276                break;
    273277            }
    274             ptr += i - 1;
    275             break;
    276         }
    277         case 'u': {
    278             c = 0;
    279             int i;
    280             for (i = 1; i <= 4; ++i) {
    281                 if (ptr + i >= patternEnd || !isASCIIHexDigit(ptr[i])) {
    282                     c = 'u';
    283                     i = 1;
    284                     break;
    285                 }
    286                 int cc = ptr[i];
    287                 if (cc >= 'a')
    288                     cc -= 32;             /* Convert to upper case */
    289                 c = c * 16 + cc - ((cc < 'A') ? '0' : ('A' - 10));
     278
     279            case 'u': {
     280                c = 0;
     281                int i;
     282                for (i = 1; i <= 4; ++i) {
     283                    if (ptr + i >= patternEnd || !isASCIIHexDigit(ptr[i])) {
     284                        c = 'u';
     285                        i = 1;
     286                        break;
     287                    }
     288                    int cc = ptr[i];
     289                    if (cc >= 'a')
     290                        cc -= 32;             /* Convert to upper case */
     291                    c = c * 16 + cc - ((cc < 'A') ? '0' : ('A' - 10));
     292                }
     293                ptr += i - 1;
     294                break;
    290295            }
    291             ptr += i - 1;
    292             break;
    293            
    294             /* Other special escapes not starting with a digit are straightforward */
    295         }
    296         case 'c':
    297             if (++ptr == patternEnd) {
    298                 *errorcodeptr = ERR2;
    299                 return 0;
     296
     297            case 'c':
     298                if (++ptr == patternEnd) {
     299                    *errorcodeptr = ERR2;
     300                    return 0;
     301                }
     302                c = *ptr;
     303               
     304                /* A letter is upper-cased; then the 0x40 bit is flipped. This coding
     305                 is ASCII-specific, but then the whole concept of \cx is ASCII-specific. */
     306                c = toASCIIUpper(c) ^ 0x40;
     307                break;
    300308            }
    301             c = *ptr;
    302            
    303             /* A letter is upper-cased; then the 0x40 bit is flipped. This coding
    304              is ASCII-specific, but then the whole concept of \cx is ASCII-specific. */
    305            
    306             if (c >= 'a' && c <= 'z')
    307                 c -= 32;
    308             c ^= 0x40;
    309             break;
    310         }
    311309    }
    312310   
     
    314312    return c;
    315313}
    316 
    317 
    318314
    319315/*************************************************
     
    332328*/
    333329
    334 static bool is_counted_repeat(const UChar* p, const UChar* patternEnd)
     330static bool isCountedRepeat(const UChar* p, const UChar* patternEnd)
    335331{
    336332    if (p >= patternEnd || !isASCIIDigit(*p))
     
    356352}
    357353
    358 
    359354/*************************************************
    360355*         Read repeat counts                     *
     
    362357
    363358/* Read an item of the form {n,m} and return the values. This is called only
    364 after is_counted_repeat() has confirmed that a repeat-count quantifier exists,
     359after isCountedRepeat() has confirmed that a repeat-count quantifier exists,
    365360so the syntax is guaranteed to be correct, but we need to check the values.
    366361
     
    376371*/
    377372
    378 static const UChar* read_repeat_counts(const UChar* p, int* minp, int* maxp, ErrorCode* errorcodeptr)
     373static const UChar* readRepeatCounts(const UChar* p, int* minp, int* maxp, ErrorCode* errorcodeptr)
    379374{
    380375    int min = 0;
     
    420415}
    421416
    422 
    423417/*************************************************
    424418*      Find first significant op code            *
     
    427421/* This is called by several functions that scan a compiled expression looking
    428422for a fixed first character, or an anchoring op code etc. It skips over things
    429 that do not influence this. For some calls, a change of option is important.
    430 For some calls, it makes sense to skip negative forward and all backward
    431 assertions, and also the \b assertion; for others it does not.
     423that do not influence this.
    432424
    433425Arguments:
    434426  code         pointer to the start of the group
    435   skipassert   true if certain assertions are to be skipped
    436 
    437427Returns:       pointer to the first significant opcode
    438428*/
    439429
    440 static const uschar* firstSignificantOpCode(const uschar* code)
     430static const unsigned char* firstSignificantOpcode(const unsigned char* code)
    441431{
    442432    while (*code == OP_BRANUMBER)
    443         code += OP_lengths[*code];
     433        code += 3;
    444434    return code;
    445435}
    446436
    447 static const uschar* firstSignificantOpCodeSkippingAssertions(const uschar* code)
     437static const unsigned char* firstSignificantOpcodeSkippingAssertions(const unsigned char* code)
    448438{
    449439    while (true) {
    450440        switch (*code) {
    451         case OP_ASSERT_NOT:
    452             do {
    453                 code += getOpcodeValueAtOffset(code, 1);
    454             } while (*code == OP_ALT);
    455             code += OP_lengths[*code];
    456             break;
    457         case OP_WORD_BOUNDARY:
    458         case OP_NOT_WORD_BOUNDARY:
    459         case OP_BRANUMBER:
    460             code += OP_lengths[*code];
    461             break;
    462         default:
    463             return code;
     441            case OP_ASSERT_NOT:
     442                advanceToEndOfBracket(code);
     443                code += 1 + LINK_SIZE;
     444                break;
     445            case OP_WORD_BOUNDARY:
     446            case OP_NOT_WORD_BOUNDARY:
     447                ++code;
     448                break;
     449            case OP_BRANUMBER:
     450                code += 3;
     451                break;
     452            default:
     453                return code;
    464454        }
    465455    }
    466     ASSERT_NOT_REACHED();
    467456}
    468 
    469 
    470 /*************************************************
    471 *        Find the fixed length of a pattern      *
    472 *************************************************/
    473 
    474 /* Scan a pattern and compute the fixed length of subject that will match it,
    475 if the length is fixed. This is needed for dealing with backward assertions.
    476 In UTF8 mode, the result is in characters rather than bytes.
    477 
    478 Arguments:
    479   code     points to the start of the pattern (the bracket)
    480   options  the compiling options
    481 
    482 Returns:   the fixed length, or -1 if there is no fixed length,
    483              or -2 if \C was encountered
    484 */
    485 
    486 static int find_fixedlength(uschar* code, int options)
    487 {
    488     int length = -1;
    489    
    490     int branchlength = 0;
    491     uschar* cc = code + 1 + LINK_SIZE;
    492    
    493     /* Scan along the opcodes for this branch. If we get to the end of the
    494      branch, check the length against that of the other branches. */
    495    
    496     while (true) {
    497         int d;
    498         int op = *cc;
    499         if (op >= OP_BRA)
    500             op = OP_BRA;
    501        
    502         switch (op) {
    503             case OP_BRA:
    504             case OP_ONCE:
    505                 d = find_fixedlength(cc, options);
    506                 if (d < 0)
    507                     return d;
    508                 branchlength += d;
    509                 do {
    510                     cc += getOpcodeValueAtOffset(cc, 1);
    511                 } while (*cc == OP_ALT);
    512                 cc += 1 + LINK_SIZE;
    513                 break;
    514                
    515                 /* Reached end of a branch; if it's a ket it is the end of a nested
    516                  call. If it's ALT it is an alternation in a nested call. If it is
    517                  END it's the end of the outer call. All can be handled by the same code. */
    518                
    519             case OP_ALT:
    520             case OP_KET:
    521             case OP_KETRMAX:
    522             case OP_KETRMIN:
    523             case OP_END:
    524                 if (length < 0)
    525                     length = branchlength;
    526                 else if (length != branchlength)
    527                     return -1;
    528                 if (*cc != OP_ALT)
    529                     return length;
    530                 cc += 1 + LINK_SIZE;
    531                 branchlength = 0;
    532                 break;
    533                
    534                 /* Skip over assertive subpatterns */
    535                
    536             case OP_ASSERT:
    537             case OP_ASSERT_NOT:
    538                 do {
    539                     cc += getOpcodeValueAtOffset(cc, 1);
    540                 } while (*cc == OP_ALT);
    541                 /* Fall through */
    542                
    543                 /* Skip over things that don't match chars */
    544                
    545             case OP_BRANUMBER:
    546             case OP_CIRC:
    547             case OP_DOLL:
    548             case OP_NOT_WORD_BOUNDARY:
    549             case OP_WORD_BOUNDARY:
    550                 cc += OP_lengths[*cc];
    551                 break;
    552                
    553                 /* Handle literal characters */
    554                
    555             case OP_CHAR:
    556             case OP_CHAR_IGNORING_CASE:
    557             case OP_NOT:
    558                 branchlength++;
    559                 cc += 2;
    560                 while ((*cc & 0xc0) == 0x80)
    561                     cc++;
    562                 break;
    563                
    564             case OP_ASCII_CHAR:
    565             case OP_ASCII_LETTER_IGNORING_CASE:
    566                 branchlength++;
    567                 cc += 2;
    568                 break;
    569                
    570                 /* Handle exact repetitions. The count is already in characters, but we
    571                  need to skip over a multibyte character in UTF8 mode.  */
    572                
    573             case OP_EXACT:
    574                 branchlength += get2ByteOpcodeValueAtOffset(cc,1);
    575                 cc += 4;
    576                 while((*cc & 0x80) == 0x80)
    577                     cc++;
    578                 break;
    579                
    580             case OP_TYPEEXACT:
    581                 branchlength += get2ByteOpcodeValueAtOffset(cc,1);
    582                 cc += 4;
    583                 break;
    584                
    585                 /* Handle single-char matchers */
    586                
    587             case OP_NOT_DIGIT:
    588             case OP_DIGIT:
    589             case OP_NOT_WHITESPACE:
    590             case OP_WHITESPACE:
    591             case OP_NOT_WORDCHAR:
    592             case OP_WORDCHAR:
    593             case OP_NOT_NEWLINE:
    594                 branchlength++;
    595                 cc++;
    596                 break;
    597                
    598                 /* Check a class for variable quantification */
    599                
    600             case OP_XCLASS:
    601                 cc += getOpcodeValueAtOffset(cc, 1) - 33;
    602                 /* Fall through */
    603                
    604             case OP_CLASS:
    605             case OP_NCLASS:
    606                 cc += 33;
    607                
    608                 switch (*cc) {
    609                 case OP_CRSTAR:
    610                 case OP_CRMINSTAR:
    611                 case OP_CRQUERY:
    612                 case OP_CRMINQUERY:
    613                     return -1;
    614                    
    615                 case OP_CRRANGE:
    616                 case OP_CRMINRANGE:
    617                     if (get2ByteOpcodeValueAtOffset(cc, 1) != get2ByteOpcodeValueAtOffset(cc, 3))
    618                         return -1;
    619                     branchlength += get2ByteOpcodeValueAtOffset(cc, 1);
    620                     cc += 5;
    621                     break;
    622                    
    623                 default:
    624                     branchlength++;
    625                 }
    626                 break;
    627                
    628                 /* Anything else is variable length */
    629                
    630             default:
    631                 return -1;
    632         }
    633     }
    634     ASSERT_NOT_REACHED();
    635 }
    636 
    637 
    638 /*************************************************
    639 *         Complete a callout item                *
    640 *************************************************/
    641 
    642 /* A callout item contains the length of the next item in the pattern, which
    643 we can't fill in till after we have reached the relevant point. This is used
    644 for both automatic and manual callouts.
    645 
    646 Arguments:
    647   previous_callout   points to previous callout item
    648   ptr                current pattern pointer
    649   cd                 pointers to tables etc
    650 */
    651 
    652 static void complete_callout(uschar* previous_callout, const UChar* ptr, const CompileData& cd)
    653 {
    654     int length = ptr - cd.start_pattern - getOpcodeValueAtOffset(previous_callout, 2);
    655     putOpcodeValueAtOffset(previous_callout, 2 + LINK_SIZE, length);
    656 }
    657 
    658 
    659457
    660458/*************************************************
     
    676474*/
    677475
    678 static bool get_othercase_range(int* cptr, int d, int* ocptr, int* odptr)
     476static bool getOthercaseRange(int* cptr, int d, int* ocptr, int* odptr)
    679477{
    680478    int c, othercase = 0;
    681479   
    682480    for (c = *cptr; c <= d; c++) {
    683         if ((othercase = _pcre_ucp_othercase(c)) >= 0)
     481        if ((othercase = kjs_pcre_ucp_othercase(c)) >= 0)
    684482            break;
    685483    }
     
    692490   
    693491    for (++c; c <= d; c++) {
    694         if (_pcre_ucp_othercase(c) != next)
     492        if (kjs_pcre_ucp_othercase(c) != next)
    695493            break;
    696494        next++;
     
    717515 */
    718516
    719 // FIXME: This should be removed as soon as all UTF8 uses are removed from PCRE
    720 int _pcre_ord2utf8(int cvalue, uschar *buffer)
     517static int encodeUTF8(int cvalue, unsigned char *buffer)
    721518{
    722519    int i;
    723     for (i = 0; i < _pcre_utf8_table1_size; i++)
    724         if (cvalue <= _pcre_utf8_table1[i])
     520    for (i = 0; i < kjs_pcre_utf8_table1_size; i++)
     521        if (cvalue <= kjs_pcre_utf8_table1[i])
    725522            break;
    726523    buffer += i;
     
    729526        cvalue >>= 6;
    730527    }
    731     *buffer = _pcre_utf8_table2[i] | cvalue;
     528    *buffer = kjs_pcre_utf8_table2[i] | cvalue;
    732529    return i + 1;
    733530}
     
    759556
    760557static bool
    761 compileBranch(int options, int* brackets, uschar** codeptr,
     558compileBranch(int options, int* brackets, unsigned char** codeptr,
    762559               const UChar** ptrptr, const UChar* patternEnd, ErrorCode* errorcodeptr, int *firstbyteptr,
    763560               int* reqbyteptr, CompileData& cd)
     
    767564    int bravalue = 0;
    768565    int reqvary, tempreqvary;
    769     int after_manual_callout = 0;
    770566    int c;
    771     uschar* code = *codeptr;
    772     uschar* tempcode;
     567    unsigned char* code = *codeptr;
     568    unsigned char* tempcode;
    773569    bool groupsetfirstbyte = false;
    774570    const UChar* ptr = *ptrptr;
    775571    const UChar* tempptr;
    776     uschar* previous = NULL;
    777     uschar* previous_callout = NULL;
    778     uschar classbits[32];
     572    unsigned char* previous = NULL;
     573    unsigned char classbits[32];
    779574   
    780575    bool class_utf8;
    781     uschar* class_utf8data;
    782     uschar utf8_char[6];
     576    unsigned char* class_utf8data;
     577    unsigned char utf8_char[6];
    783578   
    784579    /* Initialize no first byte, no required byte. REQ_UNSET means "no char
     
    815610        int subfirstbyte;
    816611        int mclength;
    817         uschar mcbuffer[8];
     612        unsigned char mcbuffer[8];
    818613       
    819614        /* Next byte in the pattern */
     
    824619         a quantifier. */
    825620       
    826         bool is_quantifier = c == '*' || c == '+' || c == '?' || (c == '{' && is_counted_repeat(ptr + 1, patternEnd));
    827        
    828         if (!is_quantifier && previous_callout && after_manual_callout-- <= 0) {
    829             complete_callout(previous_callout, ptr, cd);
    830             previous_callout = NULL;
    831         }
     621        bool is_quantifier = c == '*' || c == '+' || c == '?' || (c == '{' && isCountedRepeat(ptr + 1, patternEnd));
    832622       
    833623        switch (c) {
     
    922712                 bit map. */
    923713               
    924                 memset(classbits, 0, 32 * sizeof(uschar));
     714                memset(classbits, 0, 32 * sizeof(unsigned char));
    925715               
    926716                /* Process characters until ] is reached. The first pass
     
    939729                   
    940730                    if (c == '\\') {
    941                         c = check_escape(&ptr, patternEnd, errorcodeptr, *brackets, true);
     731                        c = checkEscape(&ptr, patternEnd, errorcodeptr, *brackets, true);
    942732                        if (c < 0) {
    943733                            class_charcount += 2;     /* Greater than 1 is what matters */
     
    1006796                        if (d == '\\') {
    1007797                            const UChar* oldptr = ptr;
    1008                             d = check_escape(&ptr, patternEnd, errorcodeptr, *brackets, true);
     798                            d = checkEscape(&ptr, patternEnd, errorcodeptr, *brackets, true);
    1009799                           
    1010800                            /* \X is literal X; any other special means the '-' was literal */
     
    1037827                                int cc = c;
    1038828                                int origd = d;
    1039                                 while (get_othercase_range(&cc, origd, &occ, &ocd)) {
     829                                while (getOthercaseRange(&cc, origd, &occ, &ocd)) {
    1040830                                    if (occ >= c && ocd <= d)
    1041831                                        continue;  /* Skip embedded ranges */
     
    1056846                                    else {
    1057847                                        *class_utf8data++ = XCL_RANGE;
    1058                                         class_utf8data += _pcre_ord2utf8(occ, class_utf8data);
     848                                        class_utf8data += encodeUTF8(occ, class_utf8data);
    1059849                                    }
    1060                                     class_utf8data += _pcre_ord2utf8(ocd, class_utf8data);
     850                                    class_utf8data += encodeUTF8(ocd, class_utf8data);
    1061851                                }
    1062852                            }
     
    1066856                           
    1067857                            *class_utf8data++ = XCL_RANGE;
    1068                             class_utf8data += _pcre_ord2utf8(c, class_utf8data);
    1069                             class_utf8data += _pcre_ord2utf8(d, class_utf8data);
     858                            class_utf8data += encodeUTF8(c, class_utf8data);
     859                            class_utf8data += encodeUTF8(d, class_utf8data);
    1070860                           
    1071861                            /* With UCP support, we are done. Without UCP support, there is no
     
    1104894                        class_utf8 = true;
    1105895                        *class_utf8data++ = XCL_SINGLE;
    1106                         class_utf8data += _pcre_ord2utf8(c, class_utf8data);
     896                        class_utf8data += encodeUTF8(c, class_utf8data);
    1107897                       
    1108898                        if (options & IgnoreCaseOption) {
    1109899                            int othercase;
    1110                             if ((othercase = _pcre_ucp_othercase(c)) >= 0) {
     900                            if ((othercase = kjs_pcre_ucp_othercase(c)) >= 0) {
    1111901                                *class_utf8data++ = XCL_SINGLE;
    1112                                 class_utf8data += _pcre_ord2utf8(othercase, class_utf8data);
     902                                class_utf8data += encodeUTF8(othercase, class_utf8data);
    1113903                            }
    1114904                        }
     
    1198988                    /* Now fill in the complete length of the item */
    1199989                   
    1200                     putOpcodeValueAtOffset(previous, 1, code - previous);
     990                    putLinkValue(previous + 1, code - previous);
    1201991                    break;   /* End of class handling */
    1202992                }
     
    12231013                if (!is_quantifier)
    12241014                    goto NORMAL_CHAR;
    1225                 ptr = read_repeat_counts(ptr+1, &repeat_min, &repeat_max, errorcodeptr);
     1015                ptr = readRepeatCounts(ptr + 1, &repeat_min, &repeat_max, errorcodeptr);
    12261016                if (*errorcodeptr)
    12271017                    goto FAILED;
     
    12611051                /* Save start of previous item, in case we have to move it up to make space
    12621052                 for an inserted OP_ONCE for the additional '+' extension. */
     1053                /* FIXME: Probably don't need this because we don't use OP_ONCE. */
    12631054               
    12641055                tempcode = previous;
     
    12891080                   
    12901081                    if (code[-1] & 0x80) {
    1291                         uschar *lastchar = code - 1;
     1082                        unsigned char *lastchar = code - 1;
    12921083                        while((*lastchar & 0xc0) == 0x80)
    12931084                            lastchar--;
     
    13351126                    int prop_value = -1;
    13361127                   
    1337                     uschar* oldcode = code;
     1128                    unsigned char* oldcode = code;
    13381129                    code = previous;                  /* Usually overwrite previous item */
    13391130                   
     
    13581149                        else {
    13591150                            *code++ = OP_UPTO + repeat_type;
    1360                             put2ByteOpcodeValueAtOffsetAndAdvance(code, 0, repeat_max);
     1151                            put2ByteValueAndAdvance(code, repeat_max);
    13611152                        }
    13621153                    }
     
    13751166                                goto END_REPEAT;
    13761167                            *code++ = OP_UPTO + repeat_type;
    1377                             put2ByteOpcodeValueAtOffsetAndAdvance(code, 0, repeat_max - 1);
     1168                            put2ByteValueAndAdvance(code, repeat_max - 1);
    13781169                        }
    13791170                    }
     
    13841175                    else {
    13851176                        *code++ = OP_EXACT + op_type;  /* NB EXACT doesn't have repeat_type */
    1386                         put2ByteOpcodeValueAtOffsetAndAdvance(code, 0, repeat_min);
     1177                        put2ByteValueAndAdvance(code, repeat_min);
    13871178                       
    13881179                        /* If the maximum is unlimited, insert an OP_STAR. Before doing so,
     
    14211212                            repeat_max -= repeat_min;
    14221213                            *code++ = OP_UPTO + repeat_type;
    1423                             put2ByteOpcodeValueAtOffsetAndAdvance(code, 0, repeat_max);
     1214                            put2ByteValueAndAdvance(code, repeat_max);
    14241215                        }
    14251216                    }
     
    14631254                    else {
    14641255                        *code++ = OP_CRRANGE + repeat_type;
    1465                         put2ByteOpcodeValueAtOffsetAndAdvance(code, 0, repeat_min);
     1256                        put2ByteValueAndAdvance(code, repeat_min);
    14661257                        if (repeat_max == -1)
    14671258                            repeat_max = 0;  /* 2-byte encoding for max */
    1468                         put2ByteOpcodeValueAtOffsetAndAdvance(code, 0, repeat_max);
     1259                        put2ByteValueAndAdvance(code, repeat_max);
    14691260                    }
    14701261                }
     
    14731264                 cases. */
    14741265               
    1475                 else if (*previous >= OP_BRA || *previous == OP_ONCE) {
     1266                else if (*previous >= OP_BRA) {
    14761267                    int ketoffset = 0;
    14771268                    int len = code - previous;
    1478                     uschar* bralink = NULL;
     1269                    unsigned char* bralink = NULL;
    14791270                   
    14801271                    /* If the maximum repeat count is unlimited, find the end of the bracket
     
    14851276                   
    14861277                    if (repeat_max == -1) {
    1487                         uschar* ket = previous;
    1488                         do {
    1489                             ket += getOpcodeValueAtOffset(ket, 1);
    1490                         } while (*ket != OP_KET);
     1278                        const unsigned char* ket = previous;
     1279                        advanceToEndOfBracket(ket);
    14911280                        ketoffset = code - ket;
    14921281                    }
     
    15401329                            int offset = (!bralink) ? 0 : previous - bralink;
    15411330                            bralink = previous;
    1542                             putOpcodeValueAtOffsetAndAdvance(previous, 0, offset);
     1331                            putLinkValueAllowZeroAndAdvance(previous, offset);
    15431332                        }
    15441333                       
     
    15811370                                int offset = (!bralink) ? 0 : code - bralink;
    15821371                                bralink = code;
    1583                                 putOpcodeValueAtOffsetAndAdvance(code, 0, offset);
     1372                                putLinkValueAllowZeroAndAdvance(code, offset);
    15841373                            }
    15851374                           
     
    15931382                        while (bralink) {
    15941383                            int offset = code - bralink + 1;
    1595                             uschar* bra = code - offset;
    1596                             int oldlinkoffset = getOpcodeValueAtOffset(bra, 1);
    1597                             bralink = oldlinkoffset ? bralink - oldlinkoffset : 0;
     1384                            unsigned char* bra = code - offset;
     1385                            int oldlinkoffset = getLinkValueAllowZero(bra + 1);
     1386                            bralink = (!oldlinkoffset) ? 0 : bralink - oldlinkoffset;
    15981387                            *code++ = OP_KET;
    1599                             putOpcodeValueAtOffsetAndAdvance(code, 0, offset);
    1600                             putOpcodeValueAtOffset(bra, 1, offset);
     1388                            putLinkValueAndAdvance(code, offset);
     1389                            putLinkValue(bra + 1, offset);
    16011390                        }
    16021391                    }
     
    16391428                if (*(++ptr) == '?') {
    16401429                    switch (*(++ptr)) {
    1641                     case ':':                 /* Non-extracting bracket */
    1642                         bravalue = OP_BRA;
    1643                         ptr++;
    1644                         break;
    1645                        
    1646                     case '=':                 /* Positive lookahead */
    1647                         bravalue = OP_ASSERT;
    1648                         ptr++;
    1649                         break;
    1650                        
    1651                     case '!':                 /* Negative lookahead */
    1652                         bravalue = OP_ASSERT_NOT;
    1653                         ptr++;
    1654                         break;
    1655                        
     1430                        case ':':                 /* Non-extracting bracket */
     1431                            bravalue = OP_BRA;
     1432                            ptr++;
     1433                            break;
     1434                           
     1435                        case '=':                 /* Positive lookahead */
     1436                            bravalue = OP_ASSERT;
     1437                            ptr++;
     1438                            break;
     1439                           
     1440                        case '!':                 /* Negative lookahead */
     1441                            bravalue = OP_ASSERT_NOT;
     1442                            ptr++;
     1443                            break;
     1444                           
    16561445                        /* Character after (? not specially recognized */
    1657                        
    1658                     default:                  /* Option setting */
    1659                         *errorcodeptr = ERR12;
    1660                         goto FAILED;
    1661                     }
     1446                           
     1447                        default:
     1448                            *errorcodeptr = ERR12;
     1449                            goto FAILED;
     1450                        }
    16621451                }
    16631452               
     
    16701459                        bravalue = OP_BRA + EXTRACT_BASIC_MAX + 1;
    16711460                        code[1 + LINK_SIZE] = OP_BRANUMBER;
    1672                         put2ByteOpcodeValueAtOffset(code, 2+LINK_SIZE, *brackets);
     1461                        put2ByteValue(code + 2 + LINK_SIZE, *brackets);
    16731462                        skipbytes = 3;
    16741463                    }
     
    16821471                 new setting for the ims options if they have changed. */
    16831472               
    1684                 previous = (bravalue >= OP_ONCE) ? code : 0;
     1473                previous = (bravalue >= OP_BRAZERO) ? code : 0;
    16851474                *code = bravalue;
    16861475                tempcode = code;
     
    17151504                groupsetfirstbyte = false;
    17161505               
    1717                 if (bravalue >= OP_BRA || bravalue == OP_ONCE) {
     1506                if (bravalue >= OP_BRA) {
    17181507                    /* If we have not yet set a firstbyte in this branch, take it from the
    17191508                     subpattern, remembering that it was set here so that a repeat of more
     
    17751564            case '\\':
    17761565                tempptr = ptr;
    1777                 c = check_escape(&ptr, patternEnd, errorcodeptr, *brackets, false);
     1566                c = checkEscape(&ptr, patternEnd, errorcodeptr, *brackets, false);
    17781567               
    17791568                /* Handle metacharacters introduced by \. For ones like \d, the ESC_ values
     
    18021591                        previous = code;
    18031592                        *code++ = OP_REF;
    1804                         put2ByteOpcodeValueAtOffsetAndAdvance(code, 0, number);
     1593                        put2ByteValueAndAdvance(code, number);
    18051594                    }
    18061595                   
     
    18381627                    }
    18391628                } else {
    1840                     mclength = _pcre_ord2utf8(c, mcbuffer);
     1629                    mclength = encodeUTF8(c, mcbuffer);
    18411630                   
    18421631                    *code++ = (options & IgnoreCaseOption) ? OP_CHAR_IGNORING_CASE : OP_CHAR;
     
    18881677    return false;
    18891678}
    1890 
    1891 
    1892 
    18931679
    18941680/*************************************************
     
    19191705
    19201706static bool
    1921 compileBracket(int options, int* brackets, uschar** codeptr,
     1707compileBracket(int options, int* brackets, unsigned char** codeptr,
    19221708    const UChar** ptrptr, const UChar* patternEnd, ErrorCode* errorcodeptr, int skipbytes,
    19231709    int* firstbyteptr, int* reqbyteptr, CompileData& cd)
    19241710{
    19251711    const UChar* ptr = *ptrptr;
    1926     uschar* code = *codeptr;
    1927     uschar* last_branch = code;
    1928     uschar* start_bracket = code;
     1712    unsigned char* code = *codeptr;
     1713    unsigned char* last_branch = code;
     1714    unsigned char* start_bracket = code;
    19291715    int firstbyte = REQ_UNSET;
    19301716    int reqbyte = REQ_UNSET;
     
    19321718    /* Offset is set zero to mark that this bracket is still open */
    19331719   
    1934     putOpcodeValueAtOffset(code, 1, 0);
     1720    putLinkValueAllowZero(code + 1, 0);
    19351721    code += 1 + LINK_SIZE + skipbytes;
    19361722   
     
    19981784            int length = code - last_branch;
    19991785            do {
    2000                 int prev_length = getOpcodeValueAtOffset(last_branch, 1);
    2001                 putOpcodeValueAtOffset(last_branch, 1, length);
     1786                int prev_length = getLinkValueAllowZero(last_branch + 1);
     1787                putLinkValue(last_branch + 1, length);
    20021788                length = prev_length;
    20031789                last_branch -= length;
     
    20071793           
    20081794            *code = OP_KET;
    2009             putOpcodeValueAtOffset(code, 1, code - start_bracket);
     1795            putLinkValue(code + 1, code - start_bracket);
    20101796            code += 1 + LINK_SIZE;
    20111797           
     
    20251811       
    20261812        *code = OP_ALT;
    2027         putOpcodeValueAtOffset(code, 1, code - last_branch);
     1813        putLinkValue(code + 1, code - last_branch);
    20281814        last_branch = code;
    20291815        code += 1 + LINK_SIZE;
     
    20321818    ASSERT_NOT_REACHED();
    20331819}
    2034 
    20351820
    20361821/*************************************************
     
    20511836*/
    20521837
    2053 static bool branchIsAnchored(const uschar* code)
     1838static bool branchIsAnchored(const unsigned char* code)
    20541839{
    2055     const uschar* scode = firstSignificantOpCode(code);
     1840    const unsigned char* scode = firstSignificantOpcode(code);
    20561841    int op = *scode;
    20571842
    20581843    /* Brackets */
    2059     if (op >= OP_BRA || op == OP_ASSERT || op == OP_ONCE)
     1844    if (op >= OP_BRA || op == OP_ASSERT)
    20601845        return bracketIsAnchored(scode);
    20611846
     
    20641849}
    20651850
    2066 static bool bracketIsAnchored(const uschar* code)
     1851static bool bracketIsAnchored(const unsigned char* code)
    20671852{
    20681853    do {
    20691854        if (!branchIsAnchored(code + 1 + LINK_SIZE))
    20701855            return false;
    2071         code += getOpcodeValueAtOffset(code, 1);
     1856        code += getLinkValue(code + 1);
    20721857    } while (*code == OP_ALT);   /* Loop for each alternative */
    20731858    return true;
     
    20961881*/
    20971882
    2098 static bool branchNeedsLineStart(const uschar* code, unsigned captureMap, unsigned backrefMap)
     1883static bool branchNeedsLineStart(const unsigned char* code, unsigned captureMap, unsigned backrefMap)
    20991884{
    2100     const uschar* scode = firstSignificantOpCode(code);
     1885    const unsigned char* scode = firstSignificantOpcode(code);
    21011886    int op = *scode;
    21021887   
     
    21051890        int captureNum = op - OP_BRA;
    21061891        if (captureNum > EXTRACT_BASIC_MAX)
    2107             captureNum = get2ByteOpcodeValueAtOffset(scode, 2 + LINK_SIZE);
     1892            captureNum = get2ByteValue(scode + 2 + LINK_SIZE);
    21081893        int bracketMask = (captureNum < 32) ? (1 << captureNum) : 1;
    21091894        return bracketNeedsLineStart(scode, captureMap | bracketMask, backrefMap);
     
    21111896   
    21121897    /* Other brackets */
    2113     if (op == OP_BRA || op == OP_ASSERT || op == OP_ONCE)
     1898    if (op == OP_BRA || op == OP_ASSERT)
    21141899        return bracketNeedsLineStart(scode, captureMap, backrefMap);
    21151900   
     
    21241909}
    21251910
    2126 static bool bracketNeedsLineStart(const uschar* code, unsigned captureMap, unsigned backrefMap)
     1911static bool bracketNeedsLineStart(const unsigned char* code, unsigned captureMap, unsigned backrefMap)
    21271912{
    21281913    do {
    21291914        if (!branchNeedsLineStart(code + 1 + LINK_SIZE, captureMap, backrefMap))
    21301915            return false;
    2131         code += getOpcodeValueAtOffset(code, 1);
     1916        code += getLinkValue(code + 1);
    21321917    } while (*code == OP_ALT);  /* Loop for each alternative */
    21331918    return true;
     
    21541939*/
    21551940
    2156 static int branchFindFirstAssertedCharacter(const uschar* code, bool inassert)
     1941static int branchFindFirstAssertedCharacter(const unsigned char* code, bool inassert)
    21571942{
    2158     const uschar* scode = firstSignificantOpCodeSkippingAssertions(code);
     1943    const unsigned char* scode = firstSignificantOpcodeSkippingAssertions(code);
    21591944    int op = *scode;
    21601945   
     
    21681953        case OP_BRA:
    21691954        case OP_ASSERT:
    2170         case OP_ONCE:
    21711955            return bracketFindFirstAssertedCharacter(scode, op == OP_ASSERT);
    21721956
     
    21871971}
    21881972
    2189 static int bracketFindFirstAssertedCharacter(const uschar* code, bool inassert)
     1973static int bracketFindFirstAssertedCharacter(const unsigned char* code, bool inassert)
    21901974{
    21911975    int c = -1;
     
    21981982        else if (c != d)
    21991983            return -1;
    2200         code += getOpcodeValueAtOffset(code, 1);
     1984        code += getLinkValue(code + 1);
    22011985    } while (*code == OP_ALT);
    22021986    return c;
     
    22182002    unsigned brastackptr = 0;
    22192003    int brastack[BRASTACK_SIZE];
    2220     uschar bralenstack[BRASTACK_SIZE];
     2004    unsigned char bralenstack[BRASTACK_SIZE];
    22212005    int bracount = 0;
    22222006   
     
    22332017
    22342018            case '\\':
    2235                 c = check_escape(&ptr, patternEnd, &errorcode, bracount, false);
     2019                c = checkEscape(&ptr, patternEnd, &errorcode, bracount, false);
    22362020                if (errorcode != 0)
    22372021                    return -1;
     
    22442028                    if (c > 127) {
    22452029                        int i;
    2246                         for (i = 0; i < _pcre_utf8_table1_size; i++)
    2247                             if (c <= _pcre_utf8_table1[i]) break;
     2030                        for (i = 0; i < kjs_pcre_utf8_table1_size; i++)
     2031                            if (c <= kjs_pcre_utf8_table1[i]) break;
    22482032                        length += i;
    22492033                        lastitemlength += i;
     
    22672051                        cd.top_backref = refnum;
    22682052                    length += 2;   /* For single back reference */
    2269                     if (safelyCheckNextChar(ptr, patternEnd, '{') && is_counted_repeat(ptr + 2, patternEnd)) {
    2270                         ptr = read_repeat_counts(ptr + 2, &minRepeats, &maxRepeats, &errorcode);
     2053                    if (safelyCheckNextChar(ptr, patternEnd, '{') && isCountedRepeat(ptr + 2, patternEnd)) {
     2054                        ptr = readRepeatCounts(ptr + 2, &minRepeats, &maxRepeats, &errorcode);
    22712055                        if (errorcode)
    22722056                            return -1;
     
    22992083
    23002084            case '{':
    2301                 if (!is_counted_repeat(ptr+1, patternEnd))
     2085                if (!isCountedRepeat(ptr + 1, patternEnd))
    23022086                    goto NORMAL_CHAR;
    2303                 ptr = read_repeat_counts(ptr+1, &minRepeats, &maxRepeats, &errorcode);
     2087                ptr = readRepeatCounts(ptr + 1, &minRepeats, &maxRepeats, &errorcode);
    23042088                if (errorcode != 0)
    23052089                    return -1;
     
    23662150                   
    23672151                    if (*ptr == '\\') {
    2368                         c = check_escape(&ptr, patternEnd, &errorcode, bracount, true);
     2152                        c = checkEscape(&ptr, patternEnd, &errorcode, bracount, true);
    23692153                        if (errorcode != 0)
    23702154                            return -1;
     
    24012185                            if (safelyCheckNextChar(ptr, patternEnd, '\\')) {
    24022186                                ptr++;
    2403                                 d = check_escape(&ptr, patternEnd, &errorcode, bracount, true);
     2187                                d = checkEscape(&ptr, patternEnd, &errorcode, bracount, true);
    24042188                                if (errorcode != 0)
    24052189                                    return -1;
     
    24222206                           
    24232207                            if ((d > 255 || (ignoreCase && d > 127))) {
    2424                                 uschar buffer[6];
     2208                                unsigned char buffer[6];
    24252209                                if (!class_utf8)         /* Allow for XCLASS overhead */
    24262210                                {
     
    24392223                                    int cc = c;
    24402224                                    int origd = d;
    2441                                     while (get_othercase_range(&cc, origd, &occ, &ocd)) {
     2225                                    while (getOthercaseRange(&cc, origd, &occ, &ocd)) {
    24422226                                        if (occ >= c && ocd <= d)
    24432227                                            continue;   /* Skip embedded */
     
    24562240                                        /* An extra item is needed */
    24572241                                       
    2458                                         length += 1 + _pcre_ord2utf8(occ, buffer) +
    2459                                         ((occ == ocd) ? 0 : _pcre_ord2utf8(ocd, buffer));
     2242                                        length += 1 + encodeUTF8(occ, buffer) +
     2243                                        ((occ == ocd) ? 0 : encodeUTF8(ocd, buffer));
    24602244                                    }
    24612245                                }
     
    24632247                                /* The length of the (possibly extended) range */
    24642248                               
    2465                                 length += 1 + _pcre_ord2utf8(c, buffer) + _pcre_ord2utf8(d, buffer);
     2249                                length += 1 + encodeUTF8(c, buffer) + encodeUTF8(d, buffer);
    24662250                            }
    24672251                           
     
    24752259                        else {
    24762260                            if ((c > 255 || (ignoreCase && c > 127))) {
    2477                                 uschar buffer[6];
     2261                                unsigned char buffer[6];
    24782262                                class_optcount = 10;     /* Ensure > 1 */
    24792263                                if (!class_utf8)         /* Allow for XCLASS overhead */
     
    24822266                                    length += LINK_SIZE + 2;
    24832267                                }
    2484                                 length += (ignoreCase ? 2 : 1) * (1 + _pcre_ord2utf8(c, buffer));
     2268                                length += (ignoreCase ? 2 : 1) * (1 + encodeUTF8(c, buffer));
    24852269                            }
    24862270                        }
     
    25082292                     we also need extra for wrapping the whole thing in a sub-pattern. */
    25092293                   
    2510                     if (safelyCheckNextChar(ptr, patternEnd, '{') && is_counted_repeat(ptr+2, patternEnd)) {
    2511                         ptr = read_repeat_counts(ptr+2, &minRepeats, &maxRepeats, &errorcode);
     2294                    if (safelyCheckNextChar(ptr, patternEnd, '{') && isCountedRepeat(ptr + 2, patternEnd)) {
     2295                        ptr = readRepeatCounts(ptr + 2, &minRepeats, &maxRepeats, &errorcode);
    25122296                        if (errorcode != 0)
    25132297                            return -1;
     
    25382322                if (safelyCheckNextChar(ptr, patternEnd, '?')) {
    25392323                    switch (c = (ptr + 2 < patternEnd ? ptr[2] : 0)) {
    2540                             /* Non-referencing groups and lookaheads just move the pointer on, and
    2541                              then behave like a non-special bracket, except that they don't increment
    2542                              the count of extracting brackets. Ditto for the "once only" bracket,
    2543                              which is in Perl from version 5.005. */
     2324                        /* Non-referencing groups and lookaheads just move the pointer on, and
     2325                         then behave like a non-special bracket, except that they don't increment
     2326                         the count of extracting brackets. Ditto for the "once only" bracket,
     2327                         which is in Perl from version 5.005. */
    25442328                           
    25452329                        case ':':
     
    25492333                            break;
    25502334                           
    2551                             /* Else loop checking valid options until ) is met. Anything else is an
    2552                              error. If we are without any brackets, i.e. at top level, the settings
    2553                              act as if specified in the options, so massage the options immediately.
    2554                              This is for backward compatibility with Perl 5.004. */
     2335                        /* Else loop checking valid options until ) is met. Anything else is an
     2336                         error. If we are without any brackets, i.e. at top level, the settings
     2337                         act as if specified in the options, so massage the options immediately.
     2338                         This is for backward compatibility with Perl 5.004. */
    25552339                           
    25562340                        default:
     
    26052389                    duplength = 0;
    26062390               
    2607                 /* Leave ptr at the final char; for read_repeat_counts this happens
     2391                /* Leave ptr at the final char; for readRepeatCounts this happens
    26082392                 automatically; for the others we need an increment. */
    26092393               
    2610                 if ((ptr + 1 < patternEnd) && (c = ptr[1]) == '{' && is_counted_repeat(ptr+2, patternEnd)) {
    2611                     ptr = read_repeat_counts(ptr+2, &minRepeats, &maxRepeats, &errorcode);
     2394                if ((ptr + 1 < patternEnd) && (c = ptr[1]) == '{' && isCountedRepeat(ptr + 2, patternEnd)) {
     2395                    ptr = readRepeatCounts(ptr + 2, &minRepeats, &maxRepeats, &errorcode);
    26122396                    if (errorcode)
    26132397                        return -1;
     
    26722456                if (c > 127) {
    26732457                    int i;
    2674                     for (i = 0; i < _pcre_utf8_table1_size; i++)
    2675                         if (c <= _pcre_utf8_table1[i])
     2458                    for (i = 0; i < kjs_pcre_utf8_table1_size; i++)
     2459                        if (c <= kjs_pcre_utf8_table1[i])
    26762460                            break;
    26772461                    length += i;
     
    27092493*/
    27102494
    2711 static JSRegExp* returnError(ErrorCode errorcode, const char** errorptr)
     2495static inline JSRegExp* returnError(ErrorCode errorcode, const char** errorptr)
    27122496{
    2713     *errorptr = error_text(errorcode);
     2497    *errorptr = errorText(errorcode);
    27142498    return 0;
    27152499}
     
    27462530     passed around in the compile data block. */
    27472531   
    2748     const uschar* codeStart = (const uschar*)(re + 1);
     2532    const unsigned char* codeStart = (const unsigned char*)(re + 1);
    27492533    cd.start_code = codeStart;
    27502534    cd.start_pattern = (const UChar*)pattern;
     
    27562540    const UChar* ptr = (const UChar*)pattern;
    27572541    const UChar* patternEnd = pattern + patternLength;
    2758     uschar* code = (uschar*)codeStart;
     2542    unsigned char* code = (unsigned char*)codeStart;
    27592543    int firstbyte, reqbyte;
    27602544    int bracketCount = 0;
Note: See TracChangeset for help on using the changeset viewer.