示例#1
0
func listCharsets(verbose bool, csname string) {
	var buf bytes.Buffer
	if !verbose {
		if csname != "" {
			cs := charset.Info(csname)
			if cs == nil {
				fatalf("no such charset %q", csname)
			}
			fmt.Fprintf(&buf, "%s %s\n", cs.Name, strings.Join(cs.Aliases, " "))
		} else {
			fmt.Fprintf(&buf, "%v\n", strings.Join(charset.Names(), " "))
		}
	} else {
		var charsets []*charset.Charset
		if csname != "" {
			cs := charset.Info(csname)
			if cs == nil {
				fatalf("no such charset %q", csname)
			}
			charsets = []*charset.Charset{cs}
		} else {
			for _, name := range charset.Names() {
				if cs := charset.Info(name); cs != nil {
					charsets = append(charsets, cs)
				}
			}
		}
		for _, cs := range charsets {
			fmt.Fprintf(&buf, "%s %s\n", cs.Name, strings.Join(cs.Aliases, " "))
			if cs.Desc != "" {
				fmt.Fprintf(&buf, "\t%s\n", cs.Desc)
			}
		}
	}
	os.Stdout.Write(buf.Bytes())
}
示例#2
0
func TestNames(t *testing.T) {
	charset.Names()
}