update to use utf8.RuneCountInString for string length comparisons

updated baked in functions:
hasLengthOf
isGt
isGte
isLt
isLte

to use utf8.RuneCountInString for string length comparisons, not counting multi-bye
characters but runes in string length comparisons.
pull/112/head
joeybloggs 10 years ago
parent b52f154023
commit 89e9d9731d
  1. 10
      baked_in.go

@ -592,7 +592,7 @@ func isGte(top interface{}, current interface{}, field interface{}, param string
case reflect.String:
p := asInt(param)
return int64(len(st.String())) >= p
return int64(utf8.RuneCountInString(st.String())) >= p
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)
@ -637,7 +637,7 @@ func isGt(top interface{}, current interface{}, field interface{}, param string)
case reflect.String:
p := asInt(param)
return int64(len(st.String())) > p
return int64(utf8.RuneCountInString(st.String())) > p
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)
@ -681,7 +681,7 @@ func hasLengthOf(top interface{}, current interface{}, field interface{}, param
case reflect.String:
p := asInt(param)
return int64(len([]rune(st.String()))) == p
return int64(utf8.RuneCountInString(st.String())) == p
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)
@ -875,7 +875,7 @@ func isLte(top interface{}, current interface{}, field interface{}, param string
case reflect.String:
p := asInt(param)
return int64(len(st.String())) <= p
return int64(utf8.RuneCountInString(st.String())) <= p
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)
@ -920,7 +920,7 @@ func isLt(top interface{}, current interface{}, field interface{}, param string)
case reflect.String:
p := asInt(param)
return int64(len(st.String())) < p
return int64(utf8.RuneCountInString(st.String())) < p
case reflect.Slice, reflect.Map, reflect.Array:
p := asInt(param)

Loading…
Cancel
Save