From a63426d965a5a86aefba220c0b877f83fb93a379 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Thu, 30 Jan 2025 10:47:01 -0500 Subject: [PATCH] Updated references to constants --- regex/compile.go | 12 ++++++------ regex/range2regex.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/regex/compile.go b/regex/compile.go index 0e0c888..799b997 100644 --- a/regex/compile.go +++ b/regex/compile.go @@ -171,7 +171,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { } re_runes = append(re_runes, []rune(regex)...) } else if c == '(' && i < len(re_runes_orig)-2 && re_runes_orig[i+1] == '?' && re_runes_orig[i+2] == ':' { - re_runes = append(re_runes, NONCAPLPAREN_CHAR) + re_runes = append(re_runes, nonCapLparenRune) i += 2 } else if c == '\\' && i < len(re_runes_orig)-1 && re_runes_orig[i+1] == '\\' { // Escaped backslash re_runes = append(re_runes, escBackslashRune) @@ -254,7 +254,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { re_postfix = append(re_postfix, re_runes[i]) // Append closing brace } if i < len(re_runes)-3 && string(re_runes[i+1:i+4]) == "(?:" { // Non-capturing lparen - re_postfix = append(re_postfix, NONCAPLPAREN_CHAR) + re_postfix = append(re_postfix, nonCapLparenRune) i += 3 } if i < len(re_runes) && re_runes[i] == '\\' { // Something is being escaped (I don't add the backslash to re_postfix, because it was already added earlier) @@ -303,7 +303,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { if i >= len(re_runes) { return nil, fmt.Errorf("unclosed lookaround") } - if re_runes[i] == '(' || re_runes[i] == NONCAPLPAREN_CHAR { + if re_runes[i] == '(' || re_runes[i] == nonCapLparenRune { numOpenParens++ } if re_runes[i] == ')' { @@ -317,7 +317,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { } continue } - if i < len(re_runes) && (re_runes[i] != '(' && re_runes[i] != NONCAPLPAREN_CHAR && re_runes[i] != '|' && re_runes[i] != '\\') || (i > 0 && re_runes[i-1] == '\\') { // Every character should be concatenated if it is escaped + if i < len(re_runes) && (re_runes[i] != '(' && re_runes[i] != nonCapLparenRune && re_runes[i] != '|' && re_runes[i] != '\\') || (i > 0 && re_runes[i-1] == '\\') { // Every character should be concatenated if it is escaped if i < len(re_runes)-1 { if re_runes[i+1] != '|' && re_runes[i+1] != '*' && re_runes[i+1] != '+' && re_runes[i+1] != '?' && re_runes[i+1] != ')' && re_runes[i+1] != '{' { re_postfix = append(re_postfix, concatRune) @@ -433,7 +433,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { if i >= len(re_postfix) { return nil, fmt.Errorf("unclosed lookaround") } - if re_postfix[i] == '(' || re_postfix[i] == NONCAPLPAREN_CHAR { + if re_postfix[i] == '(' || re_postfix[i] == nonCapLparenRune { numOpenParens++ } if re_postfix[i] == ')' { @@ -757,7 +757,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { outQueue[idx].startReps = startRangeNum outQueue[idx].endReps = endRangeNum } - if c == '(' || c == NONCAPLPAREN_CHAR { + if c == '(' || c == nonCapLparenRune { opStack = append(opStack, c) if c == '(' { // We only push _capturing_ group parentheses to outQueue outQueue = append(outQueue, newPostfixNode(c)) diff --git a/regex/range2regex.go b/regex/range2regex.go index 5bb109e..880af56 100644 --- a/regex/range2regex.go +++ b/regex/range2regex.go @@ -99,13 +99,13 @@ func range2regex(start int, end int) (string, error) { // Last range - tmp to rangeEnd ranges = append(ranges, numRange{tmp, rangeEnd}) - regex := string(NONCAPLPAREN_CHAR) + regex := string(nonCapLparenRune) // Generate the regex for i, rg := range ranges { if i > 0 { regex += "|" } - regex += string(NONCAPLPAREN_CHAR) + regex += string(nonCapLparenRune) startSlc := intToSlc(rg.start) endSlc := intToSlc(rg.end) if len(startSlc) != len(endSlc) { @@ -115,7 +115,7 @@ func range2regex(start int, end int) (string, error) { if startSlc[i] == endSlc[i] { regex += string(rune(startSlc[i] + 48)) // '0' is ascii value 48, 1 is 49 etc. To convert the digit to its character form, we can just add 48. } else { - regex += fmt.Sprintf("%c%c-%c%c", LBRACKET, rune(startSlc[i]+48), rune(endSlc[i]+48), RBRACKET) + regex += fmt.Sprintf("%c%c-%c%c", lbracketRune, rune(startSlc[i]+48), rune(endSlc[i]+48), RBRACKET) } } regex += ")"