Skip to content

Commit 89e9d97

Browse files
joeybloggsjoeybloggs
authored andcommitted
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.
1 parent b52f154 commit 89e9d97

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

baked_in.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ func isGte(top interface{}, current interface{}, field interface{}, param string
592592
case reflect.String:
593593
p := asInt(param)
594594

595-
return int64(len(st.String())) >= p
595+
return int64(utf8.RuneCountInString(st.String())) >= p
596596

597597
case reflect.Slice, reflect.Map, reflect.Array:
598598
p := asInt(param)
@@ -637,7 +637,7 @@ func isGt(top interface{}, current interface{}, field interface{}, param string)
637637
case reflect.String:
638638
p := asInt(param)
639639

640-
return int64(len(st.String())) > p
640+
return int64(utf8.RuneCountInString(st.String())) > p
641641

642642
case reflect.Slice, reflect.Map, reflect.Array:
643643
p := asInt(param)
@@ -681,7 +681,7 @@ func hasLengthOf(top interface{}, current interface{}, field interface{}, param
681681
case reflect.String:
682682
p := asInt(param)
683683

684-
return int64(len([]rune(st.String()))) == p
684+
return int64(utf8.RuneCountInString(st.String())) == p
685685

686686
case reflect.Slice, reflect.Map, reflect.Array:
687687
p := asInt(param)
@@ -875,7 +875,7 @@ func isLte(top interface{}, current interface{}, field interface{}, param string
875875
case reflect.String:
876876
p := asInt(param)
877877

878-
return int64(len(st.String())) <= p
878+
return int64(utf8.RuneCountInString(st.String())) <= p
879879

880880
case reflect.Slice, reflect.Map, reflect.Array:
881881
p := asInt(param)
@@ -920,7 +920,7 @@ func isLt(top interface{}, current interface{}, field interface{}, param string)
920920
case reflect.String:
921921
p := asInt(param)
922922

923-
return int64(len(st.String())) < p
923+
return int64(utf8.RuneCountInString(st.String())) < p
924924

925925
case reflect.Slice, reflect.Map, reflect.Array:
926926
p := asInt(param)

0 commit comments

Comments
 (0)