safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
wcsfc_s.c File Reference
#include "safe_str_lib.h"
+ Include dependency graph for wcsfc_s.c:

Functions

static int _is_lt_accented (wint_t wc)
 
EXPORT errno_t wcsfc_s (wchar_t *restrict dest, rsize_t dmax, wchar_t *restrict src, rsize_t *restrict lenp)
 Converts the wide string via full case-folding NFD normalized to lowercase. More...
 

Function Documentation

◆ _is_lt_accented()

static int _is_lt_accented ( wint_t  wc)
inlinestatic

◆ wcsfc_s()

EXPORT errno_t wcsfc_s ( wchar_t *restrict  dest,
rsize_t  dmax,
wchar_t *restrict  src,
rsize_t *restrict  lenp 
)

Converts the wide string via full case-folding NFD normalized to lowercase.

The conversion stops at the first null or after dmax characters. The conversion is determined by the LC_CTYPE category setting of the locale. Other characters are not affected. fold-case performs full case folding, i.e. if iswfc() of a character > 1, the length of dest might be greater than the length of src (max 4 per char), the conversion is done via towfc_s() and Unicode 10.0, the Unicode special-casing rules are obeyed, and composed characters are normalized to NFD via wcsnorm_decompose_s() and wcsnorm_reorder_s(). If not, the conversion is per character done via normal towlower(). Note that decomposition creates larger strings, typically 2-3 chars more.

With SAFECLIB_STR_NULL_SLACK defined all elements following the terminating null character (if any) written in the array of dmax characters pointed to by dest are nulled.

SpecialCasing checks for conditional boundary context at the begin or end of certain characters (final greek sigma), and locale sensitive rules for the Lithuanian and the Turkish/Azeri I-dot.

Composed characters are checked for the left-hand-side of the Decomposition_Mapping Unicode property, which means the codepoint will be normalized to NFD if any codepoint is composed. Technically only FCD as all FC expansions are already properly ordered, and all mangled marks will not be reordered, as the have the same Combining Class.

Parameters
[out]destwide string to hold the result (~130% larger than src)
[in]dmaxmaximum result buffer size
[in]srcwide string
[out]lenppointer to length of the result, may be NULL
Precondition
dest and src shall not be null pointers.
dmax shall not be smaller than 5 and big enough for dest.
dmax shall not be greater than RSIZE_MAX_WSTR.
Return values
EOKon successful operation
ESNULLPwhen dest or src is NULL pointer
ESZEROLwhen dmax = 0
ESLEMAXwhen dmax > RSIZE_MAX_WSTR or a cp > 0x10ffff
ESNOSPCwhen dmax is too small for the decomposition. *lenp is still written, to know how much space is needed.
ESNOTFNDInternal error as returned by towfc_s() for multi-char foldings. happens only when the internal implementations of iswfc() and towfc_s() are mismatched.
See also
iswfc(), towfc_s(), towupper(), wcslwr_s(), wcsupr_s()