all repos — grayfriday @ f4655604b394cf7f941cbebea9bbf0e3ed9afd88

blackfriday fork with a few changes

Cleanup a random bunch of repetitive loops

Replace them with helper function calls.
Vytautas Ĺ altenis vytas@rtfb.lt
Tue, 07 Apr 2015 21:59:42 +0300
commit

f4655604b394cf7f941cbebea9bbf0e3ed9afd88

parent

36787eca3aa824e3c17b9c00feaf307c543fbe97

2 files changed, 18 insertions(+), 34 deletions(-)

jump to
M block.goblock.go

@@ -196,11 +196,8 @@ level := 0

for level < 6 && data[level] == '#' { level++ } - i, end := 0, 0 - for i = level; data[i] == ' '; i++ { - } - for end = i; data[end] != '\n'; end++ { - } + i := skipChar(data, level, ' ') + end := skipUntilChar(data, i, '\n') skip := end id := "" if p.flags&EXTENSION_HEADER_IDS != 0 {

@@ -245,13 +242,8 @@

func (p *parser) isUnderlinedHeader(data []byte) int { // test of level 1 header if data[0] == '=' { - i := 1 - for data[i] == '=' { - i++ - } - for data[i] == ' ' { - i++ - } + i := skipChar(data, 1, '=') + i = skipChar(data, i, ' ') if data[i] == '\n' { return 1 } else {

@@ -261,13 +253,8 @@ }

// test of level 2 header if data[0] == '-' { - i := 1 - for data[i] == '-' { - i++ - } - for data[i] == ' ' { - i++ - } + i := skipChar(data, 1, '-') + i = skipChar(data, i, ' ') if data[i] == '\n' { return 2 } else {

@@ -596,10 +583,7 @@ }

if syntax != nil { syn := 0 - - for i < len(data) && data[i] == ' ' { - i++ - } + i = skipChar(data, i, ' ') if i >= len(data) { return

@@ -643,9 +627,7 @@ language := string(data[syntaxStart : syntaxStart+syn])

*syntax = &language } - for i < len(data) && data[i] == ' ' { - i++ - } + i = skipChar(data, i, ' ') if i >= len(data) || data[i] != '\n' { return }

@@ -674,11 +656,7 @@ break

} // copy the current line - end := beg - for end < len(data) && data[end] != '\n' { - end++ - } - end++ + end := skipUntilChar(data, beg, '\n') + 1 // did we reach the end of the buffer without a closing marker? if end >= len(data) {

@@ -781,9 +759,7 @@

if data[i] == '|' && !isBackslashEscaped(data, i) { i++ } - for data[i] == ' ' { - i++ - } + i = skipChar(data, i, ' ') // each column header is of form: / *:?-+:? *|/ with # dashes + # colons >= 3 // and trailing | optional on last column
M html.gohtml.go

@@ -867,6 +867,14 @@ }

return i } +func skipChar(data []byte, start int, char byte) int { + i := start + for i < len(data) && data[i] == char { + i++ + } + return i +} + func doubleSpace(out *bytes.Buffer) { if out.Len() > 0 { out.WriteByte('\n')