Documentation ¶
Overview ¶
Package validate provides routines for validating texts
Index ¶
- func HashtagIsValid(hashtag string) bool
- func TextIsValid(text string, args ValidationArgs) bool
- func TextLength(text string) int
- func TextValidate(text string, args ValidationArgs) error
- func URLIsValid(url string, requireProtocol bool, allowUnicode bool) bool
- func UsernameIsValid(username string) bool
- type EmptyError
- type InvalidCharacterError
- type TooLongError
- type ValidationArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HashtagIsValid ¶
HashtagIsValid returns true if the given text represents a valid #hashtag
func TextIsValid ¶
func TextIsValid(text string, args ValidationArgs) bool
TextIsValid checks whether a string is a valid text and returns true or false
func TextLength ¶
TextLength returns the length of the string as it would be displayed. This is equivalent to the length of the Unicode NFC (See: http://www.unicode.org/reports/tr15). This is needed in order to consistently calculate the length of a string no matter which actual form was transmitted. For example:
U+0065 Latin Small Letter E
+ U+0301 Combining Acute Accent ---------- = 2 bytes, 2 characters, displayed as é (1 visual glyph) … The NFC of {U+0065, U+0301} is {U+00E9}, which is a single character and a +display_length+ of 1 The string could also contain U+00E9 already, in which case the canonicalization will not change the value.
func TextValidate ¶
func TextValidate(text string, args ValidationArgs) error
TextValidate checks whether a string is a valid text. Returns nil if the string is valid. Otherwise, it returns an error in the following cases: - The text is too long - The text is empty - The text contains invalid characters
func URLIsValid ¶
URLIsValid returns true if the given text represents a valid URL
func UsernameIsValid ¶
UsernameIsValid returns true if the given text represents a valid @username
Types ¶
type EmptyError ¶
type EmptyError struct{}
EmptyError is returned when text is empty
func (EmptyError) Error ¶
func (e EmptyError) Error() string
type InvalidCharacterError ¶
InvalidCharacterError is returned when text contains an invalid character. This error embeds the value of the invalid character, and its byte-offset within the input string
func (InvalidCharacterError) Error ¶
func (e InvalidCharacterError) Error() string
type TooLongError ¶
type TooLongError struct {
// contains filtered or unexported fields
}
TooLongError is returned when text is too long to be valid. The value of the error is the actual length of the input string
func (TooLongError) Error ¶
func (e TooLongError) Error() string