Function
uni_caseconv
Perform case conversion.
Parameters 🔗
| casing | in | Casing operation to apply to |
| src | in | Text to case convert. |
| src_len | in | Number of code units in |
| src_attr | in | Attributes of |
| dst | out | Buffer to write the case converted result to (can be |
| dst_len | inout | Capacity of |
| dst_attr | in | Attributes of |
Return Value 🔗
| UNI_OK | If |
| UNI_BAD_OPERATION | If |
| UNI_BAD_ENCODING | If |
| UNI_NO_SPACE | If |
| 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;
}