all repos — grayfriday @ e02c392dc656371e48ec50c6b0acdfbfbee31439

blackfriday fork with a few changes

Extract useful code to separate func
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 22 Jan 2014 00:45:43 +0200
commit

e02c392dc656371e48ec50c6b0acdfbfbee31439

parent

5405274d9994556c49bed724889558c8de335ffe

1 files changed, 26 insertions(+), 17 deletions(-)

jump to
M html.gohtml.go

@@ -722,6 +722,29 @@ found, _ := findHtmlTagPos(tag, tagname)

return found } +// Look for a character, but ignore it when it's in any kind of quotes, it +// might be JavaScript +func skipUntilCharIgnoreQuotes(html []byte, start int, char byte) int { + inSingleQuote := false + inDoubleQuote := false + inGraveQuote := false + i := start + for i < len(html) { + switch { + case html[i] == char && !inSingleQuote && !inDoubleQuote && !inGraveQuote: + return i + case html[i] == '\'': + inSingleQuote = !inSingleQuote + case html[i] == '"': + inDoubleQuote = !inDoubleQuote + case html[i] == '`': + inGraveQuote = !inGraveQuote + } + i++ + } + return start +} + func findHtmlTagPos(tag []byte, tagname string) (bool, int) { i := 0 if i < len(tag) && tag[0] != '<' {

@@ -750,23 +773,9 @@ if i == len(tag) {

return false, -1 } - // Now look for closing '>', but ignore it when it's in any kind of quotes, - // it might be JavaScript - inSingleQuote := false - inDoubleQuote := false - inGraveQuote := false - for i < len(tag) { - switch { - case tag[i] == '>' && !inSingleQuote && !inDoubleQuote && !inGraveQuote: - return true, i - case tag[i] == '\'': - inSingleQuote = !inSingleQuote - case tag[i] == '"': - inDoubleQuote = !inDoubleQuote - case tag[i] == '`': - inGraveQuote = !inGraveQuote - } - i++ + rightAngle := skipUntilCharIgnoreQuotes(tag, i, '>') + if rightAngle > i { + return true, rightAngle } return false, -1