_C_STD_BEGIN _CRTIMP2_PURE wchar_t __CLRCALL_PURE_OR_CDECL _Towlower(wchar_t _Ch, const _Ctypevec *_Ctype) { /* convert element to lower case */ wchar_t _Res = _Ch; if (_Ch == WEOF) ; else if (_Ctype->_LocaleName == NULL && _Ch < 256) { /* handle ASCII character in C locale */ if (L'A' <= _Ch && _Ch <= L'Z') _Res = (wchar_t)(_Ch - L'A' + L'a'); } else if (__crtLCMapStringW(_Ctype->_LocaleName, LCMAP_LOWERCASE, &_Ch, 1, &_Res, 1) == 0) _Res = _Ch; return (_Res); }
_CRTIMP2_PURE wchar_t __CLRCALL_PURE_OR_CDECL _Towupper(wchar_t _Ch, const _Ctypevec *_Ctype) { /* convert element to upper case */ wchar_t _Res = _Ch; if (_Ch != WEOF) { if (_Ctype->_Hand == 0 && _Ch < 256) { /* handle ASCII character in C locale */ if (L'a' <= _Ch && _Ch <= L'z') { _Res = (wchar_t)(_Ch - L'a' + L'A'); } } else if (__crtLCMapStringW(_Ctype->_Hand, LCMAP_UPPERCASE, &_Ch, 1, &_Res, 1) == 0) { _Res = _Ch; } } return (_Res); }
wchar_t __cdecl _towlower_lk ( wchar_t c ) { #endif /* _MT */ wchar_t widechar; if (c == WEOF) return c; if (__lc_handle[LC_CTYPE] == _CLOCALEHANDLE) { if ( (c >= L'A') && (c <= L'Z') ) c = c - L'A' + L'a'; return c; } /* if checking case of c does not require API call, do it */ if (c < 256) { if (!iswupper(c)) { return c; } } /* convert wide char to lowercase */ if ( 0 == __crtLCMapStringW( __lc_handle[LC_CTYPE], LCMAP_LOWERCASE, (LPCWSTR)&c, 1, (LPWSTR)&widechar, 1, 0) ) { return c; } return widechar; }
static errno_t __cdecl _wcslwr_s_l_stat ( wchar_t * wsrc, size_t sizeInWords, _locale_t plocinfo ) { wchar_t *p; /* traverses string for C locale conversion */ wchar_t *wdst; /* wide version of string in alternate case */ int dstsize; /* size in wide chars of wdst string buffer (include null) */ errno_t e = 0; size_t stringlen; /* validation section */ _VALIDATE_RETURN_ERRCODE(wsrc != NULL, EINVAL); stringlen = wcsnlen(wsrc, sizeInWords); if (stringlen >= sizeInWords) { _RESET_STRING(wsrc, sizeInWords); _RETURN_DEST_NOT_NULL_TERMINATED(wsrc, sizeInWords); } _FILL_STRING(wsrc, sizeInWords, stringlen + 1); if ( plocinfo->locinfo->locale_name[LC_CTYPE] == NULL) { for ( p = wsrc ; *p ; p++ ) { if ( (*p >= (wchar_t)L'A') && (*p <= (wchar_t)L'Z') ) { *p -= L'A' - L'a'; } } return 0; } /* C locale */ /* Inquire size of wdst string */ if ( (dstsize = __crtLCMapStringW( plocinfo->locinfo->locale_name[LC_CTYPE], LCMAP_LOWERCASE, wsrc, -1, NULL, 0 )) == 0 ) { errno = EILSEQ; return errno; } if (sizeInWords < (size_t)dstsize) { _RESET_STRING(wsrc, sizeInWords); _RETURN_BUFFER_TOO_SMALL(wsrc, sizeInWords); } /* Allocate space for wdst */ wdst = (wchar_t *)_calloca(dstsize, sizeof(wchar_t)); if (wdst == NULL) { errno = ENOMEM; return errno; } /* Map wrc string to wide-character wdst string in alternate case */ if (__crtLCMapStringW( plocinfo->locinfo->locale_name[LC_CTYPE], LCMAP_LOWERCASE, wsrc, -1, wdst, dstsize ) != 0) { /* Copy wdst string to user string */ e = wcscpy_s(wsrc, sizeInWords, wdst); } else { e = errno = EILSEQ; } _freea(wdst); return e; }
_MRTIMP2_NCEEPURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm( wchar_t* _string1, wchar_t* _end1, const wchar_t* _string2, const wchar_t* _end2, const _Collvec* ploc ) { size_t _n1 = _end1 - _string1; size_t _n2 = _end2 - _string2; size_t size = (size_t) - 1; unsigned char* bbuffer = NULL; LCID handle; if (ploc == 0) { handle = ___lc_handle_func()[LC_COLLATE]; } else { handle = ploc->_Hand; } if (handle == _CLOCALEHANDLE) { if (_n2 <= _n1) { memcpy(_string1, _string2, _n2 * sizeof(wchar_t)); } size = _n2; } else { /* * When using LCMAP_SORTKEY, LCMapStringW handles BYTES not wide * chars. We use a byte buffer to hold bytes and then convert the * byte string to a wide char string and return this so it can be * compared using wcscmp(). User's buffer is _n1 wide chars, so * use an internal buffer of _n1 bytes. */ if (NULL != (bbuffer = (unsigned char*)_malloc_crt(_n1))) { if (0 == (size = __crtLCMapStringW(NULL, handle, LCMAP_SORTKEY, _string2, (int)_n2, (wchar_t*)bbuffer, (int)_n1, ___lc_collate_cp_func()))) { /* buffer not big enough, get size required. */ if (0 == (size = __crtLCMapStringW(NULL, handle, LCMAP_SORTKEY, _string2, (int)_n2, NULL, 0, ___lc_collate_cp_func()))) { size = INT_MAX; /* default error */ } } else { size_t i; /* string successfully mapped, convert to wide char */ for (i = 0; i < size; i++) { _string1[i] = (wchar_t)bbuffer[i]; } } } } if (bbuffer) { _free_crt(bbuffer); } return (size_t)size; }