- commit
- 48aed3604e0437c9ddc3a7df7eaa258cebf8a37f
- parent
- 3ab9a995a14d9395c18b3321e4437d74d7c23f0b
- author
- Dami <dami.etoile@gmail.com>
- kind
- refactor risk score 1.0 of 3, Jev's estimate
| M | internal/ | 37 | +++++++++++++++++------------- |
@@ -133,22 +133,7 @@ func Dump(w io.Writer, b *Book) error {
133133 sd := b.side(s)134134 q := sheet.QuoteSheet(s.name)135135 fmt.Fprintf(bw, "sheet %s\n", s.name)136- for _, k := range slices.Sorted(maps.Keys(s.fields)) {137- if k == "notebookCells" {138- for _, line := range dumpNotebook(s.name, s.fields[k]) {139- bw.WriteString(line + "\n")140- }141- continue142- }143- if k == "regions" || k == "tables" {144- what := strings.TrimSuffix(k, "s")145- for _, name := range slices.Sorted(maps.Keys(named(s.fields[k]))) {146- fmt.Fprintf(bw, "%s %s %s %s\n", s.name, what, name, named(s.fields[k])[name])147- }148- continue149- }150- fmt.Fprintf(bw, "%s %s %s\n", s.name, k, s.fields[k])151- }136+ dumpFields(bw, s)152137 for _, at := range sortedAddrs(s.cells) {153138 bw.WriteString(q + "!" + cellLine(sd, at, s.cells[at.String()]) + "\n")154139 }@@ -169,6 +154,26 @@ func Dump(w io.Writer, b *Book) error {
169154 return bw.Flush()170155 }171156 157+// dumpFields writes a sheet's fields as Dump does: a notebook's cells,158+// regions and tables one line each, and each other field whole.159+func dumpFields(bw *bufio.Writer, s *rawSheet) {160+ for _, k := range slices.Sorted(maps.Keys(s.fields)) {161+ switch k {162+ case "notebookCells":163+ for _, line := range dumpNotebook(s.name, s.fields[k]) {164+ bw.WriteString(line + "\n")165+ }166+ case "regions", "tables":167+ what := strings.TrimSuffix(k, "s")168+ for _, name := range slices.Sorted(maps.Keys(named(s.fields[k]))) {169+ fmt.Fprintf(bw, "%s %s %s %s\n", s.name, what, name, named(s.fields[k])[name])170+ }171+ default:172+ fmt.Fprintf(bw, "%s %s %s\n", s.name, k, s.fields[k])173+ }174+ }175+}176+172177 // cellLine is a cell as Dump writes it after its sheet: B7 =SUM(A1:A6)173178 // = 21 [currency, decimals 2] note: …174179 func cellLine(sd side, at sheet.Addr, raw json.RawMessage) string {