Expose missing Global/Encoding APIs in coreclr and remove empty stubs
[platform/upstream/coreclr.git] / src / classlibnative / inc / nlsinfo.h
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 ////////////////////////////////////////////////////////////////////////////
5 //
6 //  Class:    NLSInfo
7 //
8
9 //
10 //  Purpose:  This module defines the methods of the COMNlsInfo
11 //            class.  These methods are the helper functions for the
12 //            managed NLS+ classes.
13 //
14 //  Date:     August 12, 1998
15 //
16 ////////////////////////////////////////////////////////////////////////////
17
18 #ifndef _NLSINFO_H_
19 #define _NLSINFO_H_
20
21 #define DEFAULT_SORT_VERSION 0
22 #define SORT_VERSION_WHIDBEY 0x00001000
23 #define SORT_VERSION_V4      0x00060101
24
25 //
26 //This structure must map 1-for-1 with the InternalDataItem structure in
27 //System.Globalization.EncodingTable.
28 //
29 struct EncodingDataItem {
30     const char *   webName;
31     unsigned short codePage;
32     // free space here
33 };
34
35 //
36 //This structure must map 1-for-1 with the InternalCodePageDataItem structure in
37 //System.Globalization.EncodingTable.
38 //
39 struct CodePageDataItem {
40     unsigned short   codePage;
41     unsigned short   uiFamilyCodePage;
42     DWORD            dwFlags;             // only 4-bit used now
43     const char     * names;
44 };
45
46 // Normalization
47 typedef BOOL (*PFN_NORMALIZATION_IS_NORMALIZED_STRING)
48     ( int NormForm, LPCWSTR lpInString, int cchInString);
49
50 typedef int (*PFN_NORMALIZATION_NORMALIZE_STRING)
51     ( int NormForm, LPCWSTR lpInString, int cchInString, LPWSTR lpOutString, int cchOutString);
52
53 typedef BYTE* (*PFN_NORMALIZATION_INIT_NORMALIZATION)
54     ( int NormForm, BYTE* pTableData);
55
56 ////////////////////////////////////////////////////////////////////////////
57 //
58 // Forward declarations
59 //
60 ////////////////////////////////////////////////////////////////////////////
61
62 class CharTypeTable;
63 class CasingTable;
64 class SortingTable;
65 class NativeTextInfo;
66 class CultureDataBaseObject;
67
68 class COMNlsInfo {
69
70 public:
71 #ifdef FEATURE_SYNTHETIC_CULTURES
72     static INT32  WstrToInteger4(__in_z LPCWSTR wstrLocale, __in int Radix);
73 #endif // FEATURE_SYNTHETIC_CULTURES
74
75     static INT32 GetCHTLanguage();
76     static INT32 CallGetSystemDefaultUILanguage();
77     static INT32 CallGetUserDefaultUILanguage();
78     static LANGID GetDownLevelSystemDefaultUILanguage();
79
80     //
81     //  Native helper functions for methods in CultureInfo.
82     //
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);
86
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);
90 #endif
91
92     //
93     // Native helper functions for methods in DateTimeFormatInfo
94     //
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);
98
99     //
100     //  Native helper functions for CultureData
101     //
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);
106
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);
109
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);
119 #endif
120
121
122 #ifndef FEATURE_CORECLR
123     //
124     //  Native helper function for methods in TimeZone
125     //
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
131
132     //
133     //  Native helper function for methods in EncodingTable
134     //
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
142
143     //
144     //  Native helper function for methods in CharacterInfo
145     //
146     static FCDECL0(void, AllocateCharTypeTable);
147
148     //
149     //  Native helper function for methods in TextInfo
150     //
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);
155
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
162         __in                   int         cchValue,
163         __out                  int*        foundIndex);          // the index in lpStringSource where we found lpStringValue
164
165     //
166     // Native helper function for methods in Normalization
167     //
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);
175
176     static void QCALLTYPE nativeNormalizationInitNormalization(int NormForm, BYTE* pTableData);
177
178     //
179     // QCalls prototype
180     //
181
182     static int QCALLTYPE nativeEnumCultureNames(INT32 cultureTypes, QCall::ObjectHandleOnStack retStringArray);
183
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
194
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
204
205
206 private:
207
208     //
209     //  Internal helper functions.
210     //
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);
217
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);
221
222     static BOOL IsWindows7();
223
224     //
225     //  Definitions.
226     //
227
228 #ifndef FEATURE_COREFX_GLOBALIZATION
229     // Normalization
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;
234 #endif
235
236 private:
237     //
238     // Internal encoding data tables.
239     //
240     const static int m_nEncodingDataTableItems;
241     const static EncodingDataItem EncodingDataTable[];
242
243     const static int m_nCodePageTableItems;
244     const static CodePageDataItem CodePageDataTable[];
245
246     static INT_PTR EnsureValidSortHandle(INT_PTR handle, INT_PTR handleOrigin, LPCWSTR localeName);
247 };
248
249 #endif  // _NLSINFO_H_