2 * Copyright (c) 2008 Secure Endpoints Inc.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #ifndef __CM_NLS_H_ENV__
26 #define __CM_NLS_H_ENV__
30 There are three character types that we use as implementation
31 types. These should generally only be referenced by the
40 The character types that are used by code are :
50 /*! \brief Unicode UTF-16 Character */
51 typedef wchar_t cm_unichar_t;
53 /*! \brief Unicode UTF-16 Normalized Character (NF-C) */
54 typedef wchar_t cm_normchar_t;
56 /*! \brief Unicode UTF-8 Character */
57 typedef unsigned char cm_utf8char_t;
59 /*! \brief Client name */
60 typedef cm_unichar_t clientchar_t;
62 /*! \brief File Server name */
63 typedef cm_utf8char_t fschar_t;
65 /*! \brief Normalized name */
66 typedef cm_normchar_t normchar_t;
68 #define __paste(a,b) a ## b
69 #define _C(s) __paste(L,s)
71 #define _N(s) __paste(L,s)
73 #define cm_ClientStringToNormStringAlloc cm_NormalizeStringAlloc
74 #define cm_ClientStringToFsStringAlloc cm_Utf16ToUtf8Alloc
75 #define cm_ClientStringToUtf8Alloc cm_Utf16ToUtf8Alloc
76 #define cm_FsStringToClientStringAlloc cm_Utf8ToUtf16Alloc
77 #define cm_FsStringToNormStringAlloc cm_NormalizeUtf8StringToUtf16Alloc
78 #define cm_Utf8ToNormStringAlloc cm_NormalizeUtf8StringToUtf16Alloc
79 #define cm_Utf8ToClientStringAlloc cm_Utf8ToUtf16Alloc
81 #define cm_ClientStringToUtf16 cm_Utf16ToUtf16
82 #define cm_ClientStringToUtf8 cm_Utf16ToUtf8
83 #define cm_ClientStringToFsString cm_Utf16ToUtf8
84 #define cm_ClientStringToNormString cm_NormalizeString
85 #define cm_FsStringToClientString cm_Utf8ToUtf16
86 #define cm_FsStringToNormString cm_NormalizeUtf8StringToUtf16
87 #define cm_Utf8ToClientString cm_Utf8ToUtf16
88 #define cm_OemToClientString(s,cchs,d,cchd) MultiByteToWideChar(CP_OEMCP, 0, s, cchs, d, cchd)
89 #define cm_AnsiToClientString(s,cchs,d,cchd) MultiByteToWideChar(CP_ACP, 0, s, cchs, d, cchd)
91 #define cm_ClientStrCmp wcscmp
92 #define cm_ClientStrCmpI cm_stricmp_utf16
93 #define cm_ClientStrCmpIA cm_stricmp_utf16
94 #define cm_ClientStrCmpNI cm_strnicmp_utf16
95 #define cm_ClientStrCmpN wcsncmp
96 #define cm_ClientStrChr wcschr
97 #define cm_ClientStrRChr wcsrchr
98 #define cm_ClientStrCpy(d,cch,s) StringCchCopyW(d,cch,s)
99 #define cm_ClientStrCpyN(d,cch,s,n) StringCchCopyNW(d,cch,s,n)
100 #define cm_ClientStrDup wcsdup
101 #define cm_ClientStrCat(d,cch,s) StringCchCatW(d,cch,s)
102 #define cm_ClientStrCatN(d,cch,s,n) StringCchCatNW(d,cch,s,n)
103 #define cm_ClientStrPrintfN StringCchPrintfW
104 #define cm_ClientStrPrintfV StringCchVPrintfW
105 //#define cm_ClientStrPrintf swprintf
106 #define cm_ClientStrLen wcslen
107 #define cm_ClientStrLwr cm_strlwr_utf16
108 #define cm_ClientStrUpr cm_strupr_utf16
109 #define cm_ClientStrSpn wcsspn
110 #define cm_ClientStrCSpn wcscspn
111 #define osi_LogSaveClientString osi_LogSaveStringW
112 #define cm_ClientCharThis char_this_utf16
113 #define cm_ClientCharNext char_next_utf16
114 #define cm_ClientCharPrev char_prev_utf16
116 #define cm_FsStrDup strdup
117 #define cm_FsStrLen strlen
118 #define cm_FsStrCat StringCchCatA
119 #define cm_FsStrPrintf StringCchPrintfA
120 #define cm_FsStrRChr strrchr
121 #define cm_FsStrChr strchr
122 #define cm_FsStrCmpIA cm_stricmp_utf8
123 #define cm_FsStrCmpI cm_stricmp_utf8
124 #define cm_FsStrCmpA strcmp
125 #define cm_FsStrCmp strcmp
126 #define cm_FsStrCpy(d,cch,s) StringCchCopyA(d,cch,s)
127 #define osi_LogSaveFsString osi_LogSaveString
128 #define cm_FsStrCpyN(d,cch,s,n) StringCchCopyN(d,cch,s,n)
130 #define cm_NormStrDup wcsdup
131 #define cm_NormStrCmpI cm_stricmp_utf16
132 #define cm_NormStrCmp wcscmp
133 #define cm_NormCharUpr towupper
135 #define cm_IsValidClientString(s) cm_is_valid_utf16((s), -1)
136 #define cm_IsValidNormString(s) cm_is_valid_utf16((s), -1)
138 #define cm_Utf16ToClientString cm_Utf16ToUtf16
140 extern long cm_InitNormalization(void);
142 /* Functions annotated in accordance with sal.h */
146 #define __out_ecount_full_z(x)
147 #define __out_ecount_full_z_opt(x)
154 extern __out_ecount_full_z(*pcch_dest) __checkReturn __success(return != NULL) cm_normchar_t *
155 cm_NormalizeStringAlloc
156 (__in_ecount(cch_src) const cm_unichar_t * s,
158 __out_ecount_full_opt(1) int *pcch_dest);
160 extern __success(return != 0) int
162 (__in_ecount(cch_src) const cm_unichar_t * s,
164 __out_ecount_full_z_opt(cch_dest) cm_normchar_t * dest,
167 extern __out_ecount_full_z(*pcch_dest) __checkReturn __success(return != NULL) cm_utf8char_t *
169 (__in_ecount(cch_src) const cm_unichar_t * s,
171 __out_ecount_full_opt(1) int *pcch_dest);
173 extern __out_ecount_full_z(*pcch_dest) __checkReturn __success(return != NULL) cm_unichar_t *
175 (__in_ecount(cch_src) const cm_utf8char_t * src,
177 __out_ecount_full_opt(1) int *pcch_dest);
179 extern __success(return != 0) long
180 cm_NormalizeUtf8StringToUtf16
181 (__in_ecount(cch_src) const char * src,
183 __out_ecount_full_z_opt(cch_dest) cm_normchar_t * dest,
186 extern __out_ecount_full_z(*pcch_dest) __checkReturn __success(return != NULL) cm_normchar_t *
187 cm_NormalizeUtf8StringToUtf16Alloc
188 (__in_ecount(cch_src) const cm_utf8char_t * src,
190 __out_ecount_full_opt(1) int *pcch_dest);
192 extern __success(return != 0) int
194 (__in_ecount(cch_src) const cm_utf8char_t * src,
196 __out_ecount_full_z_opt(cch_dest) cm_unichar_t * dest,
199 extern __success(return != 0) int
201 (__in_ecount(cch_src) const cm_unichar_t * src,
203 __out_ecount_full_z_opt(cch_dest) cm_utf8char_t * dest,
206 extern __success(return != 0) int
208 (__in_ecount(cch_src) const cm_unichar_t * src,
210 __out_ecount_full_z_opt(cch_dest) cm_unichar_t * dest,
215 (__in_z const cm_unichar_t * str1,
216 __in_z const cm_unichar_t * str2,
221 (__in_z const cm_unichar_t * str1,
222 __in_z const cm_unichar_t * str2);
224 /* The cm_stricmp_utf8N function is identical to cm_stricmp_utf8
225 except it is used in instances where one of the strings is always
226 known to be ASCII. */
229 (__in_z const char * str1,
230 __in_z const char * str2);
231 #define cm_stricmp_utf8N cm_stricmp_utf8
235 (__in_z const char * str1,
236 __in_z const char * str2);
238 /* The cm_strnicmp_utf8N function is identical to cm_strnicmp_utf8
239 except it is used in instances where one of the strings is always
240 known to be ASCII. */
243 (__in_z const char * str1,
244 __in_z const char * str2, int n);
245 #define cm_strnicmp_utf8N cm_strnicmp_utf8
249 (__in_z const char * str1,
250 __in_z const char * str2, int n);
252 extern __out_z wchar_t *
254 (__in_z const wchar_t * c);
256 extern __out_z wchar_t *
258 (__in_z const wchar_t * c);
260 extern __out_z wchar_t *
262 (__in_z const wchar_t * c);
264 extern __out_z cm_unichar_t *
265 cm_strlwr_utf16(__inout_z cm_unichar_t * str);
267 extern __out_z cm_unichar_t *
268 cm_strupr_utf16(__inout_z cm_unichar_t * str);
271 cm_is_valid_utf16(__in_z const wchar_t * c, int cch);
274 wchar_t * cm_GetRawCharsAlloc(const wchar_t * c, int len);
279 extern long cm_NormalizeUtf16StringToUtf8(const wchar_t * src, int cch_src,
280 char * adest, int cch_adest);
282 extern char * char_next_utf8(const char * c);
284 extern char * char_prev_utf8(const char * c);
286 extern char * strupr_utf8(char * str, size_t cbstr);
290 #define lengthof(a) (sizeof(a)/sizeof(a[0]))