1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 | CString.as_text:
short: convert a C string to Text
description: >
Convert a C string to Text. This is the same conversion that `Text(str)`
performs.
errors: >
A C string is an arbitrary sequence of non-NUL bytes, but `Text` holds
Unicode, so this returns `none` when the bytes are not valid UTF-8.
return:
type: 'Text?'
description: >
The C string as a Text, or `none` if it is not valid UTF-8.
args:
str:
type: 'CString'
description: >
The C string.
example: |
assert CString("Hello").as_text() == "Hello"
assert Text(CString("Hello"))! == "Hello"
CString.bytes:
short: get the raw bytes
description: >
Convert a C string to a list of its raw bytes.
return:
type: '[Byte]'
description: >
A list of bytes (`[Byte]`) representing the C string's contents.
args:
str:
type: 'CString'
description: >
The C string.
example: |
assert CString("Hi").bytes() == [72, 105]
CString.join:
short: join a list of C strings
description: >
Join a list of C strings together with a separator.
return:
type: 'CString'
description: >
A C string of the joined together bits.
args:
glue:
type: 'CString'
description: >
The C joiner used to between elements.
pieces:
type: '[CString]'
description: >
A list of C strings to join.
example: |
assert CString(",").join([CString("a"), CString("b")]) == CString("a,b")
|