Ejemplo n.º 1
0
_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);
}
Ejemplo n.º 2
0
_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;
}
Ejemplo n.º 3
0
_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;
}
Ejemplo n.º 4
0
_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);
}
Ejemplo n.º 5
0
_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;
}
Ejemplo n.º 6
0
_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;
}