// Function to compare strings used for sort operation 
UINT CALLBACK ListViewCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	bool isAsc = (lParamSort > 0);
	int column = abs(lParamSort) - 1;
	
	UINT result = 0;

	WCHAR buf1[MAX_BUFFER_LENGTH];
	WCHAR buf2[MAX_BUFFER_LENGTH];

	// Retrieve text from items
	ListView_GetItemText(m_list, lParam1, column, buf1, sizeof(buf1) / sizeof(WCHAR));
	ListView_GetItemText(m_list, lParam2, column, buf2, sizeof(buf2) / sizeof(WCHAR));

	wcslen(buf1);
	// Perform string compare depending on sort type
	if (isAsc) 
	{
		result = CompareStringEx(LOCALE_NAME_SYSTEM_DEFAULT,
			0,
			buf1,
			wcslen(buf1),
			buf2,
			wcslen(buf2),
			NULL, NULL, 0);
	}
	else 
	{	
		result = CompareStringEx(LOCALE_NAME_SYSTEM_DEFAULT,
			0,
			buf2,
			wcslen(buf2),
			buf1,
			wcslen(buf1),
			NULL, NULL, 0);
	}

	// Make return result consistent with C runtime
	return result - 2;
}
Esempio n. 2
0
int tcscmp(const tchar_t* a,const tchar_t* b) 
{
#ifndef WINDOWS_DESKTOP
	int i = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, a, -1, b, -1, NULL, NULL, 0);
#else
	int i = CompareString(LOCALE_USER_DEFAULT,0,a,-1,b,-1);
#endif
    if (i)
        return i-CSTR_EQUAL;

    // fallback
#ifdef UNICODE
	return wcscmp(a,b);
#else
	return strcmp(a,b);
#endif
}
Esempio n. 3
0
int tcsnicmp(const tchar_t* a,const tchar_t* b,size_t n) 
{
#ifndef WINDOWS_DESKTOP
	int i = CompareStringEx(LOCALE_NAME_USER_DEFAULT, NORM_IGNORECASE, a, min(tcslen(a), n), b, min(tcslen(b), n), NULL, NULL, 0);
#else
	int i = CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,a,min(tcslen(a),n),b,min(tcslen(b),n));
#endif
    if (i)
        return i-CSTR_EQUAL;

    // fallback
#ifdef UNICODE
	return wcsnicmp(a,b,n);
#else
	return strnicmp(a,b,n);
#endif
}
Esempio n. 4
0
BOOL CALLBACK MyFuncLocaleEx(LPWSTR pStr, DWORD dwFlags, LPARAM lparam)
{
    UNREFERENCED_PARAMETER(dwFlags);
    WCHAR** argv = (WCHAR**)lparam;
    WCHAR wcBuffer[BUFFER_SIZE];
    int iResult;
    // Get its LCID 
    LCID lcid = LocaleNameToLCID(pStr, NULL);
    if (lcid != 0)
        wprintf(L"LCID for %s is %x\n", pStr, lcid);
    else
        wprintf(L"Error %d getting LCID\n", GetLastError());
    // Print out the locale name we found
    iResult = GetLocaleInfoEx(pStr, LOCALE_SENGLANGUAGE, wcBuffer, BUFFER_SIZE);
    // If it succeeds, print it out
    if (iResult > 0)
        wprintf(L"Locale %s (%s)\n", pStr, wcBuffer);
    else
        wprintf(L"Locale %s had error %d\n", pStr, GetLastError());
    // CompareStringEx if this is the system locale, let us know
    iResult = GetSystemDefaultLocaleName(wcBuffer, BUFFER_SIZE);
    if (iResult > 0)
    {
        if (CompareStringEx(LOCALE_NAME_INVARIANT,
                            LINGUISTIC_IGNORECASE,
                            wcBuffer,
                            -1,
                            pStr,
                            -1,
                            NULL,
                            NULL,
                            0) == CSTR_EQUAL)
        {
            wprintf(L"\nLocale %s is the system locale!\n", wcBuffer);
            system("Pause");
        }
    }
    else
    {
        wprintf(L"Error %d getting system locale\n", GetLastError());
        system("Pause");
    }
return (TRUE);
}
Esempio n. 5
0
int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const
{
    if (d->dirty)
        d->init();

    //* from Windows documentation *
    // Returns one of the following values if successful. To maintain the C runtime convention of
    // comparing strings, the value 2 can be subtracted from a nonzero return value. Then, the
    // meaning of <0, ==0, and >0 is consistent with the C runtime.

#ifndef USE_COMPARESTRINGEX
    return CompareString(d->localeID, d->collator,
                         reinterpret_cast<const wchar_t*>(s1), len1,
                         reinterpret_cast<const wchar_t*>(s2), len2) - 2;
#else
    return CompareStringEx(LPCWSTR(d->localeName.utf16()), d->collator,
                           reinterpret_cast<LPCWSTR>(s1), len1,
                           reinterpret_cast<LPCWSTR>(s2), len2, NULL, NULL, 0) - 2;
#endif
}