From c87a4b7136442e3e80a4227a312dd0f883b0aede Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sat, 23 Nov 2024 09:26:11 -0500 Subject: [PATCH] Added case-insensitve flag --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 266392b..9926ae9 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( const CONCAT rune = '~' var notDotChars []rune +var caseInsensitiveFlag *bool // Whether we are running in case-insensitive mode func isOperator(c rune) bool { if c == '+' || c == '?' || c == '*' || c == '|' || c == CONCAT { @@ -155,7 +156,11 @@ func shuntingYard(re string) []postfixNode { */ c := re_postfix[i] if isNormalChar(c) { - outQueue = append(outQueue, newPostfixNode(c)) + if *caseInsensitiveFlag { + outQueue = append(outQueue, newPostfixNode(allCases(c)...)) + } else { + outQueue = append(outQueue, newPostfixNode(c)) + } continue } // Escape character @@ -501,6 +506,7 @@ func main() { lineFlag := flag.Bool("l", false, "Only print lines with a match (or with no matches, if -v is enabled). Similar to grep's default.") multiLineFlag := flag.Bool("t", false, "Multi-line mode. Treats newline just like any character.") printMatchesFlag := flag.Bool("p", false, "Prints start and end index of each match. Can only be used with '-t' for multi-line mode.") + caseInsensitiveFlag = flag.Bool("i", false, "Case-insensitive. Disregard the case of all characters.") flag.Parse() // In multi-line mode, 'dot' metacharacter also matches newline