Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ScanCharClass()

RegexCharClass System.Text.RegularExpressions.RegexParser.ScanCharClass ( bool caseInsensitive,
bool scanOnly )
inlineprivate

Definition at line 481 of file RegexParser.cs.

482 {
483 char c = '\0';
484 char c2 = '\0';
485 bool flag = false;
486 bool flag2 = true;
487 bool flag3 = false;
488 RegexCharClass regexCharClass = (scanOnly ? null : new RegexCharClass());
489 if (CharsRight() > 0 && RightChar() == '^')
490 {
491 MoveRight();
492 if (!scanOnly)
493 {
494 regexCharClass.Negate = true;
495 }
496 if ((_options & RegexOptions.ECMAScript) != 0 && CharAt(_currentPos) == ']')
497 {
498 flag2 = false;
499 }
500 }
501 for (; CharsRight() > 0; flag2 = false)
502 {
503 bool flag4 = false;
504 c = RightCharMoveRight();
505 if (c == ']')
506 {
507 if (!flag2)
508 {
509 flag3 = true;
510 break;
511 }
512 }
513 else if (c == '\\' && CharsRight() > 0)
514 {
515 switch (c = RightCharMoveRight())
516 {
517 case 'D':
518 case 'd':
519 if (!scanOnly)
520 {
521 if (flag)
522 {
523 throw MakeException(RegexParseError.ShorthandClassInCharacterRange, System.SR.Format(System.SR.ShorthandClassInCharacterRange, c));
524 }
525 regexCharClass.AddDigit(UseOptionE(), c == 'D', _pattern, _currentPos);
526 }
527 continue;
528 case 'S':
529 case 's':
530 if (!scanOnly)
531 {
532 if (flag)
533 {
534 throw MakeException(RegexParseError.ShorthandClassInCharacterRange, System.SR.Format(System.SR.ShorthandClassInCharacterRange, c));
535 }
536 regexCharClass.AddSpace(UseOptionE(), c == 'S');
537 }
538 continue;
539 case 'W':
540 case 'w':
541 if (!scanOnly)
542 {
543 if (flag)
544 {
545 throw MakeException(RegexParseError.ShorthandClassInCharacterRange, System.SR.Format(System.SR.ShorthandClassInCharacterRange, c));
546 }
547 regexCharClass.AddWord(UseOptionE(), c == 'W');
548 }
549 continue;
550 case 'P':
551 case 'p':
552 if (!scanOnly)
553 {
554 if (flag)
555 {
556 throw MakeException(RegexParseError.ShorthandClassInCharacterRange, System.SR.Format(System.SR.ShorthandClassInCharacterRange, c));
557 }
558 regexCharClass.AddCategoryFromName(ParseProperty(), c != 'p', caseInsensitive, _pattern, _currentPos);
559 }
560 else
561 {
563 }
564 continue;
565 case '-':
566 if (scanOnly)
567 {
568 continue;
569 }
570 if (flag)
571 {
572 if (c2 > c)
573 {
574 throw MakeException(RegexParseError.ReversedCharacterRange, System.SR.ReversedCharacterRange);
575 }
577 flag = false;
578 c2 = '\0';
579 }
580 else
581 {
583 }
584 continue;
585 }
586 MoveLeft();
587 c = ScanCharEscape();
588 flag4 = true;
589 }
590 else if (c == '[' && CharsRight() > 0 && RightChar() == ':' && !flag)
591 {
592 int pos = Textpos();
593 MoveRight();
594 if (CharsRight() < 2 || RightCharMoveRight() != ':' || RightCharMoveRight() != ']')
595 {
596 Textto(pos);
597 }
598 }
599 if (flag)
600 {
601 flag = false;
602 if (scanOnly)
603 {
604 continue;
605 }
606 if (c == '[' && !flag4 && !flag2)
607 {
608 regexCharClass.AddChar(c2);
609 regexCharClass.AddSubtraction(ScanCharClass(caseInsensitive, scanOnly));
610 if (CharsRight() > 0 && RightChar() != ']')
611 {
612 throw MakeException(RegexParseError.ExclusionGroupNotLast, System.SR.ExclusionGroupNotLast);
613 }
614 }
615 else
616 {
617 if (c2 > c)
618 {
619 throw MakeException(RegexParseError.ReversedCharacterRange, System.SR.ReversedCharacterRange);
620 }
622 }
623 }
624 else if (CharsRight() >= 2 && RightChar() == '-' && RightChar(1) != ']')
625 {
626 c2 = c;
627 flag = true;
628 MoveRight();
629 }
630 else if (CharsRight() >= 1 && c == '-' && !flag4 && RightChar() == '[' && !flag2)
631 {
632 if (!scanOnly)
633 {
634 MoveRight(1);
635 regexCharClass.AddSubtraction(ScanCharClass(caseInsensitive, scanOnly));
636 if (CharsRight() > 0 && RightChar() != ']')
637 {
638 throw MakeException(RegexParseError.ExclusionGroupNotLast, System.SR.ExclusionGroupNotLast);
639 }
640 }
641 else
642 {
643 MoveRight(1);
644 ScanCharClass(caseInsensitive, scanOnly);
645 }
646 }
647 else if (!scanOnly)
648 {
650 }
651 }
652 if (!flag3)
653 {
654 throw MakeException(RegexParseError.UnterminatedBracket, System.SR.UnterminatedBracket);
655 }
656 if (!scanOnly && caseInsensitive)
657 {
658 regexCharClass.AddLowercase(_culture);
659 }
660 return regexCharClass;
661 }
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > collection)
static string ShorthandClassInCharacterRange
Definition SR.cs:20
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string UnterminatedBracket
Definition SR.cs:104
static string ExclusionGroupNotLast
Definition SR.cs:80
static string ReversedCharacterRange
Definition SR.cs:78
Definition SR.cs:7
RegexParseException MakeException(RegexParseError error, string message)
RegexCharClass ScanCharClass(bool caseInsensitive, bool scanOnly)

References System.Text.RegularExpressions.RegexParser._culture, System.Text.RegularExpressions.RegexParser._currentPos, System.Text.RegularExpressions.RegexParser._options, System.Text.RegularExpressions.RegexParser._pattern, System.Collections.Generic.Dictionary< TKey, TValue >.AddRange(), System.Text.RegularExpressions.RegexParser.CharAt(), System.Text.RegularExpressions.RegexParser.CharsRight(), System.SR.ExclusionGroupNotLast, System.SR.Format(), System.Text.RegularExpressions.RegexParser.MakeException(), System.Text.RegularExpressions.RegexParser.MoveLeft(), System.Text.RegularExpressions.RegexParser.MoveRight(), System.Text.RegularExpressions.RegexParser.ParseProperty(), System.SR.ReversedCharacterRange, System.Text.RegularExpressions.RegexParser.RightChar(), System.Text.RegularExpressions.RegexParser.RightCharMoveRight(), System.Text.RegularExpressions.RegexParser.ScanCharClass(), System.Text.RegularExpressions.RegexParser.ScanCharEscape(), System.SR.ShorthandClassInCharacterRange, System.Text.RegularExpressions.RegexParser.Textpos(), System.Text.RegularExpressions.RegexParser.Textto(), System.SR.UnterminatedBracket, and System.Text.RegularExpressions.RegexParser.UseOptionE().

Referenced by System.Text.RegularExpressions.RegexParser.CountCaptures(), System.Text.RegularExpressions.RegexParser.ScanCharClass(), and System.Text.RegularExpressions.RegexParser.ScanRegex().