_MRTIMP2 _Cvtvec __cdecl _Getcvt() { _Cvtvec cvt; cvt._Hand = ___lc_handle_func()[LC_CTYPE]; cvt._Page = ___lc_codepage_func(); return (cvt); }
_MRTIMP2_NCEEPURE _Collvec __CLRCALL_PURE_OR_CDECL _Getcoll() { _Collvec coll; coll._Hand = ___lc_handle_func()[LC_COLLATE]; coll._Page = ___lc_collate_cp_func(); return (coll); }
_CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Strcoll ( const char *_string1, const char *_end1, const char *_string2, const char *_end2, const _Collvec *ploc ) { int ret=0; UINT codepage; int n1 = (int)(_end1 - _string1); int n2 = (int)(_end2 - _string2); //const wchar_t *locale_name; LCID _Locale; if (ploc == 0) { //locale_name = ___lc_locale_name_func()[LC_COLLATE]; _Locale = ___lc_handle_func()[LC_COLLATE]; codepage = ___lc_collate_cp_func(); } else { //locale_name = ploc->_LocaleName; _Locale = __acrt_LocaleNameToLCID(ploc->_LocaleName, 0); codepage = ploc->_Page; } //if (locale_name == NULL) if(_Locale==0) { int ans; ans = memcmp(_string1, _string2, n1 < n2 ? n1 : n2); ret=(ans != 0 || n1 == n2 ? ans : n1 < n2 ? -1 : +1); } else { if ( 0 == (ret = __crtCompareStringA(_Locale, SORT_STRINGSORT, _string1, n1, _string2, n2, codepage )) ) { errno=EINVAL; ret=_NLSCMPERROR; } else { ret-=2; } } return ret; }
_MRTIMP2 int __cdecl _Wcrtomb ( char *s, wchar_t wchar, mbstate_t *pst, const _Cvtvec *ploc ) { LCID handle; UINT codepage; if (ploc == 0) { handle = ___lc_handle_func()[LC_CTYPE]; codepage = ___lc_codepage_func(); } else { handle = ploc->_Hand; codepage = ploc->_Page; } if ( handle == _CLOCALEHANDLE ) { if ( wchar > 255 ) /* validate high byte */ { errno = EILSEQ; return -1; } *s = (char) wchar; return sizeof(char); } else { int size; BOOL defused = 0; _locale_t locale = _GetLocaleForCP(codepage); if ( ((size = WideCharToMultiByte(codepage, 0, &wchar, 1, s, ___mb_cur_max_l_func(locale), NULL, &defused)) == 0) || (defused) ) { errno = EILSEQ; return -1; } return size; } }
_MRTIMP2_NCEEPURE int __CLRCALL_PURE_OR_CDECL _Strcoll ( const char *_string1, const char *_end1, const char *_string2, const char *_end2, const _Collvec *ploc ) { int ret=0; LCID handle; UINT codepage; int n1 = (int)(_end1 - _string1); int n2 = (int)(_end2 - _string2); if (ploc == 0) { handle = ___lc_handle_func()[LC_COLLATE]; codepage = ___lc_collate_cp_func(); } else { handle = ploc->_Hand; codepage = ploc->_Page; } if (handle == _CLOCALEHANDLE) { int ans; ans = memcmp(_string1, _string2, n1 < n2 ? n1 : n2); ret=(ans != 0 || n1 == n2 ? ans : n1 < n2 ? -1 : +1); } else { if ( 0 == (ret = __crtCompareStringA( NULL, handle, SORT_STRINGSORT, _string1, n1, _string2, n2, codepage )) ) { errno=EINVAL; ret=_NLSCMPERROR; } else { ret-=2; } } return ret; }
int __CLRCALL_PURE_OR_CDECL _Getdateorder() { // return date order for current locale wchar_t buf[2] = {0}; //__crtGetLocaleInfoEx(___lc_locale_name_func()[LC_TIME], LOCALE_ILDATE, // buf, sizeof (buf) / sizeof (buf[0])); GetLocaleInfoW(___lc_handle_func()[LC_TIME], LOCALE_ILDATE, buf, sizeof(buf) / sizeof(buf[0])); return (buf[0] == L'0' ? std::time_base::mdy : buf[0] == L'1' ? std::time_base::dmy : buf[0] == L'2' ? std::time_base::ymd : std::time_base::no_order); }
_CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Wcscoll ( const wchar_t *_string1, const wchar_t *_end1, const wchar_t *_string2, const wchar_t *_end2, const _Collvec *ploc ) { int n1 = (int)(_end1 - _string1); int n2 = (int)(_end2 - _string2); int ret=0; //const wchar_t *locale_name; LCID _Locale; if (ploc == 0) { //locale_name = ___lc_locale_name_func()[LC_COLLATE]; _Locale = ___lc_handle_func()[LC_COLLATE]; } else { //locale_name = ploc->_LocaleName; _Locale = ploc->_Hand; } if (/*locale_name == NULL*/_Locale==0) { int ans; ans = _Wmemcmp(_string1, _string2, n1 < n2 ? n1 : n2); ret=(ans != 0 || n1 == n2 ? ans : n1 < n2 ? -1 : +1); } else { if (0 == (ret = __crtCompareStringW(_Locale, SORT_STRINGSORT, _string1, n1, _string2, n2))) { errno = EINVAL; ret=_NLSCMPERROR; } else { ret-=2; } } return ret; }
_CRTIMP2_PURE _Collvec __CLRCALL_PURE_OR_CDECL _Getcoll() { _Collvec coll; coll._Page = ___lc_collate_cp_func(); auto __lc_collate = ___lc_handle_func()[LC_COLLATE]; wchar_t _LocaleName[LOCALE_NAME_MAX_LENGTH]; if (__lc_collate&&__acrt_LCIDToLocaleName(__lc_collate, _LocaleName, _countof(_LocaleName), 0)) coll._LocaleName = _wcsdup_dbg(_LocaleName, _CRT_BLOCK, __FILE__, __LINE__); else coll._LocaleName = NULL; return (coll); }
_CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Strxfrm ( char *_string1, char *_end1, const char *_string2, const char *_end2, const _Collvec *ploc ) { size_t _n1 = _end1 - _string1; size_t _n2 = _end2 - _string2; int dstlen; size_t retval = (size_t)-1; /* NON-ANSI: default if OM or API error */ UINT codepage; //const wchar_t *locale_name; LCID _Locale; if (ploc == 0) { //locale_name = ___lc_locale_name_func()[LC_COLLATE]; _Locale = ___lc_handle_func()[LC_COLLATE]; codepage = ___lc_collate_cp_func(); } else { //locale_name = ploc->_LocaleName; _Locale = __acrt_LocaleNameToLCID(ploc->_LocaleName, 0); codepage = ploc->_Page; } if ((/*locale_name*/_Locale == 0) && (codepage == CP_ACP)) { if (_n2 <= _n1) { memcpy(_string1, _string2, _n2); } retval=_n2; } else { /* Inquire size of dst string in BYTES */ if (0 != (dstlen = __crtLCMapStringA(_Locale, LCMAP_SORTKEY, _string2, (int)_n2, NULL, 0, codepage, TRUE))) { retval = dstlen; /* if not enough room, return amount needed */ if (dstlen <= (int)(_n1)) { /* Map src string to dst string */ __crtLCMapStringA(_Locale, LCMAP_SORTKEY, _string2, (int)_n2, _string1, (int)_n1, codepage, TRUE); } } } return (size_t)retval; }
_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; }