1
0
mirror of https://github.com/hustcer/deepseek-review.git synced 2026-05-13 05:16:05 +08:00

refactor: Enhance the glob pattern handling in glob-to-regex function (#151)

This commit is contained in:
Justin Ma
2025-02-28 19:17:52 +08:00
committed by GitHub
parent 7f5575257d
commit fa7541f78e

View File

@@ -364,11 +364,36 @@ export def prepare-awk [] {
# 2. Convert ? to . (optional, as needed)
# 3. Convert / to \/
def glob-to-regex [patterns: list<string>] {
# Handle empty patterns list
if ($patterns | length) == 0 { return '' }
# Define a mapping of characters to escape
let regex_escapes = {
# Escape special regex characters first
"\\.": "\\\\.",
"\\+": "\\\\+",
"\\^": "\\\\^",
"\\$": "\\\\$",
"\\(": "\\\\(",
"\\)": "\\\\)",
"\\[": "\\\\[",
"\\]": "\\\\]",
"\\{": "\\\\{",
"\\}": "\\\\}",
"\\|": "\\\\|",
# Then convert glob patterns to regex patterns
"*": ".*",
"?": ".",
"/": "\\/",
}
$patterns
| each { |pat|
$pat | str replace "*" ".*" | str replace "?" "." | str replace "/" "\\/"
$regex_escapes | columns | reduce -f $pat { |k, acc|
$acc | str replace -a $k ($regex_escapes | get $k)
}
}
| str join "|"
| str join '|'
}
# Generate the awk include regex pattern string for the specified patterns