-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
51 lines (47 loc) · 1.03 KB
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"os"
"strings"
"github.com/standupdev/runefinder"
"github.com/standupdev/runeset"
"golang.org/x/text/unicode/runenames"
)
func display(s runeset.Set) {
count := len(s)
for _, c := range s.Sorted() {
name := runenames.Name(c)
fmt.Printf("%U\t%[1]c\t%s\n", c, name)
}
var msg string
switch count {
case 0:
msg = "no character found"
case 1:
msg = "1 character found"
default:
msg = fmt.Sprintf("%d characters found", count)
}
fmt.Println(msg)
}
func main() {
query := strings.TrimSpace(strings.Join(os.Args[1:], " "))
if len(query) == 0 {
fmt.Println("Please provide one or more words or characters to search.")
return
}
nameChars := runeset.MakeFromString(" -0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
charQuery := false
for _, char := range query {
if !nameChars.Contains(char) {
charQuery = true
break
}
}
if charQuery {
display(runeset.MakeFromString(query))
} else {
index := runefinder.BuildIndex()
display(runefinder.Filter(index, query))
}
}