-
-
Save graphaelli/bc3d48040db5c0124df1eb2a5a0db884 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// program to list all unicode characters with a given name | |
// and their code points | |
import ( | |
"fmt" | |
"os" | |
"regexp" | |
"strings" | |
"unicode" | |
"golang.org/x/text/unicode/runenames" | |
) | |
func main() { | |
match := regexp.MustCompile(``) | |
if len(os.Args) > 1 { | |
match = regexp.MustCompile("(?i)" + strings.Join(os.Args[1:], " ")) | |
} | |
// unicode.Common | |
rt := unicode.Scripts["Common"] | |
print := func(r rune) { | |
name := runenames.Name(r) | |
if unicode.IsPrint(r) && match.MatchString(name) { | |
fmt.Printf("%c %U %s\n", r, r, name) | |
} | |
} | |
for _, r16 := range rt.R16 { | |
for r := r16.Lo; r <= r16.Hi; r += r16.Stride { | |
print(rune(r)) | |
} | |
} | |
for _, r32 := range rt.R32 { | |
for r := r32.Lo; r <= r32.Hi; r += r32.Stride { | |
print(rune(r)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment