pystr

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SurrogateMin       = 0xD800
	SurrogateHighMax   = 0xDBFF
	SurrogateLowMin    = 0xDC00
	SurrogateMax       = 0xDFFF
	SurrogateEscapeMin = 0xDC80
	SurrogateEscapeMax = 0xDCFF
)

Surrogate code point bounds and the range a surrogateescape decode produces

Variables

This section is empty.

Functions

func All

func All(s string, pred func(rune) bool) bool

Whole string form of a per code point predicate, false for the empty string like the str methods

func AppendRune

func AppendRune(p []byte, r rune) []byte

Appends r encoded as generalized UTF-8 so a surrogate keeps its own three bytes

func BoolToken

func BoolToken(s string) (value, ok bool)

True or false for a recognized truthy or falsy token after strip and lower, ok false for anything else

func BytesFromHex

func BytesFromHex(s string) ([]byte, error)

Bytes of hex digit pairs with ASCII whitespace allowed between pairs, the ValueError of bytes fromhex otherwise

func Capitalize

func Capitalize(s string) string

str.capitalize, the first code point in title case and the rest lowered

func Casefold

func Casefold(s string) string

str.casefold with full case folding, Cherokee folding to its uppercase letters as CaseFolding.txt maps it

func Center

func Center(s string, width int) string

str.center with spaces, the odd extra space placed where CPython puts it

func DecimalValue

func DecimalValue(r rune) (int, bool)

Numeric value of a Unicode decimal digit as Python int parses it, false for any other rune

func DecodeASCIIReplace

func DecodeASCIIReplace(b []byte) string

Decodes bytes as ascii with every byte above 127 replaced by U+FFFD

func DecodeLastRune

func DecodeLastRune(s string) (rune, int)

Trailing code point and its byte size with the same surrogate rules as the forward decode

func DecodeRune

func DecodeRune(s string) (rune, int)

Leading code point and its byte size, surrogates whole and each stray invalid byte as its surrogateescape char

func DecodeUTF8

func DecodeUTF8(raw []byte) (string, error)

Text of bytes under a strict utf-8 decode that keeps a leading BOM, the UnicodeDecodeError on invalid input

func DecodeUTF8Replace

func DecodeUTF8Replace(b []byte) string

bytes.decode utf-8 with errors replace, one U+FFFD per maximal invalid subpart

func DecodeUTF8Sig

func DecodeUTF8Sig(raw []byte) (string, error)

Text of utf-8-sig bytes, one leading BOM dropped, the strict UnicodeDecodeError on invalid UTF-8

func DecodeUTF8SigFile

func DecodeUTF8SigFile(raw []byte) (string, error)

Text of a whole utf-8-sig file read, a lone BOM start reading as empty

func DecodeUTF8SigIgnore

func DecodeUTF8SigIgnore(b []byte) string

Decodes utf-8-sig with errors ignore, the BOM stripped and every undecodable byte run dropped

func DecodeUTF8SigReplace

func DecodeUTF8SigReplace(b []byte) string

Decodes utf-8-sig with errors replace, the BOM stripped and each undecodable run shown as U+FFFD

func EncodeUTF8BackslashReplace

func EncodeUTF8BackslashReplace(s string) string

UTF-8 text of s like str.encode with errors backslashreplace, each lone surrogate becoming a backslash u escape

func EncodeUTF8Replace

func EncodeUTF8Replace(s string) []byte

UTF-8 bytes of s like str.encode with errors replace, each lone surrogate becoming a question mark

func FirstUnencodableSurrogate

func FirstUnencodableSurrogate(s string) (rune, bool)

First surrogate outside U+DC80 through U+DCFF, the match of the lone surrogate refusal pattern

func FromRunes

func FromRunes(rs []rune) string

String of code points with every surrogate written in its three byte form

func GroupThousands

func GroupThousands(n int64) string

Decimal text of n with comma thousands separators like format(n, ",")

func IntText

func IntText(s string) (*big.Int, bool)

Base ten value int of a str gives, false where int raises ValueError

func IsAlnum

func IsAlnum(r rune) bool

str.isalnum on one code point, every N category code point carrying a numeric type

func IsAlpha

func IsAlpha(r rune) bool

str.isalpha on one code point

func IsCaseIgnorable

func IsCaseIgnorable(r rune) bool

Unicode Case_Ignorable property, marks format and modifier classes plus the word break mid letter set

func IsCased

func IsCased(r rune) bool

Unicode Cased property, uppercase lowercase or titlecase letters and the Other_Lowercase and Other_Uppercase sets

func IsDecimal

func IsDecimal(r rune) bool

str.isdecimal on one code point

func IsDigit

func IsDigit(r rune) bool

str.isdigit on one code point, decimal digits plus superscripts circled and other Digit typed numbers

func IsIdentifier

func IsIdentifier(s string) bool

str.isidentifier, an XID_Start or underscore followed by XID_Continue code points

func IsPrintable

func IsPrintable(r rune) bool

str.isprintable on one code point, refusing separators other than space and the C categories

func IsSpace

func IsSpace(r rune) bool

Code points str.isspace accepts, Unicode White_Space plus the ASCII file group record and unit separators

func IsSurrogate

func IsSurrogate(r rune) bool

Whether r is a UTF-16 surrogate code point

func IsUpper

func IsUpper(s string) bool

Python str.isupper, true when no character is lowercase or titlecase and at least one is uppercase

func IsXIDContinue

func IsXIDContinue(r rune) bool

Unicode XID_Continue, XID_Start plus marks digits connectors and Other_ID_Continue

func IsXIDStart

func IsXIDStart(r rune) bool

Unicode XID_Start, letters letter numbers and Other_ID_Start minus pattern characters and NFKC unstable ones

func Len

func Len(s string) int

Python len of the str s models, one per code point with a surrogate counted once

func Ljust

func Ljust(s string, width int) string

str.ljust with spaces, padding on the right to width code points

func Lower

func Lower(s string) string

str.lower with full case mapping and the Final_Sigma rule

func Lstrip

func Lstrip(s string) string

str.lstrip with no argument

func LstripChars

func LstripChars(s, chars string) string

str.lstrip(chars)

func Rjust

func Rjust(s string, width int) string

str.rjust with spaces, padding on the left to width code points

func Rstrip

func Rstrip(s string) string

str.rstrip with no argument

func RstripChars

func RstripChars(s, chars string) string

str.rstrip(chars)

func Runes

func Runes(s string) []rune

Code points of s with surrogates and stray bytes kept as their own runes

func Slice

func Slice(s string, start, end int) string

Code points of s from start to end with Python subscript clamping and negative indexes from the end

func SplitWhitespace

func SplitWhitespace(s string, maxsplit int) []string

str.split(None, maxsplit), whitespace runs as separators and the remainder keeping trailing space once maxsplit is spent

func Splitlines

func Splitlines(s string, keepends bool) []string

str.splitlines over every Python line boundary, carrying the boundaries when keepends is set

func StrIsDigit

func StrIsDigit(s string) bool

True for a non empty string whose every character is a digit, str.isdigit

func StrictUTF8EncodeError

func StrictUTF8EncodeError(s string) error

UnicodeEncodeError of a strict utf-8 encode over the first surrogate run, nil for text holding no surrogate

func Strip

func Strip(s string) string

str.strip with no argument, removing Python whitespace from both ends

func StripChars

func StripChars(s, chars string) string

str.strip(chars) removing any code point of chars from both ends

func SurrogateAt

func SurrogateAt[T WTF8Text](s T, i int) bool

Whether the three bytes at i are the generalized UTF-8 form of a surrogate code point

func SurrogateEscapeDecode

func SurrogateEscapeDecode(b []byte) string

Python bytes.decode with utf-8 and surrogateescape, each undecodable byte becoming U+DC80 through U+DCFF

func SurrogateEscapeEncode

func SurrogateEscapeEncode(s string) ([]byte, error)

Python str.encode with utf-8 and surrogateescape, the exact inverse of the surrogateescape decode

func SurrogateRune

func SurrogateRune[T WTF8Text](s T, i int) rune

Code point of the surrogate whose three byte form starts at i

func TextwrapWrap

func TextwrapWrap(text string, o TextwrapOptions) []string

TextwrapWrap is textwrap.wrap with the given TextWrapper options

func TextwrapWrapNoHyphenBreak

func TextwrapWrapNoHyphenBreak(text string, width int, breakLongWords bool) []string

TextwrapWrapNoHyphenBreak is textwrap.wrap with break_on_hyphens False and the other options at their defaults

func Title

func Title(s string) string

str.title, titlecasing a code point after an uncased one and lowercasing it after a cased one

func TranslateNewlines

func TranslateNewlines(s string) string

Text with CRLF and lone CR turned into LF, as Python text mode reads with universal newlines

func UTF8DecodeError

func UTF8DecodeError(data []byte, pos int) error

UnicodeDecodeError text of a strict utf-8 decode that stops at pos, with the CPython reason and span

func UTF8MaximalSubpart

func UTF8MaximalSubpart(b []byte) int

Length of the maximal invalid UTF-8 subpart at the start of b

func Upper

func Upper(s string) string

str.upper with full case mapping

func ValidIndex

func ValidIndex(data []byte) (int, bool)

Offset of the first byte that is neither UTF-8 nor a three byte surrogate, ok when there is none

func WriteRune

func WriteRune(b *strings.Builder, r rune)

Writes r encoded as generalized UTF-8 so a surrogate keeps its own three bytes

Types

type TextwrapOptions

type TextwrapOptions struct {
	Width             int
	InitialIndent     string
	SubsequentIndent  string
	ExpandTabs        bool
	ReplaceWhitespace bool
	DropWhitespace    bool
	BreakLongWords    bool
	BreakOnHyphens    bool
	TabSize           int
}

TextwrapOptions are the textwrap.TextWrapper keyword arguments

func DefaultTextwrap

func DefaultTextwrap(width int) TextwrapOptions

DefaultTextwrap is TextWrapper(width) with every other argument at its Python default

type UnicodeDecodeError

type UnicodeDecodeError struct{ Msg string }

UnicodeDecodeError raised by a strict codec decode, carrying the CPython message

func (*UnicodeDecodeError) Error

func (e *UnicodeDecodeError) Error() string

func (*UnicodeDecodeError) PyTypeName

func (e *UnicodeDecodeError) PyTypeName() string

Python exception class name the error stands for

type UnicodeEncodeError

type UnicodeEncodeError struct {
	// contains filtered or unexported fields
}

UnicodeEncodeError of the utf-8 codec over the surrogate run start to end of a str

func (*UnicodeEncodeError) Error

func (e *UnicodeEncodeError) Error() string

func (*UnicodeEncodeError) PyTypeName

func (e *UnicodeEncodeError) PyTypeName() string

Python exception class name the error stands for

type WTF8Text

type WTF8Text interface{ ~string | ~[]byte }

String or byte slice holding WTF-8 text

Jump to

Keyboard shortcuts

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