picop.cystr#

Fast str accessors.

picop.cystr.find(s, sub)#
picop.cystr.is_ascii(s)#
picop.cystr.str_all_alnum_ascii(s)#

Return True if s is non-empty and every code unit is ASCII alnum. :type s: str :param s:

Return type:

bool

picop.cystr.str_all_alpha_ascii(s)#

Return True if s is non-empty and every code unit is ASCII A-Za-z. :type s: str :param s:

Return type:

bool

picop.cystr.str_all_digits(s)#

Return True if s is non-empty and every code unit is ASCII 0-9. :type s: str :param s:

Return type:

bool

picop.cystr.str_as_or_empty(obj)#

Return obj if it is an exact str, else "". :type obj: object :param obj:

Return type:

str

picop.cystr.str_char_at(s, i)#

Return the code point at i via PyUnicode_READ.

Notes

Unchecked: out-of-bounds is undefined behavior. Bound the index yourself before calling.

Parameters:
Return type:

int

picop.cystr.str_check(obj)#

Return True if obj is a str or subtype (PyUnicode_Check). :type obj: object :param obj:

Return type:

bool

picop.cystr.str_check_exact(obj)#

Return True if type(obj) is str (PyUnicode_CheckExact).

Notes

Prefer over str_is / is_str / ucheck_exact in check-pair tables (N3).

Parameters:

obj (object)

Return type:

bool

picop.cystr.str_cmp(a, b)#

Three-way compare of typed str values via PyUnicode_Compare.

Notes

Returns -1 / 0 / 1 for less / equal / greater.

Parameters:
Return type:

int

picop.cystr.str_concat(a, b)#

Return a + b via PyUnicode_Concat. :type a: str :param a: :type b: str :param b:

Return type:

str

picop.cystr.str_concat3(a, b, c)#

Return a + b + c via two PyUnicode_Concat calls. :type a: str :param a: :type b: str :param b: :type c: str :param c:

Return type:

str

picop.cystr.str_concat4(a, b, c, d)#

Return a + b + c + d via three PyUnicode_Concat calls. :type a: str :param a: :type b: str :param b: :type c: str :param c: :type d: str :param d:

Return type:

str

picop.cystr.str_contains(haystack, needle)#

Return whether needle is in haystack.

Notes

Uses 1BYTE memchr/memmem or Find depending on kind.

Parameters:
Return type:

bool

picop.cystr.str_endswith(s, suffix)#

Return whether s ends with suffix.

Notes

Uses 1BYTE memcmp or Tailmatch depending on kind.

Parameters:
Return type:

bool

picop.cystr.str_eq(a, b)#

Return whether a == b.

Notes

Uses 1BYTE memcmp or PyUnicode_Compare depending on kind.

Parameters:
Return type:

bool

picop.cystr.str_find(s, sub)#
picop.cystr.str_first_char(s)#

Return the first code point via PyUnicode_READ.

Notes

Unchecked: an empty string is undefined behavior.

Parameters:

s (str)

Return type:

int

picop.cystr.str_ge(a, b)#

Return True if typed a >= b (via str_cmp). :type a: str :param a: :type b: str :param b:

Return type:

bool

picop.cystr.str_gt(a, b)#

Return True if typed a > b (via str_cmp). :type a: str :param a: :type b: str :param b:

Return type:

bool

picop.cystr.str_is(obj)#

Return True if type(obj) is str.

Notes

Same gate as str_check_exact (N3); alias of is_str.

Parameters:

obj (object)

Return type:

bool

picop.cystr.str_is_ascii(s)#
picop.cystr.str_is_blank(s)#

Return True if every code unit is ASCII whitespace (space/tab/LF/VT/FF/CR). :type s: str :param s:

Return type:

bool

picop.cystr.str_is_empty(s)#

Return True if s has length 0. :type s: str :param s:

Return type:

bool

picop.cystr.str_is_not(obj)#

Return True if type(obj) is not str. :type obj: object :param obj:

Return type:

bool

picop.cystr.str_last_char(s)#

Return the last code point via PyUnicode_READ.

Notes

Unchecked: an empty string is undefined behavior.

Parameters:

s (str)

Return type:

int

picop.cystr.str_le(a, b)#

Return True if typed a <= b (via str_cmp). :type a: str :param a: :type b: str :param b:

Return type:

bool

picop.cystr.str_len(s)#

Return len(s) via PyUnicode_GET_LENGTH. :type s: str :param s:

Return type:

int

picop.cystr.str_lt(a, b)#

Return True if typed a < b (via str_cmp). :type a: str :param a: :type b: str :param b:

Return type:

bool

picop.cystr.str_ne(a, b)#

Return whether a != b (negated str_eq). :type a: str :param a: :type b: str :param b:

Return type:

bool

picop.cystr.str_none_to_empty(obj)#

Return obj if exact str, else "".

Notes

Also yields "" when obj is None.

Parameters:

obj (object)

Return type:

str

picop.cystr.str_not_empty(s)#

Return True if s has non-zero length. :type s: str :param s:

Return type:

bool

picop.cystr.str_or_empty(obj)#

Return obj if truthy exact str, else "". :type obj: object :param obj:

Return type:

str

picop.cystr.str_or_none(obj)#

Return obj if exact str, else None. :type obj: object :param obj:

Return type:

str | None

picop.cystr.str_startswith(s, prefix)#

Return whether s starts with prefix.

Notes

Uses 1BYTE memcmp or Tailmatch depending on kind.

Parameters:
Return type:

bool