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 ////////////////////////////////////////////////////////////////////////////
10 // Purpose: This module defines the methods of the COMNlsInfo
11 // class. These methods are the helper functions for the
12 // managed NLS+ classes.
14 // Date: August 12, 1998
16 ////////////////////////////////////////////////////////////////////////////
21 #define DEFAULT_SORT_VERSION 0
22 #define SORT_VERSION_WHIDBEY 0x00001000
23 #define SORT_VERSION_V4 0x00060101
26 //This structure must map 1-for-1 with the InternalDataItem structure in
27 //System.Globalization.EncodingTable.
29 struct EncodingDataItem {
31 unsigned short codePage;
36 //This structure must map 1-for-1 with the InternalCodePageDataItem structure in
37 //System.Globalization.EncodingTable.
39 struct CodePageDataItem {
40 unsigned short codePage;
41 unsigned short uiFamilyCodePage;
42 DWORD dwFlags; // only 4-bit used now
47 typedef BOOL (*PFN_NORMALIZATION_IS_NORMALIZED_STRING)
48 ( int NormForm, LPCWSTR lpInString, int cchInString);
50 typedef int (*PFN_NORMALIZATION_NORMALIZE_STRING)
51 ( int NormForm, LPCWSTR lpInString, int cchInString, LPWSTR lpOutString, int cchOutString);
53 typedef BYTE* (*PFN_NORMALIZATION_INIT_NORMALIZATION)
54 ( int NormForm, BYTE* pTableData);
56 ////////////////////////////////////////////////////////////////////////////
58 // Forward declarations
60 ////////////////////////////////////////////////////////////////////////////
66 class CultureDataBaseObject;
71 #ifdef FEATURE_SYNTHETIC_CULTURES
72 static INT32 WstrToInteger4(__in_z LPCWSTR wstrLocale, __in int Radix);
73 #endif // FEATURE_SYNTHETIC_CULTURES
75 static INT32 GetCHTLanguage();
76 static INT32 CallGetSystemDefaultUILanguage();
77 static INT32 CallGetUserDefaultUILanguage();
78 static LANGID GetDownLevelSystemDefaultUILanguage();
81 // Native helper functions for methods in CultureInfo.
83 static BOOL QCALLTYPE InternalGetDefaultLocaleName(INT32 langType, QCall::StringHandleOnStack defaultLocaleName);
84 static BOOL QCALLTYPE InternalGetUserDefaultUILanguage(QCall::StringHandleOnStack userDefaultUiLanguage);
85 static BOOL QCALLTYPE InternalGetSystemDefaultUILanguage(QCall::StringHandleOnStack systemDefaultUiLanguage);
87 // Added but disabled from desktop in .NET 4.0, stayed disabled in .NET 4.5
88 #ifdef FEATURE_CORECLR
89 static FCDECL0(Object*, nativeGetResourceFallbackArray);
93 // Native helper functions for methods in DateTimeFormatInfo
95 static FCDECL1(FC_BOOL_RET, nativeSetThreadLocale, StringObject* localeNameUNSAFE);
96 static FCDECL2(Object*, nativeGetLocaleInfoEx, StringObject* localeNameUNSAFE, INT32 lcType);
97 static FCDECL2(INT32, nativeGetLocaleInfoExInt, StringObject* localeNameUNSAFE, INT32 lcType);
100 // Native helper functions for CultureData
102 static FCDECL1(FC_BOOL_RET, nativeInitCultureData, CultureDataBaseObject *data);
103 static FCDECL3(FC_BOOL_RET, nativeGetNumberFormatInfoValues, StringObject* localeNameUNSAFE, NumberFormatInfo* nfi, CLR_BOOL useUserOverride);
104 static FCDECL1(Object*, LCIDToLocaleName, LCID lcid);
105 static FCDECL1(INT32, LocaleNameToLCID, StringObject* localeNameUNSAFE);
107 static INT32 QCALLTYPE InternalCompareString (INT_PTR handle, INT_PTR handleOrigin, LPCWSTR localeName, LPCWSTR string1, INT32 offset1, INT32 length1, LPCWSTR string2, INT32 offset2, INT32 length2, INT32 flags);
108 static INT32 QCALLTYPE InternalGetGlobalizedHashCode(INT_PTR handle, INT_PTR handleOrigin, LPCWSTR localeName, LPCWSTR pString, INT32 length, INT32 dwFlagsIn, BOOL bForceRandomizedHashing, INT64 additionalEntropy);
110 static BOOL QCALLTYPE InternalIsSortable(INT_PTR handle, INT_PTR handleOrigin, LPCWSTR localeName, LPCWSTR pString, INT32 length);
111 static INT_PTR QCALLTYPE InternalInitSortHandle(LPCWSTR localeName, INT_PTR* handleOrigin);
112 static INT_PTR InitSortHandleHelper(LPCWSTR localeName, INT_PTR* handleOrigin);
113 static INT_PTR InternalInitOsSortHandle(LPCWSTR localeName, INT_PTR* handleOrigin);
114 #ifndef FEATURE_CORECLR
115 static INT_PTR InternalInitVersionedSortHandle(LPCWSTR localeName, INT_PTR* handleOrigin);
116 static INT_PTR InternalInitVersionedSortHandle(LPCWSTR localeName, INT_PTR* handleOrigin, DWORD sortVersion);
117 static DWORD QCALLTYPE InternalGetSortVersion();
118 static BOOL QCALLTYPE InternalGetNlsVersionEx(INT_PTR handle, INT_PTR handleOrigin, LPCWSTR lpLocaleName, NLSVERSIONINFOEX * lpVersionInformation);
122 #ifndef FEATURE_CORECLR
124 // Native helper function for methods in TimeZone
126 static FCDECL0(LONG, nativeGetTimeZoneMinuteOffset);
127 static FCDECL0(Object*, nativeGetStandardName);
128 static FCDECL0(Object*, nativeGetDaylightName);
129 static FCDECL1(Object*, nativeGetDaylightChanges, int year);
130 #endif // FEATURE_CORECLR
133 // Native helper function for methods in EncodingTable
135 static FCDECL0(INT32, nativeGetNumEncodingItems);
136 static FCDECL0(EncodingDataItem *, nativeGetEncodingTableDataPointer);
137 static FCDECL0(CodePageDataItem *, nativeGetCodePageTableDataPointer);
138 #if FEATURE_CODEPAGES_FILE
139 static FCDECL3(LPVOID, nativeCreateOpenFileMapping,
140 StringObject* inSectionNameUNSAFE, int inBytesToAllocate, HANDLE *mappedFile);
141 #endif // FEATURE_CODEPAGES_FILE
144 // Native helper function for methods in CharacterInfo
146 static FCDECL0(void, AllocateCharTypeTable);
149 // Native helper function for methods in TextInfo
151 static FCDECL5(FC_CHAR_RET, InternalChangeCaseChar, INT_PTR handle, INT_PTR handleOrigin, StringObject* localeNameUNSAFE, CLR_CHAR wch, CLR_BOOL bIsToUpper);
152 static FCDECL5(Object*, InternalChangeCaseString, INT_PTR handle, INT_PTR handleOrigin, StringObject* localeNameUNSAFE, StringObject* pString, CLR_BOOL bIsToUpper);
153 static FCDECL6(INT32, InternalGetCaseInsHash, INT_PTR handle, INT_PTR handleOrigin, StringObject* localeNameUNSAFE, LPVOID strA, CLR_BOOL bForceRandomizedHashing, INT64 additionalEntropy);
154 static INT32 QCALLTYPE InternalCompareStringOrdinalIgnoreCase(LPCWSTR string1, INT32 index1, LPCWSTR string2, INT32 index2, INT32 length1, INT32 length2);
156 static BOOL QCALLTYPE InternalTryFindStringOrdinalIgnoreCase(
157 __in DWORD dwFindNLSStringFlags, // mutually exclusive flags: FIND_FROMSTART, FIND_STARTSWITH, FIND_FROMEND, FIND_ENDSWITH
158 __in_ecount(cchSource) LPCWSTR lpStringSource, // the string we search in
159 __in int cchSource, // number of characters lpStringSource after sourceIndex
160 __in int sourceIndex, // index from where the search will start in lpStringSource
161 __in_ecount(cchValue) LPCWSTR lpStringValue, // the string we search for
163 __out int* foundIndex); // the index in lpStringSource where we found lpStringValue
166 // Native helper function for methods in Normalization
168 static FCDECL6(int, nativeNormalizationNormalizeString,
169 int NormForm, int& iError,
170 StringObject* inString, int inLength,
171 CHARArray* outChars, int outLength);
172 static FCDECL4(FC_BOOL_RET, nativeNormalizationIsNormalizedString,
173 int NormForm, int& iError,
174 StringObject* inString, int cwLength);
176 static void QCALLTYPE nativeNormalizationInitNormalization(int NormForm, BYTE* pTableData);
182 static int QCALLTYPE nativeEnumCultureNames(INT32 cultureTypes, QCall::ObjectHandleOnStack retStringArray);
184 static int QCALLTYPE InternalFindNLSStringEx(
185 __in_opt INT_PTR handle, // optional sort handle
186 __in_opt INT_PTR handleOrigin, // optional pointer to the native function that created the sort handle
187 __in_z LPCWSTR lpLocaleName, // locale name
188 __in int dwFindNLSStringFlags, // search falg
189 __in_ecount(cchSource) LPCWSTR lpStringSource, // the string we search in
190 __in int cchSource, // number of characters lpStringSource after sourceIndex
191 __in int sourceIndex, // index from where the search will start in lpStringSource
192 __in_ecount(cchValue) LPCWSTR lpStringValue, // the string we search for
193 __in int cchValue); // length of the string we search for
195 static int QCALLTYPE InternalGetSortKey(
196 __in_opt INT_PTR handle, // PSORTHANDLE
197 __in_opt INT_PTR handleOrigin, // optional pointer to the native function that created the sort handle
198 __in_z LPCWSTR pLocaleName, // locale name
199 __in int flags, // flags
200 __in_ecount(cchSource) LPCWSTR pStringSource, // Source string
201 __in int cchSource, // number of characters in lpStringSource
202 __in_ecount(cchTarget) PBYTE pTarget, // Target data buffer (may be null to count)
203 __in int cchTarget); // Character count for target buffer
209 // Internal helper functions.
211 static LPVOID internalEnumSystemLocales(DWORD dwFlags);
212 static INT32 CompareOrdinal(__in_ecount(Length1) WCHAR* strAChars, int Length1, __in_ecount(Length2) WCHAR* strBChars, int Length2 );
213 static INT32 FastIndexOfString(__in WCHAR *sourceString, INT32 startIndex, INT32 endIndex, __in_ecount(patternLength) WCHAR *pattern, INT32 patternLength);
214 static INT32 FastIndexOfStringInsensitive(__in WCHAR *sourceString, INT32 startIndex, INT32 endIndex, __in_ecount(patternLength) WCHAR *pattern, INT32 patternLength);
215 static INT32 FastLastIndexOfString(__in WCHAR *sourceString, INT32 startIndex, INT32 endIndex, __in_ecount(patternLength) WCHAR *pattern, INT32 patternLength);
216 static INT32 FastLastIndexOfStringInsensitive(__in WCHAR *sourceString, INT32 startIndex, INT32 endIndex, __in_ecount(patternLength) WCHAR *pattern, INT32 patternLength);
218 static BOOL GetNativeDigitsFromWin32(LPCWSTR locale, PTRARRAYREF* pOutputStrAry, BOOL useUserOverride);
219 static BOOL CallGetLocaleInfoEx(LPCWSTR locale, int lcType, STRINGREF* pOutputStrRef, BOOL useUserOverride);
220 static BOOL CallGetLocaleInfoEx(LPCWSTR locale, int lcType, INT32* pOutputInt32, BOOL useUserOverride);
222 static BOOL IsWindows7();
228 #ifndef FEATURE_COREFX_GLOBALIZATION
230 static HMODULE m_hNormalization;
231 static PFN_NORMALIZATION_IS_NORMALIZED_STRING m_pfnNormalizationIsNormalizedStringFunc;
232 static PFN_NORMALIZATION_NORMALIZE_STRING m_pfnNormalizationNormalizeStringFunc;
233 static PFN_NORMALIZATION_INIT_NORMALIZATION m_pfnNormalizationInitNormalizationFunc;
238 // Internal encoding data tables.
240 const static int m_nEncodingDataTableItems;
241 const static EncodingDataItem EncodingDataTable[];
243 const static int m_nCodePageTableItems;
244 const static CodePageDataItem CodePageDataTable[];
246 static INT_PTR EnsureValidSortHandle(INT_PTR handle, INT_PTR handleOrigin, LPCWSTR localeName);
249 #endif // _NLSINFO_H_