1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 // ============================================================
8 // Implements various helper functions
10 // ============================================================
12 #include "fusionhelpers.hpp"
16 #define IS_UPPER_A_TO_Z(x) (((x) >= L'A') && ((x) <= L'Z'))
17 #define IS_LOWER_A_TO_Z(x) (((x) >= L'a') && ((x) <= L'z'))
18 #define IS_0_TO_9(x) (((x) >= L'0') && ((x) <= L'9'))
19 #define CAN_SIMPLE_UPCASE(x) (((x)&~0x7f) == 0)
20 #define SIMPLE_UPCASE(x) (IS_LOWER_A_TO_Z(x) ? ((x) - L'a' + L'A') : (x))
21 #define CAN_SIMPLE_LOWERCASE(x) (((x)&~0x7f) == 0)
22 #define SIMPLE_LOWERCASE(x) (IS_UPPER_A_TO_Z(x) ? ((x) - L'A' + L'a') : (x))
24 // ---------------------------------------------------------------------------
26 // ---------------------------------------------------------------------------
29 WCHAR FusionMapChar(WCHAR wc)
35 #ifdef FEATURE_USE_LCID
36 int iRet = WszLCMapString(g_lcid, LCMAP_UPPERCASE, &wc, 1, &wTmp, 1);
38 int iRet = LCMapStringEx(g_lcid, LCMAP_UPPERCASE, &wc, 1, &wTmp, 1, NULL, NULL, 0);
41 _ASSERTE(!"LCMapString failed!");
42 iRet = GetLastError();
46 // For PAL, no locale specific processing is done
48 #endif // !FEATURE_PAL
54 // ---------------------------------------------------------------------------
55 // FusionCompareStringN
56 // ---------------------------------------------------------------------------
57 // if nChar < 0, compare the whole string
58 int FusionCompareStringN(LPCWSTR pwz1, LPCWSTR pwz2, int nChar, BOOL bCaseSensitive)
64 _ASSERTE(pwz1 && pwz2);
66 // same point always return equal.
71 // Case sensitive comparison
74 return wcsncmp(pwz1, pwz2, nChar);
76 return wcscmp(pwz1, pwz2);
83 if (ch1 == L'\0' || ch2 == L'\0') {
87 // We use OS mapping table
88 ch1 = (CAN_SIMPLE_UPCASE(ch1)) ? (SIMPLE_UPCASE(ch1)) : (FusionMapChar(ch1));
89 ch2 = (CAN_SIMPLE_UPCASE(ch2)) ? (SIMPLE_UPCASE(ch2)) : (FusionMapChar(ch2));
92 if (ch1 != ch2 || (nChar >= 0 && nCount >= nChar)) {
100 else if (ch1 < ch2) {
107 // ---------------------------------------------------------------------------
108 // FusionCompareStringI
109 // ---------------------------------------------------------------------------
110 int FusionCompareStringI(LPCWSTR pwz1, LPCWSTR pwz2)
112 return FusionCompareStringN(pwz1, pwz2, -1, FALSE);