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.
65 lines
1.3 KiB
65 lines
1.3 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 {
|
||
5 years ago
|
if !unicode.Is(unicode.Hex_Digit, rune(s[len(s)-1])) {
|
||
5 years ago
|
s = s[:len(s)-1]
|
||
5 years ago
|
}
|
||
5 years ago
|
if !unicode.Is(unicode.Hex_Digit, rune(s[0])) {
|
||
5 years ago
|
s = s[1:]
|
||
|
}
|
||
|
fmt.Printf("%d: %s\n", i+1, s)
|
||
5 years ago
|
}
|
||
|
}
|
||
5 years ago
|
}
|
||
|
|
||
|
func main() {
|
||
|
// brackets("al|b", "ale atg bar sim nao pro par impar") In JS it's used without brackets
|
||
|
if len(os.Args) == 3 {
|
||
|
brackets(os.Args[1], os.Args[2])
|
||
|
}
|
||
5 years ago
|
}
|