Exemple #1
0
func jsonSearch(w http.ResponseWriter, words []string) {
	saved := make(chan bool)
	runeIndex := runelib.GetIndex(saved)

	result := runeIndex.Find(words)
	count := len(result)

	output := SearchResponse{
		Count:  count,
		Result: result,
	}

	serialized, _ := json.Marshal(output)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintf(w, string(serialized))
}
Exemple #2
0
func txtSearch(w http.ResponseWriter, words []string) {
	saved := make(chan bool)
	runeIndex := runelib.GetIndex(saved)
	count := 0
	template := "U+%04X  %c \t%s\n"

	for _, uchar := range runeIndex.Find(words) {
		if uchar > 0xFFFF {
			template = "U+%5X %c \t%s\n"
		}
		fmt.Fprintf(w, template, uchar, uchar, runeIndex.Name(uchar))
		count++
	}

	fmt.Fprintf(w, "%d characters found\n", count)
	if <-saved {
		fmt.Fprint(w, "Index saved.")
	}
}
Exemple #3
0
func main() {
	if len(os.Args) < 2 {
		fmt.Println("Usage:  runefinder <word>\texample: runefinder cat")
		os.Exit(1)
	}

	words := os.Args[1:]
	saved := make(chan bool)
	runeIndex := runelib.GetIndex(saved)
	count := 0
	format := "U+%04X  %c \t%s\n"

	for _, uchar := range runeIndex.Find(words) {
		if uchar > 0xFFFF {
			format = "U+%5X %c \t%s\n"
		}
		fmt.Printf(format, uchar, uchar, runeIndex.Name(uchar))
		count++
	}
	fmt.Printf("%d characters found\n", count)
	if <-saved {
		fmt.Println("Index saved.")
	}
}