// writeKeys writes keys to a special index used by the display package. // tags are assumed to be sorted by length. func writeKeys(w *gen.CodeWriter, name string, keys []string) { w.Size += int(3 * reflect.TypeOf("").Size()) w.WriteComment("Number of keys: %d", len(keys)) fmt.Fprintf(w, "var (\n\t%sIndex = tagIndex{\n", name) for i := 2; i <= 4; i++ { sub := []string{} for _, t := range keys { if len(t) != i { break } sub = append(sub, t) } s := strings.Join(sub, "") w.WriteString(s) fmt.Fprintf(w, ",\n") keys = keys[len(sub):] } fmt.Fprintln(w, "\t}") if len(keys) > 0 { w.Size += int(reflect.TypeOf([]string{}).Size()) fmt.Fprintf(w, "\t%sTagsLong = ", name) w.WriteSlice(keys) } fmt.Fprintln(w, ")\n") }
func (h *header) writeEntry(w *gen.CodeWriter, name string) { if len(dict) > 0 && dict.contains(h.tag) { fmt.Fprintf(w, "\t{ // %s\n", h.tag) fmt.Fprintf(w, "\t\t%[1]s%[2]sStr,\n\t\t%[1]s%[2]sIdx,\n", identifier(h.tag), name) fmt.Fprintln(w, "\t},") } else if len(h.data) == 0 { fmt.Fprintln(w, "\t\t{}, //", h.tag) } else { fmt.Fprintf(w, "\t{ // %s\n", h.tag) w.WriteString(h.data) fmt.Fprintln(w, ",") w.WriteSlice(h.index) fmt.Fprintln(w, ",\n\t},") } }