|
|
@ -9,12 +9,12 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
"github.com/fatih/color"
|
|
|
|
|
|
|
|
|
|
|
|
"gitea.twomorecents.org/Rockingcool/kg/greg"
|
|
|
|
reg "gitea.twomorecents.org/Rockingcool/kg/regex"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
// Flags for the regex Compile function
|
|
|
|
// Flags for the regex Compile function
|
|
|
|
flagsToCompile := make([]greg.ReFlag, 0)
|
|
|
|
flagsToCompile := make([]reg.ReFlag, 0)
|
|
|
|
|
|
|
|
|
|
|
|
invertFlag := flag.Bool("v", false, "Invert match.")
|
|
|
|
invertFlag := flag.Bool("v", false, "Invert match.")
|
|
|
|
// This flag has two 'modes':
|
|
|
|
// This flag has two 'modes':
|
|
|
@ -31,10 +31,10 @@ func main() {
|
|
|
|
|
|
|
|
|
|
|
|
// These flags have to be passed to the Compile function
|
|
|
|
// These flags have to be passed to the Compile function
|
|
|
|
if *multiLineFlag {
|
|
|
|
if *multiLineFlag {
|
|
|
|
flagsToCompile = append(flagsToCompile, greg.RE_MULTILINE, greg.RE_SINGLE_LINE)
|
|
|
|
flagsToCompile = append(flagsToCompile, reg.RE_MULTILINE, reg.RE_SINGLE_LINE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if *caseInsensitiveFlag {
|
|
|
|
if *caseInsensitiveFlag {
|
|
|
|
flagsToCompile = append(flagsToCompile, greg.RE_CASE_INSENSITIVE)
|
|
|
|
flagsToCompile = append(flagsToCompile, reg.RE_CASE_INSENSITIVE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -l and -o are mutually exclusive: -o overrides -l
|
|
|
|
// -l and -o are mutually exclusive: -o overrides -l
|
|
|
@ -78,7 +78,7 @@ func main() {
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
out := bufio.NewWriter(os.Stdout)
|
|
|
|
out := bufio.NewWriter(os.Stdout)
|
|
|
|
|
|
|
|
|
|
|
|
regComp, err := greg.Compile(re, flagsToCompile...)
|
|
|
|
regComp, err := reg.Compile(re, flagsToCompile...)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -119,14 +119,14 @@ func main() {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
matchIndices := make([]greg.Match, 0)
|
|
|
|
matchIndices := make([]reg.Match, 0)
|
|
|
|
if matchNumFlagEnabled {
|
|
|
|
if matchNumFlagEnabled {
|
|
|
|
tmp, err := greg.FindNthMatch(regComp, test_str, *matchNum)
|
|
|
|
tmp, err := reg.FindNthMatch(regComp, test_str, *matchNum)
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
matchIndices = append(matchIndices, tmp)
|
|
|
|
matchIndices = append(matchIndices, tmp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
matchIndices = greg.FindAllMatches(regComp, test_str)
|
|
|
|
matchIndices = reg.FindAllMatches(regComp, test_str)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if *printMatchesFlag {
|
|
|
|
if *printMatchesFlag {
|
|
|
|