3#include <wine/unicode.h>
24 delta /= (firsttime ?
DAMP : 2);
25 delta += delta/numpoints;
38 LPWSTR lpNameprepCharStr,
INT cchNameprepChar)
51 WCHAR buf[64], *map_str, norm_str[64], ch;
52 DWORD i, map_len, norm_len,
mask, label_start, label_end,
out = 0;
53 BOOL have_bidi_ral, prohibit_bidi_ral, ascii_only;
55 DPRINT(
"%x %p %d %p %d\n",
dwFlags, lpUnicodeCharStr, cchUnicodeChar,
56 lpNameprepCharStr, cchNameprepChar);
58 if(
dwFlags & ~(IDN_ALLOW_UNASSIGNED|IDN_USE_STD3_ASCII_RULES)) {
63 if(!lpUnicodeCharStr || cchUnicodeChar<-1) {
68 if(cchUnicodeChar == -1)
70 if(!cchUnicodeChar || (cchUnicodeChar==1 && lpUnicodeCharStr[0]==0)) {
75 for(label_start=0; label_start<(
UINT)cchUnicodeChar;) {
77 for(
i=label_start;
i<(
UINT)cchUnicodeChar;
i++) {
78 ch = lpUnicodeCharStr[
i];
80 if(
i!=cchUnicodeChar-1 && !ch) {
85 if(!ch || ch==
'.' || ch==0x3002 || ch==0xff0e || ch==0xff61)
93 if((
dwFlags&IDN_USE_STD3_ASCII_RULES) == 0)
95 if((ch>=
'a' && ch<=
'z') || (ch>=
'A' && ch<=
'Z')
96 || (ch>=
'0' && ch<=
'9') || ch==
'-')
104 if(label_start==label_end && ch) {
109 if((
dwFlags&IDN_USE_STD3_ASCII_RULES) && (lpUnicodeCharStr[label_start]==
'-' ||
110 lpUnicodeCharStr[label_end-1]==
'-')) {
117 if(label_end-label_start > 63) {
121 if(label_end < (
UINT)cchUnicodeChar)
124 if(!lpNameprepCharStr) {
125 out += label_end-label_start;
126 }
else if(
out+label_end-label_start <= (
UINT)cchNameprepChar) {
127 memcpy(lpNameprepCharStr+
out, lpUnicodeCharStr+label_start,
128 (label_end-label_start)*
sizeof(
WCHAR));
129 if(lpUnicodeCharStr[label_end-1] > 0x7f)
130 lpNameprepCharStr[
out+label_end-label_start-1] =
'.';
131 out += label_end-label_start;
137 label_start = label_end;
142 for(
i=label_start;
i<label_end;
i++) {
143 ch = lpUnicodeCharStr[
i];
147 if(!
ptr[0]) map_len++;
148 else if(!
ptr[1]) map_len++;
149 else if(!
ptr[2]) map_len += 2;
150 else if(
ptr[0]!=0xffff ||
ptr[1]!=0xffff ||
ptr[2]!=0xffff) map_len += 3;
152 if(map_len*
sizeof(
WCHAR) >
sizeof(
buf)) {
162 for(
i=label_start;
i<label_end;
i++) {
163 ch = lpUnicodeCharStr[
i];
168 map_str[map_len++] = ch;
170 map_str[map_len++] =
ptr[0];
172 map_str[map_len++] =
ptr[0];
173 map_str[map_len++] =
ptr[1];
174 }
else if(
ptr[0]!=0xffff ||
ptr[1]!=0xffff ||
ptr[2]!=0xffff) {
175 map_str[map_len++] =
ptr[0];
176 map_str[map_len++] =
ptr[1];
177 map_str[map_len++] =
ptr[2];
182 norm_str,
sizeof(norm_str)/
sizeof(
WCHAR)-1);
191 if(label_end < (
UINT)cchUnicodeChar) {
192 norm_str[norm_len++] = lpUnicodeCharStr[label_end] ?
'.' : 0;
196 if(!lpNameprepCharStr) {
198 }
else if(
out+norm_len <= (
UINT)cchNameprepChar) {
206 have_bidi_ral = prohibit_bidi_ral =
FALSE;
208 if((
dwFlags&IDN_ALLOW_UNASSIGNED) == 0)
210 for(
i=0;
i<norm_len;
i++) {
221 have_bidi_ral =
TRUE;
223 prohibit_bidi_ral =
TRUE;
229 if((
flags & BIDI_RAL) == 0)
230 prohibit_bidi_ral =
TRUE;
232 ch = norm_str[norm_len-1];
234 if((
flags & BIDI_RAL) == 0)
235 prohibit_bidi_ral =
TRUE;
238 if(have_bidi_ral && prohibit_bidi_ral) {
243 label_start = label_end;
252 static const WCHAR prefixW[] = {
'x',
'n',
'-',
'-'};
255 INT i, label_start, label_end, norm_len, out_label,
out = 0;
257 DPRINT(
"%x %p %d %p %d\n",
dwFlags, lpUnicodeCharStr, cchUnicodeChar,
258 lpASCIICharStr, cchASCIIChar);
269 cchUnicodeChar, norm_str, norm_len);
275 for(label_start=0; label_start<norm_len;) {
277 INT delta = 0,
b = 0,
h;
280 for(
i=label_start;
i<norm_len && norm_str[
i]!=
'.' &&
281 norm_str[
i]!=0x3002 && norm_str[
i]!=
'\0';
i++)
282 if(norm_str[
i] < 0x80)
286 if(
b == label_end-label_start) {
287 if(label_end < norm_len)
289 if(!lpASCIICharStr) {
291 }
else if(
out+
b <= cchASCIIChar) {
299 label_start = label_end+1;
303 if(!lpASCIICharStr) {
305 }
else if(
out+5+
b <= cchASCIIChar) {
306 memcpy(lpASCIICharStr+
out, prefixW,
sizeof(prefixW));
308 for(
i=label_start;
i<label_end;
i++)
309 if(norm_str[
i] < 0x80)
310 lpASCIICharStr[
out++] = norm_str[
i];
311 lpASCIICharStr[
out++] =
'-';
320 for(
h=
b;
h<label_end-label_start;) {
323 for(
i=label_start;
i<label_end;
i++) {
324 if(norm_str[
i]>=
n &&
m>norm_str[
i])
327 delta += (
m-
n)*(
h+1);
330 for(
i=label_start;
i<label_end;
i++) {
331 if(norm_str[
i] <
n) {
333 }
else if(norm_str[
i] ==
n) {
337 if(!lpASCIICharStr) {
339 }
else if(
out+1 <= cchASCIIChar) {
340 lpASCIICharStr[
out++] = disp<=
'z'-
'a' ?
341 'a'+disp :
'0'+disp-
'z'+
'a'-1;
360 if(
out-out_label > 63) {
366 if(label_end < norm_len) {
367 if(!lpASCIICharStr) {
369 }
else if(
out+1 <= cchASCIIChar) {
370 lpASCIICharStr[
out++] = norm_str[label_end] ?
'.' : 0;
377 label_start = label_end+1;
static INT adapt(INT delta, INT numpoints, BOOL firsttime)
INT WINAPI IdnToAscii(DWORD dwFlags, LPCWSTR lpUnicodeCharStr, INT cchUnicodeChar, LPWSTR lpASCIICharStr, INT cchASCIIChar)
static unsigned short get_table_entry(const unsigned short *table, WCHAR ch)
INT WINAPI IdnToNameprepUnicode(DWORD dwFlags, LPCWSTR lpUnicodeCharStr, INT cchUnicodeChar, LPWSTR lpNameprepCharStr, INT cchNameprepChar)
#define ERROR_NOT_ENOUGH_MEMORY
#define ERROR_INSUFFICIENT_BUFFER
#define ERROR_INVALID_PARAMETER
#define HeapFree(x, y, z)
#define ERROR_INVALID_NAME
INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)
GLdouble GLdouble GLdouble GLdouble q
GLboolean GLboolean GLboolean b
GLenum GLuint GLenum GLsizei const GLchar * buf
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define memcpy(s1, s2, n)
const unsigned short nameprep_char_type[4432]
const unsigned short nameprep_mapping[5856]
DWORD WINAPI GetLastError(void)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
#define ERROR_NO_UNICODE_TRANSLATION
#define ERROR_INVALID_FLAGS