Documentation ¶
Overview ¶
Package text implements text processing and validation.
Index ¶
- Constants
- func DefaultValidate(text, fieldname string, minbytes, maxbytes int64) error
- func DefaultValidateAndNormalize(text, fieldname string, minbytes, maxbytes int64, extra ...TextValidator) (string, error)
- func DefaultValidateNoNewlineAndNormalize(text, fieldname string, minbytes, maxbytes int64, extra ...TextValidator) (string, error)
- func Normalize(text, fieldname string, normalizers ...TextNormalizer) (string, error)
- func ToCaselessNFKC(text, fieldname string) (string, error)
- func ToCaselessNFKCUnsafe(text, fieldname string) (string, error)
- func ToNFC(text, fieldname string) (string, error)
- func ToNFCUnsafe(text, fieldname string) (string, error)
- func TrimSpace(text, fieldname string) (string, error)
- func TrimSpaceUnsafe(text, fieldname string) (string, error)
- func Validate(text, fieldname string, validators ...TextValidator) error
- func ValidateAndNormalize(text, fieldname string, textnorm TextNormalizer, validators ...TextValidator) (string, error)
- func ValidateAndNormalizeMulti(text, fieldname string, textnorms []TextNormalizer, ...) (string, error)
- func ValidateCodepoints(text, fieldname string) error
- func ValidateEncoding(text, fieldname string) error
- func ValidateMaxBytes(text, fieldname string, min, max int64) error
- func ValidateNoNewlines(text, fieldname string) error
- func ValidateNoNewlinesUnsafe(text, fieldname string) error
- type TextNormalizer
- type TextValidator
Constants ¶
const UnicodeVersion = unicode.Version
Variables ¶
This section is empty.
Functions ¶
func DefaultValidate ¶
DefaultValidate performs regular validation. Use this by default
func DefaultValidateAndNormalize ¶
func DefaultValidateAndNormalize( text, fieldname string, minbytes, maxbytes int64, extra ...TextValidator) (string, error)
DefaultValidateAndNormalize performs regular normalization. Use this by default.
func DefaultValidateNoNewlineAndNormalize ¶
func DefaultValidateNoNewlineAndNormalize( text, fieldname string, minbytes, maxbytes int64, extra ...TextValidator) (string, error)
DefaultValidateNoNewlineAndNormalize performs regular normalization and fails on Newlines.
func Normalize ¶
func Normalize(text, fieldname string, normalizers ...TextNormalizer) (string, error)
Normalize normalizes text.
func ToCaselessNFKC ¶
ToCaselessCompatible normalizes to NFKC and casefolds text for comparison.
func ToCaselessNFKCUnsafe ¶
ToCaselessNFKCUnsafe converts prevalidated text into caseless NFKC. Text *must* have been previously validated in order to use this function. This never returns a non-nil error, and ignores the fieldname.
func ToNFCUnsafe ¶
ToNFCUnsafe converts prevalidated text into NFC. Text *must* have been previously validated in order to use this function. This never returns a non-nil error, and ignores the fieldname.
func TrimSpaceUnsafe ¶
TrimSpaceUnsafe removes leading and trailing whitespace. Text *must* have been previously validated in order to use this function. This never returns a non-nil error, and ignores the fieldname.
func Validate ¶
func Validate(text, fieldname string, validators ...TextValidator) error
Validate validates text.
func ValidateAndNormalize ¶
func ValidateAndNormalize( text, fieldname string, textnorm TextNormalizer, validators ...TextValidator) (string, error)
ValidateAndNormalize validates text, normalizes it, and then revalidates it.
func ValidateAndNormalizeMulti ¶
func ValidateAndNormalizeMulti( text, fieldname string, textnorms []TextNormalizer, validators ...TextValidator) (string, error)
ValidateAndNormalize validates text, normalizes it, and then revalidates it.
func ValidateCodepoints ¶
ValidateCodepoints ensures that the string only contains reasonable characters. By default, Unicode classes Cc (controls), Co (private use), Cs (surrogates), and Noncharacters are forbidden. (\t, \r, and \n are allowed, though). Allowed classes include L (letters), M (marks), N (numbers), P (punctuation), S (symbols), Z (separators/spaces), and Cf (formats). Additionally, reserved characters, i.e. those for future use are allowed, as they may become mapped in the future.
func ValidateEncoding ¶
ValidateEncoding ensures that the given string is valid UTF-8.
func ValidateMaxBytes ¶
ValidateMaxBytes ensures that the string is bounded by min and max, inclusive.
func ValidateNoNewlines ¶
ValidateNoNewlines ensures there are no newlines or other vertical spacing characters in the string. This includes \r, \n, and Unicode classes Zl and Zp.
func ValidateNoNewlinesUnsafe ¶
ValidateNoNewlinesUnsafe ensures there are no newlines or other vertical spacing characters in the string. This includes \r, \n, and Unicode classes Zl, and Zp. Text *must* have been previously validated in order to use this function.
Types ¶
type TextNormalizer ¶
TextNormalizer normalizes some text
type TextValidator ¶
TextValidator validates some text
func DefaultValidator ¶
func DefaultValidator(min, max int64) TextValidator
DefaultValidator produces a TextValidator that checks for the default validation
func MaxBytesValidator ¶
func MaxBytesValidator(min, max int64) TextValidator
MaxBytesValidator produces a TextValidator that checks text length in bytes.