crow/string.crow
(source)
char8
builtin
This could be any byte in a UTF-8 string.
char32
builtin
32-bit Unicode character.
c-string
alias
C-style string. Always const.
This should be a valid pointer whose content ends in a "\0", though this is not enforced.
Thus, all operations on c-string
are unsafe.
string
builtin
A sequence of char32
s.
(It's stored as a char8[]
and is decoded as it's iterated.)
It can be efficiently concatenated or split, but doesn't support indexed access.
to
char8
(a
nat8
) bare
to
nat8
(a
char8
) bare
==
bool
(a
char8
, b
char8
) bare
to
char8
array
(a
string
) bare
to
char32
(a
char8
) bare
to
char32
array
(a
string
)
~~
string
(a
string
, b
string
)
interpolate
string
(...
parts
string
array
)
interpolate
char8
*
(...
parts
string
array
) unsafe
new
string
() bare
Same as ""
.
is-empty
bool
(a
string
) bare
Same as a == ""
.
size-char8s
nat64
(a
string
) bare
Size in char8
s
size
nat64
(a
string
)
==
bool
(a
string
, b
string
)
==
bool
(a
char32
, b
char32
) bare
to
nat32
(a
char32
) bare
unsafe-to
char32
(a
nat32
) bare
, unsafe
This is unsafe because a 'char32' should be a valid unicode character.
to
char32
(a
nat32
) bare
<=>
comparison
(a
string
, b
string
)
<=>
comparison
(a
char8
, b
char8
) bare
<=>
comparison
(a
char32
, b
char32
) bare
hash-mix
void
(hasher
hasher
, a
string
)
hash-mix
void
(hasher
hasher
, a
char8
)
hash-mix
void
(hasher
hasher
, a
char32
)
to
string
(a
char32
array
)
to
string
(a
char8
array
)
Treats UTF-8 character codes as a string. O(n) due to validation.
move-to
string
(a
char8
mut[]
) unsafe
as-string
string
(bytes
nat8
array
)
Validates that bytes are UTF-8 character codes, and returns them as a string.
to
nat64
(a
char8
) bare
to-bytes
nat8
array
(a
string
)
Treats a string as a list of UTF-8 bytes.
This is O(1).
to
nat8
array
(a
string
)
to
char8
*
(a
string
) unsafe
Converts a string to a c-string by appending "\0".
This is O(n).
WARN: The resulting string is allocated from GC memory but isn't traced by the garbage collector,
so it may be freed after the current task.
as-string
string
(a
char8
*
) unsafe
Treats a c-string as a string by walking to the end.
Unsafe because this does not copy the memory, and because a
must end in a "\0"
character.
to
char8
array
(a
char8
*
) unsafe
to
string
(a
char8
*
) unsafe
Unlike 'as-string' this copies the 'c-string'.
This is still unsafe because 'a' must end in a "\0"
character.
show
[t
] spec
show
string
(a
t
)
show
string
(a
bool
) bare
"true"
or "false"
.
to
string
(a
char8
)
String containing a single character.
show
string
(a
char8
)
to
string
(a
char32
)
show
string
(a
char32
)
show
string
(a
nat64
)
Converts a nat64 to a string.
Result is only digits, no punctuation.
to-binary
string
(a
nat8
)
to-binary
string
(a
nat16
)
to-binary
string
(a
nat32
)
to-binary
string
(a
nat64
)
to-hex
string
(a
nat8
)
to-hex
string
(a
nat16
)
to-hex
string
(a
nat32
)
to-hex
string
(a
nat64
)
show
string
(a
char8
*
) unsafe
show
string
(a
string
) bare
show
string
(a
nat8
)
show
string
(a
nat16
)
show
string
(a
nat32
)
show
string
(a
int8
)
show
string
(a
int16
)
show
string
(a
int32
)
show
string
(a
int64
)
show
string
(a
float32
)
show
string
(a
float64
)
iterate
bool
(a
string
, f
mut
bool
(char32
))
string-iterator
record
(has non-public fields)
==
bool
(a
string-iterator
, b
string-iterator
)
<=>
comparison
(a
string-iterator
, b
string-iterator
)
begin
string-iterator
(a
string
) bare
end
string-iterator
(a
string
) bare
collection
string
(a
string-iterator
) bare
slice
string
(a
string-iterator
, b
string-iterator
) bare
next
(char32
, string-iterator
) tuple2
?
(a
string-iterator
)
prev
(string-iterator
, char32
) tuple2
?
(a
string-iterator
)
string-builder
record
mut
(has non-public fields)
build
string
(a
build-options
, f
mut
void
(string-builder
))
~=
void
(a
string-builder
, value
char32
)
~~=
void
(a
string-builder
, s
string
)
invalid-unicode-character
record
exception
variant-member
exception
variant-membercharacter
nat32
show
string
(a
invalid-unicode-character
)
unicode-decode-error
record
exception
variant-member
exception
variant-membershow
string
(anonymous
unicode-decode-error
)
lines
string
array
(a
string
)
lower-case
string
(a
string
)
Lower cases every character in a
.
upper-case
string
(a
string
)
Capitalizes every character in a
.
replace-all
string
(a
string
, find
string
, replace-with
string
)
Replaces every instance of the substring find
with replace-with
.
strip
string
(a
string
)
Strips whitespace from both ends.
strip-left
string
(a
string
)
Strips whitespace from the front.
strip-right
string
(a
string
)
Strips whitespace from the end.
is-whitespace
bool
(a
char32
)
normalize-newlines
string
(a
string
)
quote
string
(a
string
)
Enclose a string in quotes and escape special characters.
unindent
string
(a
string
)
join
string
(joiner
string
, parts
string
array
)
Equivalent to parts[0] ~~ joiner ~~ parts[1] ~~ joiner ~~ ... ~~ parts[n]
.