diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-10-10 19:50:04 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-10-10 19:50:04 +0200 |
commit | 10d7c513c47441f9260946ecc4ccc80cdbb966d9 (patch) | |
tree | 3c5a666911c55e3bf57eb7c94cac96acabbc48fb /formatter | |
parent | 01f27f6ee3dad6f25cecc27e7051380644733066 (diff) |
Don’t use lambdas, and just use a damn for-loop
Diffstat (limited to 'formatter')
-rw-r--r-- | formatter/formatter.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/formatter/formatter.go b/formatter/formatter.go index 633c067..b8ec85f 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -2,7 +2,6 @@ package formatter import ( "fmt" - "slices" "unicode" "git.thomasvoss.com/gsp/parser" @@ -48,14 +47,16 @@ func PrintAst(ast parser.AstNode) { } func printAttrs(attrs []parser.Attr) { - classes := make([]parser.Attr, len(attrs), cap(attrs)) - copy(classes, attrs) - classes = slices.DeleteFunc(classes, func(a parser.Attr) bool { - return a.Key != "class" - }) - attrs = slices.DeleteFunc(attrs, func(a parser.Attr) bool { - return a.Key == "class" - }) + classes := make([]parser.Attr, 0, cap(attrs)) + nClasses := make([]parser.Attr, 0, cap(attrs)) + + for _, a := range attrs { + if a.Key == "class" { + classes = append(classes, a) + } else { + nClasses = append(nClasses, a) + } + } if len(classes) > 0 { fmt.Print(" class=\"") |