2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
17 #include "wine/unicode.h"
24 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(string
);
29 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
30 * MUST contain all #defines from winnls.h
31 * last entry has NULL name, 0 id.
33 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
34 static const struct tagLOCALE_NAME2ID
{
38 LOCALE_ENTRY(ILANGUAGE
),
39 LOCALE_ENTRY(SLANGUAGE
),
40 LOCALE_ENTRY(SENGLANGUAGE
),
41 LOCALE_ENTRY(SABBREVLANGNAME
),
42 LOCALE_ENTRY(SNATIVELANGNAME
),
43 LOCALE_ENTRY(ICOUNTRY
),
44 LOCALE_ENTRY(SCOUNTRY
),
45 LOCALE_ENTRY(SENGCOUNTRY
),
46 LOCALE_ENTRY(SABBREVCTRYNAME
),
47 LOCALE_ENTRY(SNATIVECTRYNAME
),
48 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
49 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
50 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
51 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
52 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
54 LOCALE_ENTRY(IMEASURE
),
55 LOCALE_ENTRY(SDECIMAL
),
56 LOCALE_ENTRY(STHOUSAND
),
57 LOCALE_ENTRY(SGROUPING
),
58 LOCALE_ENTRY(IDIGITS
),
60 LOCALE_ENTRY(INEGNUMBER
),
61 LOCALE_ENTRY(SNATIVEDIGITS
),
62 LOCALE_ENTRY(SCURRENCY
),
63 LOCALE_ENTRY(SINTLSYMBOL
),
64 LOCALE_ENTRY(SMONDECIMALSEP
),
65 LOCALE_ENTRY(SMONTHOUSANDSEP
),
66 LOCALE_ENTRY(SMONGROUPING
),
67 LOCALE_ENTRY(ICURRDIGITS
),
68 LOCALE_ENTRY(IINTLCURRDIGITS
),
69 LOCALE_ENTRY(ICURRENCY
),
70 LOCALE_ENTRY(INEGCURR
),
73 LOCALE_ENTRY(SSHORTDATE
),
74 LOCALE_ENTRY(SLONGDATE
),
75 LOCALE_ENTRY(STIMEFORMAT
),
79 LOCALE_ENTRY(ITIMEMARKPOSN
),
80 LOCALE_ENTRY(ICENTURY
),
81 LOCALE_ENTRY(ITLZERO
),
82 LOCALE_ENTRY(IDAYLZERO
),
83 LOCALE_ENTRY(IMONLZERO
),
86 LOCALE_ENTRY(ICALENDARTYPE
),
87 LOCALE_ENTRY(IOPTIONALCALENDAR
),
88 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
89 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
90 LOCALE_ENTRY(SDAYNAME1
),
91 LOCALE_ENTRY(SDAYNAME2
),
92 LOCALE_ENTRY(SDAYNAME3
),
93 LOCALE_ENTRY(SDAYNAME4
),
94 LOCALE_ENTRY(SDAYNAME5
),
95 LOCALE_ENTRY(SDAYNAME6
),
96 LOCALE_ENTRY(SDAYNAME7
),
97 LOCALE_ENTRY(SABBREVDAYNAME1
),
98 LOCALE_ENTRY(SABBREVDAYNAME2
),
99 LOCALE_ENTRY(SABBREVDAYNAME3
),
100 LOCALE_ENTRY(SABBREVDAYNAME4
),
101 LOCALE_ENTRY(SABBREVDAYNAME5
),
102 LOCALE_ENTRY(SABBREVDAYNAME6
),
103 LOCALE_ENTRY(SABBREVDAYNAME7
),
104 LOCALE_ENTRY(SMONTHNAME1
),
105 LOCALE_ENTRY(SMONTHNAME2
),
106 LOCALE_ENTRY(SMONTHNAME3
),
107 LOCALE_ENTRY(SMONTHNAME4
),
108 LOCALE_ENTRY(SMONTHNAME5
),
109 LOCALE_ENTRY(SMONTHNAME6
),
110 LOCALE_ENTRY(SMONTHNAME7
),
111 LOCALE_ENTRY(SMONTHNAME8
),
112 LOCALE_ENTRY(SMONTHNAME9
),
113 LOCALE_ENTRY(SMONTHNAME10
),
114 LOCALE_ENTRY(SMONTHNAME11
),
115 LOCALE_ENTRY(SMONTHNAME12
),
116 LOCALE_ENTRY(SMONTHNAME13
),
117 LOCALE_ENTRY(SABBREVMONTHNAME1
),
118 LOCALE_ENTRY(SABBREVMONTHNAME2
),
119 LOCALE_ENTRY(SABBREVMONTHNAME3
),
120 LOCALE_ENTRY(SABBREVMONTHNAME4
),
121 LOCALE_ENTRY(SABBREVMONTHNAME5
),
122 LOCALE_ENTRY(SABBREVMONTHNAME6
),
123 LOCALE_ENTRY(SABBREVMONTHNAME7
),
124 LOCALE_ENTRY(SABBREVMONTHNAME8
),
125 LOCALE_ENTRY(SABBREVMONTHNAME9
),
126 LOCALE_ENTRY(SABBREVMONTHNAME10
),
127 LOCALE_ENTRY(SABBREVMONTHNAME11
),
128 LOCALE_ENTRY(SABBREVMONTHNAME12
),
129 LOCALE_ENTRY(SABBREVMONTHNAME13
),
130 LOCALE_ENTRY(SPOSITIVESIGN
),
131 LOCALE_ENTRY(SNEGATIVESIGN
),
132 LOCALE_ENTRY(IPOSSIGNPOSN
),
133 LOCALE_ENTRY(INEGSIGNPOSN
),
134 LOCALE_ENTRY(IPOSSYMPRECEDES
),
135 LOCALE_ENTRY(IPOSSEPBYSPACE
),
136 LOCALE_ENTRY(INEGSYMPRECEDES
),
137 LOCALE_ENTRY(INEGSEPBYSPACE
),
138 LOCALE_ENTRY(FONTSIGNATURE
),
139 LOCALE_ENTRY(SISO639LANGNAME
),
140 LOCALE_ENTRY(SISO3166CTRYNAME
),
144 static char *GetLocaleSubkeyName( DWORD lctype
);
146 /***********************************************************************
147 * GetUserDefaultLCID [KERNEL32.425]
149 LCID WINAPI
GetUserDefaultLCID(void)
151 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
154 /***********************************************************************
155 * GetSystemDefaultLCID [KERNEL32.400]
157 LCID WINAPI
GetSystemDefaultLCID(void)
159 return GetUserDefaultLCID();
162 /***********************************************************************
163 * GetUserDefaultLangID [KERNEL32.426]
165 LANGID WINAPI
GetUserDefaultLangID(void)
167 /* caching result, if defined from environment, which should (?) not change during a WINE session */
168 static LANGID userLCID
= 0;
173 char *lang
,*country
,*charset
,*dialect
,*next
;
175 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
176 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
177 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
178 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
179 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
181 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
184 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
185 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
190 next
=strchr(lang
,':'); if (next
) *next
++='\0';
191 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
192 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
193 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
195 userLCID
= MAIN_GetLanguageID(lang
, country
, charset
, dialect
);
198 } while (lang
&& !userLCID
);
202 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
204 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
210 /***********************************************************************
211 * GetSystemDefaultLangID [KERNEL32.401]
213 LANGID WINAPI
GetSystemDefaultLangID(void)
215 return GetUserDefaultLangID();
218 /******************************************************************************
219 * ConvertDefaultLocale [KERNEL32.147]
221 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
223 { case LOCALE_SYSTEM_DEFAULT
:
224 return GetSystemDefaultLCID();
225 case LOCALE_USER_DEFAULT
:
226 return GetUserDefaultLCID();
228 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
230 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
233 /* Enhanced version of LoadStringW.
234 * It takes LanguageId to find and load language dependant resources.
235 * Resource is copied as is: "binary" strings are not truncated.
236 * Return: length of resource + 1 to distinguish absent resources
237 * from the resources with zero length.
239 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
247 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
250 hmem
= LoadResource(hModule
, hrsrc
);
253 p
= LockResource(hmem
);
254 string_num
= res_id
& 0x000f;
255 for(i
= 0; i
< string_num
; i
++)
258 TRACE("strlen = %d\n", (int)*p
);
260 if (buffer
== NULL
) return *p
;
261 i
= min(buflen
- 1, *p
);
263 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
264 buffer
[i
] = (WCHAR
) 0;
267 buffer
[0] = (WCHAR
) 0;
271 TRACE("\"%s\" loaded!\n", debugstr_w(buffer
));
275 /******************************************************************************
276 * GetLocaleInfoA [KERNEL32.342]
279 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
281 * MS online documentation states that the string returned is NULL terminated
282 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
283 * terminated string".
285 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
287 LPCSTR retString
= NULL
;
291 DWORD dwBufferSize
=128;
293 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
295 if (len
&& (! buf
) ) {
296 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
300 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
|| (LCType
& LOCALE_NOUSEROVERRIDE
) )
302 lcid
= GetSystemDefaultLCID();
304 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
306 lcid
= GetUserDefaultLCID();
308 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
310 /* First, check if it's in the registry. */
311 /* All user customized values are stored in the registry by SetLocaleInfo */
313 if ( (pacKey
= GetLocaleSubkeyName(LCType
)) )
318 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
320 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
321 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
323 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
324 &dwBufferSize
) == ERROR_SUCCESS
)
326 retString
= acBuffer
;
333 /* If not in the registry, get it from the NLS entries. */
338 /* check if language is registered in the kernel32 resources */
339 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LOWORD(lcid
),
340 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
341 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
342 retString
= acBuffer
;
347 /* if not found report a most descriptive error */
350 /* If we are through all of this, retLen should not be zero anymore.
351 If it is, the value is not supported */
353 while (locale_name2id
[i
].name
!=NULL
) {
354 if (LCType
== locale_name2id
[i
].id
) {
355 retString
= locale_name2id
[i
].name
;
361 FIXME("Unkown LC type %lX\n", LCType
);
363 ERR("'%s' not supported for your language (%04X)\n",
364 retString
, LOWORD(lcid
));
365 SetLastError(ERROR_INVALID_PARAMETER
);
369 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
370 if (LCType
== LOCALE_FONTSIGNATURE
) {
372 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
373 memcpy(buf
, retString
, len
);
376 return sizeof(FONTSIGNATURE
);
378 /* if len=0 return only the length, don't touch the buffer*/
380 lstrcpynA(buf
,retString
,len
);
381 return strlen(buf
) + 1;
383 return strlen(retString
)+1;
386 /******************************************************************************
387 * GetLocaleInfoW [KERNEL32.343]
390 * MS documentation states that len "specifies the size, in bytes (ANSI version)
391 * or characters (Unicode version), of" wbuf. Thus the number returned is
392 * the same between GetLocaleInfoW and GetLocaleInfoA.
394 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
398 if (len
&& (! wbuf
) )
399 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
403 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
404 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
406 if (wlen
&& len
) /* if len=0 return only the length*/
407 lstrcpynAtoW(wbuf
,abuf
,len
);
409 HeapFree(GetProcessHeap(),0,abuf
);
413 /******************************************************************************
415 * GetLocaleSubkeyName [helper function]
417 * - For use with the registry.
418 * - Gets the registry subkey name for a given lctype.
420 static char *GetLocaleSubkeyName( DWORD lctype
)
426 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
427 * the values are stored in the registry, confirmed under Windows,
428 * for the ones that actually assign pacKey. Cases that aren't finished
429 * have not been confirmed, so that must be done before they can be
432 case LOCALE_SDATE
: /* The date separator. */
435 case LOCALE_ICURRDIGITS
:
436 pacKey
= "iCurrDigits";
438 case LOCALE_SDECIMAL
:
441 case LOCALE_ICURRENCY
:
442 pacKey
= "iCurrency";
444 case LOCALE_SGROUPING
:
445 pacKey
= "sGrouping";
453 /* case LOCALE_ICALENDARTYPE: */
454 /* case LOCALE_IFIRSTDAYOFWEEK: */
455 /* case LOCALE_IFIRSTWEEKOFYEAR: */
456 /* case LOCALE_SYEARMONTH : */
457 /* case LOCALE_SPOSITIVESIGN : */
458 /* case LOCALE_IPAPERSIZE: */
460 case LOCALE_SLONGDATE
:
461 pacKey
= "sLongDate";
463 case LOCALE_SMONDECIMALSEP
:
464 pacKey
= "sMonDecimalSep";
466 case LOCALE_SMONGROUPING
:
467 pacKey
= "sMonGrouping";
469 case LOCALE_IMEASURE
:
472 case LOCALE_SMONTHOUSANDSEP
:
473 pacKey
= "sMonThousandSep";
475 case LOCALE_INEGCURR
:
478 case LOCALE_SNEGATIVESIGN
:
479 pacKey
= "sNegativeSign";
481 case LOCALE_INEGNUMBER
:
482 pacKey
= "iNegNumber";
484 case LOCALE_SSHORTDATE
:
485 pacKey
= "sShortDate";
487 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
496 case LOCALE_ITIME
: /* Time format specifier. */
499 case LOCALE_STHOUSAND
:
500 pacKey
= "sThousand";
502 case LOCALE_S1159
: /* AM */
508 case LOCALE_S2359
: /* PM */
511 case LOCALE_STIMEFORMAT
:
512 pacKey
= "sTimeFormat";
514 case LOCALE_SCURRENCY
:
515 pacKey
= "sCurrency";
518 /* The following are not listed under MSDN as supported,
519 * but seem to be used and also stored in the registry.
525 case LOCALE_SCOUNTRY
:
528 case LOCALE_ICOUNTRY
:
531 case LOCALE_SLANGUAGE
:
532 pacKey
= "sLanguage";
542 /******************************************************************************
543 * SetLocaleInfoA [KERNEL32.656]
545 BOOL16 WINAPI
SetLocaleInfoA(DWORD lcid
, DWORD lctype
, LPCSTR data
)
551 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
553 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
554 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
555 &hKey
) == ERROR_SUCCESS
)
557 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
558 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
560 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
567 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
572 /******************************************************************************
573 * IsValidLocale [KERNEL32.489]
575 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
577 /* check if language is registered in the kernel32 resources */
578 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
584 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
585 LPCWSTR name
, WORD LangID
, LONG lParam
)
589 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
590 sprintf(bufA
, "%08X", (UINT
)LangID
);
591 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
592 return lpfnLocaleEnum(bufW
);
595 /******************************************************************************
596 * EnumSystemLocalesW [KERNEL32.209]
598 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
601 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
603 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
604 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
605 (LONG
)lpfnLocaleEnum
);
610 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
611 LPCSTR name
, WORD LangID
, LONG lParam
)
614 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
615 sprintf(bufA
, "%08X", (UINT
)LangID
);
616 return lpfnLocaleEnum(bufA
);
619 /******************************************************************************
620 * EnumSystemLocalesA [KERNEL32.208]
622 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
625 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
627 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
628 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
629 (LONG
)lpfnLocaleEnum
);
634 static const unsigned char CT_CType2_LUT
[] = {
635 C2_NOTAPPLICABLE
, /* - 0 */
636 C2_NOTAPPLICABLE
, /* - 1 */
637 C2_NOTAPPLICABLE
, /* - 2 */
638 C2_NOTAPPLICABLE
, /* - 3 */
639 C2_NOTAPPLICABLE
, /* - 4 */
640 C2_NOTAPPLICABLE
, /* - 5 */
641 C2_NOTAPPLICABLE
, /* - 6 */
642 C2_NOTAPPLICABLE
, /* - 7 */
643 C2_NOTAPPLICABLE
, /* - 8 */
644 C2_SEGMENTSEPARATOR
, /* - 9 */
645 C2_NOTAPPLICABLE
, /* - 10 */
646 C2_NOTAPPLICABLE
, /* - 11 */
647 C2_NOTAPPLICABLE
, /* - 12 */
648 C2_NOTAPPLICABLE
, /* - 13 */
649 C2_NOTAPPLICABLE
, /* - 14 */
650 C2_NOTAPPLICABLE
, /* - 15 */
651 C2_NOTAPPLICABLE
, /* - 16 */
652 C2_NOTAPPLICABLE
, /* - 17 */
653 C2_NOTAPPLICABLE
, /* - 18 */
654 C2_NOTAPPLICABLE
, /* - 19 */
655 C2_NOTAPPLICABLE
, /* - 20 */
656 C2_NOTAPPLICABLE
, /* - 21 */
657 C2_NOTAPPLICABLE
, /* - 22 */
658 C2_NOTAPPLICABLE
, /* - 23 */
659 C2_NOTAPPLICABLE
, /* - 24 */
660 C2_NOTAPPLICABLE
, /* - 25 */
661 C2_NOTAPPLICABLE
, /* - 26 */
662 C2_NOTAPPLICABLE
, /* - 27 */
663 C2_NOTAPPLICABLE
, /* - 28 */
664 C2_NOTAPPLICABLE
, /* - 29 */
665 C2_NOTAPPLICABLE
, /* - 30 */
666 C2_NOTAPPLICABLE
, /* - 31 */
667 C2_WHITESPACE
, /* - 32 */
668 C2_OTHERNEUTRAL
, /* ! - 33 */
669 C2_OTHERNEUTRAL
, /* " - 34 */ /* " */
670 C2_EUROPETERMINATOR
, /* # - 35 */
671 C2_EUROPETERMINATOR
, /* $ - 36 */
672 C2_EUROPETERMINATOR
, /* % - 37 */
673 C2_LEFTTORIGHT
, /* & - 38 */
674 C2_OTHERNEUTRAL
, /* ' - 39 */
675 C2_OTHERNEUTRAL
, /* ( - 40 */
676 C2_OTHERNEUTRAL
, /* ) - 41 */
677 C2_OTHERNEUTRAL
, /* * - 42 */
678 C2_EUROPETERMINATOR
, /* + - 43 */
679 C2_COMMONSEPARATOR
, /* , - 44 */
680 C2_EUROPETERMINATOR
, /* - - 45 */
681 C2_EUROPESEPARATOR
, /* . - 46 */
682 C2_EUROPESEPARATOR
, /* / - 47 */
683 C2_EUROPENUMBER
, /* 0 - 48 */
684 C2_EUROPENUMBER
, /* 1 - 49 */
685 C2_EUROPENUMBER
, /* 2 - 50 */
686 C2_EUROPENUMBER
, /* 3 - 51 */
687 C2_EUROPENUMBER
, /* 4 - 52 */
688 C2_EUROPENUMBER
, /* 5 - 53 */
689 C2_EUROPENUMBER
, /* 6 - 54 */
690 C2_EUROPENUMBER
, /* 7 - 55 */
691 C2_EUROPENUMBER
, /* 8 - 56 */
692 C2_EUROPENUMBER
, /* 9 - 57 */
693 C2_COMMONSEPARATOR
, /* : - 58 */
694 C2_OTHERNEUTRAL
, /* ; - 59 */
695 C2_OTHERNEUTRAL
, /* < - 60 */
696 C2_OTHERNEUTRAL
, /* = - 61 */
697 C2_OTHERNEUTRAL
, /* > - 62 */
698 C2_OTHERNEUTRAL
, /* ? - 63 */
699 C2_LEFTTORIGHT
, /* @ - 64 */
700 C2_LEFTTORIGHT
, /* A - 65 */
701 C2_LEFTTORIGHT
, /* B - 66 */
702 C2_LEFTTORIGHT
, /* C - 67 */
703 C2_LEFTTORIGHT
, /* D - 68 */
704 C2_LEFTTORIGHT
, /* E - 69 */
705 C2_LEFTTORIGHT
, /* F - 70 */
706 C2_LEFTTORIGHT
, /* G - 71 */
707 C2_LEFTTORIGHT
, /* H - 72 */
708 C2_LEFTTORIGHT
, /* I - 73 */
709 C2_LEFTTORIGHT
, /* J - 74 */
710 C2_LEFTTORIGHT
, /* K - 75 */
711 C2_LEFTTORIGHT
, /* L - 76 */
712 C2_LEFTTORIGHT
, /* M - 77 */
713 C2_LEFTTORIGHT
, /* N - 78 */
714 C2_LEFTTORIGHT
, /* O - 79 */
715 C2_LEFTTORIGHT
, /* P - 80 */
716 C2_LEFTTORIGHT
, /* Q - 81 */
717 C2_LEFTTORIGHT
, /* R - 82 */
718 C2_LEFTTORIGHT
, /* S - 83 */
719 C2_LEFTTORIGHT
, /* T - 84 */
720 C2_LEFTTORIGHT
, /* U - 85 */
721 C2_LEFTTORIGHT
, /* V - 86 */
722 C2_LEFTTORIGHT
, /* W - 87 */
723 C2_LEFTTORIGHT
, /* X - 88 */
724 C2_LEFTTORIGHT
, /* Y - 89 */
725 C2_LEFTTORIGHT
, /* Z - 90 */
726 C2_OTHERNEUTRAL
, /* [ - 91 */
727 C2_OTHERNEUTRAL
, /* \ - 92 */
728 C2_OTHERNEUTRAL
, /* ] - 93 */
729 C2_OTHERNEUTRAL
, /* ^ - 94 */
730 C2_OTHERNEUTRAL
, /* _ - 95 */
731 C2_OTHERNEUTRAL
, /* ` - 96 */
732 C2_LEFTTORIGHT
, /* a - 97 */
733 C2_LEFTTORIGHT
, /* b - 98 */
734 C2_LEFTTORIGHT
, /* c - 99 */
735 C2_LEFTTORIGHT
, /* d - 100 */
736 C2_LEFTTORIGHT
, /* e - 101 */
737 C2_LEFTTORIGHT
, /* f - 102 */
738 C2_LEFTTORIGHT
, /* g - 103 */
739 C2_LEFTTORIGHT
, /* h - 104 */
740 C2_LEFTTORIGHT
, /* i - 105 */
741 C2_LEFTTORIGHT
, /* j - 106 */
742 C2_LEFTTORIGHT
, /* k - 107 */
743 C2_LEFTTORIGHT
, /* l - 108 */
744 C2_LEFTTORIGHT
, /* m - 109 */
745 C2_LEFTTORIGHT
, /* n - 110 */
746 C2_LEFTTORIGHT
, /* o - 111 */
747 C2_LEFTTORIGHT
, /* p - 112 */
748 C2_LEFTTORIGHT
, /* q - 113 */
749 C2_LEFTTORIGHT
, /* r - 114 */
750 C2_LEFTTORIGHT
, /* s - 115 */
751 C2_LEFTTORIGHT
, /* t - 116 */
752 C2_LEFTTORIGHT
, /* u - 117 */
753 C2_LEFTTORIGHT
, /* v - 118 */
754 C2_LEFTTORIGHT
, /* w - 119 */
755 C2_LEFTTORIGHT
, /* x - 120 */
756 C2_LEFTTORIGHT
, /* y - 121 */
757 C2_LEFTTORIGHT
, /* z - 122 */
758 C2_OTHERNEUTRAL
, /* { - 123 */
759 C2_OTHERNEUTRAL
, /* | - 124 */
760 C2_OTHERNEUTRAL
, /* } - 125 */
761 C2_OTHERNEUTRAL
, /* ~ - 126 */
762 C2_NOTAPPLICABLE
, /* \x7f - 127 */
763 C2_NOTAPPLICABLE
, /* € - 128 */
764 C2_NOTAPPLICABLE
, /* � - 129 */
765 C2_OTHERNEUTRAL
, /* ‚ - 130 */
766 C2_LEFTTORIGHT
, /* ƒ - 131 */
767 C2_OTHERNEUTRAL
, /* „ - 132 */
768 C2_OTHERNEUTRAL
, /* … - 133 */
769 C2_OTHERNEUTRAL
, /* † - 134 */
770 C2_OTHERNEUTRAL
, /* ‡ - 135 */
771 C2_LEFTTORIGHT
, /* ˆ - 136 */
772 C2_EUROPETERMINATOR
, /* ‰ - 137 */
773 C2_LEFTTORIGHT
, /* Š - 138 */
774 C2_OTHERNEUTRAL
, /* ‹ - 139 */
775 C2_LEFTTORIGHT
, /* Œ - 140 */
776 C2_NOTAPPLICABLE
, /* � - 141 */
777 C2_NOTAPPLICABLE
, /* Ž - 142 */
778 C2_NOTAPPLICABLE
, /* � - 143 */
779 C2_NOTAPPLICABLE
, /* � - 144 */
780 C2_OTHERNEUTRAL
, /* ‘ - 145 */
781 C2_OTHERNEUTRAL
, /* ’ - 146 */
782 C2_OTHERNEUTRAL
, /* “ - 147 */
783 C2_OTHERNEUTRAL
, /* ” - 148 */
784 C2_OTHERNEUTRAL
, /* • - 149 */
785 C2_OTHERNEUTRAL
, /* – - 150 */
786 C2_OTHERNEUTRAL
, /* — - 151 */
787 C2_LEFTTORIGHT
, /* ˜ - 152 */
788 C2_OTHERNEUTRAL
, /* ™ - 153 */
789 C2_LEFTTORIGHT
, /* š - 154 */
790 C2_OTHERNEUTRAL
, /* › - 155 */
791 C2_LEFTTORIGHT
, /* œ - 156 */
792 C2_NOTAPPLICABLE
, /* � - 157 */
793 C2_NOTAPPLICABLE
, /* ž - 158 */
794 C2_LEFTTORIGHT
, /* Ÿ - 159 */
795 C2_WHITESPACE
, /* - 160 */
796 C2_OTHERNEUTRAL
, /* ¡ - 161 */
797 C2_EUROPETERMINATOR
, /* ¢ - 162 */
798 C2_EUROPETERMINATOR
, /* £ - 163 */
799 C2_EUROPETERMINATOR
, /* ¤ - 164 */
800 C2_EUROPETERMINATOR
, /* ¥ - 165 */
801 C2_OTHERNEUTRAL
, /* ¦ - 166 */
802 C2_OTHERNEUTRAL
, /* § - 167 */
803 C2_OTHERNEUTRAL
, /* ¨ - 168 */
804 C2_OTHERNEUTRAL
, /* © - 169 */
805 C2_OTHERNEUTRAL
, /* ª - 170 */
806 C2_OTHERNEUTRAL
, /* « - 171 */
807 C2_OTHERNEUTRAL
, /* ¬ - 172 */
808 C2_OTHERNEUTRAL
, /* - 173 */
809 C2_OTHERNEUTRAL
, /* ® - 174 */
810 C2_OTHERNEUTRAL
, /* ¯ - 175 */
811 C2_EUROPETERMINATOR
, /* ° - 176 */
812 C2_EUROPETERMINATOR
, /* ± - 177 */
813 C2_EUROPENUMBER
, /* ² - 178 */
814 C2_EUROPENUMBER
, /* ³ - 179 */
815 C2_OTHERNEUTRAL
, /* ´ - 180 */
816 C2_OTHERNEUTRAL
, /* µ - 181 */
817 C2_OTHERNEUTRAL
, /* ¶ - 182 */
818 C2_OTHERNEUTRAL
, /* · - 183 */
819 C2_OTHERNEUTRAL
, /* ¸ - 184 */
820 C2_EUROPENUMBER
, /* ¹ - 185 */
821 C2_OTHERNEUTRAL
, /* º - 186 */
822 C2_OTHERNEUTRAL
, /* » - 187 */
823 C2_OTHERNEUTRAL
, /* ¼ - 188 */
824 C2_OTHERNEUTRAL
, /* ½ - 189 */
825 C2_OTHERNEUTRAL
, /* ¾ - 190 */
826 C2_OTHERNEUTRAL
, /* ¿ - 191 */
827 C2_LEFTTORIGHT
, /* À - 192 */
828 C2_LEFTTORIGHT
, /* Á - 193 */
829 C2_LEFTTORIGHT
, /* Â - 194 */
830 C2_LEFTTORIGHT
, /* Ã - 195 */
831 C2_LEFTTORIGHT
, /* Ä - 196 */
832 C2_LEFTTORIGHT
, /* Å - 197 */
833 C2_LEFTTORIGHT
, /* Æ - 198 */
834 C2_LEFTTORIGHT
, /* Ç - 199 */
835 C2_LEFTTORIGHT
, /* È - 200 */
836 C2_LEFTTORIGHT
, /* É - 201 */
837 C2_LEFTTORIGHT
, /* Ê - 202 */
838 C2_LEFTTORIGHT
, /* Ë - 203 */
839 C2_LEFTTORIGHT
, /* Ì - 204 */
840 C2_LEFTTORIGHT
, /* Í - 205 */
841 C2_LEFTTORIGHT
, /* Î - 206 */
842 C2_LEFTTORIGHT
, /* Ï - 207 */
843 C2_LEFTTORIGHT
, /* Ð - 208 */
844 C2_LEFTTORIGHT
, /* Ñ - 209 */
845 C2_LEFTTORIGHT
, /* Ò - 210 */
846 C2_LEFTTORIGHT
, /* Ó - 211 */
847 C2_LEFTTORIGHT
, /* Ô - 212 */
848 C2_LEFTTORIGHT
, /* Õ - 213 */
849 C2_LEFTTORIGHT
, /* Ö - 214 */
850 C2_OTHERNEUTRAL
, /* × - 215 */
851 C2_LEFTTORIGHT
, /* Ø - 216 */
852 C2_LEFTTORIGHT
, /* Ù - 217 */
853 C2_LEFTTORIGHT
, /* Ú - 218 */
854 C2_LEFTTORIGHT
, /* Û - 219 */
855 C2_LEFTTORIGHT
, /* Ü - 220 */
856 C2_LEFTTORIGHT
, /* Ý - 221 */
857 C2_LEFTTORIGHT
, /* Þ - 222 */
858 C2_LEFTTORIGHT
, /* ß - 223 */
859 C2_LEFTTORIGHT
, /* à - 224 */
860 C2_LEFTTORIGHT
, /* á - 225 */
861 C2_LEFTTORIGHT
, /* â - 226 */
862 C2_LEFTTORIGHT
, /* ã - 227 */
863 C2_LEFTTORIGHT
, /* ä - 228 */
864 C2_LEFTTORIGHT
, /* å - 229 */
865 C2_LEFTTORIGHT
, /* æ - 230 */
866 C2_LEFTTORIGHT
, /* ç - 231 */
867 C2_LEFTTORIGHT
, /* è - 232 */
868 C2_LEFTTORIGHT
, /* é - 233 */
869 C2_LEFTTORIGHT
, /* ê - 234 */
870 C2_LEFTTORIGHT
, /* ë - 235 */
871 C2_LEFTTORIGHT
, /* ì - 236 */
872 C2_LEFTTORIGHT
, /* í - 237 */
873 C2_LEFTTORIGHT
, /* î - 238 */
874 C2_LEFTTORIGHT
, /* ï - 239 */
875 C2_LEFTTORIGHT
, /* ð - 240 */
876 C2_LEFTTORIGHT
, /* ñ - 241 */
877 C2_LEFTTORIGHT
, /* ò - 242 */
878 C2_LEFTTORIGHT
, /* ó - 243 */
879 C2_LEFTTORIGHT
, /* ô - 244 */
880 C2_LEFTTORIGHT
, /* õ - 245 */
881 C2_LEFTTORIGHT
, /* ö - 246 */
882 C2_OTHERNEUTRAL
, /* ÷ - 247 */
883 C2_LEFTTORIGHT
, /* ø - 248 */
884 C2_LEFTTORIGHT
, /* ù - 249 */
885 C2_LEFTTORIGHT
, /* ú - 250 */
886 C2_LEFTTORIGHT
, /* û - 251 */
887 C2_LEFTTORIGHT
, /* ü - 252 */
888 C2_LEFTTORIGHT
, /* ý - 253 */
889 C2_LEFTTORIGHT
, /* þ - 254 */
890 C2_LEFTTORIGHT
/* ÿ - 255 */
893 const WORD OLE2NLS_CT_CType3_LUT
[] = {
928 0x0448, /* " - 34 */ /* " */
994 0x8040, /* d - 100 */
995 0x8040, /* e - 101 */
996 0x8040, /* f - 102 */
997 0x8040, /* g - 103 */
998 0x8040, /* h - 104 */
999 0x8040, /* i - 105 */
1000 0x8040, /* j - 106 */
1001 0x8040, /* k - 107 */
1002 0x8040, /* l - 108 */
1003 0x8040, /* m - 109 */
1004 0x8040, /* n - 110 */
1005 0x8040, /* o - 111 */
1006 0x8040, /* p - 112 */
1007 0x8040, /* q - 113 */
1008 0x8040, /* r - 114 */
1009 0x8040, /* s - 115 */
1010 0x8040, /* t - 116 */
1011 0x8040, /* u - 117 */
1012 0x8040, /* v - 118 */
1013 0x8040, /* w - 119 */
1014 0x8040, /* x - 120 */
1015 0x8040, /* y - 121 */
1016 0x8040, /* z - 122 */
1017 0x0048, /* { - 123 */
1018 0x0048, /* | - 124 */
1019 0x0048, /* } - 125 */
1020 0x0448, /* ~ - 126 */
1021 0x0000, /* \x7f - 127 */
1022 0x0000, /* € - 128 */
1023 0x0000, /* � - 129 */
1024 0x0008, /* ‚ - 130 */
1025 0x8000, /* ƒ - 131 */
1026 0x0008, /* „ - 132 */
1027 0x0008, /* … - 133 */
1028 0x0008, /* † - 134 */
1029 0x0008, /* ‡ - 135 */
1030 0x0001, /* ˆ - 136 */
1031 0x0008, /* ‰ - 137 */
1032 0x8003, /* Š - 138 */
1033 0x0008, /* ‹ - 139 */
1034 0x8000, /* Œ - 140 */
1035 0x0000, /* � - 141 */
1036 0x0000, /* Ž - 142 */
1037 0x0000, /* � - 143 */
1038 0x0000, /* � - 144 */
1039 0x0088, /* ‘ - 145 */
1040 0x0088, /* ’ - 146 */
1041 0x0088, /* “ - 147 */
1042 0x0088, /* ” - 148 */
1043 0x0008, /* • - 149 */
1044 0x0400, /* – - 150 */
1045 0x0400, /* — - 151 */
1046 0x0408, /* ˜ - 152 */
1047 0x0000, /* ™ - 153 */
1048 0x8003, /* š - 154 */
1049 0x0008, /* › - 155 */
1050 0x8000, /* œ - 156 */
1051 0x0000, /* � - 157 */
1052 0x0000, /* ž - 158 */
1053 0x8003, /* Ÿ - 159 */
1055 0x0008, /* ¡ - 161 */
1056 0x0048, /* ¢ - 162 */
1057 0x0048, /* £ - 163 */
1058 0x0008, /* ¤ - 164 */
1059 0x0048, /* ¥ - 165 */
1060 0x0048, /* ¦ - 166 */
1061 0x0008, /* § - 167 */
1062 0x0408, /* ¨ - 168 */
1063 0x0008, /* © - 169 */
1064 0x0400, /* ª - 170 */
1065 0x0008, /* « - 171 */
1066 0x0048, /* ¬ - 172 */
1067 0x0408, /* - 173 */
1068 0x0008, /* ® - 174 */
1069 0x0448, /* ¯ - 175 */
1070 0x0008, /* ° - 176 */
1071 0x0008, /* ± - 177 */
1072 0x0000, /* ² - 178 */
1073 0x0000, /* ³ - 179 */
1074 0x0408, /* ´ - 180 */
1075 0x0008, /* µ - 181 */
1076 0x0008, /* ¶ - 182 */
1077 0x0008, /* · - 183 */
1078 0x0408, /* ¸ - 184 */
1079 0x0000, /* ¹ - 185 */
1080 0x0400, /* º - 186 */
1081 0x0008, /* » - 187 */
1082 0x0000, /* ¼ - 188 */
1083 0x0000, /* ½ - 189 */
1084 0x0000, /* ¾ - 190 */
1085 0x0008, /* ¿ - 191 */
1086 0x8003, /* À - 192 */
1087 0x8003, /* Á - 193 */
1088 0x8003, /* Â - 194 */
1089 0x8003, /* Ã - 195 */
1090 0x8003, /* Ä - 196 */
1091 0x8003, /* Å - 197 */
1092 0x8000, /* Æ - 198 */
1093 0x8003, /* Ç - 199 */
1094 0x8003, /* È - 200 */
1095 0x8003, /* É - 201 */
1096 0x8003, /* Ê - 202 */
1097 0x8003, /* Ë - 203 */
1098 0x8003, /* Ì - 204 */
1099 0x8003, /* Í - 205 */
1100 0x8003, /* Î - 206 */
1101 0x8003, /* Ï - 207 */
1102 0x8000, /* Ð - 208 */
1103 0x8003, /* Ñ - 209 */
1104 0x8003, /* Ò - 210 */
1105 0x8003, /* Ó - 211 */
1106 0x8003, /* Ô - 212 */
1107 0x8003, /* Õ - 213 */
1108 0x8003, /* Ö - 214 */
1109 0x0008, /* × - 215 */
1110 0x8003, /* Ø - 216 */
1111 0x8003, /* Ù - 217 */
1112 0x8003, /* Ú - 218 */
1113 0x8003, /* Û - 219 */
1114 0x8003, /* Ü - 220 */
1115 0x8003, /* Ý - 221 */
1116 0x8000, /* Þ - 222 */
1117 0x8000, /* ß - 223 */
1118 0x8003, /* à - 224 */
1119 0x8003, /* á - 225 */
1120 0x8003, /* â - 226 */
1121 0x8003, /* ã - 227 */
1122 0x8003, /* ä - 228 */
1123 0x8003, /* å - 229 */
1124 0x8000, /* æ - 230 */
1125 0x8003, /* ç - 231 */
1126 0x8003, /* è - 232 */
1127 0x8003, /* é - 233 */
1128 0x8003, /* ê - 234 */
1129 0x8003, /* ë - 235 */
1130 0x8003, /* ì - 236 */
1131 0x8003, /* í - 237 */
1132 0x8003, /* î - 238 */
1133 0x8003, /* ï - 239 */
1134 0x8000, /* ð - 240 */
1135 0x8003, /* ñ - 241 */
1136 0x8003, /* ò - 242 */
1137 0x8003, /* ó - 243 */
1138 0x8003, /* ô - 244 */
1139 0x8003, /* õ - 245 */
1140 0x8003, /* ö - 246 */
1141 0x0008, /* ÷ - 247 */
1142 0x8003, /* ø - 248 */
1143 0x8003, /* ù - 249 */
1144 0x8003, /* ú - 250 */
1145 0x8003, /* û - 251 */
1146 0x8003, /* ü - 252 */
1147 0x8003, /* ý - 253 */
1148 0x8000, /* þ - 254 */
1149 0x8003 /* ÿ - 255 */
1152 /******************************************************************************
1153 * GetStringTypeA [KERNEL32.396]
1155 BOOL WINAPI
GetStringTypeA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1156 INT cchSrc
,LPWORD chartype
)
1158 return GetStringTypeExA(locale
,dwInfoType
,src
,cchSrc
,chartype
);
1161 /******************************************************************************
1162 * GetStringTypeExA [KERNEL32.397]
1164 * FIXME: Ignores the locale.
1166 BOOL WINAPI
GetStringTypeExA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1167 INT cchSrc
,LPWORD chartype
)
1171 if ((src
==NULL
) || (chartype
==NULL
) || (src
==(LPSTR
)chartype
))
1173 SetLastError(ERROR_INVALID_PARAMETER
);
1178 cchSrc
=lstrlenA(src
)+1;
1180 switch (dwInfoType
) {
1182 for (i
=0;i
<cchSrc
;i
++)
1185 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1186 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1187 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1188 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1189 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1190 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1191 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1192 /* FIXME: isblank() is a GNU extension */
1193 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1194 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1200 for (i
=0;i
<cchSrc
;i
++)
1202 chartype
[i
]=(WORD
)CT_CType2_LUT
[i
];
1207 for (i
=0;i
<cchSrc
;i
++)
1209 chartype
[i
]=OLE2NLS_CT_CType3_LUT
[i
];
1214 ERR("Unknown dwInfoType:%ld\n",dwInfoType
);
1219 /******************************************************************************
1220 * GetStringTypeW [KERNEL32.399]
1223 * Yes, this is missing LCID locale. MS fault.
1225 BOOL WINAPI
GetStringTypeW(DWORD dwInfoType
,LPCWSTR src
,INT cchSrc
,
1228 return GetStringTypeExW(0/*defaultlocale*/,dwInfoType
,src
,cchSrc
,chartype
);
1231 /******************************************************************************
1232 * GetStringTypeExW [KERNEL32.398]
1234 * FIXME: unicode chars are assumed chars
1236 BOOL WINAPI
GetStringTypeExW(LCID locale
,DWORD dwInfoType
,LPCWSTR src
,
1237 INT cchSrc
,LPWORD chartype
)
1243 cchSrc
=lstrlenW(src
)+1;
1245 switch (dwInfoType
) {
1247 FIXME("CT_CTYPE2 not supported.\n");
1250 FIXME("CT_CTYPE3 not supported.\n");
1254 for (i
=0;i
<cchSrc
;i
++) {
1256 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1257 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1258 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1259 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1260 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1261 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1262 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1263 /* FIXME: isblank() is a GNU extension */
1264 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1265 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1271 /***********************************************************************
1272 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1274 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
1279 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
)
, LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1282 /***********************************************************************
1283 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1285 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
1290 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
)
, LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1294 static const unsigned char LCM_Unicode_LUT
[] = {
1327 7 , 28, /* ! - 33 */
1328 7 , 29, /* " - 34 */ /* " */
1329 7 , 31, /* # - 35 */
1330 7 , 33, /* $ - 36 */
1331 7 , 35, /* % - 37 */
1332 7 , 37, /* & - 38 */
1333 6 , 128, /* ' - 39 */
1334 7 , 39, /* ( - 40 */
1335 7 , 42, /* ) - 41 */
1336 7 , 45, /* * - 42 */
1338 7 , 47, /* , - 44 */
1339 6 , 130, /* - - 45 */
1340 7 , 51, /* . - 46 */
1341 7 , 53, /* / - 47 */
1342 12 , 3, /* 0 - 48 */
1343 12 , 33, /* 1 - 49 */
1344 12 , 51, /* 2 - 50 */
1345 12 , 70, /* 3 - 51 */
1346 12 , 88, /* 4 - 52 */
1347 12 , 106, /* 5 - 53 */
1348 12 , 125, /* 6 - 54 */
1349 12 , 144, /* 7 - 55 */
1350 12 , 162, /* 8 - 56 */
1351 12 , 180, /* 9 - 57 */
1352 7 , 55, /* : - 58 */
1353 7 , 58, /* ; - 59 */
1354 8 , 14, /* < - 60 */
1355 8 , 18, /* = - 61 */
1356 8 , 20, /* > - 62 */
1357 7 , 60, /* ? - 63 */
1358 7 , 62, /* @ - 64 */
1359 14 , 2, /* A - 65 */
1360 14 , 9, /* B - 66 */
1361 14 , 10, /* C - 67 */
1362 14 , 26, /* D - 68 */
1363 14 , 33, /* E - 69 */
1364 14 , 35, /* F - 70 */
1365 14 , 37, /* G - 71 */
1366 14 , 44, /* H - 72 */
1367 14 , 50, /* I - 73 */
1368 14 , 53, /* J - 74 */
1369 14 , 54, /* K - 75 */
1370 14 , 72, /* L - 76 */
1371 14 , 81, /* M - 77 */
1372 14 , 112, /* N - 78 */
1373 14 , 124, /* O - 79 */
1374 14 , 126, /* P - 80 */
1375 14 , 137, /* Q - 81 */
1376 14 , 138, /* R - 82 */
1377 14 , 145, /* S - 83 */
1378 14 , 153, /* T - 84 */
1379 14 , 159, /* U - 85 */
1380 14 , 162, /* V - 86 */
1381 14 , 164, /* W - 87 */
1382 14 , 166, /* X - 88 */
1383 14 , 167, /* Y - 89 */
1384 14 , 169, /* Z - 90 */
1385 7 , 63, /* [ - 91 */
1386 7 , 65, /* \ - 92 */
1387 7 , 66, /* ] - 93 */
1388 7 , 67, /* ^ - 94 */
1389 7 , 68, /* _ - 95 */
1390 7 , 72, /* ` - 96 */
1391 14 , 2, /* a - 97 */
1392 14 , 9, /* b - 98 */
1393 14 , 10, /* c - 99 */
1394 14 , 26, /* d - 100 */
1395 14 , 33, /* e - 101 */
1396 14 , 35, /* f - 102 */
1397 14 , 37, /* g - 103 */
1398 14 , 44, /* h - 104 */
1399 14 , 50, /* i - 105 */
1400 14 , 53, /* j - 106 */
1401 14 , 54, /* k - 107 */
1402 14 , 72, /* l - 108 */
1403 14 , 81, /* m - 109 */
1404 14 , 112, /* n - 110 */
1405 14 , 124, /* o - 111 */
1406 14 , 126, /* p - 112 */
1407 14 , 137, /* q - 113 */
1408 14 , 138, /* r - 114 */
1409 14 , 145, /* s - 115 */
1410 14 , 153, /* t - 116 */
1411 14 , 159, /* u - 117 */
1412 14 , 162, /* v - 118 */
1413 14 , 164, /* w - 119 */
1414 14 , 166, /* x - 120 */
1415 14 , 167, /* y - 121 */
1416 14 , 169, /* z - 122 */
1417 7 , 74, /* { - 123 */
1418 7 , 76, /* | - 124 */
1419 7 , 78, /* } - 125 */
1420 7 , 80, /* ~ - 126 */
1421 6 , 29, /* \x7f - 127 */
1422 6 , 30, /* € - 128 */
1423 6 , 31, /* � - 129 */
1424 7 , 123, /* ‚ - 130 */
1425 14 , 35, /* ƒ - 131 */
1426 7 , 127, /* „ - 132 */
1427 10 , 21, /* … - 133 */
1428 10 , 15, /* † - 134 */
1429 10 , 16, /* ‡ - 135 */
1430 7 , 67, /* ˆ - 136 */
1431 10 , 22, /* ‰ - 137 */
1432 14 , 145, /* Š - 138 */
1433 7 , 136, /* ‹ - 139 */
1434 14 + 16 , 124, /* Œ - 140 */
1435 6 , 43, /* � - 141 */
1436 6 , 44, /* Ž - 142 */
1437 6 , 45, /* � - 143 */
1438 6 , 46, /* � - 144 */
1439 7 , 121, /* ‘ - 145 */
1440 7 , 122, /* ’ - 146 */
1441 7 , 125, /* “ - 147 */
1442 7 , 126, /* ” - 148 */
1443 10 , 17, /* • - 149 */
1444 6 , 137, /* – - 150 */
1445 6 , 139, /* — - 151 */
1446 7 , 93, /* ˜ - 152 */
1447 14 , 156, /* ™ - 153 */
1448 14 , 145, /* š - 154 */
1449 7 , 137, /* › - 155 */
1450 14 + 16 , 124, /* œ - 156 */
1451 6 , 59, /* � - 157 */
1452 6 , 60, /* ž - 158 */
1453 14 , 167, /* Ÿ - 159 */
1455 7 , 81, /* ¡ - 161 */
1456 10 , 2, /* ¢ - 162 */
1457 10 , 3, /* £ - 163 */
1458 10 , 4, /* ¤ - 164 */
1459 10 , 5, /* ¥ - 165 */
1460 7 , 82, /* ¦ - 166 */
1461 10 , 6, /* § - 167 */
1462 7 , 83, /* ¨ - 168 */
1463 10 , 7, /* © - 169 */
1464 14 , 2, /* ª - 170 */
1465 8 , 24, /* « - 171 */
1466 10 , 8, /* ¬ - 172 */
1467 6 , 131, /* - 173 */
1468 10 , 9, /* ® - 174 */
1469 7 , 84, /* ¯ - 175 */
1470 10 , 10, /* ° - 176 */
1471 8 , 23, /* ± - 177 */
1472 12 , 51, /* ² - 178 */
1473 12 , 70, /* ³ - 179 */
1474 7 , 85, /* ´ - 180 */
1475 10 , 11, /* µ - 181 */
1476 10 , 12, /* ¶ - 182 */
1477 10 , 13, /* · - 183 */
1478 7 , 86, /* ¸ - 184 */
1479 12 , 33, /* ¹ - 185 */
1480 14 , 124, /* º - 186 */
1481 8 , 26, /* » - 187 */
1482 12 , 21, /* ¼ - 188 */
1483 12 , 25, /* ½ - 189 */
1484 12 , 29, /* ¾ - 190 */
1485 7 , 87, /* ¿ - 191 */
1486 14 , 2, /* À - 192 */
1487 14 , 2, /* Á - 193 */
1488 14 , 2, /* Â - 194 */
1489 14 , 2, /* Ã - 195 */
1490 14 , 2, /* Ä - 196 */
1491 14 , 2, /* Å - 197 */
1492 14 + 16 , 2, /* Æ - 198 */
1493 14 , 10, /* Ç - 199 */
1494 14 , 33, /* È - 200 */
1495 14 , 33, /* É - 201 */
1496 14 , 33, /* Ê - 202 */
1497 14 , 33, /* Ë - 203 */
1498 14 , 50, /* Ì - 204 */
1499 14 , 50, /* Í - 205 */
1500 14 , 50, /* Î - 206 */
1501 14 , 50, /* Ï - 207 */
1502 14 , 26, /* Ð - 208 */
1503 14 , 112, /* Ñ - 209 */
1504 14 , 124, /* Ò - 210 */
1505 14 , 124, /* Ó - 211 */
1506 14 , 124, /* Ô - 212 */
1507 14 , 124, /* Õ - 213 */
1508 14 , 124, /* Ö - 214 */
1509 8 , 28, /* × - 215 */
1510 14 , 124, /* Ø - 216 */
1511 14 , 159, /* Ù - 217 */
1512 14 , 159, /* Ú - 218 */
1513 14 , 159, /* Û - 219 */
1514 14 , 159, /* Ü - 220 */
1515 14 , 167, /* Ý - 221 */
1516 14 + 32 , 153, /* Þ - 222 */
1517 14 + 48 , 145, /* ß - 223 */
1518 14 , 2, /* à - 224 */
1519 14 , 2, /* á - 225 */
1520 14 , 2, /* â - 226 */
1521 14 , 2, /* ã - 227 */
1522 14 , 2, /* ä - 228 */
1523 14 , 2, /* å - 229 */
1524 14 + 16 , 2, /* æ - 230 */
1525 14 , 10, /* ç - 231 */
1526 14 , 33, /* è - 232 */
1527 14 , 33, /* é - 233 */
1528 14 , 33, /* ê - 234 */
1529 14 , 33, /* ë - 235 */
1530 14 , 50, /* ì - 236 */
1531 14 , 50, /* í - 237 */
1532 14 , 50, /* î - 238 */
1533 14 , 50, /* ï - 239 */
1534 14 , 26, /* ð - 240 */
1535 14 , 112, /* ñ - 241 */
1536 14 , 124, /* ò - 242 */
1537 14 , 124, /* ó - 243 */
1538 14 , 124, /* ô - 244 */
1539 14 , 124, /* õ - 245 */
1540 14 , 124, /* ö - 246 */
1541 8 , 29, /* ÷ - 247 */
1542 14 , 124, /* ø - 248 */
1543 14 , 159, /* ù - 249 */
1544 14 , 159, /* ú - 250 */
1545 14 , 159, /* û - 251 */
1546 14 , 159, /* ü - 252 */
1547 14 , 167, /* ý - 253 */
1548 14 + 32 , 153, /* þ - 254 */
1549 14 , 167 /* ÿ - 255 */ };
1551 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1553 #define LCM_Diacritic_Start 131
1555 static const unsigned char LCM_Diacritic_LUT
[] = {
1683 /******************************************************************************
1684 * OLE2NLS_isPunctuation [INTERNAL]
1686 static int OLE2NLS_isPunctuation(unsigned char c
)
1688 /* "punctuation character" in this context is a character which is
1689 considered "less important" during word sort comparison.
1690 See LCMapString implementation for the precise definition
1691 of "less important". */
1693 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1696 /******************************************************************************
1697 * OLE2NLS_isNonSpacing [INTERNAL]
1699 static int OLE2NLS_isNonSpacing(unsigned char c
)
1701 /* This function is used by LCMapStringA. Characters
1702 for which it returns true are ignored when mapping a
1703 string with NORM_IGNORENONSPACE */
1704 return ((c
==136) || (c
==170) || (c
==186));
1707 /******************************************************************************
1708 * OLE2NLS_isSymbol [INTERNAL]
1710 static int OLE2NLS_isSymbol(unsigned char c
)
1712 /* This function is used by LCMapStringA. Characters
1713 for which it returns true are ignored when mapping a
1714 string with NORM_IGNORESYMBOLS */
1715 return ( (c
!=0) && !IsCharAlphaNumericA(c
) );
1718 /******************************************************************************
1719 * identity [Internal]
1721 static int identity(int c
)
1726 /*************************************************************************
1727 * LCMapStringA [KERNEL32.492]
1729 * Convert a string, or generate a sort key from it.
1731 * If (mapflags & LCMAP_SORTKEY), the function will generate
1732 * a sort key for the source string. Else, it will convert it
1733 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1737 * Success : length of the result string.
1740 * If called with scrlen = -1, the function will compute the length
1741 * of the 0-terminated string strsrc by itself.
1743 * If called with dstlen = 0, returns the buffer length that
1744 * would be required.
1746 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1747 * as if they are equal.
1748 * In the only code page implemented so far, there may not be
1749 * wide characters in strings passed to LCMapStringA,
1750 * so there is nothing to be done for this flag.
1752 INT WINAPI
LCMapStringA(
1753 LCID lcid
/* locale identifier created with MAKELCID;
1754 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1755 predefined values. */,
1756 DWORD mapflags
/* flags */,
1757 LPCSTR srcstr
/* source buffer */,
1758 INT srclen
/* source length */,
1759 LPSTR dststr
/* destination buffer */,
1760 INT dstlen
/* destination buffer length */)
1764 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1765 lcid
,mapflags
,srcstr
,srclen
,dststr
,dstlen
);
1767 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1769 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr
, dststr
);
1770 SetLastError(ERROR_INVALID_PARAMETER
);
1774 srclen
= lstrlenA(srcstr
) + 1 ; /* (include final '\0') */
1776 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1780 NORM_IGNORENONSPACE | \
1782 NORM_IGNOREWIDTH | \
1783 NORM_IGNOREKANATYPE)
1784 /* FIXME: as long as we don't support Kanakana nor Hirigana
1785 * characters, we can support NORM_IGNOREKANATYPE
1787 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1789 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1790 "unimplemented flags: 0x%08lx\n",
1797 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1801 if ( !(mapflags
& LCMAP_SORTKEY
) )
1804 int (*f
)(int) = identity
;
1805 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1806 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1808 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1810 /* For some values of mapflags, the length of the resulting
1811 string is not known at this point. Windows does map the string
1812 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1816 /* Compute required length */
1817 for (i
=j
=0; i
< srclen
; i
++)
1819 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1820 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1832 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1836 if (mapflags
& LCMAP_UPPERCASE
)
1838 else if (mapflags
& LCMAP_LOWERCASE
)
1840 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1841 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1843 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1844 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1846 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1853 /* FIXME: This function completely ignores the "lcid" parameter. */
1854 /* else ... (mapflags & LCMAP_SORTKEY) */
1858 int diacritic_len
=0;
1859 int delayed_punctuation_len
=0;
1860 char *case_component
;
1861 char *diacritic_component
;
1862 char *delayed_punctuation_component
;
1864 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1866 /* compute how much room we will need */
1867 for (i
=0;i
<srclen
;i
++)
1870 unsigned char source_char
= srcstr
[i
];
1871 if (source_char
!='\0')
1873 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
1876 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
1877 unicode_len
++; /* double letter */
1881 delayed_punctuation_len
++;
1885 if (isupper(source_char
))
1886 case_len
=unicode_len
;
1888 ofs
= source_char
- LCM_Diacritic_Start
;
1889 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
1890 diacritic_len
=unicode_len
;
1893 if (mapflags
& NORM_IGNORECASE
)
1895 if (mapflags
& NORM_IGNORENONSPACE
)
1898 room
= 2 * unicode_len
/* "unicode" component */
1899 + diacritic_len
/* "diacritic" component */
1900 + case_len
/* "case" component */
1901 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
1902 + 4 /* four '\1' separators */
1903 + 1 ; /* terminal '\0' */
1906 else if (dstlen
<room
)
1908 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1912 /*FIXME the Pointercheck should not be nessesary */
1913 if (IsBadWritePtr (dststr
,room
))
1914 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
1915 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1919 /* locate each component, write separators */
1920 diacritic_component
= dststr
+ 2*unicode_len
;
1921 *diacritic_component
++ = '\1';
1922 case_component
= diacritic_component
+ diacritic_len
;
1923 *case_component
++ = '\1';
1924 delayed_punctuation_component
= case_component
+ case_len
;
1925 *delayed_punctuation_component
++ = '\1';
1926 *delayed_punctuation_component
++ = '\1';
1928 /* read source string char by char, write
1929 corresponding weight in each component. */
1930 for (i
=0,count
=0;i
<srclen
;i
++)
1932 unsigned char source_char
=srcstr
[i
];
1933 if (source_char
!='\0')
1936 type
= LCM_Unicode_LUT
[-2+2*source_char
];
1937 longcode
= type
>> 4;
1939 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
1941 UINT16 encrypted_location
= (1<<15) + 7 + 4*count
;
1942 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
1943 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
1944 /* big-endian is used here because it lets string comparison be
1945 compatible with numerical comparison */
1947 *delayed_punctuation_component
++ = type
;
1948 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
1949 /* assumption : a punctuation character is never a
1950 double or accented letter */
1954 dststr
[2*count
] = type
;
1955 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
1959 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1960 if (count
<diacritic_len
)
1961 diacritic_component
[count
] = 2; /* assumption: a double letter
1962 is never accented */
1965 dststr
[2*count
] = type
;
1966 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
1967 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1968 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1969 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1973 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1974 if (count
<diacritic_len
)
1976 int ofs
= source_char
- LCM_Diacritic_Start
;
1977 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
1983 dststr
[room
-1] = '\0';
1988 /*************************************************************************
1989 * LCMapStringW [KERNEL32.493]
1991 * Convert a string, or generate a sort key from it.
1995 * See LCMapStringA for documentation
1997 INT WINAPI
LCMapStringW(
1998 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
2003 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2004 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
2006 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
2008 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
2009 SetLastError(ERROR_INVALID_PARAMETER
);
2013 srclen
= lstrlenW(srcstr
)+1;
2015 /* FIXME: Both this function and it's companion LCMapStringA()
2016 * completely ignore the "lcid" parameter. In place of the "lcid"
2017 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2018 * environment variable prior to invoking this function. */
2019 if (mapflags
& LCMAP_SORTKEY
)
2021 /* Possible values of LC_COLLATE. */
2022 char *lc_collate_default
= 0; /* value prior to this function */
2023 char *lc_collate_env
= 0; /* value retrieved from the environment */
2025 /* General purpose index into strings of any type. */
2028 /* Lengths of various strings where the length is measured in
2029 * wide characters for wide character strings and in bytes for
2030 * native strings. The lengths include the NULL terminator. */
2031 size_t returned_len
= 0;
2032 size_t src_native_len
= 0;
2033 size_t dst_native_len
= 0;
2034 size_t dststr_libc_len
= 0;
2036 /* Native (character set determined by locale) versions of the
2037 * strings source and destination strings. */
2038 LPSTR src_native
= 0;
2039 LPSTR dst_native
= 0;
2041 /* Version of the source and destination strings using the
2042 * "wchar_t" Unicode data type needed by various libc functions. */
2043 wchar_t *srcstr_libc
= 0;
2044 wchar_t *dststr_libc
= 0;
2046 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2047 srclen
* sizeof(wchar_t))))
2049 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2050 srclen
* sizeof(wchar_t));
2051 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2055 /* Convert source string to a libc Unicode string. */
2056 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
2058 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
2061 /* src_native should contain at most 3 bytes for each
2062 * multibyte characters in the original srcstr string. */
2063 src_native_len
= 3 * srclen
;
2064 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
2067 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
2068 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2069 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2073 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2074 * current value is backed up so it can be restored after the
2075 * last LC_COLLATE sensitive function returns.
2077 * Even though the locale is adjusted for a minimum amount of
2078 * time a race condition exists where other threads may be
2079 * affected if they invoke LC_COLLATE sensitive functions. One
2080 * possible solution is to wrap all LC_COLLATE sensitive Wine
2081 * functions, like LCMapStringW(), in a mutex.
2083 * Another enhancement to the following would be to set the
2084 * LC_COLLATE locale category as a function of the "lcid"
2085 * parameter instead of the "LC_COLLATE" environment variable. */
2086 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
2088 ERR("Unable to query the LC_COLLATE catagory\n");
2089 SetLastError(ERROR_INVALID_PARAMETER
);
2090 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2091 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2095 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
2097 ERR("Unable to inherit the LC_COLLATE locale category from the "
2098 "environment. The \"LC_COLLATE\" environment variable is "
2099 "\"%s\".\n", getenv("LC_COLLATE") ?
2100 getenv("LC_COLLATE") : "<unset>");
2101 SetLastError(ERROR_INVALID_PARAMETER
);
2102 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2103 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2107 TRACE("lc_collate_default = %s\n", lc_collate_default
);
2108 TRACE("lc_collate_env = %s\n", lc_collate_env
);
2110 /* Convert the libc Unicode string to a native multibyte character
2112 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
2113 if(returned_len
== 0)
2115 LPSTR srcstr_ascii
= (LPSTR
)HEAP_strdupWtoA(GetProcessHeap(),
2117 ERR("wcstombs failed. The string specified (%s) may contains an "
2118 "invalid character.\n", srcstr_ascii
);
2119 SetLastError(ERROR_INVALID_PARAMETER
);
2120 if(srcstr_ascii
) HeapFree(GetProcessHeap(), 0, srcstr_ascii
);
2121 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2122 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2123 setlocale(LC_COLLATE
, lc_collate_default
);
2126 else if(returned_len
> src_native_len
)
2128 src_native
[src_native_len
- 1] = 0;
2129 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2130 "than expected (%d bytes).\n", src_native
, returned_len
,
2133 /* Since this is an internal error I'm not sure what the correct
2135 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2137 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2138 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2139 setlocale(LC_COLLATE
, lc_collate_default
);
2142 src_native_len
= returned_len
;
2144 TRACE("src_native = %s src_native_len = %d\n",
2145 src_native
, src_native_len
);
2147 /* dst_native seems to contain at most 4 bytes for each byte in
2148 * the original src_native string. Change if need be since this
2149 * isn't documented by the strxfrm() man page. */
2150 dst_native_len
= 4 * src_native_len
;
2151 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
2153 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
2154 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2155 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2156 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2157 setlocale(LC_COLLATE
, lc_collate_default
);
2161 /* The actual translation is done by the following call to
2162 * strxfrm(). The surrounding code could have been simplified
2163 * by calling wcsxfrm() instead except that wcsxfrm() is not
2164 * available on older Linux systems (RedHat 4.1 with
2167 * Also, it is possible that the translation could be done by
2168 * various tables as it is done in LCMapStringA(). However, I'm
2169 * not sure what those tables are. */
2170 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
2172 if(returned_len
> dst_native_len
)
2174 dst_native
[dst_native_len
- 1] = 0;
2175 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2176 "than expected (%d bytes).\n", dst_native
, returned_len
,
2179 /* Since this is an internal error I'm not sure what the correct
2181 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2183 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2184 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2185 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2186 setlocale(LC_COLLATE
, lc_collate_default
);
2189 dst_native_len
= returned_len
;
2191 TRACE("dst_native = %s dst_native_len = %d\n",
2192 dst_native
, dst_native_len
);
2194 dststr_libc_len
= dst_native_len
;
2195 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2196 dststr_libc_len
* sizeof(wchar_t))))
2198 ERR("Unable to allocate %d bytes for dststr_libc\n",
2199 dststr_libc_len
* sizeof(wchar_t));
2200 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2201 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2202 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2203 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2204 setlocale(LC_COLLATE
, lc_collate_default
);
2208 /* Convert the native multibyte string to a libc Unicode string. */
2209 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
2211 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2212 * function has returned. */
2213 setlocale(LC_COLLATE
, lc_collate_default
);
2215 if(returned_len
== 0)
2217 ERR("mbstowcs failed. The native version of the translated string "
2218 "(%s) may contain an invalid character.\n", dst_native
);
2219 SetLastError(ERROR_INVALID_PARAMETER
);
2220 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2221 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2222 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2223 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2228 if(returned_len
> dstlen
)
2230 ERR("mbstowcs returned a string that was longer (%d chars) "
2231 "than the buffer provided (%d chars).\n", returned_len
,
2233 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2234 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2235 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2236 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2237 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2240 dstlen
= returned_len
;
2242 /* Convert a libc Unicode string to the destination string. */
2243 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
2245 dststr
[str_idx
] = dststr_libc
[str_idx
];
2247 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2248 *(((int *)dststr
) + 0),
2249 *(((int *)dststr
) + 1),
2250 *(((int *)dststr
) + 2),
2251 *(((int *)dststr
) + 3));
2255 dstlen
= returned_len
;
2257 TRACE("dstlen (return) = %d\n", dstlen
);
2258 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2259 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2260 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2261 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2266 int (*f
)(int)=identity
;
2272 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2276 if (mapflags
& LCMAP_UPPERCASE
)
2278 else if (mapflags
& LCMAP_LOWERCASE
)
2280 for (i
=0; i
< srclen
; i
++)
2281 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
2287 /***********************************************************************
2288 * OLE2NLS_EstimateMappingLength
2290 * Estimates the number of characters required to hold the string
2291 * computed by LCMapStringA.
2293 * The size is always over-estimated, with a fixed limit on the
2294 * amount of estimation error.
2296 * Note that len == -1 is not permitted.
2298 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
2299 LPCSTR str
, DWORD len
)
2301 /* Estimate only for small strings to keep the estimation error from
2302 * becoming too large. */
2303 if (len
< 128) return len
* 8 + 5;
2304 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
2307 /******************************************************************************
2308 * CompareStringA [KERNEL32.143]
2309 * Compares two strings using locale
2313 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2318 * Defaults to a word sort, but uses a string sort if
2319 * SORT_STRINGSORT is set.
2320 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2324 * This implementation ignores the locale
2328 * Quite inefficient.
2330 UINT WINAPI
CompareStringA(
2331 DWORD lcid
, /* locale ID */
2332 DWORD fdwStyle
, /* comparison-style options */
2333 LPCSTR s1
, /* first string */
2334 DWORD l1
, /* length of first string */
2335 LPCSTR s2
, /* second string */
2336 DWORD l2
) /* length of second string */
2338 int mapstring_flags
;
2342 TRACE("%s and %s\n",
2343 debugstr_a (s1
), debugstr_a (s2
));
2345 if ( (s1
==NULL
) || (s2
==NULL
) )
2347 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1
, s2
);
2348 SetLastError(ERROR_INVALID_PARAMETER
);
2352 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2353 FIXME("IGNORESYMBOLS not supported\n");
2355 if (l1
== -1) l1
= lstrlenA(s1
);
2356 if (l2
== -1) l2
= lstrlenA(s2
);
2358 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
2359 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
2360 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
2362 if ((len1
==0)||(len2
==0))
2363 return 0; /* something wrong happened */
2365 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
2367 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
2368 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
2370 ERR("Bug in LCmapStringA.\n");
2375 /* strcmp doesn't necessarily return -1, 0, or 1 */
2376 result
= strcmp(sk1
,sk2
);
2378 HeapFree(GetProcessHeap(),0,sk1
);
2385 /* must be greater, if we reach this point */
2389 /******************************************************************************
2390 * CompareStringW [KERNEL32.144]
2391 * This implementation ignores the locale
2392 * FIXME : Does only string sort. Should
2393 * be reimplemented the same way as CompareStringA.
2395 UINT WINAPI
CompareStringW(DWORD lcid
, DWORD fdwStyle
,
2396 LPCWSTR s1
, DWORD l1
, LPCWSTR s2
,DWORD l2
)
2399 if(fdwStyle
& NORM_IGNORENONSPACE
)
2400 FIXME("IGNORENONSPACE not supprted\n");
2401 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2402 FIXME("IGNORESYMBOLS not supported\n");
2404 /* Is strcmp defaulting to string sort or to word sort?? */
2405 /* FIXME: Handle NORM_STRINGSORT */
2406 l1
= (l1
==-1)?lstrlenW(s1
):l1
;
2407 l2
= (l2
==-1)?lstrlenW(s2
):l2
;
2408 len
= l1
<l2
? l1
:l2
;
2409 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
2410 /* not equal, return 1 or 3 */
2411 if(ret
!=0) return ret
+2;
2412 /* same len, return 2 */
2413 if(l1
==l2
) return 2;
2414 /* the longer one is lexically greater */
2415 return (l1
<l2
)? 1 : 3;
2418 /******************************************************************************
2419 * OLE_GetFormatA [Internal]
2422 * If datelen == 0, it should return the reguired string length.
2424 This function implements stuff for GetDateFormat() and
2427 d single-digit (no leading zero) day (of month)
2428 dd two-digit day (of month)
2429 ddd short day-of-week name
2430 dddd long day-of-week name
2431 M single-digit month
2433 MMM short month name
2434 MMMM full month name
2435 y two-digit year, no leading 0
2437 yyyy four-digit year
2439 h hours with no leading zero (12-hour)
2440 hh hours with full two digits
2441 H hours with no leading zero (24-hour)
2442 HH hours with full two digits
2443 m minutes with no leading zero
2444 mm minutes with full two digits
2445 s seconds with no leading zero
2446 ss seconds with full two digits
2447 t time marker (A or P)
2448 tt time marker (AM, PM)
2449 '' used to quote literal characters
2450 '' (within a quoted string) indicates a literal '
2452 These functions REQUIRE valid locale, date, and format.
2454 static INT
OLE_GetFormatA(LCID locale
,
2458 LPCSTR _format
, /*in*/
2463 int count
, type
, inquote
, Overflow
;
2469 const char * _dgfmt
[] = { "%d", "%02d" };
2470 const char ** dgfmt
= _dgfmt
- 1;
2472 /* report, for debugging */
2473 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2474 locale
, flags
, tflags
,
2475 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2476 _format
, _format
, date
, datelen
);
2479 FIXME("datelen = 0, returning 255\n");
2483 /* initalize state variables and output buffer */
2485 count
= 0; inquote
= 0; Overflow
= 0;
2487 date
[0] = buf
[0] = '\0';
2489 strcpy(format
,_format
);
2491 /* alter the formatstring, while it works for all languages now in wine
2492 its possible that it fails when the time looks like ss:mm:hh as example*/
2493 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2494 { if ((pos
= strstr ( format
, ":mm")))
2495 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2498 if (tflags
& (TIME_NOSECONDS
))
2499 { if ((pos
= strstr ( format
, ":ss")))
2500 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2504 for (inpos
= 0;; inpos
++) {
2505 /* TRACE("STATE inpos=%2d outpos=%2d count=%d inquote=%d type=%c buf,date = %c,%c\n", inpos, outpos, count, inquote, type, buf[inpos], date[outpos]); */
2507 if (format
[inpos
] == '\'') {
2508 if (format
[inpos
+1] == '\'') {
2510 date
[outpos
++] = '\'';
2513 continue; /* we did nothing to the output */
2515 } else if (format
[inpos
] == '\0') {
2516 date
[outpos
++] = '\0';
2517 if (outpos
> datelen
) Overflow
= 1;
2520 date
[outpos
++] = format
[inpos
];
2521 if (outpos
> datelen
) {
2523 date
[outpos
-1] = '\0'; /* this is the last place where
2524 it's safe to write */
2528 } else if ( (count
&& (format
[inpos
] != type
))
2530 || (count
== 2 && strchr("ghHmst", type
)) )
2534 GetLocaleInfoA(locale
,
2536 + xtime
->wDayOfWeek
- 1,
2538 } else if (count
== 3) {
2539 GetLocaleInfoA(locale
,
2540 LOCALE_SABBREVDAYNAME1
2541 + xtime
->wDayOfWeek
- 1,
2544 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2546 } else if (type
== 'M') {
2548 GetLocaleInfoA(locale
,
2549 LOCALE_SABBREVMONTHNAME1
2550 + xtime
->wMonth
- 1,
2552 } else if (count
== 4) {
2553 GetLocaleInfoA(locale
,
2555 + xtime
->wMonth
- 1,
2558 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2560 } else if (type
== 'y') {
2562 sprintf(buf
, "%d", xtime
->wYear
);
2563 } else if (count
== 3) {
2565 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2567 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2569 } else if (type
== 'g') {
2571 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2575 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2577 } else if (type
== 'h') {
2578 /* gives us hours 1:00 -- 12:00 */
2579 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2580 } else if (type
== 'H') {
2582 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2583 } else if ( type
== 'm') {
2584 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2585 } else if ( type
== 's') {
2586 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2587 } else if (type
== 't') {
2589 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2590 } else if (count
== 2) {
2591 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2592 GetLocaleInfoA(locale
,
2594 ? LOCALE_S1159
: LOCALE_S2359
,
2599 /* we need to check the next char in the format string
2600 again, no matter what happened */
2603 /* add the contents of buf to the output */
2604 buflen
= strlen(buf
);
2605 if (outpos
+ buflen
< datelen
) {
2606 date
[outpos
] = '\0'; /* for strcat to hook onto */
2610 date
[outpos
] = '\0';
2611 strncat(date
, buf
, datelen
- outpos
);
2612 date
[datelen
- 1] = '\0';
2613 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2614 WARN("insufficient buffer\n");
2618 /* reset the variables we used to keep track of this item */
2621 } else if (format
[inpos
] == '\0') {
2622 /* we can't check for this at the loop-head, because
2623 that breaks the printing of the last format-item */
2624 date
[outpos
] = '\0';
2627 /* continuing a code for an item */
2630 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2631 type
= format
[inpos
];
2634 } else if (format
[inpos
] == '\'') {
2638 date
[outpos
++] = format
[inpos
];
2640 /* now deal with a possible buffer overflow */
2641 if (outpos
>= datelen
) {
2642 date
[datelen
- 1] = '\0';
2643 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2649 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2652 /* finish it off with a string terminator */
2655 if (outpos
> datelen
-1) outpos
= datelen
-1;
2656 date
[outpos
] = '\0';
2658 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2663 /******************************************************************************
2664 * OLE_GetFormatW [INTERNAL]
2666 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2669 LPWSTR output
, INT outlen
)
2672 int count
, type
=0, inquote
;
2673 int Overflow
; /* loop check */
2676 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2677 WCHAR arg2
[] = {'%','0','2','d',0};
2679 int datevars
=0, timevars
=0;
2685 /* make a debug report */
2686 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2687 "%p with max len %d\n",
2688 locale
, flags
, tflags
,
2689 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2690 debugstr_w(format
), format
, output
, outlen
);
2693 FIXME("outlen = 0, returning 255\n");
2697 /* initialize state variables */
2700 inquote
= Overflow
= 0;
2701 /* this is really just a sanity check */
2702 output
[0] = buf
[0] = 0;
2704 /* this loop is the core of the function */
2705 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2707 if (format
[inpos
] == (WCHAR
) '\'') {
2708 if (format
[inpos
+1] == '\'') {
2710 output
[outpos
++] = '\'';
2715 } else if (format
[inpos
] == 0) {
2716 output
[outpos
++] = 0;
2717 if (outpos
> outlen
) Overflow
= 1;
2718 break; /* normal exit (within a quote) */
2720 output
[outpos
++] = format
[inpos
]; /* copy input */
2721 if (outpos
> outlen
) {
2723 output
[outpos
-1] = 0;
2727 } else if ( (count
&& (format
[inpos
] != type
))
2728 || ( (count
==4 && type
=='y') ||
2729 (count
==4 && type
=='M') ||
2730 (count
==4 && type
=='d') ||
2731 (count
==2 && type
=='g') ||
2732 (count
==2 && type
=='h') ||
2733 (count
==2 && type
=='H') ||
2734 (count
==2 && type
=='m') ||
2735 (count
==2 && type
=='s') ||
2736 (count
==2 && type
=='t') ) ) {
2739 GetLocaleInfoW(locale
,
2740 LOCALE_SDAYNAME1
+ xtime
->wDayOfWeek
-1,
2741 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2742 } else if (count
== 3) {
2743 GetLocaleInfoW(locale
,
2744 LOCALE_SABBREVDAYNAME1
+
2745 xtime
->wDayOfWeek
-1,
2746 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2748 wsnprintfW(buf
, 5, argarr
[count
], xtime
->wDay
);
2750 } else if (type
== 'M') {
2752 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2753 xtime
->wMonth
-1, buf
,
2754 sizeof(buf
)/sizeof(WCHAR
) );
2755 } else if (count
== 3) {
2756 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2757 xtime
->wMonth
-1, buf
,
2758 sizeof(buf
)/sizeof(WCHAR
) );
2760 wsnprintfW(buf
, 5, argarr
[count
], xtime
->wMonth
);
2762 } else if (type
== 'y') {
2764 wsnprintfW(buf
, 6, argarr
[1] /* "%d" */,
2766 } else if (count
== 3) {
2767 lstrcpynAtoW(buf
, "yyy", 5);
2769 wsnprintfW(buf
, 6, argarr
[count
],
2770 xtime
->wYear
% 100);
2772 } else if (type
== 'g') {
2774 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2775 lstrcpynAtoW(buf
, "AD", 5);
2777 /* Win API sez we copy it verbatim */
2778 lstrcpynAtoW(buf
, "g", 5);
2780 } else if (type
== 'h') {
2781 /* hours 1:00-12:00 --- is this right? */
2782 wsnprintfW(buf
, 5, argarr
[count
],
2783 (xtime
->wHour
-1)%12 +1);
2784 } else if (type
== 'H') {
2785 wsnprintfW(buf
, 5, argarr
[count
],
2787 } else if (type
== 'm' ) {
2788 wsnprintfW(buf
, 5, argarr
[count
],
2790 } else if (type
== 's' ) {
2791 wsnprintfW(buf
, 5, argarr
[count
],
2793 } else if (type
== 't') {
2794 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2795 LOCALE_S1159
: LOCALE_S2359
,
2802 /* no matter what happened, we need to check this next
2803 character the next time we loop through */
2806 /* cat buf onto the output */
2807 outlen
= lstrlenW(buf
);
2808 if (outpos
+ buflen
< outlen
) {
2809 lstrcpyW( output
+ outpos
, buf
);
2812 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2814 break; /* Abnormal exit */
2817 /* reset the variables we used this time */
2820 } else if (format
[inpos
] == 0) {
2821 /* we can't check for this at the beginning, because that
2822 would keep us from printing a format spec that ended the
2825 break; /* NORMAL EXIT */
2827 /* how we keep track of the middle of a format spec */
2830 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2831 format
[inpos
]=='M' ||
2832 format
[inpos
]=='y' ||
2833 format
[inpos
]=='g') ) ||
2834 (timevars
&& (format
[inpos
]=='H' ||
2835 format
[inpos
]=='h' ||
2836 format
[inpos
]=='m' ||
2837 format
[inpos
]=='s' ||
2838 format
[inpos
]=='t') ) ) {
2839 type
= format
[inpos
];
2842 } else if (format
[inpos
] == '\'') {
2846 /* unquoted literals */
2847 output
[outpos
++] = format
[inpos
];
2852 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2853 WARN(" buffer overflow\n");
2856 /* final string terminator and sanity check */
2858 if (outpos
> outlen
-1) outpos
= outlen
-1;
2859 output
[outpos
] = '0';
2861 TRACE(" returning %s\n", debugstr_w(output
));
2863 return (!Overflow
) ? outlen
: 0;
2868 /******************************************************************************
2869 * GetDateFormatA [KERNEL32.310]
2870 * Makes an ASCII string of the date
2872 * This function uses format to format the date, or, if format
2873 * is NULL, uses the default for the locale. format is a string
2874 * of literal fields and characters as follows:
2876 * - d single-digit (no leading zero) day (of month)
2877 * - dd two-digit day (of month)
2878 * - ddd short day-of-week name
2879 * - dddd long day-of-week name
2880 * - M single-digit month
2881 * - MM two-digit month
2882 * - MMM short month name
2883 * - MMMM full month name
2884 * - y two-digit year, no leading 0
2885 * - yy two-digit year
2886 * - yyyy four-digit year
2890 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
2892 LPCSTR format
, LPSTR date
,INT datelen
)
2895 char format_buf
[40];
2898 LPSYSTEMTIME thistime
;
2902 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2903 locale
,flags
,xtime
,format
,date
,datelen
);
2906 locale
= LOCALE_SYSTEM_DEFAULT
;
2909 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
2910 thislocale
= GetSystemDefaultLCID();
2911 } else if (locale
== LOCALE_USER_DEFAULT
) {
2912 thislocale
= GetUserDefaultLCID();
2914 thislocale
= locale
;
2917 if (xtime
== NULL
) {
2924 if (format
== NULL
) {
2925 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
2927 : LOCALE_SSHORTDATE
),
2928 format_buf
, sizeof(format_buf
));
2929 thisformat
= format_buf
;
2931 thisformat
= format
;
2935 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
2940 "GetDateFormatA() returning %d, with data=%s\n",
2945 /******************************************************************************
2946 * GetDateFormatW [KERNEL32.311]
2947 * Makes a Unicode string of the date
2949 * Acts the same as GetDateFormatA(), except that it's Unicode.
2950 * Accepts & returns sizes as counts of Unicode characters.
2953 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
2956 LPWSTR date
, INT datelen
)
2958 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
2960 FIXME("STUB (should call OLE_GetFormatW)\n");
2961 lstrcpynW(date
, datearr
, datelen
);
2962 return ( datelen
< 9) ? datelen
: 9;
2967 /**************************************************************************
2968 * EnumDateFormatsA (KERNEL32.198)
2970 BOOL WINAPI
EnumDateFormatsA(
2971 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2973 LCID Loc
= GetUserDefaultLCID();
2974 if(!lpDateFmtEnumProc
)
2976 SetLastError(ERROR_INVALID_PARAMETER
);
2983 case 0x00000407: /* (Loc,"de_DE") */
2987 case DATE_SHORTDATE
:
2988 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2989 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
2990 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2991 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2994 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
2995 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
2996 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
2999 FIXME("Unknown date format (%ld)\n", dwFlags
);
3000 SetLastError(ERROR_INVALID_PARAMETER
);
3005 case 0x0000040c: /* (Loc,"fr_FR") */
3009 case DATE_SHORTDATE
:
3010 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3011 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3012 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3013 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3016 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
3017 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
3018 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3021 FIXME("Unknown date format (%ld)\n", dwFlags
);
3022 SetLastError(ERROR_INVALID_PARAMETER
);
3027 case 0x00000c0c: /* (Loc,"fr_CA") */
3031 case DATE_SHORTDATE
:
3032 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3033 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3034 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
3035 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3038 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
3039 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
3042 FIXME("Unknown date format (%ld)\n", dwFlags
);
3043 SetLastError(ERROR_INVALID_PARAMETER
);
3048 case 0x00000809: /* (Loc,"en_UK") */
3052 case DATE_SHORTDATE
:
3053 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3054 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3055 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3056 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3059 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3060 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3063 FIXME("Unknown date format (%ld)\n", dwFlags
);
3064 SetLastError(ERROR_INVALID_PARAMETER
);
3069 case 0x00000c09: /* (Loc,"en_AU") */
3073 case DATE_SHORTDATE
:
3074 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3075 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3076 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3079 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
3080 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3083 FIXME("Unknown date format (%ld)\n", dwFlags
);
3084 SetLastError(ERROR_INVALID_PARAMETER
);
3089 case 0x00001009: /* (Loc,"en_CA") */
3093 case DATE_SHORTDATE
:
3094 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3095 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3096 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3097 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
3100 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
3101 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
3104 FIXME("Unknown date format (%ld)\n", dwFlags
);
3105 SetLastError(ERROR_INVALID_PARAMETER
);
3110 case 0x00001409: /* (Loc,"en_NZ") */
3114 case DATE_SHORTDATE
:
3115 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3116 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3117 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3120 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3121 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
3124 FIXME("Unknown date format (%ld)\n", dwFlags
);
3125 SetLastError(ERROR_INVALID_PARAMETER
);
3130 case 0x00001809: /* (Loc,"en_IE") */
3134 case DATE_SHORTDATE
:
3135 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3136 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3137 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3140 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3141 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3144 FIXME("Unknown date format (%ld)\n", dwFlags
);
3145 SetLastError(ERROR_INVALID_PARAMETER
);
3150 case 0x00001c09: /* (Loc,"en_ZA") */
3154 case DATE_SHORTDATE
:
3155 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3158 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3161 FIXME("Unknown date format (%ld)\n", dwFlags
);
3162 SetLastError(ERROR_INVALID_PARAMETER
);
3167 case 0x00002009: /* (Loc,"en_JM") */
3171 case DATE_SHORTDATE
:
3172 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3175 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
3176 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
3177 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
3178 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
3181 FIXME("Unknown date format (%ld)\n", dwFlags
);
3182 SetLastError(ERROR_INVALID_PARAMETER
);
3187 case 0x00002809: /* (Loc,"en_BZ") */
3188 case 0x00002c09: /* (Loc,"en_TT") */
3192 case DATE_SHORTDATE
:
3193 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3196 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
3199 FIXME("Unknown date format (%ld)\n", dwFlags
);
3200 SetLastError(ERROR_INVALID_PARAMETER
);
3205 default: /* default to US English "en_US" */
3209 case DATE_SHORTDATE
:
3210 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
3211 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
3212 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
3213 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
3214 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3215 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
3218 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
3219 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
3220 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
3221 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
3224 FIXME("Unknown date format (%ld)\n", dwFlags
);
3225 SetLastError(ERROR_INVALID_PARAMETER
);
3232 /**************************************************************************
3233 * EnumDateFormatsW (KERNEL32.199)
3235 BOOL WINAPI
EnumDateFormatsW(
3236 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3238 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
3239 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3243 /**************************************************************************
3244 * EnumTimeFormatsA (KERNEL32.210)
3246 BOOL WINAPI
EnumTimeFormatsA(
3247 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3249 LCID Loc
= GetUserDefaultLCID();
3250 if(!lpTimeFmtEnumProc
)
3252 SetLastError(ERROR_INVALID_PARAMETER
);
3257 FIXME("Unknown time format (%ld)\n", dwFlags
);
3262 case 0x00000407: /* (Loc,"de_DE") */
3264 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3265 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3266 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3267 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
3268 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
3272 case 0x0000040c: /* (Loc,"fr_FR") */
3273 case 0x00000c0c: /* (Loc,"fr_CA") */
3275 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
3276 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3277 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3278 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3279 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
3283 case 0x00000809: /* (Loc,"en_UK") */
3284 case 0x00000c09: /* (Loc,"en_AU") */
3285 case 0x00001409: /* (Loc,"en_NZ") */
3286 case 0x00001809: /* (Loc,"en_IE") */
3288 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3289 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3290 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3294 case 0x00001c09: /* (Loc,"en_ZA") */
3295 case 0x00002809: /* (Loc,"en_BZ") */
3296 case 0x00002c09: /* (Loc,"en_TT") */
3298 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3299 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3303 default: /* default to US style "en_US" */
3305 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3306 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3307 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3308 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3314 /**************************************************************************
3315 * EnumTimeFormatsW (KERNEL32.211)
3317 BOOL WINAPI
EnumTimeFormatsW(
3318 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3320 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
3321 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3325 /**************************************************************************
3326 * This function is used just locally !
3327 * Description: Inverts a string.
3329 static void OLE_InvertString(char* string
)
3331 char sTmpArray
[128];
3334 for (counter
= strlen(string
); counter
> 0; counter
--)
3336 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
3339 memcpy(sTmpArray
+ i
, "\0", 1);
3340 strcpy(string
, sTmpArray
);
3343 /***************************************************************************************
3344 * This function is used just locally !
3345 * Description: Test if the given string (psNumber) is valid or not.
3346 * The valid characters are the following:
3347 * - Characters '0' through '9'.
3348 * - One decimal point (dot) if the number is a floating-point value.
3349 * - A minus sign in the first character position if the number is
3351 * If the function succeeds, psBefore/psAfter will point to the string
3352 * on the right/left of the decimal symbol. pbNegative indicates if the
3353 * number is negative.
3355 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
3357 char sNumberSet
[] = "0123456789";
3358 BOOL bInDecimal
= FALSE
;
3360 /* Test if we do have a minus sign */
3361 if ( *pInput
== '-' )
3364 pInput
++; /* Jump to the next character. */
3367 while(*pInput
!= '\0')
3369 /* Do we have a valid numeric character */
3370 if ( strchr(sNumberSet
, *pInput
) != NULL
)
3372 if (bInDecimal
== TRUE
)
3373 *psAfter
++ = *pInput
;
3375 *psBefore
++ = *pInput
;
3379 /* Is this a decimal point (dot) */
3380 if ( *pInput
== '.' )
3382 /* Is it the first time we find it */
3383 if ((bInDecimal
== FALSE
))
3386 return -1; /* ERROR: Invalid parameter */
3390 /* It's neither a numeric character, nor a decimal point.
3391 * Thus, return an error.
3399 /* Add an End of Line character to the output buffers */
3406 /**************************************************************************
3407 * This function is used just locally !
3408 * Description: A number could be formatted using different numbers
3409 * of "digits in group" (example: 4;3;2;0).
3410 * The first parameter of this function is an array
3411 * containing the rule to be used. It's format is the following:
3412 * |NDG|DG1|DG2|...|0|
3413 * where NDG is the number of used "digits in group" and DG1, DG2,
3414 * are the corresponding "digits in group".
3415 * Thus, this function returns the grouping value in the array
3416 * pointed by the second parameter.
3418 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3420 char sData
[2], sRuleSize
[2];
3421 INT nData
, nRuleSize
;
3423 memcpy(sRuleSize
, sRule
, 1);
3424 memcpy(sRuleSize
+1, "\0", 1);
3425 nRuleSize
= atoi(sRuleSize
);
3427 if (index
> 0 && index
< nRuleSize
)
3429 memcpy(sData
, sRule
+index
, 1);
3430 memcpy(sData
+1, "\0", 1);
3431 nData
= atoi(sData
);
3436 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3437 memcpy(sData
+1, "\0", 1);
3438 nData
= atoi(sData
);
3444 /**************************************************************************
3445 * GetNumberFormatA (KERNEL32.355)
3447 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3448 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3449 LPSTR lpNumberStr
, int cchNumber
)
3451 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3452 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3453 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3454 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3455 char *pStr
= NULL
, *pTmpStr
= NULL
;
3456 LCID systemDefaultLCID
;
3457 BOOL bNegative
= FALSE
;
3466 strncpy(sNumber
, lpvalue
, 128);
3467 sNumber
[127] = '\0';
3469 /* Make sure we have a valid input string, get the number
3470 * of digits before and after the decimal symbol, and check
3471 * if this is a negative number.
3473 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3475 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3476 nDigits
= strlen(sDigitsAfterDecimal
);
3480 SetLastError(ERROR_INVALID_PARAMETER
);
3484 /* Which source will we use to format the string */
3485 used_operation
= RETURN_ERROR
;
3486 if (lpFormat
!= NULL
)
3489 used_operation
= USE_PARAMETER
;
3493 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3494 used_operation
= USE_LOCALEINFO
;
3496 used_operation
= USE_SYSTEMDEFAULT
;
3499 /* Load the fields we need */
3500 switch(used_operation
)
3502 case USE_LOCALEINFO
:
3503 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3504 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3505 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3506 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3507 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3508 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3511 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3512 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3513 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3514 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3515 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3516 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3518 case USE_SYSTEMDEFAULT
:
3519 systemDefaultLCID
= GetSystemDefaultLCID();
3520 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3521 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3522 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3523 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3524 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3525 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3528 SetLastError(ERROR_INVALID_PARAMETER
);
3532 nNumberDigits
= atoi(sNumberDigits
);
3534 /* Remove the ";" */
3537 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3539 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3541 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3546 sprintf(sBuffer
, "%d", i
);
3547 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3548 memcpy(sRule
+ j
, "\0", 1);
3550 /* First, format the digits before the decimal. */
3551 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3553 /* Working on an inverted string is easier ! */
3554 OLE_InvertString(sDigitsBeforeDecimal
);
3556 nStep
= nCounter
= i
= j
= 0;
3558 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3560 /* Here, we will loop until we reach the end of the string.
3561 * An internal counter (j) is used in order to know when to
3562 * insert the "digit group symbol".
3564 while (nNumberDecimal
> 0)
3566 i
= nCounter
+ nStep
;
3567 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3573 if (nRuleIndex
< sRule
[0])
3575 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3576 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3577 nStep
+= strlen(sDigitGroupSymbol
);
3583 memcpy(sDestination
+ i
+1, "\0", 1);
3584 /* Get the string in the right order ! */
3585 OLE_InvertString(sDestination
);
3589 nLZ
= atoi(sILZero
);
3592 /* Use 0.xxx instead of .xxx */
3593 memcpy(sDestination
, "0", 1);
3594 memcpy(sDestination
+1, "\0", 1);
3597 memcpy(sDestination
, "\0", 1);
3601 /* Second, format the digits after the decimal. */
3603 nCounter
= nNumberDigits
;
3604 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3606 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3607 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3608 j
= strlen(sDigitsAfterDecimal
);
3609 if (j
< nNumberDigits
)
3610 nCounter
= nNumberDigits
-j
;
3612 for (i
=0;i
<nCounter
;i
++)
3613 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3614 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3616 i
= strlen(sDestination
);
3617 j
= strlen(sDigitsAfterDecimal
);
3618 /* Finally, construct the resulting formatted string. */
3620 for (nCounter
=0; nCounter
<i
; nCounter
++)
3621 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3623 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3626 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3627 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3629 /* Is it a negative number */
3630 if (bNegative
== TRUE
)
3632 i
= atoi(sNegNumber
);
3633 pStr
= sDestination
;
3639 while (*sNumber
!= '\0')
3640 *pStr
++ = *pTmpStr
++;
3645 while (*pTmpStr
!= '\0')
3646 *pStr
++ = *pTmpStr
++;
3651 while (*pTmpStr
!= '\0')
3652 *pStr
++ = *pTmpStr
++;
3655 while (*pTmpStr
!= '\0')
3656 *pStr
++ = *pTmpStr
++;
3660 while (*pTmpStr
!= '\0')
3661 *pStr
++ = *pTmpStr
++;
3666 while (*pTmpStr
!= '\0')
3667 *pStr
++ = *pTmpStr
++;
3672 strcpy(sDestination
, sNumber
);
3674 /* If cchNumber is zero, then returns the number of bytes or characters
3675 * required to hold the formatted number string
3678 retVal
= strlen(sDestination
) + 1;
3681 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3682 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3683 retVal
= strlen(lpNumberStr
);
3689 /**************************************************************************
3690 * GetNumberFormatW (KERNEL32.xxx)
3692 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3693 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3694 LPWSTR lpNumberStr
, int cchNumber
)
3696 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue
));
3698 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3699 return cchNumber
? lstrlenW( lpNumberStr
) : 0;
3702 /**************************************************************************
3703 * GetCurrencyFormatA (KERNEL32.302)
3705 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3706 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3707 LPSTR lpCurrencyStr
, int cchCurrency
)
3709 UINT nPosOrder
, nNegOrder
;
3711 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3712 char *pDestination
= sDestination
;
3713 char sNumberFormated
[128];
3714 char *pNumberFormated
= sNumberFormated
;
3715 LCID systemDefaultLCID
;
3716 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3725 NUMBERFMTA numberFmt
;
3727 /* Which source will we use to format the string */
3728 used_operation
= RETURN_ERROR
;
3729 if (lpFormat
!= NULL
)
3732 used_operation
= USE_PARAMETER
;
3736 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3737 used_operation
= USE_LOCALEINFO
;
3739 used_operation
= USE_SYSTEMDEFAULT
;
3742 /* Load the fields we need */
3743 switch(used_operation
)
3745 case USE_LOCALEINFO
:
3746 /* Specific to CURRENCYFMTA*/
3747 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3748 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3749 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3751 nPosOrder
= atoi(sPosOrder
);
3752 nNegOrder
= atoi(sNegOrder
);
3755 /* Specific to CURRENCYFMTA*/
3756 nNegOrder
= lpFormat
->NegativeOrder
;
3757 nPosOrder
= lpFormat
->PositiveOrder
;
3758 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3760 case USE_SYSTEMDEFAULT
:
3761 systemDefaultLCID
= GetSystemDefaultLCID();
3762 /* Specific to CURRENCYFMTA*/
3763 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3764 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3765 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3767 nPosOrder
= atoi(sPosOrder
);
3768 nNegOrder
= atoi(sNegOrder
);
3771 SetLastError(ERROR_INVALID_PARAMETER
);
3775 /* Construct a temporary number format structure */
3776 if (lpFormat
!= NULL
)
3778 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3779 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3780 numberFmt
.Grouping
= lpFormat
->Grouping
;
3781 numberFmt
.NegativeOrder
= 0;
3782 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3783 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3784 bValidFormat
= TRUE
;
3787 /* Make a call to GetNumberFormatA() */
3788 if (*lpvalue
== '-')
3790 bIsPositive
= FALSE
;
3791 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3796 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3802 /* construct the formatted string */
3807 case 0: /* Prefix, no separation */
3808 strcpy (pDestination
, sCurrencySymbol
);
3809 strcat (pDestination
, pNumberFormated
);
3811 case 1: /* Suffix, no separation */
3812 strcpy (pDestination
, pNumberFormated
);
3813 strcat (pDestination
, sCurrencySymbol
);
3815 case 2: /* Prefix, 1 char separation */
3816 strcpy (pDestination
, sCurrencySymbol
);
3817 strcat (pDestination
, " ");
3818 strcat (pDestination
, pNumberFormated
);
3820 case 3: /* Suffix, 1 char separation */
3821 strcpy (pDestination
, pNumberFormated
);
3822 strcat (pDestination
, " ");
3823 strcat (pDestination
, sCurrencySymbol
);
3826 SetLastError(ERROR_INVALID_PARAMETER
);
3830 else /* negative number */
3834 case 0: /* format: ($1.1) */
3835 strcpy (pDestination
, "(");
3836 strcat (pDestination
, sCurrencySymbol
);
3837 strcat (pDestination
, pNumberFormated
);
3838 strcat (pDestination
, ")");
3840 case 1: /* format: -$1.1 */
3841 strcpy (pDestination
, "-");
3842 strcat (pDestination
, sCurrencySymbol
);
3843 strcat (pDestination
, pNumberFormated
);
3845 case 2: /* format: $-1.1 */
3846 strcpy (pDestination
, sCurrencySymbol
);
3847 strcat (pDestination
, "-");
3848 strcat (pDestination
, pNumberFormated
);
3850 case 3: /* format: $1.1- */
3851 strcpy (pDestination
, sCurrencySymbol
);
3852 strcat (pDestination
, pNumberFormated
);
3853 strcat (pDestination
, "-");
3855 case 4: /* format: (1.1$) */
3856 strcpy (pDestination
, "(");
3857 strcat (pDestination
, pNumberFormated
);
3858 strcat (pDestination
, sCurrencySymbol
);
3859 strcat (pDestination
, ")");
3861 case 5: /* format: -1.1$ */
3862 strcpy (pDestination
, "-");
3863 strcat (pDestination
, pNumberFormated
);
3864 strcat (pDestination
, sCurrencySymbol
);
3866 case 6: /* format: 1.1-$ */
3867 strcpy (pDestination
, pNumberFormated
);
3868 strcat (pDestination
, "-");
3869 strcat (pDestination
, sCurrencySymbol
);
3871 case 7: /* format: 1.1$- */
3872 strcpy (pDestination
, pNumberFormated
);
3873 strcat (pDestination
, sCurrencySymbol
);
3874 strcat (pDestination
, "-");
3876 case 8: /* format: -1.1 $ */
3877 strcpy (pDestination
, "-");
3878 strcat (pDestination
, pNumberFormated
);
3879 strcat (pDestination
, " ");
3880 strcat (pDestination
, sCurrencySymbol
);
3882 case 9: /* format: -$ 1.1 */
3883 strcpy (pDestination
, "-");
3884 strcat (pDestination
, sCurrencySymbol
);
3885 strcat (pDestination
, " ");
3886 strcat (pDestination
, pNumberFormated
);
3888 case 10: /* format: 1.1 $- */
3889 strcpy (pDestination
, pNumberFormated
);
3890 strcat (pDestination
, " ");
3891 strcat (pDestination
, sCurrencySymbol
);
3892 strcat (pDestination
, "-");
3894 case 11: /* format: $ 1.1- */
3895 strcpy (pDestination
, sCurrencySymbol
);
3896 strcat (pDestination
, " ");
3897 strcat (pDestination
, pNumberFormated
);
3898 strcat (pDestination
, "-");
3900 case 12: /* format: $ -1.1 */
3901 strcpy (pDestination
, sCurrencySymbol
);
3902 strcat (pDestination
, " ");
3903 strcat (pDestination
, "-");
3904 strcat (pDestination
, pNumberFormated
);
3906 case 13: /* format: 1.1- $ */
3907 strcpy (pDestination
, pNumberFormated
);
3908 strcat (pDestination
, "-");
3909 strcat (pDestination
, " ");
3910 strcat (pDestination
, sCurrencySymbol
);
3912 case 14: /* format: ($ 1.1) */
3913 strcpy (pDestination
, "(");
3914 strcat (pDestination
, sCurrencySymbol
);
3915 strcat (pDestination
, " ");
3916 strcat (pDestination
, pNumberFormated
);
3917 strcat (pDestination
, ")");
3919 case 15: /* format: (1.1 $) */
3920 strcpy (pDestination
, "(");
3921 strcat (pDestination
, pNumberFormated
);
3922 strcat (pDestination
, " ");
3923 strcat (pDestination
, sCurrencySymbol
);
3924 strcat (pDestination
, ")");
3927 SetLastError(ERROR_INVALID_PARAMETER
);
3932 if (cchCurrency
== 0)
3933 return strlen(pDestination
) + 1;
3937 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
3938 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
3939 return strlen(lpCurrencyStr
);
3943 /**************************************************************************
3944 * GetCurrencyFormatW (KERNEL32.303)
3946 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
3947 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
3948 LPWSTR lpCurrencyStr
, int cchCurrency
)
3950 FIXME("This API function is NOT implemented !\n");
3954 /******************************************************************************
3955 * OLE2NLS_CheckLocale [intern]
3957 static LCID
OLE2NLS_CheckLocale (LCID locale
)
3960 { locale
= LOCALE_SYSTEM_DEFAULT
;
3963 if (locale
== LOCALE_SYSTEM_DEFAULT
)
3964 { return GetSystemDefaultLCID();
3966 else if (locale
== LOCALE_USER_DEFAULT
)
3967 { return GetUserDefaultLCID();
3973 /******************************************************************************
3974 * GetTimeFormatA [KERNEL32.422]
3975 * Makes an ASCII string of the time
3977 * Formats date according to format, or locale default if format is
3978 * NULL. The format consists of literal characters and fields as follows:
3980 * h hours with no leading zero (12-hour)
3981 * hh hours with full two digits
3982 * H hours with no leading zero (24-hour)
3983 * HH hours with full two digits
3984 * m minutes with no leading zero
3985 * mm minutes with full two digits
3986 * s seconds with no leading zero
3987 * ss seconds with full two digits
3988 * t time marker (A or P)
3989 * tt time marker (AM, PM)
3993 GetTimeFormatA(LCID locale
, /* in */
3994 DWORD flags
, /* in */
3995 LPSYSTEMTIME xtime
, /* in */
3996 LPCSTR format
, /* in */
3997 LPSTR timestr
, /* out */
3998 INT timelen
/* in */)
3999 { char format_buf
[40];
4002 LPSYSTEMTIME thistime
;
4004 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4007 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
4009 thislocale
= OLE2NLS_CheckLocale ( locale
);
4011 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4012 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4015 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4018 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4019 { thislocale
= GetSystemDefaultLCID();
4021 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
4022 thisformat
= format_buf
;
4025 { thisformat
= format
;
4028 if (xtime
== NULL
) /* NULL means use the current local time*/
4035 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4041 /******************************************************************************
4042 * GetTimeFormatW [KERNEL32.423]
4043 * Makes a Unicode string of the time
4046 GetTimeFormatW(LCID locale
, /* in */
4047 DWORD flags
, /* in */
4048 LPSYSTEMTIME xtime
, /* in */
4049 LPCWSTR format
, /* in */
4050 LPWSTR timestr
, /* out */
4051 INT timelen
/* in */)
4052 { WCHAR format_buf
[40];
4055 LPSYSTEMTIME thistime
;
4057 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4060 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
4061 xtime
,debugstr_w(format
),timestr
,timelen
);
4063 thislocale
= OLE2NLS_CheckLocale ( locale
);
4065 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4066 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4069 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4072 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4073 { thislocale
= GetSystemDefaultLCID();
4075 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
4076 thisformat
= format_buf
;
4079 { thisformat
= format
;
4082 if (xtime
== NULL
) /* NULL means use the current local time*/
4083 { GetSystemTime(&t
);
4090 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4095 /******************************************************************************
4096 * EnumCalendarInfoA [KERNEL32.196]
4098 BOOL WINAPI
EnumCalendarInfoA(
4099 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
4101 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);