Function
uni_casefold
Perform case folding.
Parameters 🔗
casing | in | Case fold form to apply to |
src | in | Text to case fold. |
src_len | in | Number of code units in |
src_attr | in | Attributes of |
dst | out | Buffer to write the case folded 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 folding. |
UNI_NO_MEMORY | If dynamic memory allocation failed. |
Discussion 🔗
Case folds 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 casefolds a string for canonical caseless comparison.
The example will produce an output string that is longer than the input string. This is because the German 'ß' (U+00DF) case folds to 'ss' (U+0073 U+0073) and the Latin small letter 'ö' with diaeresis (U+00F6) canonically normalizes to an 'o' (U+006F) followed by a combining diaeresis character (U+0308).
#include <unicorn.h>
#include <stdio.h>
int main(void)
{
const char *in = u8"Stößen";
char out[32];
unisize outlen = sizeof(out);
if (uni_casefold(UNI_CANONICAL, in, -1, UNI_UTF8, out, &outlen, UNI_UTF8) != UNI_OK)
{
// something went wrong
return 1;
}
printf("%.*s", outlen, out); // prints "stössen"
return 0;
}