690
switch (char) {
691
case '\\':
693
>
// If we're already escaped, then just leave the escaped slash and the preceeding slash that escapes it.
694
>
// The two escaped slashes will result in a single slash and whatever processes the glob later will properly process the escape
695
>
if (inBraces) {
696
>
strInBraces += '\\' + char;
697
>
} else {
698
fixedStart += '\\' + char;
699
}
701
>
} else {
702
>
escaped = true;
703
>
}
704
>
break;
705
case '{':
707
>
// if we escaped this opening bracket, then it is to be taken literally. Remove the `\` because we've acknowleged it and add the `{` to the appropriate string
708
>
if (inBraces) {
709
strInBraces += char;
711
>
fixedStart += char;
712
>
}
713
>
escaped = false;
714
>
} else {
715
>
if (inBraces) {
716
>
// ripgrep treats this as attempting to do a nested alternate group, which is invalid. Return with pattern including changes from escaped braces.
717
>
return { strInBraces: fixedStart + '{' + strInBraces + '{' + pattern.substring(i + 1) };
718
>
} else {
719
>
inBraces = true;
720
>
}
721
>
}
722
>
break;
723
case '}':
725
>
// same as `}`, but for closing bracket
726
>
if (inBraces) {
727
>
strInBraces += char;
728
>
} else {
729
fixedStart += char;
730
}
732
>
} else if (inBraces) {
733
>
// we found an end bracket to a valid opening bracket. Return the appropriate strings.
734
>
return { fixedStart, strInBraces, fixedEnd: pattern.substring(i + 1) };
735
>
} else {
736
>
// if we're not in braces and not escaped, then this is a literal `}` character and we're still adding to fixedStart.
737
>
fixedStart += char;
738
>
}
739
>
break;
740
default:
741
// similar to the `\\` case, we didn't do anything with the escape, so we should re-insert it into the appropriate string
742
// to be consumed later when individual parts of the glob are processed
743
if (inBraces) {
745
} else {
746
fixedStart += (escaped ? '\\' : '') + char;