Browse Source

Use strings.Trim instead of regex to trim unicodeString

fixes #142
Mihail Stoykov 5 years ago
parent
commit
7bb4acfa4c
1 changed files with 1 additions and 6 deletions
  1. 1 6
      string_unicode.go

+ 1 - 6
string_unicode.go

@@ -9,7 +9,6 @@ import (
 	"io"
 	"math"
 	"reflect"
-	"regexp"
 	"strings"
 	"unicode/utf16"
 	"unicode/utf8"
@@ -30,10 +29,6 @@ var (
 	InvalidRuneError = errors.New("Invalid rune")
 )
 
-var (
-	unicodeTrimRegexp = regexp.MustCompile("^[" + parser.WhitespaceChars + "]*(.*?)[" + parser.WhitespaceChars + "]*$")
-)
-
 func (rr runeReaderReplace) ReadRune() (r rune, size int, err error) {
 	r, size, err = rr.wrapped.ReadRune()
 	if err == InvalidRuneError {
@@ -96,7 +91,7 @@ func (s unicodeString) toTrimmedUTF8() string {
 	if len(s) == 0 {
 		return ""
 	}
-	return unicodeTrimRegexp.FindStringSubmatch(s.String())[1]
+	return strings.Trim(s.String(), parser.WhitespaceChars)
 }
 
 func (s unicodeString) ToNumber() Value {