text

package
v0.0.0-...-95d4a42 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package text implements text processing and validation.

Index

Constants

View Source
const UnicodeVersion = unicode.Version

Variables

This section is empty.

Functions

func DefaultValidate

func DefaultValidate(text, fieldname string, minbytes, maxbytes int64) error

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

func ToCaselessNFKC(text, fieldname string) (string, error)

ToCaselessCompatible normalizes to NFKC and casefolds text for comparison.

func ToCaselessNFKCUnsafe

func ToCaselessNFKCUnsafe(text, fieldname string) (string, error)

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 ToNFC

func ToNFC(text, fieldname string) (string, error)

ToNFC normalizes text to NFC, suitable for storage and transmission.

func ToNFCUnsafe

func ToNFCUnsafe(text, fieldname string) (string, error)

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 TrimSpace

func TrimSpace(text, fieldname string) (string, error)

TrimSpace removes leading and trailing whitespace.

func TrimSpaceUnsafe

func TrimSpaceUnsafe(text, fieldname string) (string, error)

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

func ValidateCodepoints(text, fieldname string) error

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

func ValidateEncoding(text, fieldname string) error

ValidateEncoding ensures that the given string is valid UTF-8.

func ValidateMaxBytes

func ValidateMaxBytes(text, fieldname string, min, max int64) error

ValidateMaxBytes ensures that the string is bounded by min and max, inclusive.

func ValidateNoNewlines

func ValidateNoNewlines(text, fieldname string) error

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

func ValidateNoNewlinesUnsafe(text, fieldname string) error

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

type TextNormalizer func(text, fieldname string) (string, error)

TextNormalizer normalizes some text

type TextValidator

type TextValidator func(text, fieldname string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL