all repos — grayfriday @ a5270b6f564501a64972e7d7fb907e9937102c35

blackfriday fork with a few changes

Shorten method receivers in Smartypants
Vytautas Šaltenis vytas@rtfb.lt
Thu, 28 Jul 2016 19:26:25 +0300
commit

a5270b6f564501a64972e7d7fb907e9937102c35

parent

46b7355a788e9af2207ab63452dbb1c236e31f6d

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

jump to
M smartypants.gosmartypants.go

@@ -109,7 +109,7 @@ out.WriteString("quo;")

return true } -func (smrt *SPRenderer) smartSingleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartSingleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { if len(text) >= 2 { t1 := tolower(text[1])

@@ -118,7 +118,7 @@ nextChar := byte(0)

if len(text) >= 3 { nextChar = text[2] } - if smartQuoteHelper(out, previousChar, nextChar, 'd', &smrt.inDoubleQuote) { + if smartQuoteHelper(out, previousChar, nextChar, 'd', &r.inDoubleQuote) { return 1 } }

@@ -143,7 +143,7 @@ nextChar := byte(0)

if len(text) > 1 { nextChar = text[1] } - if smartQuoteHelper(out, previousChar, nextChar, 's', &smrt.inSingleQuote) { + if smartQuoteHelper(out, previousChar, nextChar, 's', &r.inSingleQuote) { return 0 }

@@ -151,7 +151,7 @@ out.WriteByte(text[0])

return 0 } -func (smrt *SPRenderer) smartParens(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartParens(out *bytes.Buffer, previousChar byte, text []byte) int { if len(text) >= 3 { t1 := tolower(text[1]) t2 := tolower(text[2])

@@ -176,7 +176,7 @@ out.WriteByte(text[0])

return 0 } -func (smrt *SPRenderer) smartDash(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartDash(out *bytes.Buffer, previousChar byte, text []byte) int { if len(text) >= 2 { if text[1] == '-' { out.WriteString("—")

@@ -193,7 +193,7 @@ out.WriteByte(text[0])

return 0 } -func (smrt *SPRenderer) smartDashLatex(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartDashLatex(out *bytes.Buffer, previousChar byte, text []byte) int { if len(text) >= 3 && text[1] == '-' && text[2] == '-' { out.WriteString("—") return 2

@@ -207,13 +207,13 @@ out.WriteByte(text[0])

return 0 } -func (smrt *SPRenderer) smartAmpVariant(out *bytes.Buffer, previousChar byte, text []byte, quote byte) int { +func (r *SPRenderer) smartAmpVariant(out *bytes.Buffer, previousChar byte, text []byte, quote byte) int { if bytes.HasPrefix(text, []byte(""")) { nextChar := byte(0) if len(text) >= 7 { nextChar = text[6] } - if smartQuoteHelper(out, previousChar, nextChar, quote, &smrt.inDoubleQuote) { + if smartQuoteHelper(out, previousChar, nextChar, quote, &r.inDoubleQuote) { return 5 } }

@@ -226,15 +226,15 @@ out.WriteByte('&')

return 0 } -func (smrt *SPRenderer) smartAmp(out *bytes.Buffer, previousChar byte, text []byte) int { - return smrt.smartAmpVariant(out, previousChar, text, 'd') +func (r *SPRenderer) smartAmp(out *bytes.Buffer, previousChar byte, text []byte) int { + return r.smartAmpVariant(out, previousChar, text, 'd') } -func (smrt *SPRenderer) smartAmpAngledQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - return smrt.smartAmpVariant(out, previousChar, text, 'a') +func (r *SPRenderer) smartAmpAngledQuote(out *bytes.Buffer, previousChar byte, text []byte) int { + return r.smartAmpVariant(out, previousChar, text, 'a') } -func (smrt *SPRenderer) smartPeriod(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartPeriod(out *bytes.Buffer, previousChar byte, text []byte) int { if len(text) >= 3 && text[1] == '.' && text[2] == '.' { out.WriteString("…") return 2

@@ -249,13 +249,13 @@ out.WriteByte(text[0])

return 0 } -func (smrt *SPRenderer) smartBacktick(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartBacktick(out *bytes.Buffer, previousChar byte, text []byte) int { if len(text) >= 2 && text[1] == '`' { nextChar := byte(0) if len(text) >= 3 { nextChar = text[2] } - if smartQuoteHelper(out, previousChar, nextChar, 'd', &smrt.inDoubleQuote) { + if smartQuoteHelper(out, previousChar, nextChar, 'd', &r.inDoubleQuote) { return 1 } }

@@ -264,7 +264,7 @@ out.WriteByte(text[0])

return 0 } -func (smrt *SPRenderer) smartNumberGeneric(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartNumberGeneric(out *bytes.Buffer, previousChar byte, text []byte) int { if wordBoundary(previousChar) && previousChar != '/' && len(text) >= 3 { // is it of the form digits/digits(word boundary)?, i.e., \d+/\d+\b // note: check for regular slash (/) or fraction slash (⁄, 0x2044, or 0xe2 81 84 in utf-8)

@@ -306,7 +306,7 @@ out.WriteByte(text[0])

return 0 } -func (smrt *SPRenderer) smartNumber(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartNumber(out *bytes.Buffer, previousChar byte, text []byte) int { if wordBoundary(previousChar) && previousChar != '/' && len(text) >= 3 { if text[0] == '1' && text[1] == '/' && text[2] == '2' { if len(text) < 4 || wordBoundary(text[3]) && text[3] != '/' {

@@ -334,27 +334,27 @@ out.WriteByte(text[0])

return 0 } -func (smrt *SPRenderer) smartDoubleQuoteVariant(out *bytes.Buffer, previousChar byte, text []byte, quote byte) int { +func (r *SPRenderer) smartDoubleQuoteVariant(out *bytes.Buffer, previousChar byte, text []byte, quote byte) int { nextChar := byte(0) if len(text) > 1 { nextChar = text[1] } - if !smartQuoteHelper(out, previousChar, nextChar, quote, &smrt.inDoubleQuote) { + if !smartQuoteHelper(out, previousChar, nextChar, quote, &r.inDoubleQuote) { out.WriteString("&quot;") } return 0 } -func (smrt *SPRenderer) smartDoubleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - return smrt.smartDoubleQuoteVariant(out, previousChar, text, 'd') +func (r *SPRenderer) smartDoubleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { + return r.smartDoubleQuoteVariant(out, previousChar, text, 'd') } -func (smrt *SPRenderer) smartAngledDoubleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { - return smrt.smartDoubleQuoteVariant(out, previousChar, text, 'a') +func (r *SPRenderer) smartAngledDoubleQuote(out *bytes.Buffer, previousChar byte, text []byte) int { + return r.smartDoubleQuoteVariant(out, previousChar, text, 'a') } -func (smrt *SPRenderer) smartLeftAngle(out *bytes.Buffer, previousChar byte, text []byte) int { +func (r *SPRenderer) smartLeftAngle(out *bytes.Buffer, previousChar byte, text []byte) int { i := 0 for i < len(text) && text[i] != '>' {

@@ -401,13 +401,13 @@ return &r

} // Process is the entry point of the Smartypants renderer. -func (smrt *SPRenderer) Process(text []byte) []byte { +func (r *SPRenderer) Process(text []byte) []byte { var buff bytes.Buffer // first do normal entity escaping text = esc(text) mark := 0 for i := 0; i < len(text); i++ { - if action := smrt.callbacks[text[i]]; action != nil { + if action := r.callbacks[text[i]]; action != nil { if i > mark { buff.Write(text[mark:i]) }