Permalink
Browse files

Stop using regexes in clean

clean replaces special characters with '-'. Regexes are overkill for
this simple character replacement, so replace it with a simple loop.
  • Loading branch information...
prashantv committed Jan 21, 2016
1 parent a8c6b0e commit 87fa6d9ae553234169aeac719a67c4d39eca2777
Showing with 10 additions and 4 deletions.
  1. +10 −4 stats/reporter.go
View
@@ -3,7 +3,6 @@ package stats
import (
"flag"
"fmt"
"regexp"
"strings"
"time"
)
@@ -56,10 +55,17 @@ func addTagsToName(name string, tags map[string]string) string {
return strings.Join(parts, ".")
}
var specialChars = regexp.MustCompile(`[{}/\\:\s.]`)
// clean takes a string that may contain special characters, and replaces these
// characters with a '-'.
func clean(value string) string {
return specialChars.ReplaceAllString(value, "-")
newStr := make([]byte, len(value))
for i := 0; i < len(value); i++ {
switch c := value[i]; c {
case '{', '}', '/', '\\', ':', ' ', '\t', '.':
newStr[i] = '-'
default:
newStr[i] = c
}
}
return string(newStr)
}

0 comments on commit 87fa6d9

Please sign in to comment.