1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "golang.org/x/text/internal/colltab"
15 // table is an intermediate structure that roughly resembles the table in collate.
22 // print writes the table as Go compilable code to w. It prefixes the
23 // variable names with name. It returns the number of bytes written
24 // and the size of the resulting table.
25 func (t *table) fprint(w io.Writer, name string) (n, size int, err error) {
26 update := func(nn, sz int, e error) {
33 // Write arrays needed for the structure.
34 update(printColElems(w, t.ExpandElem, name+"ExpandElem"))
35 update(printColElems(w, t.ContractElem, name+"ContractElem"))
36 update(t.trie.printArrays(w, name))
37 update(printArray(t.ContractTries, w, name))
39 nn, e := fmt.Fprintf(w, "// Total size of %sTable is %d bytes\n", name, size)
44 func (t *table) fprintIndex(w io.Writer, h *trieHandle, id string) (n int, err error) {
45 p := func(f string, a ...interface{}) {
46 nn, e := fmt.Fprintf(w, f, a...)
53 p("\t\tlookupOffset: 0x%x,\n", h.lookupStart)
54 p("\t\tvaluesOffset: 0x%x,\n", h.valueStart)
59 func printColElems(w io.Writer, a []uint32, name string) (n, sz int, err error) {
60 p := func(f string, a ...interface{}) {
61 nn, e := fmt.Fprintf(w, f, a...)
67 sz = len(a) * int(reflect.TypeOf(uint32(0)).Size())
68 p("// %s: %d entries, %d bytes\n", name, len(a), sz)
69 p("var %s = [%d]uint32 {", name, len(a))
73 p("\n\t// Block %d, offset 0x%x\n", i/64, i)