From b58d7cf68fc68b9ce6a932bb4f5e48f0a26f19d6 Mon Sep 17 00:00:00 2001 From: Jonathan Gautheron Date: Sun, 8 Nov 2020 15:11:42 +0100 Subject: [PATCH] Improvements after review --- visitor.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/visitor.go b/visitor.go index 8284bd9..b14f7c7 100644 --- a/visitor.go +++ b/visitor.go @@ -1,9 +1,9 @@ package goconst import ( - "fmt" "go/ast" "go/token" + "strconv" "strings" ) @@ -112,13 +112,11 @@ func (v *treeVisitor) Visit(node ast.Node) ast.Visitor { // addString adds a string in the map along with its position in the tree. func (v *treeVisitor) addString(str string, pos token.Pos) { + // Drop quotes if any if strings.HasPrefix(str, `"`) || strings.HasPrefix(str, "`") { - // Drop first and last character, quote, backquote... - str = str[1 : len(str)-1] + str, _ = strconv.Unquote(str) } - fmt.Println(str) - // Ignore empty strings if len(str) == 0 { return