Skip to content

Commit 7c2abfe

Browse files
authored
Fix character counting (#5)
1 parent d5f5416 commit 7c2abfe

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

processors/strings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func StringToSlug(input string) string {
6060

6161
// CountNumberCharacters count number of Characters including spaces.
6262
func CountNumberCharacters(input string) string {
63-
return fmt.Sprintf("%d", len(input))
63+
return fmt.Sprintf("%d", len([]rune(input)))
6464
}
6565

6666
// CountWords count number of words in string.

processors/strings_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ func TestCountNumberCharacters(t *testing.T) {
1818
}, {
1919
name: "Emoji",
2020
args: args{input: "😃😇🙃🙂😉😌😙😗🇮🇳"},
21-
want: "40",
21+
want: "10",
2222
}, {
2323
name: "Multi line string",
2424
args: args{input: "123345\nabcd\n456\n123\nabc\n567\n7890"},
2525
want: "32",
2626
},
27+
{
28+
name: "Double-byte characters",
29+
args: args{input: "你好"},
30+
want: "2",
31+
},
2732
}
2833
for _, tt := range tests {
2934
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)