Function

uni_caseconv

Perform case conversion.

Since v1.0
unistat uni_caseconv(
unicaseconv casing, const void *src, unisize src_len, uniattr src_attr, void *dst, unisize *dst_len, uniattr dst_attr)

Parameters πŸ”—

casing in

Casing operation to apply to src.

src in

Text to case convert.

src_len in

Number of code units in src or -1 if src is null terminated.

src_attr in

Attributes of src.

dst out

Buffer to write the case converted result to (can be NULL).

dst_len inout

Capacity of dst in code units on input; number of code units in src when case converted on output.

dst_attr in

Attributes of dst.

Return Value πŸ”—

UNI_OK

If src was case converted successfully.

UNI_BAD_OPERATION

If src is NULL, if dst_len is NULL, or if dst is NULL and dst_len is non-zero.

UNI_BAD_ENCODING

If src is not well-formed (checks are omitted if src_attr has UNI_TRUST).

UNI_NO_SPACE

If dst was not large enough to accommodate the case converted text.

UNI_FEATURE_DISABLED

If the library was built without support for case conversion.

Discussion πŸ”—

Case converts src to casing form casing and writes the result to dst. The capacity of dst is specified by dst_len.

If dst is not NULL, then the implementation writes to dst_len the total number of code units written to dst. If the capacity of dst is insufficient, then UNI_NO_SPACE is returned otherwise it returns UNI_OK.

If dst is NULL, then dst_len must be zero and the implementation writes to dst_len the number of code units in the fully case converted text and returns UNI_OK. Call the function this way to compute the total length of the destination buffer before calling it again with a sufficiently sized buffer.

Examples πŸ”—

This example case converts a string to uppercase.

#include <unicorn.h>
#include <stdio.h>

int main(void)
{
    const char *in = u8"hello, δΈ–η•Œ";
    char out[32];
    unisize outlen = sizeof(out);

    if (uni_caseconv(UNI_UPPER, in, -1, UNI_UTF8, out, &outlen, UNI_UTF8) != UNI_OK)
    {
        // something went wrong
        return 1;
    }

    printf("%.*s", outlen, out); // prints "HELLO, δΈ–η•Œ"
    return 0;
}