aboutsummaryrefslogtreecommitdiff
path: root/src/html
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2017-11-13 09:43:17 +0000
committerDaniel Martí <mvdan@mvdan.cc>2018-02-19 21:33:14 +0000
commit60cf9ec677cb87cce1480b2d442c64f051b7c007 (patch)
tree8bc5756389a6563c9a6afa1e450ea16b5c1a0e8a /src/html
parent3cb54c86043a92ab080a89c06643d80015a5638e (diff)
downloadgo-60cf9ec677cb87cce1480b2d442c64f051b7c007.tar.gz
go-60cf9ec677cb87cce1480b2d442c64f051b7c007.zip
all: add more uses of stringer
By grepping for ]string{$, one can find many manual implementations of stringer. The debug/dwarf ones needed the new -trimprefix flag, too. html/template was fairly simple, just implementing the fallback as stringer would. The changes there are trivial. The ones in debug/dwarf needed a bit of extra logic since the GoString wants to use its own format, depending on whether or not the value is one of the known constants. Change-Id: I501ea7deaa538fa425c8e9c2bb895f480169273f Reviewed-on: https://go-review.googlesource.com/77253 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/html')
-rw-r--r--src/html/template/attr_string.go16
-rw-r--r--src/html/template/context.go18
2 files changed, 18 insertions, 16 deletions
diff --git a/src/html/template/attr_string.go b/src/html/template/attr_string.go
new file mode 100644
index 0000000000..babe70c08b
--- /dev/null
+++ b/src/html/template/attr_string.go
@@ -0,0 +1,16 @@
+// Code generated by "stringer -type attr"; DO NOT EDIT.
+
+package template
+
+import "strconv"
+
+const _attr_name = "attrNoneattrScriptattrScriptTypeattrStyleattrURLattrSrcset"
+
+var _attr_index = [...]uint8{0, 8, 18, 32, 41, 48, 58}
+
+func (i attr) String() string {
+ if i >= attr(len(_attr_index)-1) {
+ return "attr(" + strconv.FormatInt(int64(i), 10) + ")"
+ }
+ return _attr_name[_attr_index[i]:_attr_index[i+1]]
+}
diff --git a/src/html/template/context.go b/src/html/template/context.go
index 50730d3f2b..7e28cf47e2 100644
--- a/src/html/template/context.go
+++ b/src/html/template/context.go
@@ -314,6 +314,8 @@ func (e element) String() string {
return fmt.Sprintf("illegal element %d", int(e))
}
+//go:generate stringer -type attr
+
// attr identifies the current HTML attribute when inside the attribute,
// that is, starting from stateAttrName until stateTag/stateText (exclusive).
type attr uint8
@@ -332,19 +334,3 @@ const (
// attrSrcset corresponds to a srcset attribute.
attrSrcset
)
-
-var attrNames = [...]string{
- attrNone: "attrNone",
- attrScript: "attrScript",
- attrScriptType: "attrScriptType",
- attrStyle: "attrStyle",
- attrURL: "attrURL",
- attrSrcset: "attrSrcset",
-}
-
-func (a attr) String() string {
- if int(a) < len(attrNames) {
- return attrNames[a]
- }
- return fmt.Sprintf("illegal attr %d", int(a))
-}