mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.1 KiB
61 lines
1.1 KiB
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strings"
|
||
5 years ago
|
"unicode"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func singleSearch(exp []string, text string) []string {
|
||
|
items := strings.Split(text, " ")
|
||
|
var result []string
|
||
5 years ago
|
|
||
5 years ago
|
for _, item := range items {
|
||
|
for _, word := range exp {
|
||
|
if strings.Contains(item, word) {
|
||
|
result = append(result, item)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
}
|
||
5 years ago
|
return result
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
func simpleSearch(runes []rune, text string) []string {
|
||
|
exp := string(runes)
|
||
5 years ago
|
|
||
|
var result []string
|
||
5 years ago
|
if !strings.ContainsRune(exp, '|') {
|
||
5 years ago
|
helper := []string{exp}
|
||
|
result = append(singleSearch(helper, text))
|
||
|
} else {
|
||
|
expWords := strings.Split(exp, "|")
|
||
|
result = append(result, singleSearch(expWords, text)...)
|
||
|
}
|
||
|
return result
|
||
|
}
|
||
|
|
||
5 years ago
|
func brackets(regexp, text string) {
|
||
|
if text == "" || regexp == "" {
|
||
|
return
|
||
|
}
|
||
|
runes := []rune(regexp)
|
||
5 years ago
|
|
||
5 years ago
|
if runes[0] == '(' && runes[len(runes)-1] == ')' {
|
||
|
runes = runes[1 : len(runes)-1]
|
||
|
result := simpleSearch(runes, text)
|
||
|
for i, s := range result {
|
||
4 years ago
|
if !unicode.IsLetter(rune(s[len(s)-1])) {
|
||
4 years ago
|
s = s[0 : len(s)-1]
|
||
5 years ago
|
}
|
||
5 years ago
|
fmt.Printf("%d: %s\n", i+1, s)
|
||
5 years ago
|
}
|
||
|
}
|
||
5 years ago
|
}
|
||
4 years ago
|
|
||
5 years ago
|
func main() {
|
||
|
if len(os.Args) == 3 {
|
||
|
brackets(os.Args[1], os.Args[2])
|
||
|
}
|
||
5 years ago
|
}
|