Documentation
¶
Overview ¶
Package validate provides routines for validating tweets
Index ¶
- func HashtagIsValid(hashtag string) bool
- func ListIsValid(list string) bool
- func TweetIsValid(text string) bool
- func TweetLength(text string) int
- func UrlIsValid(url string, requireProtocol bool, allowUnicode bool) bool
- func UsernameIsValid(username string) bool
- func ValidateTweet(text string) error
- type EmptyError
- type InvalidCharacterError
- type TooLongError
- type Tweet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HashtagIsValid ¶
Returns true if the given text represents a valid #hashtag
func ListIsValid ¶
Returns true if the given text represents a valid @twitter/list
func TweetIsValid ¶
Checks whether a string is a valid tweet and returns true or false
func TweetLength ¶
Returns the V1 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. Note that per twitter-text, this method is deprecated and will always return the v1 values New clients should use ParseTweet
func UrlIsValid ¶
Returns true if the given text represents a valid URL
func UsernameIsValid ¶
Returns true if the given text represents a valid @username
func ValidateTweet ¶
Checks whether a string is a valid tweet. 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
Types ¶
type EmptyError ¶
type EmptyError struct{}
Validation error returned when text is empty
func (EmptyError) Error ¶
func (e EmptyError) Error() string
type InvalidCharacterError ¶
Validation error 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 int
Validation error returned when text is too long to be a valid tweet. The value of the error is the actual length of the input string
func (TooLongError) Error ¶
func (e TooLongError) Error() string