Refactor how newlines are added to a document
This commit is contained in:
parent
7a8abf8d41
commit
19b4c30578
9
main.go
9
main.go
|
@ -52,7 +52,6 @@ func buildInfoText(ln string) string {
|
|||
out.WriteString("i")
|
||||
out.WriteString(ln)
|
||||
out.WriteString("\tfalse\tnull.host\t1")
|
||||
out.WriteString("\n")
|
||||
return out.String()
|
||||
}
|
||||
|
||||
|
@ -60,9 +59,9 @@ func deconstructInfoText(ln string) string {
|
|||
text := strings.SplitN(ln, "\t", 2)
|
||||
infotext := text[0]
|
||||
if len(infotext) > 1 {
|
||||
return infotext[1:] + "\n"
|
||||
return infotext[1:]
|
||||
}
|
||||
return "\n"
|
||||
return ""
|
||||
}
|
||||
|
||||
func readFile(path string, build bool) bytes.Buffer {
|
||||
|
@ -81,10 +80,10 @@ func processFile(file io.Reader, build bool) bytes.Buffer {
|
|||
l := scanner.Text()
|
||||
if exp := re.MatchString(l); exp {
|
||||
outFile.WriteString(l)
|
||||
outFile.WriteString("\n")
|
||||
} else {
|
||||
outFile.WriteString(buildInfoText(l))
|
||||
}
|
||||
outFile.WriteString("\n")
|
||||
}
|
||||
} else {
|
||||
for scanner.Scan() {
|
||||
|
@ -93,8 +92,8 @@ func processFile(file io.Reader, build bool) bytes.Buffer {
|
|||
outFile.WriteString(deconstructInfoText(l))
|
||||
} else {
|
||||
outFile.WriteString(l)
|
||||
outFile.WriteString("\n")
|
||||
}
|
||||
outFile.WriteString("\n")
|
||||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
|
|
|
@ -12,7 +12,7 @@ var buildInfoTextTestCases = []struct {
|
|||
{
|
||||
//Plain line of text is converted to info text
|
||||
"A line of text",
|
||||
"iA line of text false null.host 1\n",
|
||||
"iA line of text false null.host 1",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue