goutils
goutils copied to clipboard
fix: handle multi-byte UTF-8 characters in DeleteWhiteSpace
Fixes #29
Problem
DeleteWhiteSpace iterates by byte index (str[i]) and casts each byte to rune. For multi-byte UTF-8 characters (Chinese, Japanese, Korean, emoji, etc.), this produces mojibake:
DeleteWhiteSpace(" 测试 测试 ")
// Got: "æµ\x8dè¯\x95æµ\x8dè¯\x95"
// Expect: "测试测试"
Fix
Use range-based iteration which correctly yields Unicode runes instead of raw bytes.
// Before
for i := 0; i < sz; i++ {
ch := rune(str[i]) // BUG: treats each byte as a rune
// After
for _, ch := range str { // correctly iterates runes
All existing tests pass.