Documentation
¶
Overview ¶
html_utils.go
utf_utils.go
Index ¶
- func ChecksumAdler32(input []byte) uint32
- func ChecksumCRC32(input []byte) uint32
- func CompressGzip(data []byte) ([]byte, error)
- func ContainsHTMLTags(s string) bool
- func ConvertISO8859ToUTF8(input []byte) (string, error)
- func ConvertToValidUTF8String(data []byte) string
- func ConvertUTF8ToISO8859(input string) ([]byte, error)
- func ConvertUTF8ToUTF16(s string) []uint16
- func ConvertUTF16BytesToUTF8(data []byte) (string, error)
- func ConvertUTF16ToUTF8(u16 []uint16) string
- func CountUnicodeCharacters(s string) int
- func DecodeGOB(data []byte, out any) error
- func DecodeSpecialChars(s string) string
- func DecompressGzip(data []byte) ([]byte, error)
- func DecryptAES(ciphertext []byte, key []byte) ([]byte, error)
- func DetectUTF16BOM(data []byte) string
- func EncodeGOB(input any) ([]byte, error)
- func EncodeSpecialChars(s string) string
- func EncryptAES(plain []byte, key []byte) ([]byte, error)
- func FixUTF8(data []byte) string
- func HTMLEscape(s string) string
- func HTMLUnescape(s string) string
- func HashFNV32(input []byte) string
- func HashFNV64(input []byte) string
- func HashSHA256(input []byte) string
- func HashSHA512(input []byte) string
- func IsHTMLEscaped(s string) bool
- func IsValidUTF8(data []byte) bool
- func MurmurHash64(data []byte, seed uint64) uint64
- func NormalizeNFC(s string) string
- func NormalizeNFD(s string) string
- func StripHTMLTags(s string) string
- func StripInvalidUTF8(data []byte) []byte
- func URLDecode(input string) (string, error)
- func URLEncode(input string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChecksumAdler32 ¶
ChecksumAdler32 computes the Adler-32 checksum of the input data. It returns the checksum as a uint32 value. Adler-32 is a checksum algorithm that is faster than CRC32 but less reliable. It is suitable for applications where speed is more important than reliability. This function is useful for data integrity checks and error detection. Note: The Adler-32 checksum is not suitable for cryptographic purposes.
func ChecksumCRC32 ¶
ChecksumCRC32 computes the CRC32 checksum of the input data. It returns the checksum as a uint32 value. This function is useful for data integrity checks and error detection.
func CompressGzip ¶
CompressGzip compresses data using gzip compression. It returns the compressed data as a byte slice.
func ContainsHTMLTags ¶
ContainsHTMLTags checks whether a string likely contains HTML tags. This is a simple heuristic and may not be 100% accurate.
func ConvertISO8859ToUTF8 ¶
ConvertISO8859ToUTF8 decodes an ISO-8859-1 (Latin-1) byte slice into a UTF-8 string.
func ConvertToValidUTF8String ¶
ConvertToValidUTF8String converts a potentially invalid UTF-8 byte slice into a valid UTF-8 string. It returns the original string if valid, or a fixed version with invalid bytes replaced.
func ConvertUTF8ToISO8859 ¶
ConvertUTF8ToISO8859 encodes a UTF-8 string into ISO-8859-1 (Latin-1) format bytes.
func ConvertUTF8ToUTF16 ¶
ConvertUTF8ToUTF16 converts a UTF-8 string to a slice of UTF-16 code units (LE format).
func ConvertUTF16BytesToUTF8 ¶
ConvertUTF16BytesToUTF8 converts a byte slice encoded in UTF-16 (with BOM) into a UTF-8 string. Supports both little-endian and big-endian formats.
func ConvertUTF16ToUTF8 ¶
ConvertUTF16ToUTF8 converts a slice of UTF-16 code units to a UTF-8 encoded string.
func CountUnicodeCharacters ¶
CountUnicodeCharacters returns the number of Unicode code points (runes) in the input string.
func DecodeGOB ¶
DecodeGOB deserializes binary gob data into the provided output object. The out parameter should be a pointer to the target struct.
func DecodeSpecialChars ¶
DecodeSpecialChars replaces basic HTML entities back to their original characters. EscapeHTMLForAttribute escapes special characters in a string for use in HTML attributes.
func DecompressGzip ¶
DecompressGzip decompresses gzip-compressed data. It returns the decompressed data as a byte slice.
func DecryptAES ¶
DecryptAES decrypts the given ciphertext using AES decryption with the provided key. The key must be either 16, 24, or 32 bytes long.
func DetectUTF16BOM ¶
DetectUTF16BOM checks for a UTF-16 byte order mark (BOM) at the start of the byte slice. Returns "LE" for little-endian, "BE" for big-endian, or an empty string if no BOM is found.
func EncodeSpecialChars ¶
EncodeSpecialChars replaces certain ASCII characters with their corresponding HTML entities. This is useful for escaping characters that have special meaning in HTML attributes.
func EncryptAES ¶
EncryptAES encrypts the given plaintext using AES encryption with the provided key. The key must be either 16, 24, or 32 bytes long.
func FixUTF8 ¶
FixUTF8 replaces invalid UTF-8 byte sequences in the input with the Unicode replacement character (\uFFFD).
func HTMLEscape ¶
HTMLEscape escapes special characters in a string so it can be safely used in HTML. For example, '<' becomes '<', '>' becomes '>', etc.
func HTMLUnescape ¶
HTMLUnescape unescapes a string that contains HTML character entities back to its original form. For example, '<' becomes '<', '>' becomes '>', etc.
func HashFNV32 ¶
HashFNV32 computes the FNV-1a hash of the input data. It returns the hash as a hexadecimal string.
func HashFNV64 ¶
HashFNV64 computes the FNV-1a hash of the input data. It returns the hash as a hexadecimal string.
func HashSHA256 ¶
HashSHA256 computes the SHA-256 hash of the input data. It returns the hash as a hexadecimal string.
func HashSHA512 ¶
HashSHA512 computes the SHA-512 hash of the input data. It returns the hash as a hexadecimal string.
func IsHTMLEscaped ¶
IsHTMLEscaped checks if the string contains any HTML-escaped sequences. This is a simple heuristic and may not be 100% accurate.
func IsValidUTF8 ¶
IsValidUTF8 returns true if the input byte slice is valid UTF-8.
func MurmurHash64 ¶
This implementation is adapted from publicly available sources of MurmurHash3. MurmurHash3 was created by Austin Appleby and is available under the MIT License. See: https://github.com/aappleby/smhasher
MurmurHash is a non-cryptographic hash function designed for general hash-based lookups.
func NormalizeNFC ¶
NormalizeNFC returns the NFC (Normalization Form C) version of the input string. Useful for canonical representation and string comparisons.
func NormalizeNFD ¶
NormalizeNFD returns the NFD (Normalization Form D) version of the input string. This form decomposes characters into base characters and combining marks.
func StripHTMLTags ¶
StripHTMLTags removes all HTML tags from the input string. It does not parse or sanitize malformed HTML, but removes everything between '<' and '>'. This is a simple heuristic and may not be 100% accurate.
func StripInvalidUTF8 ¶
StripInvalidUTF8 removes any invalid UTF-8 sequences from the input byte slice. Valid sequences are preserved; invalid ones are skipped entirely.
Types ¶
This section is empty.