stringutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSeemsInvalid = fmt.Errorf("input seems not a valid string of specified charset")
)

Functions

func Clean

func Clean(s string) string

Clean: 1. removes non-graphic (excluding spaces) characters from the given string. Non-graphic chars are the ones for which unicode.IsGraphic() returns false. For details, see https://stackoverflow.com/a/58994297/1705598 . 2. TrimSpace.

func CleanTitle

func CleanTitle(s string) string

CleanTitle: 1. Remove line breaks (replace them with space). 2. Clean (Remove invisible chars then TrimSpace).

func ContainsI

func ContainsI(str string, substr string) bool

func DecodeText

func DecodeText(input []byte, charset string, force bool) ([]byte, error)

func GetCjkCharsetStrings

func GetCjkCharsetStrings(strs ...string) (result []string)

返回 strs (UTF-8 字符串) 的 GBK, Shift_JIS, Big5 等编码版本 []byte string.

func HasAnySuffix

func HasAnySuffix(str string, suffixes ...string) bool

func IsUrl

func IsUrl(str string) bool

Check whether str is a "http://" or "https://"" url

func PrintStringInWidth

func PrintStringInWidth(output io.Writer, str string, width int, padRight bool) (remain string)

func StringFromBytes

func StringFromBytes(data []byte) string

data should be a UTF-8 text file contents. Return canonical string from data that is: 1. UTF-8 BOM removed. 2. Line breaks converted to \n.

func StringPrefixInBytes

func StringPrefixInBytes(str string, max int) string

Return prefix of str that is at most max bytes encoded in UTF-8. It replace invalid UTF-8 byte(s) in str with RuneError ("Unicode replacement character"), so the returned result is always valid UTF-8 string.

func StringPrefixInWidth

func StringPrefixInWidth(str string, width int) (string, int)

Return prefix of string at most width and actual width. ASCII char has 1 width. CJK char has 2 width.

Types

This section is empty.

Jump to

Keyboard shortcuts

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