Skip to content

Commit

Permalink
chore: sort template functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenhilton committed May 17, 2024
1 parent b5e1664 commit 9907d6a
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions templatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,6 @@ func NewFuncMap() template.FuncMap {
}
}

// prefixLinesTemplateFunc is the core implementation of the `prefixLines`
// template function.
func prefixLinesTemplateFunc(prefix, s string) string {
type stateType int
const (
startOfLine stateType = iota
inLine
)

state := startOfLine
var builder strings.Builder
builder.Grow(2 * len(s))
for _, r := range s {
switch state {
case startOfLine:
if _, err := builder.WriteString(prefix); err != nil {
panic(err)
}
if _, err := builder.WriteRune(r); err != nil {
panic(err)
}
if r != '\n' {
state = inLine
}
case inLine:
if _, err := builder.WriteRune(r); err != nil {
panic(err)
}
if r == '\n' {
state = startOfLine
}
}
}
return builder.String()
}

// eqFoldTemplateFunc is the core implementation of the `eqFold` template
// function.
func eqFoldTemplateFunc(first, second string, more ...string) bool {
Expand Down Expand Up @@ -145,6 +109,42 @@ func lstatTemplateFunc(name string) any {
}
}

// prefixLinesTemplateFunc is the core implementation of the `prefixLines`
// template function.
func prefixLinesTemplateFunc(prefix, s string) string {
type stateType int
const (
startOfLine stateType = iota
inLine
)

state := startOfLine
var builder strings.Builder
builder.Grow(2 * len(s))
for _, r := range s {
switch state {
case startOfLine:
if _, err := builder.WriteString(prefix); err != nil {
panic(err)
}
if _, err := builder.WriteRune(r); err != nil {
panic(err)
}
if r != '\n' {
state = inLine
}
case inLine:
if _, err := builder.WriteRune(r); err != nil {
panic(err)
}
if r == '\n' {
state = startOfLine
}
}
}
return builder.String()
}

// regexpReplaceAllTemplateFunc is the core implementation of the
// `regexpReplaceAll` template function.
func regexpReplaceAllTemplateFunc(expr, repl, s string) string {
Expand Down

0 comments on commit 9907d6a

Please sign in to comment.