Module pico8lib.strings

String manipulation and creation

Local Functions

repr (o) Unambiguous string serialization of arbitrary objects

Miscellaneous

int32_to_str (n) Represent n*32768 as a string 0x0000.0001 is "1", 0x7fff.ffff is "2147483647", and 0x8000.0000 is "-2147483648"
hex_unpadded (v) Format a number as hexadecimal with no 0x prefix or zero padding
hex_unpadded (v, n) Format a number as hexadecimal with no 0x prefix or zero padding Optionally prints minus prefix instead of twos complement negative numbers
binary (n) Format a number as binary
replace (str, fnd, rep) Replace fnd with rep in str 58 tokens
replace (str, fnd, rep) Replace fnd with rep in str 66 tokens, 5% faster than 58 token implementation
char_in_string (c, s) Check if a char exists in a string
wrap (str) Wrap a long string to fit on the screen
wrap (str, m) Wrap a long string to fit on the screen this version supports wide glyphs, although they might extend past the end of the screen this version supports an optional max width
split (str, delim) Split a string on a delimiter, return a list of strings split("abc,def,",",") returns {"abc","def",""}
splitd (input, delim, ...) Split a string on multiple delimiters, return an n-dimensional array of strings splitd(",a,b;c,d|e,f;","|",";",",") returns {{{"","a","b"},{"c","d"}},{{"e","f"},{}}}
str_center (str, x) Center align string at given x coordinate x defaults to 64 (screen center)
str_center (str, x) Center align string at given x coordinate x defaults to 64 (screen center) support for wide glyphs
ssub (str, idx, len) Substring function with length instead of end position ssub(a,b) == sub(a,b,b) ssub(a,b,c) == sub(a,b,b+c)
starts_with (str, prefix) Check if a string starts with a given prefix returns true if it does, false otherwise
pad_left (s, l, p) Pad a string on the left

tostr

tostr_tostring (n, ...) tostr respects __tostring
tostr_tables (t, ...) tostr recursive handling of tables all keys unordered
tostr_arrays_tables (n, ...) tostr recursive handling of tables array values in order, remaining keys unordered
tostr_tostring_arrays_tables (n, ...) tostr respects __tostring recursive handling of tables array values in order, remaining keys unordered

Run Length Encoding

rle_decode (str) RLE decode turns "ab2c4de" into "abccdddde"
rle_decode (str) RLE encode turns "abccdddde" into "ab2c4de" support for escaped digits and backslash as \1 ...


Local Functions

repr (o)
Unambiguous string serialization of arbitrary objects

Parameters:

  • o The object to serialize

Returns:

    A string representation of o

Miscellaneous

int32_to_str (n)
Represent n*32768 as a string 0x0000.0001 is "1", 0x7fff.ffff is "2147483647", and 0x8000.0000 is "-2147483648"

Parameters:

  • n
hex_unpadded (v)
Format a number as hexadecimal with no 0x prefix or zero padding

Parameters:

  • v originally from https //www.lexaloffle.com/bbs/?tid=30910
hex_unpadded (v, n)
Format a number as hexadecimal with no 0x prefix or zero padding Optionally prints minus prefix instead of twos complement negative numbers

Parameters:

  • v
  • n
binary (n)
Format a number as binary

Parameters:

  • n
replace (str, fnd, rep)
Replace fnd with rep in str 58 tokens

Parameters:

  • str originally from https
  • fnd
  • rep //www.lexaloffle.com/bbs/?pid=72818 "yes. please use it!" - shiftalow [2020-02-07 02:19]
replace (str, fnd, rep)
Replace fnd with rep in str 66 tokens, 5% faster than 58 token implementation

Parameters:

  • str
  • fnd
  • rep
char_in_string (c, s)
Check if a char exists in a string

Parameters:

  • c
  • s
wrap (str)
Wrap a long string to fit on the screen

Parameters:

  • str
wrap (str, m)
Wrap a long string to fit on the screen this version supports wide glyphs, although they might extend past the end of the screen this version supports an optional max width

Parameters:

  • str
  • m
split (str, delim)
Split a string on a delimiter, return a list of strings split("abc,def,",",") returns {"abc","def",""}

Parameters:

  • str
  • delim
splitd (input, delim, ...)
Split a string on multiple delimiters, return an n-dimensional array of strings splitd(",a,b;c,d|e,f;","|",";",",") returns {{{"","a","b"},{"c","d"}},{{"e","f"},{}}}

Parameters:

  • input
  • delim
  • ...
str_center (str, x)
Center align string at given x coordinate x defaults to 64 (screen center)

Parameters:

  • str
  • x
str_center (str, x)
Center align string at given x coordinate x defaults to 64 (screen center) support for wide glyphs

Parameters:

  • str
  • x
ssub (str, idx, len)
Substring function with length instead of end position ssub(a,b) == sub(a,b,b) ssub(a,b,c) == sub(a,b,b+c)

Parameters:

  • str
  • idx
  • len
starts_with (str, prefix)
Check if a string starts with a given prefix returns true if it does, false otherwise

Parameters:

  • str
  • prefix
pad_left (s, l, p)
Pad a string on the left

Parameters:

  • s string String to pad
  • l number Length to pad to
  • p string Padding character

tostr

tostr_tostring (n, ...)
tostr respects __tostring

Parameters:

  • n
  • ...
tostr_tables (t, ...)
tostr recursive handling of tables all keys unordered

Parameters:

  • t
  • ...
tostr_arrays_tables (n, ...)
tostr recursive handling of tables array values in order, remaining keys unordered

Parameters:

  • n
  • ...
tostr_tostring_arrays_tables (n, ...)
tostr respects __tostring recursive handling of tables array values in order, remaining keys unordered

Parameters:

  • n
  • ...

Run Length Encoding

rle_decode (str)
RLE decode turns "ab2c4de" into "abccdddde"

Parameters:

  • str
rle_decode (str)
RLE encode turns "abccdddde" into "ab2c4de" support for escaped digits and backslash as \1 ... \9 and \\ turns "a3\12bc" into "a111bbc"

Parameters:

  • str
generated by LDoc 1.5.0 Last updated 2024-09-08 14:28:56