从符文获取unicode类别

Tyl*_*eat 3 unicode go rune

我正在寻找一种RangeTableruneGo中获取unicode category()的方法.例如,角色a映射到Ll类别.该unicode软件包指定了所有类别(http://golang.org/pkg/unicode/#pkg-variables),但我没有看到任何方法从给定的类别中查找类别rune.我是否需要RangeTablerune使用适当的偏移量手动构建?

Ale*_*hov 8

"unicode"包的文档没有返回符文范围的方法,但构建符号并不是很棘手:

func cat(r rune) (names []string) {
    names = make([]string, 0)
    for name, table := range unicode.Categories {
        if unicode.Is(table, r) {
            names = append(names, name)
        }
    }
    return
}
Run Code Online (Sandbox Code Playgroud)