Add util functions

This commit is contained in:
Tim Hockin
2015-07-10 16:17:51 -07:00
parent 95cd66d3a0
commit 8ff8559c4c
2 changed files with 75 additions and 0 deletions

View File

@@ -71,3 +71,30 @@ func updateMacroBlock(lines []string, beginMark, endMark, insertThis string) ([]
}
return buffer.Bytes(), nil
}
// Tests that a document, represented as a slice of lines, has a line. Ignores
// leading and trailing space.
func hasLine(lines []string, needle string) bool {
for _, line := range lines {
trimmedLine := strings.Trim(line, " \n")
if trimmedLine == needle {
return true
}
}
return false
}
// Tests that a document, represented as a slice of lines, has a macro block.
func hasMacroBlock(lines []string, begin string, end string) bool {
foundBegin := false
for _, line := range lines {
trimmedLine := strings.Trim(line, " \n")
switch {
case !foundBegin && trimmedLine == begin:
foundBegin = true
case foundBegin && trimmedLine == end:
return true
}
}
return false
}