[TBC] List of standard library functions
Closed this issue · 4 comments
std.debug.print([args...])
-
Prints all
args
to the standard error stream, separated by
spaces. A line break is appended to terminate the line. -
Returns
true
if the operation succeeds; otherwisenull
.
std.debug.dump(value, [indent_increment])
-
Prints the value to the standard error stream with detailed
information.indent_increment
specifies the number of spaces
used as a single level of indent. Its value is clamped between
0
and10
inclusively. If it is set to0
, no line break is
inserted and output lines are not indented. It has a default
value of2
. -
Returns
true
if the operation succeeds; otherwisenull
.
std.chrono.utc_now()
-
Retrieves the wall clock time in UTC.
-
Returns the number of milliseconds since the Unix epoch,
represented as aninteger
.
std.chrono.local_now()
-
Retrieves the wall clock time in the local time zone.
-
Returns the number of milliseconds since
1970-01-01 00:00:00
in the local time zone, represented as aninteger
.
std.chrono.hires_now()
-
Retrieves a time point from a high resolution clock. The clock
goes monotonically and cannot be adjusted, being suitable for
time measurement. This function provides accuracy and might be
quite heavyweight. -
Returns the number of milliseconds since an unspecified time
point, represented as areal
.
std.chrono.steady_now()
-
Retrieves a time point from a steady clock. The clock goes
monotonically and cannot be adjusted, being suitable for time
measurement. This function is supposed to be fast and might
have poor accuracy. -
Returns the number of milliseconds since an unspecified time
point, represented as aninteger
.
std.chrono.local_from_utc(time_utc)
-
Converts a UTC time point to a local one.
time_utc
shall be
the number of milliseconds since the Unix epoch. -
Returns the number of milliseconds since
1970-01-01 00:00:00
in the local time zone, represented as aninteger
.
std.chrono.utc_from_local(time_local)
-
Converts a local time point to a UTC one.
time_local
shall
be the number of milliseconds since1970-01-01 00:00:00
in
the local time zone. -
Returns the number of milliseconds since the Unix epoch,
represented as aninteger
.
std.chrono.parse_datetime(time_str)
-
Parses
time_str
, which is an ASCII string representing a time
point in the format1970-01-01 00:00:00.000
, according to the
ISO 8601 standard; the subsecond part is optional and may have
fewer or more digits. There shall be no leading or trailing
spaces. -
Returns the number of milliseconds since
1970-01-01 00:00:00
if the time string has been parsed successfully; otherwise
null
.
std.chrono.format_datetime(time_point, [with_ms])
-
Converts
time_point
, which represents the number of
milliseconds since1970-01-01 00:00:00
, to an ASCII string in
the aforementioned format, according to the ISO 8601 standard.
Ifwith_ms
is set totrue
, the string will have a 3-digit
fractional part. By default, no fractional part is added. -
Returns a
string
representing the time point.
std.chrono.min_datetime([with_ms])
-
Gets the special string that denotes the negative infinity time
point. Calling this function has the same effect as calling
format_datetime(-0x8000000000000000, with_ms)
. -
Returns the string
'1601-01-01 00:00:00'
or the string
'1601-01-01 00:00:00.000'
according towith_ms
.
std.chrono.max_datetime([with_ms])
-
Gets the special string that denotes the positive infinity time
point. Calling this function has the same effect as calling
format_datetime(0x7FFFFFFFFFFFFFFF, with_ms)
. -
Returns the string
'9999-01-01 00:00:00'
or the string
'9999-01-01 00:00:00.000'
according towith_ms
.
std.string
std.string.substr(text, from, [length])
-
Copies a subrange of
text
to create a new byte string. Bytes
are copied fromfrom
if it is non-negative, and from
lengthof(text) + from
otherwise. Iflength
is set to an
integer
, no more than this number of bytes will be copied. If
it is absent, all bytes fromfrom
to the end oftext
will
be copied. Iffrom
is outsidetext
, an emptystring
is
returned. -
Returns the specified substring of
text
.
std.string.replace_substr(text, from, replacement)
-
Replaces all bytes from
from
to the end oftext
with
replacement
and returns the new byte string. Iffrom
is
negative, it specifies an offset from the end oftext
. This
function returns a newstring
without modifyingtext
. -
Returns a
string
with the subrange replaced.
std.string.replace_substr(text, from, [length], replacement)
-
Replaces all bytes from
from
to the end oftext
with
replacement
and returns the new byte string. Iffrom
is
negative, it specifies an offset from the end oftext
. If
length
is set to aninteger
, no more than this number of
bytes will be copied. If it isnull
, this function is
equivalent toreplace_substr(text, from, replacement)
. This
function returns a newstring
without modifyingtext
. -
Returns a
string
with the subrange replaced.
std.string.compare(text1, text2, [length])
-
Performs lexicographical comparison on two byte strings. If
length
is set to aninteger
, no more than this number of
bytes are compared. This function behaves like thestrncmp()
function in C, except that null characters do not terminate
strings. -
Returns a positive
integer
iftext1
compares greater than
text2
, a negativeinteger
iftext1
compares less than
text2
, or zero iftext1
compares equal totext2
.
std.string.starts_with(text, prefix)
-
Checks whether
prefix
is a prefix oftext
. The empty
string
is considered to be a prefix of any string. -
Returns
true
ifprefix
is a prefix oftext
; otherwise
false
.
std.string.ends_with(text, suffix)
-
Checks whether
suffix
is a suffix oftext
. The empty
string
is considered to be a suffix of any string. -
Returns
true
ifsuffix
is a suffix oftext
; otherwise
false
.
std.string.find(text, pattern)
-
Searches
text
for the first occurrence ofpattern
. -
Returns the subscript of the first byte of the first match of
pattern
intext
if one is found, which is always
non-negative; otherwisenull
.
std.string.find(text, [from], pattern)
-
Searches
text
for the first occurrence ofpattern
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0)
. -
Returns the subscript of the first byte of the first match of
pattern
intext
if one is found, which is always
non-negative; otherwisenull
.
std.string.find(text, [from], [length], pattern)
-
Searches
text
for the first occurrence ofpattern
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0, length)
. -
Returns the subscript of the first byte of the first match of
pattern
intext
if one is found, which is always
non-negative; otherwisenull
.
std.string.rfind(text, pattern)
-
Searches
text
for the last occurrence ofpattern
. -
Returns the subscript of the first byte of the last match of
pattern
intext
if one is found, which is always
non-negative; otherwisenull
.
std.string.rfind(text, [from], pattern)
-
Searches
text
for the last occurrence ofpattern
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0)
. -
Returns the subscript of the first byte of the last match of
pattern
intext
if one is found, which is always
non-negative; otherwisenull
.
std.string.rfind(text, [from], [length], pattern)
-
Searches
text
for the last occurrence ofpattern
. -
Returns the subscript of the first byte of the last match of
pattern
intext
if one is found, which is always
non-negative; otherwisenull
.
std.string.find_and_replace(text, pattern, replacement)
-
Searches
text
for the first occurrence ofpattern
. If a
match is found, it is replaced withreplacement
. This
function returns a newstring
without modifyingtext
. -
Returns the string with
pattern
replaced. Iftext
does not
containpattern
, it is returned intact.
std.string.find_and_replace(text, [from], pattern, replacement)
-
Searches
text
for the first occurrence ofpattern
. If a
match is found, it is replaced withreplacement
. The search
operation is performed on the same subrange that would be
returned bysubstr(text, from ?? 0)
. This function returns a
newstring
without modifyingtext
. -
Returns the string with
pattern
replaced. Iftext
does not
containpattern
, it is returned intact.
std.string.find_and_replace(text, [from], [length], pattern, replacement)
-
Searches
text
for the first occurrence ofpattern
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0, length)
. If a match is
found, it is replaced withreplacement
. The search operation
is performed on the same subrange that would be returned by
substr(text, from ?? 0)
. This function returns a newstring
without modifyingtext
. -
Returns the string with
pattern
replaced. Iftext
does not
containpattern
, it is returned intact.
std.string.rfind_and_replace(text, pattern, replacement)
-
Searches
text
for the last occurrence ofpattern
. If a
match is found, it is replaced withreplacement
. This
function returns a newstring
without modifyingtext
. -
Returns the string with
pattern
replaced. Iftext
does not
containpattern
, it is returned intact.
std.string.rfind_and_replace(text, [from], pattern, replacement)
-
Searches
text
for the last occurrence ofpattern
. If a
match is found, it is replaced withreplacement
. The search
operation is performed on the same subrange that would be
returned bysubstr(text, from ?? 0)
. This function returns a
newstring
without modifyingtext
. -
Returns the string with
pattern
replaced. Iftext
does not
containpattern
, it is returned intact.
std.string.rfind_and_replace(text, [from], [length], pattern, replacement)
-
Searches
text
for the last occurrence ofpattern
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0, length)
. If a match is
found, it is replaced withreplacement
. The search operation
is performed on the same subrange that would be returned by
substr(text, from ?? 0)
. This function returns a newstring
without modifyingtext
. -
Returns the string with
pattern
replaced. Iftext
does not
containpattern
, it is returned intact.
std.string.find_any_of(text, accept)
-
Searches
text
for bytes that exist inaccept
. -
Returns the subscript of the first byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.find_any_of(text, [from], accept)
-
Searches
text
for bytes that exist inaccept
. The search
operation is performed on the same subrange that would be
returned bysubstr(text, from ?? 0)
. -
Returns the subscript of the first byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.find_any_of(text, [from], [length], accept)
-
Searches
text
for bytes that exist inaccept
. The search
operation is performed on the same subrange that would be
returned bysubstr(text, from ?? 0, length)
. -
Returns the subscript of the first byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.rfind_any_of(text, accept)
-
Searches
text
for bytes that exist inaccept
. -
Returns the subscript of the last byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.rfind_any_of(text, [from], accept)
-
Searches
text
for bytes that exist inaccept
. The search
operation is performed on the same subrange that would be
returned bysubstr(text, from ?? 0)
. -
Returns the subscript of the last byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.rfind_any_of(text, [from], [length], accept)
-
Searches
text
for bytes that exist inaccept
. The search
operation is performed on the same subrange that would be
returned bysubstr(text, from ?? 0, length)
. -
Returns the subscript of the last byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.find_not_of(text, reject)
-
Searches
text
for bytes that does not exist inreject
. -
Returns the subscript of the first byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.find_not_of(text, [from], reject)
-
Searches
text
for bytes that does not exist inreject
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0)
. -
Returns the subscript of the first byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.find_not_of(text, [from], [length], reject)
-
Searches
text
for bytes that does not exist inreject
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0, length)
. -
Returns the subscript of the first byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.rfind_not_of(text, reject)
-
Searches
text
for bytes that does not exist inreject
. -
Returns the subscript of the last byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.rfind_not_of(text, [from], reject)
-
Searches
text
for bytes that does not exist inreject
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0)
. -
Returns the subscript of the last byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.rfind_not_of(text, [from], [length], reject)
-
Searches
text
for bytes that does not exist inreject
. The
search operation is performed on the same subrange that would
be returned bysubstr(text, from ?? 0, length)
. -
Returns the subscript of the last byte found, which is always
non-negative; ornull
if no such byte exists.
std.string.reverse(text)
-
Reverses a byte
string
. This function returns a newstring
without modifyingtext
. -
Returns the reversed
string
.
std.string.trim(text, [reject])
-
Removes the longest prefix and suffix consisting solely bytes
fromreject
. Ifreject
is empty, no byte is removed. If
reject
is not specified, spaces and tabs are removed. This
function returns a newstring
without modifyingtext
. -
Returns the trimmed
string
.
std.string.ltrim(text, [reject])
-
Removes the longest prefix consisting solely bytes from
reject
. Ifreject
is empty, no byte is removed. Ifreject
is not specified, spaces and tabs are removed. This function
returns a newstring
without modifyingtext
. -
Returns the trimmed
string
.
std.string.rtrim(text, [reject])
-
Removes the longest suffix consisting solely bytes from
reject
. Ifreject
is empty, no byte is removed. Ifreject
is not specified, spaces and tabs are removed. This function
returns a newstring
without modifyingtext
. -
Returns the trimmed string.
std.string.to_upper(text)
-
Converts all lowercase English letters in
text
to their
uppercase counterparts. This function returns a newstring
without modifyingtext
. -
Returns a new
string
after the conversion.
std.string.to_lower(text)
-
Converts all uppercase English letters in
text
to their
lowercase counterparts. This function returns a newstring
without modifyingtext
. -
Returns a new
string
after the conversion.
std.string.explode(text, [delim], [limit])
-
Breaks
text
down into segments, separated bydelim
. If
delim
isnull
or an emptystring
, every byte becomes a
segment. Iflimit
is set to a positiveinteger
, there will
be no more segments than this number; the last segment will
contain all the remaining bytes of thetext
. -
Returns an
array
containing the broken-down segments. If
text
is empty, an emptyarray
is returned. -
Throws an exception if
limit
is zero or negative.
std.string.implode(segments, [delim])
-
Concatenates elements of an array,
segments
, to create a new
string
. All segments shall bestring
s. Ifdelim
is
specified, it is inserted between adjacent segments. -
Returns a
string
containing all segments. Ifsegments
is
empty, an emptystring
is returned.
std.string.hex_encode(text, [delim], [uppercase])
-
Encodes all bytes in
text
as 2-digit hexadecimal numbers and
concatenates them. Ifdelim
is specified, it is inserted
between adjacent bytes. Ifuppercase
is set totrue
,
hexadecimal digits above9
are encoded asABCDEF
; otherwise
they are encoded asabcdef
. -
Returns the encoded
string
. Iftext
is empty, an empty
string
is returned.
std.string.hex_decode(hstr)
-
Decodes all hexadecimal digits from
hstr
and converts them to
bytes. Whitespaces are ignored. Characters that are neither
hexadecimal digits nor whitespaces will cause parse errors. -
Returns a
string
containing decoded bytes. Ifhstr
is empty
or consists only whitespaces, an emptystring
is returned. In
the case of parse errors,null
is returned.
std.string.translate(text, inputs, [outputs])
-
Performs bytewise translation on the given string. For every
byte intext
that is also found ininputs
, if there is a
corresponding replacement byte inoutputs
with the same
subscript, it is replaced with the latter; if no replacement
exists, becauseoutputs
is shorter thaninputs
or is null,
it is deleted. Ifoutputs
is longer thaninputs
, excess
bytes are ignored. Bytes that do not exist ininputs
are left
intact. This function returns a newstring
without modifying
text
. -
Returns the translated
string
.
std.string.utf8_encode(code_points, [permissive])
-
Encodes code points from
code_points
into an UTF-8string
.
Code points shall beinteger
s. When an invalid code point is
encountered, ifpermissive
is set totrue
, it is replaced
with the replacement character"\uFFFD"
and consequently
encoded as"\xEF\xBF\xBD"
; otherwise this function fails. -
Returns the encoded
string
on success; otherwisenull
.
std.string.utf8_decode(text, [permissive])
-
Decodes
text
, which is expected to be astring
containing
UTF-8 code units, into anarray
of code points, represented
asinteger
s. When an invalid code sequence is encountered, if
permissive
is set totrue
, all code units of it are
re-interpreted as isolated bytes according to ISO/IEC 8859-1;
otherwise this function fails. -
Returns an
array
containing decoded code points; otherwise
null
.
std.string.pack_8(ints)
-
Packs a series of 8-bit integers into a
string
.ints
shall
be anarray
ofinteger
s, all of which are truncated to 8
bits then copied into astring
. -
Returns the packed
string
.
std.string.unpack_8(text)
-
Unpacks 8-bit integers from a
string
. The contents oftext
are re-interpreted as contiguous signed 8-bit integers, all of
which are sign-extended to 64 bits then copied into anarray
. -
Returns an
array
containing unpacked integers.
std.string.pack_16be(ints)
-
Packs a series of 16-bit integers into a
string
.ints
shall
be anarray
ofinteger
s, all of which are truncated to 16
bits then copied into astring
in the big-endian byte order. -
Returns the packed
string
.
std.string.unpack_16be(text)
-
Unpacks 16-bit integers from a
string
. The contents oftext
are re-interpreted as contiguous signed 16-bit integers in the
big-endian byte order, all of which are sign-extended to 64
bits then copied into anarray
. -
Returns an
array
containing unpacked integers. -
Throws an exception if the length of
text
is not a multiple
of 2.
std.string.pack_16le(ints)
-
Packs a series of 16-bit integers into a
string
.ints
shall
be anarray
ofinteger
s, all of which are truncated to 16
bits then copied into astring
in the little-endian byte
order. -
Returns the packed
string
.
std.string.unpack_16le(text)
-
Unpacks 16-bit integers from a
string
. The contents oftext
are re-interpreted as contiguous signed 16-bit integers in the
little-endian byte order, all of which are sign-extended to 64
bits then copied into anarray
. -
Returns an
array
containing unpacked integers. -
Throws an exception if the length of
text
is not a multiple
of 2.
std.string.pack_32be(ints)
-
Packs a series of 32-bit integers into a
string
.ints
shall
be anarray
ofinteger
s, all of which are truncated to 32
bits then copied into astring
in the big-endian byte order. -
Returns the packed
string
.
std.string.unpack_32be(text)
-
Unpacks 32-bit integers from a
string
. The contents oftext
are re-interpreted as contiguous signed 32-bit integers in the
big-endian byte order, all of which are sign-extended to 64
bits then copied into anarray
. -
Returns an
array
containing unpacked integers. -
Throws an exception if the length of
text
is not a multiple
of 4.
std.string.pack_32le(ints)
-
Packs a series of 32-bit integers into a
string
.ints
shall
be anarray
ofinteger
s, all of which are truncated to 32
bits then copied into astring
in the little-endian byte
order. -
Returns the packed
string
.
std.string.unpack_32le(text)
-
Unpacks 32-bit integers from a
string
. The contents oftext
are re-interpreted as contiguous signed 32-bit integers in the
little-endian byte order, all of which are sign-extended to 64
bits then copied into anarray
. -
Returns an
array
containing unpacked integers. -
Throws an exception if the length of
text
is not a multiple
of 4.
std.string.pack_64be(ints)
-
Packs a series of 64-bit integers into a
string
.ints
shall
be anarray
ofinteger
s, all of which are copied into a
string
in the big-endian byte order. -
Returns the packed
string
.
std.string.unpack_64be(text)
-
Unpacks 64-bit integers from a
string
. The contents oftext
are re-interpreted as contiguous signed 64-bit integers in the
big-endian byte order, all of which are copied into anarray
. -
Returns an
array
containing unpacked integers. -
Throws an exception if the length of
text
is not a multiple
of 8.
std.string.pack_64le(ints)
-
Packs a series of 64-bit integers into a
string
.ints
shall
be anarray
ofinteger
s, all of which are copied into a
string
in the little-endian byte order. -
Returns the packed
string
.
std.string.unpack_64le(text)
-
Unpacks 64-bit integers from a
string
. The contents oftext
are re-interpreted as contiguous signed 64-bit integers in the
little-endian byte order, all of which are copied into an
array
. -
Returns an
array
containing unpacked integers. -
Throws an exception if the length of
text
is not a multiple
of 8.
I am replacing this issue with a wish list.