Description
Proposal Details
The standard packages write their own ASCII helper functions many times, for examples you can find ASCII-only isSpace
, toUpper
and equalFold
in "encoding/json", "net", "internal/filepathlite". The "net/http" also has a internal package called net/http/internal/ascii
.
Handling ASCII-encoded characters is a common requirement in the standard library, so a new package can share these logic and eliminate duplicate codes.
Based on my investigation of the standard library code, the new package should have these functions in it:
- Is/IsString (check if it is ASCII)
- IsLower/IsUpper
- ToLower/ToUpper (for single char)
- ToLowerString/ToUpperString
- EqualFold
- IsSpace
- TrimSpace
- IsDigit
- IsLetter
- IsPrint
This package should minimize external dependencies, and some necessary constants can be copied from packages such as "unicode".
Normal users can continue to use "bytes", "strings" and "unicode" for most tasks, so there is little point in making this package public. However, many standard packages can't directly import packages like "unicode", "strings", etc., so I thought it would be appropriate to put this new package in "internal".