unicode package provides data and functions to test Unicode code point properties.
Character Classification
Case Conversion
Character Categories
Ranges and Scripts
unicode/utf8
UTF-8 encoding/decoding.unicode/utf16
UTF-16 encoding/decoding.Practical Examples
Count Character Types
Title Case
Strip Non-Letters
Validate Identifier
Count Bytes vs Runes
Common Character Sets
Best Practices
- Use utf8.RuneCountInString - Not len() for character count
- Range over runes - Use
for _, r := range str - Validate UTF-8 - Check with ValidString before processing
- Handle multi-byte - Be aware of bytes vs runes
- Use unicode functions - For proper case conversion
- Consider normalization - Use golang.org/x/text/unicode/norm