CharInClass() static private method

static private CharInClass ( char ch, String set ) : bool
ch char
set String
return bool
Esempio n. 1
0
 protected static bool CharInClass(char ch, String charClass)
 {
     return(RegexCharClass.CharInClass(ch, charClass));
 }
        protected override void Go()
        {
            Goto(0);

            int advance = -1;

            while (true)
            {
                if (advance >= 0)
                {
                    // https://github.com/dotnet/coreclr/pull/14850#issuecomment-342256447
                    // Single common Advance call to reduce method size; and single method inline point
                    Advance(advance);
                    advance = -1;
                }
#if DEBUG
                if (runmatch.Debug)
                {
                    DumpState();
                }
#endif

                CheckTimeout();

                switch (Operator())
                {
                case RegexCode.Stop:
                    return;

                case RegexCode.Nothing:
                    break;

                case RegexCode.Goto:
                    Goto(Operand(0));
                    continue;

                case RegexCode.Testref:
                    if (!IsMatched(Operand(0)))
                    {
                        break;
                    }
                    advance = 1;
                    continue;

                case RegexCode.Lazybranch:
                    TrackPush(Textpos());
                    advance = 1;
                    continue;

                case RegexCode.Lazybranch | RegexCode.Back:
                    TrackPop();
                    Textto(TrackPeek());
                    Goto(Operand(0));
                    continue;

                case RegexCode.Setmark:
                    StackPush(Textpos());
                    TrackPush();
                    advance = 0;
                    continue;

                case RegexCode.Nullmark:
                    StackPush(-1);
                    TrackPush();
                    advance = 0;
                    continue;

                case RegexCode.Setmark | RegexCode.Back:
                case RegexCode.Nullmark | RegexCode.Back:
                    StackPop();
                    break;

                case RegexCode.Getmark:
                    StackPop();
                    TrackPush(StackPeek());
                    Textto(StackPeek());
                    advance = 0;
                    continue;

                case RegexCode.Getmark | RegexCode.Back:
                    TrackPop();
                    StackPush(TrackPeek());
                    break;

                case RegexCode.Capturemark:
                    if (Operand(1) != -1 && !IsMatched(Operand(1)))
                    {
                        break;
                    }
                    StackPop();
                    if (Operand(1) != -1)
                    {
                        TransferCapture(Operand(0), Operand(1), StackPeek(), Textpos());
                    }
                    else
                    {
                        Capture(Operand(0), StackPeek(), Textpos());
                    }
                    TrackPush(StackPeek());

                    advance = 2;

                    continue;

                case RegexCode.Capturemark | RegexCode.Back:
                    TrackPop();
                    StackPush(TrackPeek());
                    Uncapture();
                    if (Operand(0) != -1 && Operand(1) != -1)
                    {
                        Uncapture();
                    }

                    break;

                case RegexCode.Branchmark:
                {
                    int matched;
                    StackPop();

                    matched = Textpos() - StackPeek();

                    if (matched != 0)
                    {                                      // Nonempty match -> loop now
                        TrackPush(StackPeek(), Textpos()); // Save old mark, textpos
                        StackPush(Textpos());              // Make new mark
                        Goto(Operand(0));                  // Loop
                    }
                    else
                    {                                          // Empty match -> straight now
                        TrackPush2(StackPeek());               // Save old mark
                        advance = 1;                           // Straight
                    }
                    continue;
                }

                case RegexCode.Branchmark | RegexCode.Back:
                    TrackPop(2);
                    StackPop();
                    Textto(TrackPeek(1));                           // Recall position
                    TrackPush2(TrackPeek());                        // Save old mark
                    advance = 1;                                    // Straight
                    continue;

                case RegexCode.Branchmark | RegexCode.Back2:
                    TrackPop();
                    StackPush(TrackPeek());                         // Recall old mark
                    break;                                          // Backtrack

                case RegexCode.Lazybranchmark:
                {
                    // We hit this the first time through a lazy loop and after each
                    // successful match of the inner expression.  It simply continues
                    // on and doesn't loop.
                    StackPop();

                    int oldMarkPos = StackPeek();

                    if (Textpos() != oldMarkPos)
                    {                      // Nonempty match -> try to loop again by going to 'back' state
                        if (oldMarkPos != -1)
                        {
                            TrackPush(oldMarkPos, Textpos());           // Save old mark, textpos
                        }
                        else
                        {
                            TrackPush(Textpos(), Textpos());
                        }
                    }
                    else
                    {
                        // The inner expression found an empty match, so we'll go directly to 'back2' if we
                        // backtrack.  In this case, we need to push something on the stack, since back2 pops.
                        // However, in the case of ()+? or similar, this empty match may be legitimate, so push the text
                        // position associated with that empty match.
                        StackPush(oldMarkPos);

                        TrackPush2(StackPeek());                        // Save old mark
                    }
                    advance = 1;
                    continue;
                }

                case RegexCode.Lazybranchmark | RegexCode.Back:
                {
                    // After the first time, Lazybranchmark | RegexCode.Back occurs
                    // with each iteration of the loop, and therefore with every attempted
                    // match of the inner expression.  We'll try to match the inner expression,
                    // then go back to Lazybranchmark if successful.  If the inner expression
                    // fails, we go to Lazybranchmark | RegexCode.Back2
                    int pos;

                    TrackPop(2);
                    pos = TrackPeek(1);
                    TrackPush2(TrackPeek());                        // Save old mark
                    StackPush(pos);                                 // Make new mark
                    Textto(pos);                                    // Recall position
                    Goto(Operand(0));                               // Loop
                    continue;
                }

                case RegexCode.Lazybranchmark | RegexCode.Back2:
                    // The lazy loop has failed.  We'll do a true backtrack and
                    // start over before the lazy loop.
                    StackPop();
                    TrackPop();
                    StackPush(TrackPeek());                          // Recall old mark
                    break;

                case RegexCode.Setcount:
                    StackPush(Textpos(), Operand(0));
                    TrackPush();
                    advance = 1;
                    continue;

                case RegexCode.Nullcount:
                    StackPush(-1, Operand(0));
                    TrackPush();
                    advance = 1;
                    continue;

                case RegexCode.Setcount | RegexCode.Back:
                    StackPop(2);
                    break;

                case RegexCode.Nullcount | RegexCode.Back:
                    StackPop(2);
                    break;

                case RegexCode.Branchcount:
                    // StackPush:
                    //  0: Mark
                    //  1: Count
                {
                    StackPop(2);
                    int mark    = StackPeek();
                    int count   = StackPeek(1);
                    int matched = Textpos() - mark;

                    if (count >= Operand(1) || (matched == 0 && count >= 0))
                    {                                           // Max loops or empty match -> straight now
                        TrackPush2(mark, count);                // Save old mark, count
                        advance = 2;                            // Straight
                    }
                    else
                    {                                          // Nonempty match -> count+loop now
                        TrackPush(mark);                       // remember mark
                        StackPush(Textpos(), count + 1);       // Make new mark, incr count
                        Goto(Operand(0));                      // Loop
                    }
                    continue;
                }

                case RegexCode.Branchcount | RegexCode.Back:
                    // TrackPush:
                    //  0: Previous mark
                    // StackPush:
                    //  0: Mark (= current pos, discarded)
                    //  1: Count
                    TrackPop();
                    StackPop(2);
                    if (StackPeek(1) > 0)
                    {                                              // Positive -> can go straight
                        Textto(StackPeek());                       // Zap to mark
                        TrackPush2(TrackPeek(), StackPeek(1) - 1); // Save old mark, old count
                        advance = 2;                               // Straight
                        continue;
                    }
                    StackPush(TrackPeek(), StackPeek(1) - 1);           // recall old mark, old count
                    break;

                case RegexCode.Branchcount | RegexCode.Back2:
                    // TrackPush:
                    //  0: Previous mark
                    //  1: Previous count
                    TrackPop(2);
                    StackPush(TrackPeek(), TrackPeek(1));               // Recall old mark, old count
                    break;                                              // Backtrack


                case RegexCode.Lazybranchcount:
                    // StackPush:
                    //  0: Mark
                    //  1: Count
                {
                    StackPop(2);
                    int mark  = StackPeek();
                    int count = StackPeek(1);

                    if (count < 0)
                    {                                    // Negative count -> loop now
                        TrackPush2(mark);                // Save old mark
                        StackPush(Textpos(), count + 1); // Make new mark, incr count
                        Goto(Operand(0));                // Loop
                    }
                    else
                    {                                          // Nonneg count -> straight now
                        TrackPush(mark, count, Textpos());     // Save mark, count, position
                        advance = 2;                           // Straight
                    }
                    continue;
                }

                case RegexCode.Lazybranchcount | RegexCode.Back:
                    // TrackPush:
                    //  0: Mark
                    //  1: Count
                    //  2: Textpos
                {
                    TrackPop(3);
                    int mark    = TrackPeek();
                    int textpos = TrackPeek(2);

                    if (TrackPeek(1) < Operand(1) && textpos != mark)
                    {                                         // Under limit and not empty match -> loop
                        Textto(textpos);                      // Recall position
                        StackPush(textpos, TrackPeek(1) + 1); // Make new mark, incr count
                        TrackPush2(mark);                     // Save old mark
                        Goto(Operand(0));                     // Loop
                        continue;
                    }
                    else
                    {                                                  // Max loops or empty match -> backtrack
                        StackPush(TrackPeek(), TrackPeek(1));          // Recall old mark, count
                        break;                                         // backtrack
                    }
                }

                case RegexCode.Lazybranchcount | RegexCode.Back2:
                    // TrackPush:
                    //  0: Previous mark
                    // StackPush:
                    //  0: Mark (== current pos, discarded)
                    //  1: Count
                    TrackPop();
                    StackPop(2);
                    StackPush(TrackPeek(), StackPeek(1) - 1);       // Recall old mark, count
                    break;                                          // Backtrack

                case RegexCode.Setjump:
                    StackPush(Trackpos(), Crawlpos());
                    TrackPush();
                    advance = 0;
                    continue;

                case RegexCode.Setjump | RegexCode.Back:
                    StackPop(2);
                    break;

                case RegexCode.Backjump:
                    // StackPush:
                    //  0: Saved trackpos
                    //  1: Crawlpos
                    StackPop(2);
                    Trackto(StackPeek());

                    while (Crawlpos() != StackPeek(1))
                    {
                        Uncapture();
                    }

                    break;

                case RegexCode.Forejump:
                    // StackPush:
                    //  0: Saved trackpos
                    //  1: Crawlpos
                    StackPop(2);
                    Trackto(StackPeek());
                    TrackPush(StackPeek(1));
                    advance = 0;
                    continue;

                case RegexCode.Forejump | RegexCode.Back:
                    // TrackPush:
                    //  0: Crawlpos
                    TrackPop();

                    while (Crawlpos() != TrackPeek())
                    {
                        Uncapture();
                    }

                    break;

                case RegexCode.Bol:
                    if (Leftchars() > 0 && CharAt(Textpos() - 1) != '\n')
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.Eol:
                    if (Rightchars() > 0 && CharAt(Textpos()) != '\n')
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.Boundary:
                    if (!IsBoundary(Textpos(), runtextbeg, runtextend))
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.Nonboundary:
                    if (IsBoundary(Textpos(), runtextbeg, runtextend))
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.ECMABoundary:
                    if (!IsECMABoundary(Textpos(), runtextbeg, runtextend))
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.NonECMABoundary:
                    if (IsECMABoundary(Textpos(), runtextbeg, runtextend))
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.Beginning:
                    if (Leftchars() > 0)
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.Start:
                    if (Textpos() != Textstart())
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.EndZ:
                    if (Rightchars() > 1 || Rightchars() == 1 && CharAt(Textpos()) != '\n')
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.End:
                    if (Rightchars() > 0)
                    {
                        break;
                    }
                    advance = 0;
                    continue;

                case RegexCode.One:
                    if (Forwardchars() < 1 || Forwardcharnext() != (char)Operand(0))
                    {
                        break;
                    }

                    advance = 1;
                    continue;

                case RegexCode.Notone:
                    if (Forwardchars() < 1 || Forwardcharnext() == (char)Operand(0))
                    {
                        break;
                    }

                    advance = 1;
                    continue;

                case RegexCode.Set:
                    if (Forwardchars() < 1 || !RegexCharClass.CharInClass(Forwardcharnext(), _code.Strings[Operand(0)]))
                    {
                        break;
                    }

                    advance = 1;
                    continue;

                case RegexCode.Multi:
                {
                    if (!Stringmatch(_code.Strings[Operand(0)]))
                    {
                        break;
                    }

                    advance = 1;
                    continue;
                }

                case RegexCode.Ref:
                {
                    int capnum = Operand(0);

                    if (IsMatched(capnum))
                    {
                        if (!Refmatch(MatchIndex(capnum), MatchLength(capnum)))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if ((runregex.roptions & RegexOptions.ECMAScript) == 0)
                        {
                            break;
                        }
                    }

                    advance = 1;
                    continue;
                }

                case RegexCode.Onerep:
                {
                    int c = Operand(1);

                    if (Forwardchars() < c)
                    {
                        break;
                    }

                    char ch = (char)Operand(0);

                    while (c-- > 0)
                    {
                        if (Forwardcharnext() != ch)
                        {
                            goto BreakBackward;
                        }
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Notonerep:
                {
                    int c = Operand(1);

                    if (Forwardchars() < c)
                    {
                        break;
                    }

                    char ch = (char)Operand(0);

                    while (c-- > 0)
                    {
                        if (Forwardcharnext() == ch)
                        {
                            goto BreakBackward;
                        }
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Setrep:
                {
                    int c = Operand(1);

                    if (Forwardchars() < c)
                    {
                        break;
                    }

                    string set = _code.Strings[Operand(0)];

                    while (c-- > 0)
                    {
                        // Check the timeout every 2000th iteration. The additional if check
                        // in every iteration can be neglected as the cost of the CharInClass
                        // check is many times higher.
                        if ((uint)c % LoopTimeoutCheckCount == 0)
                        {
                            CheckTimeout();
                        }

                        if (!RegexCharClass.CharInClass(Forwardcharnext(), set))
                        {
                            goto BreakBackward;
                        }
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Oneloop:
                {
                    int c = Operand(1);

                    if (c > Forwardchars())
                    {
                        c = Forwardchars();
                    }

                    char ch = (char)Operand(0);
                    int  i;

                    for (i = c; i > 0; i--)
                    {
                        if (Forwardcharnext() != ch)
                        {
                            Backwardnext();
                            break;
                        }
                    }

                    if (c > i)
                    {
                        TrackPush(c - i - 1, Textpos() - Bump());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Notoneloop:
                {
                    int c = Operand(1);

                    if (c > Forwardchars())
                    {
                        c = Forwardchars();
                    }

                    char ch = (char)Operand(0);
                    int  i;

                    for (i = c; i > 0; i--)
                    {
                        if (Forwardcharnext() == ch)
                        {
                            Backwardnext();
                            break;
                        }
                    }

                    if (c > i)
                    {
                        TrackPush(c - i - 1, Textpos() - Bump());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Setloop:
                {
                    int c = Operand(1);

                    if (c > Forwardchars())
                    {
                        c = Forwardchars();
                    }

                    string set = _code.Strings[Operand(0)];
                    int    i;

                    for (i = c; i > 0; i--)
                    {
                        // Check the timeout every 2000th iteration. The additional if check
                        // in every iteration can be neglected as the cost of the CharInClass
                        // check is many times higher.
                        if ((uint)i % LoopTimeoutCheckCount == 0)
                        {
                            CheckTimeout();
                        }

                        if (!RegexCharClass.CharInClass(Forwardcharnext(), set))
                        {
                            Backwardnext();
                            break;
                        }
                    }

                    if (c > i)
                    {
                        TrackPush(c - i - 1, Textpos() - Bump());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Oneloop | RegexCode.Back:
                case RegexCode.Notoneloop | RegexCode.Back:
                {
                    TrackPop(2);
                    int i   = TrackPeek();
                    int pos = TrackPeek(1);

                    Textto(pos);

                    if (i > 0)
                    {
                        TrackPush(i - 1, pos - Bump());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Setloop | RegexCode.Back:
                {
                    TrackPop(2);
                    int i   = TrackPeek();
                    int pos = TrackPeek(1);

                    Textto(pos);

                    if (i > 0)
                    {
                        TrackPush(i - 1, pos - Bump());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Onelazy:
                case RegexCode.Notonelazy:
                {
                    int c = Operand(1);

                    if (c > Forwardchars())
                    {
                        c = Forwardchars();
                    }

                    if (c > 0)
                    {
                        TrackPush(c - 1, Textpos());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Setlazy:
                {
                    int c = Operand(1);

                    if (c > Forwardchars())
                    {
                        c = Forwardchars();
                    }

                    if (c > 0)
                    {
                        TrackPush(c - 1, Textpos());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Onelazy | RegexCode.Back:
                {
                    TrackPop(2);
                    int pos = TrackPeek(1);
                    Textto(pos);

                    if (Forwardcharnext() != (char)Operand(0))
                    {
                        break;
                    }

                    int i = TrackPeek();

                    if (i > 0)
                    {
                        TrackPush(i - 1, pos + Bump());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Notonelazy | RegexCode.Back:
                {
                    TrackPop(2);
                    int pos = TrackPeek(1);
                    Textto(pos);

                    if (Forwardcharnext() == (char)Operand(0))
                    {
                        break;
                    }

                    int i = TrackPeek();

                    if (i > 0)
                    {
                        TrackPush(i - 1, pos + Bump());
                    }

                    advance = 2;
                    continue;
                }

                case RegexCode.Setlazy | RegexCode.Back:
                {
                    TrackPop(2);
                    int pos = TrackPeek(1);
                    Textto(pos);

                    if (!RegexCharClass.CharInClass(Forwardcharnext(), _code.Strings[Operand(0)]))
                    {
                        break;
                    }

                    int i = TrackPeek();

                    if (i > 0)
                    {
                        TrackPush(i - 1, pos + Bump());
                    }

                    advance = 2;
                    continue;
                }

                default:
                    throw NotImplemented.ByDesignWithMessage(SR.UnimplementedState);
                }

BreakBackward:
                ;

                // "break Backward" comes here:
                Backtrack();
            }
        }
Esempio n. 3
0
        protected static bool CharInSet(char ch, String set, String category)
        {
            string charClass = RegexCharClass.ConvertOldStringsToClass(set, category);

            return(RegexCharClass.CharInClass(ch, charClass));
        }
        protected override bool FindFirstChar()
        {
            if (0 != (_code.Anchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End)))
            {
                if (!_code.RightToLeft)
                {
                    if ((0 != (_code.Anchors & RegexFCD.Beginning) && runtextpos > runtextbeg) ||
                        (0 != (_code.Anchors & RegexFCD.Start) && runtextpos > runtextstart))
                    {
                        runtextpos = runtextend;
                        return(false);
                    }
                    if (0 != (_code.Anchors & RegexFCD.EndZ) && runtextpos < runtextend - 1)
                    {
                        runtextpos = runtextend - 1;
                    }
                    else if (0 != (_code.Anchors & RegexFCD.End) && runtextpos < runtextend)
                    {
                        runtextpos = runtextend;
                    }
                }
                else
                {
                    if ((0 != (_code.Anchors & RegexFCD.End) && runtextpos < runtextend) ||
                        (0 != (_code.Anchors & RegexFCD.EndZ) && (runtextpos < runtextend - 1 ||
                                                                  (runtextpos == runtextend - 1 && CharAt(runtextpos) != '\n'))) ||
                        (0 != (_code.Anchors & RegexFCD.Start) && runtextpos < runtextstart))
                    {
                        runtextpos = runtextbeg;
                        return(false);
                    }
                    if (0 != (_code.Anchors & RegexFCD.Beginning) && runtextpos > runtextbeg)
                    {
                        runtextpos = runtextbeg;
                    }
                }

                if (_code.BMPrefix != null)
                {
                    return(_code.BMPrefix.IsMatch(runtext, runtextpos, runtextbeg, runtextend));
                }

                return(true); // found a valid start or end anchor
            }
            else if (_code.BMPrefix != null)
            {
                runtextpos = _code.BMPrefix.Scan(runtext, runtextpos, runtextbeg, runtextend);

                if (runtextpos == -1)
                {
                    runtextpos = (_code.RightToLeft ? runtextbeg : runtextend);
                    return(false);
                }

                return(true);
            }
            else if (_code.FCPrefix == null)
            {
                return(true);
            }

            _rightToLeft     = _code.RightToLeft;
            _caseInsensitive = _code.FCPrefix.GetValueOrDefault().CaseInsensitive;
            string set = _code.FCPrefix.GetValueOrDefault().Prefix;

            if (RegexCharClass.IsSingleton(set))
            {
                char ch = RegexCharClass.SingletonChar(set);

                for (int i = Forwardchars(); i > 0; i--)
                {
                    if (ch == Forwardcharnext())
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            else
            {
                for (int i = Forwardchars(); i > 0; i--)
                {
                    if (RegexCharClass.CharInClass(Forwardcharnext(), set))
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 5
0
        protected override bool FindFirstChar()
        {
            int    i;
            String set;

            if (0 != (_code._anchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End)))
            {
                if (!_code._rightToLeft)
                {
                    if ((0 != (_code._anchors & RegexFCD.Beginning) && _runtextpos > _runtextbeg) ||
                        (0 != (_code._anchors & RegexFCD.Start) && _runtextpos > _runtextstart))
                    {
                        _runtextpos = _runtextend;
                        return(false);
                    }
                    if (0 != (_code._anchors & RegexFCD.EndZ) && _runtextpos < _runtextend - 1)
                    {
                        _runtextpos = _runtextend - 1;
                    }
                    else if (0 != (_code._anchors & RegexFCD.End) && _runtextpos < _runtextend)
                    {
                        _runtextpos = _runtextend;
                    }
                }
                else
                {
                    if ((0 != (_code._anchors & RegexFCD.End) && _runtextpos < _runtextend) ||
                        (0 != (_code._anchors & RegexFCD.EndZ) && (_runtextpos < _runtextend - 1 ||
                                                                   (_runtextpos == _runtextend - 1 && CharAt(_runtextpos) != '\n'))) ||
                        (0 != (_code._anchors & RegexFCD.Start) && _runtextpos < _runtextstart))
                    {
                        _runtextpos = _runtextbeg;
                        return(false);
                    }
                    if (0 != (_code._anchors & RegexFCD.Beginning) && _runtextpos > _runtextbeg)
                    {
                        _runtextpos = _runtextbeg;
                    }
                }

                if (_code._bmPrefix != null)
                {
                    return(_code._bmPrefix.IsMatch(_runtext, _runtextpos, _runtextbeg, _runtextend));
                }

                return(true); // found a valid start or end anchor
            }
            else if (_code._bmPrefix != null)
            {
                _runtextpos = _code._bmPrefix.Scan(_runtext, _runtextpos, _runtextbeg, _runtextend);

                if (_runtextpos == -1)
                {
                    _runtextpos = (_code._rightToLeft ? _runtextbeg : _runtextend);
                    return(false);
                }

                return(true);
            }
            else if (_code._fcPrefix == null)
            {
                return(true);
            }

            _rightToLeft     = _code._rightToLeft;
            _caseInsensitive = _code._fcPrefix.CaseInsensitive;
            set = _code._fcPrefix.Prefix;

            if (RegexCharClass.IsSingleton(set))
            {
                char ch = RegexCharClass.SingletonChar(set);

                for (i = Forwardchars(); i > 0; i--)
                {
                    if (ch == Forwardcharnext())
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            else
            {
                for (i = Forwardchars(); i > 0; i--)
                {
                    if (RegexCharClass.CharInClass(Forwardcharnext(), set))
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 6
0
        protected override bool FindFirstChar()
        {
            int    i;
            String set;

            if (0 != (runanchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End)))
            {
                if (!runcode._rightToLeft)
                {
                    if ((0 != (runanchors & RegexFCD.Beginning) && runtextpos > runtextbeg) ||
                        (0 != (runanchors & RegexFCD.Start) && runtextpos > runtextstart))
                    {
                        runtextpos = runtextend;
                        return(false);
                    }
                    if (0 != (runanchors & RegexFCD.EndZ) && runtextpos < runtextend - 1)
                    {
                        runtextpos = runtextend - 1;
                    }
                    else if (0 != (runanchors & RegexFCD.End) && runtextpos < runtextend)
                    {
                        runtextpos = runtextend;
                    }
                }
                else
                {
                    if ((0 != (runanchors & RegexFCD.End) && runtextpos < runtextend) ||
                        (0 != (runanchors & RegexFCD.EndZ) && (runtextpos < runtextend - 1 ||
                                                               (runtextpos == runtextend - 1 && CharAt(runtextpos) != '\n'))) ||
                        (0 != (runanchors & RegexFCD.Start) && runtextpos < runtextstart))
                    {
                        runtextpos = runtextbeg;
                        return(false);
                    }
                    if (0 != (runanchors & RegexFCD.Beginning) && runtextpos > runtextbeg)
                    {
                        runtextpos = runtextbeg;
                    }
                }

                if (runbmPrefix != null)
                {
                    return(runbmPrefix.IsMatch(runtext, runtextpos, runtextbeg, runtextend));
                }
            }
            else if (runbmPrefix != null)
            {
                runtextpos = runbmPrefix.Scan(runtext, runtextpos, runtextbeg, runtextend);

                if (runtextpos == -1)
                {
                    runtextpos = (runcode._rightToLeft ? runtextbeg : runtextend);
                    return(false);
                }

                return(true);
            }

            if (runfcPrefix == null)
            {
                return(true);
            }

            runrtl = runcode._rightToLeft;
            runci  = runfcPrefix.CaseInsensitive;
            set    = runfcPrefix.Prefix;

            if (RegexCharClass.IsSingleton(set))
            {
                char ch = RegexCharClass.SingletonChar(set);

                for (i = Forwardchars(); i > 0; i--)
                {
                    if (ch == Forwardcharnext())
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            else
            {
                for (i = Forwardchars(); i > 0; i--)
                {
                    if (RegexCharClass.CharInClass(Forwardcharnext(), set))
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            return(false);
        }
        protected override bool FindFirstChar()
        {
            int num;

            if ((this.runanchors & 0x35) != 0)
            {
                if (!this.runcode._rightToLeft)
                {
                    if ((((this.runanchors & 1) != 0) && (base.runtextpos > base.runtextbeg)) || (((this.runanchors & 4) != 0) && (base.runtextpos > base.runtextstart)))
                    {
                        base.runtextpos = base.runtextend;
                        return(false);
                    }
                    if (((this.runanchors & 0x10) != 0) && (base.runtextpos < (base.runtextend - 1)))
                    {
                        base.runtextpos = base.runtextend - 1;
                    }
                    else if (((this.runanchors & 0x20) != 0) && (base.runtextpos < base.runtextend))
                    {
                        base.runtextpos = base.runtextend;
                    }
                }
                else
                {
                    if (((((this.runanchors & 0x20) != 0) && (base.runtextpos < base.runtextend)) || (((this.runanchors & 0x10) != 0) && ((base.runtextpos < (base.runtextend - 1)) || ((base.runtextpos == (base.runtextend - 1)) && (this.CharAt(base.runtextpos) != '\n'))))) || (((this.runanchors & 4) != 0) && (base.runtextpos < base.runtextstart)))
                    {
                        base.runtextpos = base.runtextbeg;
                        return(false);
                    }
                    if (((this.runanchors & 1) != 0) && (base.runtextpos > base.runtextbeg))
                    {
                        base.runtextpos = base.runtextbeg;
                    }
                }
                if (this.runbmPrefix != null)
                {
                    return(this.runbmPrefix.IsMatch(base.runtext, base.runtextpos, base.runtextbeg, base.runtextend));
                }
                return(true);
            }
            if (this.runbmPrefix != null)
            {
                base.runtextpos = this.runbmPrefix.Scan(base.runtext, base.runtextpos, base.runtextbeg, base.runtextend);
                if (base.runtextpos == -1)
                {
                    base.runtextpos = this.runcode._rightToLeft ? base.runtextbeg : base.runtextend;
                    return(false);
                }
                return(true);
            }
            if (this.runfcPrefix == null)
            {
                return(true);
            }
            this.runrtl = this.runcode._rightToLeft;
            this.runci  = this.runfcPrefix.CaseInsensitive;
            string prefix = this.runfcPrefix.Prefix;

            if (RegexCharClass.IsSingleton(prefix))
            {
                char ch = RegexCharClass.SingletonChar(prefix);
                for (num = this.Forwardchars(); num > 0; num--)
                {
                    if (ch == this.Forwardcharnext())
                    {
                        this.Backwardnext();
                        return(true);
                    }
                }
            }
            else
            {
                for (num = this.Forwardchars(); num > 0; num--)
                {
                    if (RegexCharClass.CharInClass(this.Forwardcharnext(), prefix))
                    {
                        this.Backwardnext();
                        return(true);
                    }
                }
            }
            return(false);
        }
        protected override void Go()
        {
            this.Goto(0);
Label_0007:
            switch (this.Operator())
            {
            case 0:
            {
                int num12 = this.Operand(1);
                if (this.Forwardchars() < num12)
                {
                    goto Label_0E4E;
                }
                char ch = (char)this.Operand(0);
                while (num12-- > 0)
                {
                    if (this.Forwardcharnext() != ch)
                    {
                        goto Label_0E4E;
                    }
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 1:
            {
                int num13 = this.Operand(1);
                if (this.Forwardchars() < num13)
                {
                    goto Label_0E4E;
                }
                char ch2 = (char)this.Operand(0);
                while (num13-- > 0)
                {
                    if (this.Forwardcharnext() == ch2)
                    {
                        goto Label_0E4E;
                    }
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 2:
            {
                int num14 = this.Operand(1);
                if (this.Forwardchars() < num14)
                {
                    goto Label_0E4E;
                }
                string set = this.runstrings[this.Operand(0)];
                while (num14-- > 0)
                {
                    if (!RegexCharClass.CharInClass(this.Forwardcharnext(), set))
                    {
                        goto Label_0E4E;
                    }
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 3:
            {
                int num15 = this.Operand(1);
                if (num15 > this.Forwardchars())
                {
                    num15 = this.Forwardchars();
                }
                char ch3   = (char)this.Operand(0);
                int  num16 = num15;
                while (num16 > 0)
                {
                    if (this.Forwardcharnext() != ch3)
                    {
                        this.Backwardnext();
                        break;
                    }
                    num16--;
                }
                if (num15 > num16)
                {
                    this.TrackPush((num15 - num16) - 1, this.Textpos() - this.Bump());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 4:
            {
                int num17 = this.Operand(1);
                if (num17 > this.Forwardchars())
                {
                    num17 = this.Forwardchars();
                }
                char ch4   = (char)this.Operand(0);
                int  num18 = num17;
                while (num18 > 0)
                {
                    if (this.Forwardcharnext() == ch4)
                    {
                        this.Backwardnext();
                        break;
                    }
                    num18--;
                }
                if (num17 > num18)
                {
                    this.TrackPush((num17 - num18) - 1, this.Textpos() - this.Bump());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 5:
            {
                int num19 = this.Operand(1);
                if (num19 > this.Forwardchars())
                {
                    num19 = this.Forwardchars();
                }
                string str2  = this.runstrings[this.Operand(0)];
                int    num20 = num19;
                while (num20 > 0)
                {
                    if (!RegexCharClass.CharInClass(this.Forwardcharnext(), str2))
                    {
                        this.Backwardnext();
                        break;
                    }
                    num20--;
                }
                if (num19 > num20)
                {
                    this.TrackPush((num19 - num20) - 1, this.Textpos() - this.Bump());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 6:
            case 7:
            {
                int num25 = this.Operand(1);
                if (num25 > this.Forwardchars())
                {
                    num25 = this.Forwardchars();
                }
                if (num25 > 0)
                {
                    this.TrackPush(num25 - 1, this.Textpos());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 8:
            {
                int num26 = this.Operand(1);
                if (num26 > this.Forwardchars())
                {
                    num26 = this.Forwardchars();
                }
                if (num26 > 0)
                {
                    this.TrackPush(num26 - 1, this.Textpos());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 9:
                if ((this.Forwardchars() < 1) || (this.Forwardcharnext() != ((char)this.Operand(0))))
                {
                    goto Label_0E4E;
                }
                this.Advance(1);
                goto Label_0007;

            case 10:
                if ((this.Forwardchars() < 1) || (this.Forwardcharnext() == ((char)this.Operand(0))))
                {
                    goto Label_0E4E;
                }
                this.Advance(1);
                goto Label_0007;

            case 11:
                if ((this.Forwardchars() < 1) || !RegexCharClass.CharInClass(this.Forwardcharnext(), this.runstrings[this.Operand(0)]))
                {
                    goto Label_0E4E;
                }
                this.Advance(1);
                goto Label_0007;

            case 12:
                if (!this.Stringmatch(this.runstrings[this.Operand(0)]))
                {
                    goto Label_0E4E;
                }
                this.Advance(1);
                goto Label_0007;

            case 13:
            {
                int cap = this.Operand(0);
                if (!base.IsMatched(cap))
                {
                    if ((base.runregex.roptions & RegexOptions.ECMAScript) == RegexOptions.None)
                    {
                        goto Label_0E4E;
                    }
                    goto Label_09E4;
                }
                if (this.Refmatch(base.MatchIndex(cap), base.MatchLength(cap)))
                {
                    goto Label_09E4;
                }
                goto Label_0E4E;
            }

            case 14:
                if ((this.Leftchars() > 0) && (this.CharAt(this.Textpos() - 1) != '\n'))
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 15:
                if ((this.Rightchars() > 0) && (this.CharAt(this.Textpos()) != '\n'))
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 0x10:
                if (!base.IsBoundary(this.Textpos(), base.runtextbeg, base.runtextend))
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 0x11:
                if (base.IsBoundary(this.Textpos(), base.runtextbeg, base.runtextend))
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 0x12:
                if (this.Leftchars() > 0)
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 0x13:
                if (this.Textpos() != this.Textstart())
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 20:
                if ((this.Rightchars() > 1) || ((this.Rightchars() == 1) && (this.CharAt(this.Textpos()) != '\n')))
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 0x15:
                if (this.Rightchars() > 0)
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 0x16:
                goto Label_0E4E;

            case 0x17:
                this.TrackPush(this.Textpos());
                this.Advance(1);
                goto Label_0007;

            case 0x18:
                this.StackPop();
                if ((this.Textpos() - this.StackPeek()) == 0)
                {
                    this.TrackPush2(this.StackPeek());
                    this.Advance(1);
                }
                else
                {
                    this.TrackPush(this.StackPeek(), this.Textpos());
                    this.StackPush(this.Textpos());
                    this.Goto(this.Operand(0));
                }
                goto Label_0007;

            case 0x19:
            {
                this.StackPop();
                int num2 = this.StackPeek();
                if (this.Textpos() == num2)
                {
                    this.StackPush(num2);
                    this.TrackPush2(this.StackPeek());
                    break;
                }
                if (num2 == -1)
                {
                    this.TrackPush(this.Textpos(), this.Textpos());
                    break;
                }
                this.TrackPush(num2, this.Textpos());
                break;
            }

            case 0x1a:
                this.StackPush(-1, this.Operand(0));
                this.TrackPush();
                this.Advance(1);
                goto Label_0007;

            case 0x1b:
                this.StackPush(this.Textpos(), this.Operand(0));
                this.TrackPush();
                this.Advance(1);
                goto Label_0007;

            case 0x1c:
            {
                this.StackPop(2);
                int num4 = this.StackPeek();
                int num5 = this.StackPeek(1);
                int num6 = this.Textpos() - num4;
                if ((num5 < this.Operand(1)) && ((num6 != 0) || (num5 < 0)))
                {
                    this.TrackPush(num4);
                    this.StackPush(this.Textpos(), num5 + 1);
                    this.Goto(this.Operand(0));
                }
                else
                {
                    this.TrackPush2(num4, num5);
                    this.Advance(2);
                }
                goto Label_0007;
            }

            case 0x1d:
            {
                this.StackPop(2);
                int num7 = this.StackPeek();
                int num8 = this.StackPeek(1);
                if (num8 >= 0)
                {
                    this.TrackPush(num7, num8, this.Textpos());
                    this.Advance(2);
                }
                else
                {
                    this.TrackPush2(num7);
                    this.StackPush(this.Textpos(), num8 + 1);
                    this.Goto(this.Operand(0));
                }
                goto Label_0007;
            }

            case 30:
                this.StackPush(-1);
                this.TrackPush();
                this.Advance();
                goto Label_0007;

            case 0x1f:
                this.StackPush(this.Textpos());
                this.TrackPush();
                this.Advance();
                goto Label_0007;

            case 0x20:
                if ((this.Operand(1) != -1) && !base.IsMatched(this.Operand(1)))
                {
                    goto Label_0E4E;
                }
                this.StackPop();
                if (this.Operand(1) != -1)
                {
                    base.TransferCapture(this.Operand(0), this.Operand(1), this.StackPeek(), this.Textpos());
                }
                else
                {
                    base.Capture(this.Operand(0), this.StackPeek(), this.Textpos());
                }
                this.TrackPush(this.StackPeek());
                this.Advance(2);
                goto Label_0007;

            case 0x21:
                this.StackPop();
                this.TrackPush(this.StackPeek());
                this.Textto(this.StackPeek());
                this.Advance();
                goto Label_0007;

            case 0x22:
                this.StackPush(this.Trackpos(), base.Crawlpos());
                this.TrackPush();
                this.Advance();
                goto Label_0007;

            case 0x23:
                this.StackPop(2);
                this.Trackto(this.StackPeek());
                while (base.Crawlpos() != this.StackPeek(1))
                {
                    base.Uncapture();
                }
                goto Label_0E4E;

            case 0x24:
                this.StackPop(2);
                this.Trackto(this.StackPeek());
                this.TrackPush(this.StackPeek(1));
                this.Advance();
                goto Label_0007;

            case 0x25:
                if (!base.IsMatched(this.Operand(0)))
                {
                    goto Label_0E4E;
                }
                this.Advance(1);
                goto Label_0007;

            case 0x26:
                this.Goto(this.Operand(0));
                goto Label_0007;

            case 40:
                return;

            case 0x29:
                if (!base.IsECMABoundary(this.Textpos(), base.runtextbeg, base.runtextend))
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 0x2a:
                if (base.IsECMABoundary(this.Textpos(), base.runtextbeg, base.runtextend))
                {
                    goto Label_0E4E;
                }
                this.Advance();
                goto Label_0007;

            case 0x83:
            case 0x84:
            {
                this.TrackPop(2);
                int num21  = this.TrackPeek();
                int newpos = this.TrackPeek(1);
                this.Textto(newpos);
                if (num21 > 0)
                {
                    this.TrackPush(num21 - 1, newpos - this.Bump());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 0x85:
            {
                this.TrackPop(2);
                int num23 = this.TrackPeek();
                int num24 = this.TrackPeek(1);
                this.Textto(num24);
                if (num23 > 0)
                {
                    this.TrackPush(num23 - 1, num24 - this.Bump());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 0x86:
            {
                this.TrackPop(2);
                int num27 = this.TrackPeek(1);
                this.Textto(num27);
                if (this.Forwardcharnext() != ((char)this.Operand(0)))
                {
                    goto Label_0E4E;
                }
                int num28 = this.TrackPeek();
                if (num28 > 0)
                {
                    this.TrackPush(num28 - 1, num27 + this.Bump());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 0x87:
            {
                this.TrackPop(2);
                int num29 = this.TrackPeek(1);
                this.Textto(num29);
                if (this.Forwardcharnext() == ((char)this.Operand(0)))
                {
                    goto Label_0E4E;
                }
                int num30 = this.TrackPeek();
                if (num30 > 0)
                {
                    this.TrackPush(num30 - 1, num29 + this.Bump());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 0x88:
            {
                this.TrackPop(2);
                int num31 = this.TrackPeek(1);
                this.Textto(num31);
                if (!RegexCharClass.CharInClass(this.Forwardcharnext(), this.runstrings[this.Operand(0)]))
                {
                    goto Label_0E4E;
                }
                int num32 = this.TrackPeek();
                if (num32 > 0)
                {
                    this.TrackPush(num32 - 1, num31 + this.Bump());
                }
                this.Advance(2);
                goto Label_0007;
            }

            case 0x97:
                this.TrackPop();
                this.Textto(this.TrackPeek());
                this.Goto(this.Operand(0));
                goto Label_0007;

            case 0x98:
                this.TrackPop(2);
                this.StackPop();
                this.Textto(this.TrackPeek(1));
                this.TrackPush2(this.TrackPeek());
                this.Advance(1);
                goto Label_0007;

            case 0x99:
            {
                this.TrackPop(2);
                int num3 = this.TrackPeek(1);
                this.TrackPush2(this.TrackPeek());
                this.StackPush(num3);
                this.Textto(num3);
                this.Goto(this.Operand(0));
                goto Label_0007;
            }

            case 0x9a:
                this.StackPop(2);
                goto Label_0E4E;

            case 0x9b:
                this.StackPop(2);
                goto Label_0E4E;

            case 0x9c:
                this.TrackPop();
                this.StackPop(2);
                if (this.StackPeek(1) <= 0)
                {
                    this.StackPush(this.TrackPeek(), this.StackPeek(1) - 1);
                    goto Label_0E4E;
                }
                this.Textto(this.StackPeek());
                this.TrackPush2(this.TrackPeek(), this.StackPeek(1) - 1);
                this.Advance(2);
                goto Label_0007;

            case 0x9d:
            {
                this.TrackPop(3);
                int num9  = this.TrackPeek();
                int num10 = this.TrackPeek(2);
                if ((this.TrackPeek(1) >= this.Operand(1)) || (num10 == num9))
                {
                    this.StackPush(this.TrackPeek(), this.TrackPeek(1));
                    goto Label_0E4E;
                }
                this.Textto(num10);
                this.StackPush(num10, this.TrackPeek(1) + 1);
                this.TrackPush2(num9);
                this.Goto(this.Operand(0));
                goto Label_0007;
            }

            case 0x9e:
            case 0x9f:
                this.StackPop();
                goto Label_0E4E;

            case 160:
                this.TrackPop();
                this.StackPush(this.TrackPeek());
                base.Uncapture();
                if ((this.Operand(0) != -1) && (this.Operand(1) != -1))
                {
                    base.Uncapture();
                }
                goto Label_0E4E;

            case 0xa1:
                this.TrackPop();
                this.StackPush(this.TrackPeek());
                goto Label_0E4E;

            case 0xa2:
                this.StackPop(2);
                goto Label_0E4E;

            case 0xa4:
                this.TrackPop();
                while (base.Crawlpos() != this.TrackPeek())
                {
                    base.Uncapture();
                }
                goto Label_0E4E;

            case 280:
                this.TrackPop();
                this.StackPush(this.TrackPeek());
                goto Label_0E4E;

            case 0x119:
                this.StackPop();
                this.TrackPop();
                this.StackPush(this.TrackPeek());
                goto Label_0E4E;

            case 0x11c:
                this.TrackPop(2);
                this.StackPush(this.TrackPeek(), this.TrackPeek(1));
                goto Label_0E4E;

            case 0x11d:
                this.TrackPop();
                this.StackPop(2);
                this.StackPush(this.TrackPeek(), this.StackPeek(1) - 1);
                goto Label_0E4E;

            default:
                throw new NotImplementedException(SR.GetString("UnimplementedState"));
            }
            this.Advance(1);
            goto Label_0007;
Label_09E4:
            this.Advance(1);
            goto Label_0007;
Label_0E4E:
            this.Backtrack();
            goto Label_0007;
        }