summaryrefslogtreecommitdiffstats
path: root/cnmfmt/cnmfmt.go
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2017-08-24 17:21:03 +0200
committerclsr <clsr@clsr.net>2017-08-24 17:21:03 +0200
commit0cf5f7a9b1fcb272cd9d632bc76219edd7077c39 (patch)
tree106230b508851a313aaab30982402d25085c6378 /cnmfmt/cnmfmt.go
parent4184f047985bb28e79dd11863fe76c71865d89db (diff)
downloadcnm-go-0cf5f7a9b1fcb272cd9d632bc76219edd7077c39.tar.gz
cnm-go-0cf5f7a9b1fcb272cd9d632bc76219edd7077c39.zip
Export WriteIndent
Diffstat (limited to 'cnmfmt/cnmfmt.go')
-rw-r--r--cnmfmt/cnmfmt.go27
1 files changed, 2 insertions, 25 deletions
diff --git a/cnmfmt/cnmfmt.go b/cnmfmt/cnmfmt.go
index cb8dc64..fa2ec65 100644
--- a/cnmfmt/cnmfmt.go
+++ b/cnmfmt/cnmfmt.go
@@ -199,7 +199,7 @@ func (t Text) WriteIndent(w io.Writer, n int) error {
si = cleanupTags(state[:], order, span.Format)
format = span.Format
}
- return writeIndent(w, strings.Join(line, ""), n)
+ return cnm.WriteIndent(w, strings.Join(line, ""), n)
}
func tagOrder(state []byte, old, new Format) []byte {
@@ -430,7 +430,7 @@ func NewTextFmtBlock(paragraphs []Text) *cnm.TextBlock {
func (tf TextFmtContents) WriteIndent(w io.Writer, n int) error {
for i, p := range tf.Paragraphs {
if i != 0 {
- if err := writeIndent(w, "", 0); err != nil {
+ if err := cnm.WriteIndent(w, "", 0); err != nil {
return err
}
}
@@ -469,29 +469,6 @@ func Parse(paragraphs string) []Text {
return txt
}
-func writeIndent(w io.Writer, s string, depth int) error {
- const tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
-
- if s == "" {
- _, err := w.Write([]byte{'\n'})
- return err
- }
- if depth == 0 {
- _, err := w.Write([]byte(s + "\n"))
- return err
- }
-
- var ind string
- if depth <= len(tabs) {
- ind = tabs[:depth]
- } else {
- ind = strings.Repeat("\t", depth)
- }
- _, err := w.Write([]byte(ind + s + "\n"))
- return err
-
-}
-
func parseTextFmt(p *cnm.Parser, block *cnm.TokenBlock) (cnm.TextContents, error) {
txt := TextFmtContents{}
var paragraph []string