From 16da6101d07dc4f8801b6479c936280bf9a2fd5c Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Mon, 1 Oct 2012 13:55:44 -0700 Subject: [PATCH] extract readlines --- tool/generate.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tool/generate.go b/tool/generate.go index c0abe3a..8d5bedf 100644 --- a/tool/generate.go +++ b/tool/generate.go @@ -30,6 +30,12 @@ func pipe(bin string, arg []string, src string) string { return string(bytes) } +func readLines(path string) []string { + srcBytes, err := ioutil.ReadFile(path) + check(err) + return strings.Split(string(srcBytes), "\n") +} + var docsPat = regexp.MustCompile("^\\s*(\\/\\/|#)\\s") var headerPat = regexp.MustCompile("^\\s*(\\/\\/|#)\\s#+\\s") @@ -50,9 +56,7 @@ func main() { pygmentizePath, err := exec.LookPath("pygmentize") check(err) - srcBytes, err := ioutil.ReadFile(sourcePath) - check(err) - lines := strings.Split(string(srcBytes), "\n") + lines := readLines(sourcePath) segs := []*seg{} segs = append(segs, &seg{code: "", docs: ""})