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;
169 if (Options
.language
) {
170 return Languages
[Options
.language
].langid
;
175 char *lang
,*country
,*charset
,*dialect
,*next
;
178 buf
=getenv("LANGUAGE");
179 if (!buf
) buf
=getenv("LANG");
180 if (!buf
) buf
=getenv("LC_ALL");
181 if (!buf
) buf
=getenv("LC_MESSAGES");
182 if (!buf
) buf
=getenv("LC_CTYPE");
183 if (!buf
) return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
185 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C")) {
186 return MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
192 next
=strchr(lang
,':'); if (next
) *next
++='\0';
193 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
194 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
195 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
197 ret
=MAIN_GetLanguageID(lang
, country
, charset
, dialect
);
201 } while (lang
&& !ret
);
203 /* FIXME : are strings returned by getenv() to be free()'ed ? */
204 userLCID
= (LANGID
)ret
;
209 /***********************************************************************
210 * GetSystemDefaultLangID [KERNEL32.401]
212 LANGID WINAPI
GetSystemDefaultLangID(void)
214 return GetUserDefaultLangID();
217 /******************************************************************************
218 * ConvertDefaultLocale [KERNEL32.147]
220 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
222 { case LOCALE_SYSTEM_DEFAULT
:
223 return GetSystemDefaultLCID();
224 case LOCALE_USER_DEFAULT
:
225 return GetUserDefaultLCID();
227 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
229 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
232 /* Enhanced version of LoadStringW.
233 * It takes LanguageId to find and load language dependant resources.
234 * Resource is copied as is: "binary" strings are not truncated.
235 * Return: length of resource + 1 to distinguish absent resources
236 * from the resources with zero length.
238 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
246 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
249 hmem
= LoadResource(hModule
, hrsrc
);
252 p
= LockResource(hmem
);
253 string_num
= res_id
& 0x000f;
254 for(i
= 0; i
< string_num
; i
++)
257 TRACE("strlen = %d\n", (int)*p
);
259 if (buffer
== NULL
) return *p
;
260 i
= min(buflen
- 1, *p
);
262 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
263 buffer
[i
] = (WCHAR
) 0;
266 buffer
[0] = (WCHAR
) 0;
270 TRACE("\"%s\" loaded!\n", debugstr_w(buffer
));
274 /******************************************************************************
275 * GetLocaleInfoA [KERNEL32.342]
278 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
280 * MS online documentation states that the string returned is NULL terminated
281 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
282 * terminated string".
284 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
286 LPCSTR retString
= NULL
;
290 DWORD dwBufferSize
=128;
292 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
294 if (len
&& (! buf
) ) {
295 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
299 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
|| (LCType
& LOCALE_NOUSEROVERRIDE
) )
301 lcid
= GetSystemDefaultLCID();
303 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
305 lcid
= GetUserDefaultLCID();
307 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
309 /* First, check if it's in the registry. */
310 /* All user customized values are stored in the registry by SetLocaleInfo */
312 if ( (pacKey
= GetLocaleSubkeyName(LCType
)) )
317 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
319 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
320 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
322 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
323 &dwBufferSize
) == ERROR_SUCCESS
)
325 retString
= acBuffer
;
332 /* If not in the registry, get it from the NLS entries. */
337 /* check if language is registered in the kernel32 resources */
338 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LOWORD(lcid
),
339 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
340 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
341 retString
= acBuffer
;
346 /* if not found report a most descriptive error */
349 /* If we are through all of this, retLen should not be zero anymore.
350 If it is, the value is not supported */
352 while (locale_name2id
[i
].name
!=NULL
) {
353 if (LCType
== locale_name2id
[i
].id
) {
354 retString
= locale_name2id
[i
].name
;
360 FIXME("Unkown LC type %lX\n", LCType
);
362 ERR("'%s' not supported for your language (%04X)\n",
363 retString
, LOWORD(lcid
));
364 SetLastError(ERROR_INVALID_PARAMETER
);
368 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
369 if (LCType
== LOCALE_FONTSIGNATURE
) {
371 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
372 memcpy(buf
, retString
, len
);
375 return sizeof(FONTSIGNATURE
);
377 /* if len=0 return only the length, don't touch the buffer*/
379 lstrcpynA(buf
,retString
,len
);
380 return strlen(buf
) + 1;
382 return strlen(retString
)+1;
385 /******************************************************************************
386 * GetLocaleInfoW [KERNEL32.343]
389 * MS documentation states that len "specifies the size, in bytes (ANSI version)
390 * or characters (Unicode version), of" wbuf. Thus the number returned is
391 * the same between GetLocaleInfoW and GetLocaleInfoA.
393 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
397 if (len
&& (! wbuf
) )
398 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
402 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
403 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
405 if (wlen
&& len
) /* if len=0 return only the length*/
406 lstrcpynAtoW(wbuf
,abuf
,len
);
408 HeapFree(GetProcessHeap(),0,abuf
);
412 /******************************************************************************
414 * GetLocaleSubkeyName [helper function]
416 * - For use with the registry.
417 * - Gets the registry subkey name for a given lctype.
419 static char *GetLocaleSubkeyName( DWORD lctype
)
425 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
426 * the values are stored in the registry, confirmed under Windows,
427 * for the ones that actually assign pacKey. Cases that aren't finished
428 * have not been confirmed, so that must be done before they can be
431 case LOCALE_SDATE
: /* The date separator. */
434 case LOCALE_ICURRDIGITS
:
435 pacKey
= "iCurrDigits";
437 case LOCALE_SDECIMAL
:
440 case LOCALE_ICURRENCY
:
441 pacKey
= "iCurrency";
443 case LOCALE_SGROUPING
:
444 pacKey
= "sGrouping";
452 /* case LOCALE_ICALENDARTYPE: */
453 /* case LOCALE_IFIRSTDAYOFWEEK: */
454 /* case LOCALE_IFIRSTWEEKOFYEAR: */
455 /* case LOCALE_SYEARMONTH : */
456 /* case LOCALE_SPOSITIVESIGN : */
457 /* case LOCALE_IPAPERSIZE: */
459 case LOCALE_SLONGDATE
:
460 pacKey
= "sLongDate";
462 case LOCALE_SMONDECIMALSEP
:
463 pacKey
= "sMonDecimalSep";
465 case LOCALE_SMONGROUPING
:
466 pacKey
= "sMonGrouping";
468 case LOCALE_IMEASURE
:
471 case LOCALE_SMONTHOUSANDSEP
:
472 pacKey
= "sMonThousandSep";
474 case LOCALE_INEGCURR
:
477 case LOCALE_SNEGATIVESIGN
:
478 pacKey
= "sNegativeSign";
480 case LOCALE_INEGNUMBER
:
481 pacKey
= "iNegNumber";
483 case LOCALE_SSHORTDATE
:
484 pacKey
= "sShortDate";
486 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
495 case LOCALE_ITIME
: /* Time format specifier. */
498 case LOCALE_STHOUSAND
:
499 pacKey
= "sThousand";
501 case LOCALE_S1159
: /* AM */
507 case LOCALE_S2359
: /* PM */
510 case LOCALE_STIMEFORMAT
:
511 pacKey
= "sTimeFormat";
513 case LOCALE_SCURRENCY
:
514 pacKey
= "sCurrency";
517 /* The following are not listed under MSDN as supported,
518 * but seem to be used and also stored in the registry.
524 case LOCALE_SCOUNTRY
:
527 case LOCALE_ICOUNTRY
:
530 case LOCALE_SLANGUAGE
:
531 pacKey
= "sLanguage";
541 /******************************************************************************
542 * SetLocaleInfoA [KERNEL32.656]
544 BOOL16 WINAPI
SetLocaleInfoA(DWORD lcid
, DWORD lctype
, LPCSTR data
)
550 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
552 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
553 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
554 &hKey
) == ERROR_SUCCESS
)
556 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
557 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
559 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
566 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
571 /******************************************************************************
572 * IsValidLocale [KERNEL32.489]
574 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
576 /* check if language is registered in the kernel32 resources */
577 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
583 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
584 LPCWSTR name
, WORD LangID
, LONG lParam
)
588 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
589 sprintf(bufA
, "%08X", (UINT
)LangID
);
590 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
591 return lpfnLocaleEnum(bufW
);
594 /******************************************************************************
595 * EnumSystemLocalesW [KERNEL32.209]
597 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
600 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
602 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
603 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
604 (LONG
)lpfnLocaleEnum
);
609 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
610 LPCSTR name
, WORD LangID
, LONG lParam
)
613 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
614 sprintf(bufA
, "%08X", (UINT
)LangID
);
615 return lpfnLocaleEnum(bufA
);
618 /******************************************************************************
619 * EnumSystemLocalesA [KERNEL32.208]
621 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
624 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
626 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
627 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
628 (LONG
)lpfnLocaleEnum
);
633 static const unsigned char CT_CType2_LUT
[] = {
634 C2_NOTAPPLICABLE
, /* - 0 */
635 C2_NOTAPPLICABLE
, /* - 1 */
636 C2_NOTAPPLICABLE
, /* - 2 */
637 C2_NOTAPPLICABLE
, /* - 3 */
638 C2_NOTAPPLICABLE
, /* - 4 */
639 C2_NOTAPPLICABLE
, /* - 5 */
640 C2_NOTAPPLICABLE
, /* - 6 */
641 C2_NOTAPPLICABLE
, /* - 7 */
642 C2_NOTAPPLICABLE
, /* - 8 */
643 C2_SEGMENTSEPARATOR
, /* - 9 */
644 C2_NOTAPPLICABLE
, /* - 10 */
645 C2_NOTAPPLICABLE
, /* - 11 */
646 C2_NOTAPPLICABLE
, /* - 12 */
647 C2_NOTAPPLICABLE
, /* - 13 */
648 C2_NOTAPPLICABLE
, /* - 14 */
649 C2_NOTAPPLICABLE
, /* - 15 */
650 C2_NOTAPPLICABLE
, /* - 16 */
651 C2_NOTAPPLICABLE
, /* - 17 */
652 C2_NOTAPPLICABLE
, /* - 18 */
653 C2_NOTAPPLICABLE
, /* - 19 */
654 C2_NOTAPPLICABLE
, /* - 20 */
655 C2_NOTAPPLICABLE
, /* - 21 */
656 C2_NOTAPPLICABLE
, /* - 22 */
657 C2_NOTAPPLICABLE
, /* - 23 */
658 C2_NOTAPPLICABLE
, /* - 24 */
659 C2_NOTAPPLICABLE
, /* - 25 */
660 C2_NOTAPPLICABLE
, /* - 26 */
661 C2_NOTAPPLICABLE
, /* - 27 */
662 C2_NOTAPPLICABLE
, /* - 28 */
663 C2_NOTAPPLICABLE
, /* - 29 */
664 C2_NOTAPPLICABLE
, /* - 30 */
665 C2_NOTAPPLICABLE
, /* - 31 */
666 C2_WHITESPACE
, /* - 32 */
667 C2_OTHERNEUTRAL
, /* ! - 33 */
668 C2_OTHERNEUTRAL
, /* " - 34 */ /* " */
669 C2_EUROPETERMINATOR
, /* # - 35 */
670 C2_EUROPETERMINATOR
, /* $ - 36 */
671 C2_EUROPETERMINATOR
, /* % - 37 */
672 C2_LEFTTORIGHT
, /* & - 38 */
673 C2_OTHERNEUTRAL
, /* ' - 39 */
674 C2_OTHERNEUTRAL
, /* ( - 40 */
675 C2_OTHERNEUTRAL
, /* ) - 41 */
676 C2_OTHERNEUTRAL
, /* * - 42 */
677 C2_EUROPETERMINATOR
, /* + - 43 */
678 C2_COMMONSEPARATOR
, /* , - 44 */
679 C2_EUROPETERMINATOR
, /* - - 45 */
680 C2_EUROPESEPARATOR
, /* . - 46 */
681 C2_EUROPESEPARATOR
, /* / - 47 */
682 C2_EUROPENUMBER
, /* 0 - 48 */
683 C2_EUROPENUMBER
, /* 1 - 49 */
684 C2_EUROPENUMBER
, /* 2 - 50 */
685 C2_EUROPENUMBER
, /* 3 - 51 */
686 C2_EUROPENUMBER
, /* 4 - 52 */
687 C2_EUROPENUMBER
, /* 5 - 53 */
688 C2_EUROPENUMBER
, /* 6 - 54 */
689 C2_EUROPENUMBER
, /* 7 - 55 */
690 C2_EUROPENUMBER
, /* 8 - 56 */
691 C2_EUROPENUMBER
, /* 9 - 57 */
692 C2_COMMONSEPARATOR
, /* : - 58 */
693 C2_OTHERNEUTRAL
, /* ; - 59 */
694 C2_OTHERNEUTRAL
, /* < - 60 */
695 C2_OTHERNEUTRAL
, /* = - 61 */
696 C2_OTHERNEUTRAL
, /* > - 62 */
697 C2_OTHERNEUTRAL
, /* ? - 63 */
698 C2_LEFTTORIGHT
, /* @ - 64 */
699 C2_LEFTTORIGHT
, /* A - 65 */
700 C2_LEFTTORIGHT
, /* B - 66 */
701 C2_LEFTTORIGHT
, /* C - 67 */
702 C2_LEFTTORIGHT
, /* D - 68 */
703 C2_LEFTTORIGHT
, /* E - 69 */
704 C2_LEFTTORIGHT
, /* F - 70 */
705 C2_LEFTTORIGHT
, /* G - 71 */
706 C2_LEFTTORIGHT
, /* H - 72 */
707 C2_LEFTTORIGHT
, /* I - 73 */
708 C2_LEFTTORIGHT
, /* J - 74 */
709 C2_LEFTTORIGHT
, /* K - 75 */
710 C2_LEFTTORIGHT
, /* L - 76 */
711 C2_LEFTTORIGHT
, /* M - 77 */
712 C2_LEFTTORIGHT
, /* N - 78 */
713 C2_LEFTTORIGHT
, /* O - 79 */
714 C2_LEFTTORIGHT
, /* P - 80 */
715 C2_LEFTTORIGHT
, /* Q - 81 */
716 C2_LEFTTORIGHT
, /* R - 82 */
717 C2_LEFTTORIGHT
, /* S - 83 */
718 C2_LEFTTORIGHT
, /* T - 84 */
719 C2_LEFTTORIGHT
, /* U - 85 */
720 C2_LEFTTORIGHT
, /* V - 86 */
721 C2_LEFTTORIGHT
, /* W - 87 */
722 C2_LEFTTORIGHT
, /* X - 88 */
723 C2_LEFTTORIGHT
, /* Y - 89 */
724 C2_LEFTTORIGHT
, /* Z - 90 */
725 C2_OTHERNEUTRAL
, /* [ - 91 */
726 C2_OTHERNEUTRAL
, /* \ - 92 */
727 C2_OTHERNEUTRAL
, /* ] - 93 */
728 C2_OTHERNEUTRAL
, /* ^ - 94 */
729 C2_OTHERNEUTRAL
, /* _ - 95 */
730 C2_OTHERNEUTRAL
, /* ` - 96 */
731 C2_LEFTTORIGHT
, /* a - 97 */
732 C2_LEFTTORIGHT
, /* b - 98 */
733 C2_LEFTTORIGHT
, /* c - 99 */
734 C2_LEFTTORIGHT
, /* d - 100 */
735 C2_LEFTTORIGHT
, /* e - 101 */
736 C2_LEFTTORIGHT
, /* f - 102 */
737 C2_LEFTTORIGHT
, /* g - 103 */
738 C2_LEFTTORIGHT
, /* h - 104 */
739 C2_LEFTTORIGHT
, /* i - 105 */
740 C2_LEFTTORIGHT
, /* j - 106 */
741 C2_LEFTTORIGHT
, /* k - 107 */
742 C2_LEFTTORIGHT
, /* l - 108 */
743 C2_LEFTTORIGHT
, /* m - 109 */
744 C2_LEFTTORIGHT
, /* n - 110 */
745 C2_LEFTTORIGHT
, /* o - 111 */
746 C2_LEFTTORIGHT
, /* p - 112 */
747 C2_LEFTTORIGHT
, /* q - 113 */
748 C2_LEFTTORIGHT
, /* r - 114 */
749 C2_LEFTTORIGHT
, /* s - 115 */
750 C2_LEFTTORIGHT
, /* t - 116 */
751 C2_LEFTTORIGHT
, /* u - 117 */
752 C2_LEFTTORIGHT
, /* v - 118 */
753 C2_LEFTTORIGHT
, /* w - 119 */
754 C2_LEFTTORIGHT
, /* x - 120 */
755 C2_LEFTTORIGHT
, /* y - 121 */
756 C2_LEFTTORIGHT
, /* z - 122 */
757 C2_OTHERNEUTRAL
, /* { - 123 */
758 C2_OTHERNEUTRAL
, /* | - 124 */
759 C2_OTHERNEUTRAL
, /* } - 125 */
760 C2_OTHERNEUTRAL
, /* ~ - 126 */
761 C2_NOTAPPLICABLE
, /* \x7f - 127 */
762 C2_NOTAPPLICABLE
, /* € - 128 */
763 C2_NOTAPPLICABLE
, /* � - 129 */
764 C2_OTHERNEUTRAL
, /* ‚ - 130 */
765 C2_LEFTTORIGHT
, /* ƒ - 131 */
766 C2_OTHERNEUTRAL
, /* „ - 132 */
767 C2_OTHERNEUTRAL
, /* … - 133 */
768 C2_OTHERNEUTRAL
, /* † - 134 */
769 C2_OTHERNEUTRAL
, /* ‡ - 135 */
770 C2_LEFTTORIGHT
, /* ˆ - 136 */
771 C2_EUROPETERMINATOR
, /* ‰ - 137 */
772 C2_LEFTTORIGHT
, /* Š - 138 */
773 C2_OTHERNEUTRAL
, /* ‹ - 139 */
774 C2_LEFTTORIGHT
, /* Œ - 140 */
775 C2_NOTAPPLICABLE
, /* � - 141 */
776 C2_NOTAPPLICABLE
, /* Ž - 142 */
777 C2_NOTAPPLICABLE
, /* � - 143 */
778 C2_NOTAPPLICABLE
, /* � - 144 */
779 C2_OTHERNEUTRAL
, /* ‘ - 145 */
780 C2_OTHERNEUTRAL
, /* ’ - 146 */
781 C2_OTHERNEUTRAL
, /* “ - 147 */
782 C2_OTHERNEUTRAL
, /* ” - 148 */
783 C2_OTHERNEUTRAL
, /* • - 149 */
784 C2_OTHERNEUTRAL
, /* – - 150 */
785 C2_OTHERNEUTRAL
, /* — - 151 */
786 C2_LEFTTORIGHT
, /* ˜ - 152 */
787 C2_OTHERNEUTRAL
, /* ™ - 153 */
788 C2_LEFTTORIGHT
, /* š - 154 */
789 C2_OTHERNEUTRAL
, /* › - 155 */
790 C2_LEFTTORIGHT
, /* œ - 156 */
791 C2_NOTAPPLICABLE
, /* � - 157 */
792 C2_NOTAPPLICABLE
, /* ž - 158 */
793 C2_LEFTTORIGHT
, /* Ÿ - 159 */
794 C2_WHITESPACE
, /* - 160 */
795 C2_OTHERNEUTRAL
, /* ¡ - 161 */
796 C2_EUROPETERMINATOR
, /* ¢ - 162 */
797 C2_EUROPETERMINATOR
, /* £ - 163 */
798 C2_EUROPETERMINATOR
, /* ¤ - 164 */
799 C2_EUROPETERMINATOR
, /* ¥ - 165 */
800 C2_OTHERNEUTRAL
, /* ¦ - 166 */
801 C2_OTHERNEUTRAL
, /* § - 167 */
802 C2_OTHERNEUTRAL
, /* ¨ - 168 */
803 C2_OTHERNEUTRAL
, /* © - 169 */
804 C2_OTHERNEUTRAL
, /* ª - 170 */
805 C2_OTHERNEUTRAL
, /* « - 171 */
806 C2_OTHERNEUTRAL
, /* ¬ - 172 */
807 C2_OTHERNEUTRAL
, /* - 173 */
808 C2_OTHERNEUTRAL
, /* ® - 174 */
809 C2_OTHERNEUTRAL
, /* ¯ - 175 */
810 C2_EUROPETERMINATOR
, /* ° - 176 */
811 C2_EUROPETERMINATOR
, /* ± - 177 */
812 C2_EUROPENUMBER
, /* ² - 178 */
813 C2_EUROPENUMBER
, /* ³ - 179 */
814 C2_OTHERNEUTRAL
, /* ´ - 180 */
815 C2_OTHERNEUTRAL
, /* µ - 181 */
816 C2_OTHERNEUTRAL
, /* ¶ - 182 */
817 C2_OTHERNEUTRAL
, /* · - 183 */
818 C2_OTHERNEUTRAL
, /* ¸ - 184 */
819 C2_EUROPENUMBER
, /* ¹ - 185 */
820 C2_OTHERNEUTRAL
, /* º - 186 */
821 C2_OTHERNEUTRAL
, /* » - 187 */
822 C2_OTHERNEUTRAL
, /* ¼ - 188 */
823 C2_OTHERNEUTRAL
, /* ½ - 189 */
824 C2_OTHERNEUTRAL
, /* ¾ - 190 */
825 C2_OTHERNEUTRAL
, /* ¿ - 191 */
826 C2_LEFTTORIGHT
, /* À - 192 */
827 C2_LEFTTORIGHT
, /* Á - 193 */
828 C2_LEFTTORIGHT
, /* Â - 194 */
829 C2_LEFTTORIGHT
, /* Ã - 195 */
830 C2_LEFTTORIGHT
, /* Ä - 196 */
831 C2_LEFTTORIGHT
, /* Å - 197 */
832 C2_LEFTTORIGHT
, /* Æ - 198 */
833 C2_LEFTTORIGHT
, /* Ç - 199 */
834 C2_LEFTTORIGHT
, /* È - 200 */
835 C2_LEFTTORIGHT
, /* É - 201 */
836 C2_LEFTTORIGHT
, /* Ê - 202 */
837 C2_LEFTTORIGHT
, /* Ë - 203 */
838 C2_LEFTTORIGHT
, /* Ì - 204 */
839 C2_LEFTTORIGHT
, /* Í - 205 */
840 C2_LEFTTORIGHT
, /* Î - 206 */
841 C2_LEFTTORIGHT
, /* Ï - 207 */
842 C2_LEFTTORIGHT
, /* Ð - 208 */
843 C2_LEFTTORIGHT
, /* Ñ - 209 */
844 C2_LEFTTORIGHT
, /* Ò - 210 */
845 C2_LEFTTORIGHT
, /* Ó - 211 */
846 C2_LEFTTORIGHT
, /* Ô - 212 */
847 C2_LEFTTORIGHT
, /* Õ - 213 */
848 C2_LEFTTORIGHT
, /* Ö - 214 */
849 C2_OTHERNEUTRAL
, /* × - 215 */
850 C2_LEFTTORIGHT
, /* Ø - 216 */
851 C2_LEFTTORIGHT
, /* Ù - 217 */
852 C2_LEFTTORIGHT
, /* Ú - 218 */
853 C2_LEFTTORIGHT
, /* Û - 219 */
854 C2_LEFTTORIGHT
, /* Ü - 220 */
855 C2_LEFTTORIGHT
, /* Ý - 221 */
856 C2_LEFTTORIGHT
, /* Þ - 222 */
857 C2_LEFTTORIGHT
, /* ß - 223 */
858 C2_LEFTTORIGHT
, /* à - 224 */
859 C2_LEFTTORIGHT
, /* á - 225 */
860 C2_LEFTTORIGHT
, /* â - 226 */
861 C2_LEFTTORIGHT
, /* ã - 227 */
862 C2_LEFTTORIGHT
, /* ä - 228 */
863 C2_LEFTTORIGHT
, /* å - 229 */
864 C2_LEFTTORIGHT
, /* æ - 230 */
865 C2_LEFTTORIGHT
, /* ç - 231 */
866 C2_LEFTTORIGHT
, /* è - 232 */
867 C2_LEFTTORIGHT
, /* é - 233 */
868 C2_LEFTTORIGHT
, /* ê - 234 */
869 C2_LEFTTORIGHT
, /* ë - 235 */
870 C2_LEFTTORIGHT
, /* ì - 236 */
871 C2_LEFTTORIGHT
, /* í - 237 */
872 C2_LEFTTORIGHT
, /* î - 238 */
873 C2_LEFTTORIGHT
, /* ï - 239 */
874 C2_LEFTTORIGHT
, /* ð - 240 */
875 C2_LEFTTORIGHT
, /* ñ - 241 */
876 C2_LEFTTORIGHT
, /* ò - 242 */
877 C2_LEFTTORIGHT
, /* ó - 243 */
878 C2_LEFTTORIGHT
, /* ô - 244 */
879 C2_LEFTTORIGHT
, /* õ - 245 */
880 C2_LEFTTORIGHT
, /* ö - 246 */
881 C2_OTHERNEUTRAL
, /* ÷ - 247 */
882 C2_LEFTTORIGHT
, /* ø - 248 */
883 C2_LEFTTORIGHT
, /* ù - 249 */
884 C2_LEFTTORIGHT
, /* ú - 250 */
885 C2_LEFTTORIGHT
, /* û - 251 */
886 C2_LEFTTORIGHT
, /* ü - 252 */
887 C2_LEFTTORIGHT
, /* ý - 253 */
888 C2_LEFTTORIGHT
, /* þ - 254 */
889 C2_LEFTTORIGHT
/* ÿ - 255 */
892 const WORD OLE2NLS_CT_CType3_LUT
[] = {
927 0x0448, /* " - 34 */ /* " */
993 0x8040, /* d - 100 */
994 0x8040, /* e - 101 */
995 0x8040, /* f - 102 */
996 0x8040, /* g - 103 */
997 0x8040, /* h - 104 */
998 0x8040, /* i - 105 */
999 0x8040, /* j - 106 */
1000 0x8040, /* k - 107 */
1001 0x8040, /* l - 108 */
1002 0x8040, /* m - 109 */
1003 0x8040, /* n - 110 */
1004 0x8040, /* o - 111 */
1005 0x8040, /* p - 112 */
1006 0x8040, /* q - 113 */
1007 0x8040, /* r - 114 */
1008 0x8040, /* s - 115 */
1009 0x8040, /* t - 116 */
1010 0x8040, /* u - 117 */
1011 0x8040, /* v - 118 */
1012 0x8040, /* w - 119 */
1013 0x8040, /* x - 120 */
1014 0x8040, /* y - 121 */
1015 0x8040, /* z - 122 */
1016 0x0048, /* { - 123 */
1017 0x0048, /* | - 124 */
1018 0x0048, /* } - 125 */
1019 0x0448, /* ~ - 126 */
1020 0x0000, /* \x7f - 127 */
1021 0x0000, /* € - 128 */
1022 0x0000, /* � - 129 */
1023 0x0008, /* ‚ - 130 */
1024 0x8000, /* ƒ - 131 */
1025 0x0008, /* „ - 132 */
1026 0x0008, /* … - 133 */
1027 0x0008, /* † - 134 */
1028 0x0008, /* ‡ - 135 */
1029 0x0001, /* ˆ - 136 */
1030 0x0008, /* ‰ - 137 */
1031 0x8003, /* Š - 138 */
1032 0x0008, /* ‹ - 139 */
1033 0x8000, /* Œ - 140 */
1034 0x0000, /* � - 141 */
1035 0x0000, /* Ž - 142 */
1036 0x0000, /* � - 143 */
1037 0x0000, /* � - 144 */
1038 0x0088, /* ‘ - 145 */
1039 0x0088, /* ’ - 146 */
1040 0x0088, /* “ - 147 */
1041 0x0088, /* ” - 148 */
1042 0x0008, /* • - 149 */
1043 0x0400, /* – - 150 */
1044 0x0400, /* — - 151 */
1045 0x0408, /* ˜ - 152 */
1046 0x0000, /* ™ - 153 */
1047 0x8003, /* š - 154 */
1048 0x0008, /* › - 155 */
1049 0x8000, /* œ - 156 */
1050 0x0000, /* � - 157 */
1051 0x0000, /* ž - 158 */
1052 0x8003, /* Ÿ - 159 */
1054 0x0008, /* ¡ - 161 */
1055 0x0048, /* ¢ - 162 */
1056 0x0048, /* £ - 163 */
1057 0x0008, /* ¤ - 164 */
1058 0x0048, /* ¥ - 165 */
1059 0x0048, /* ¦ - 166 */
1060 0x0008, /* § - 167 */
1061 0x0408, /* ¨ - 168 */
1062 0x0008, /* © - 169 */
1063 0x0400, /* ª - 170 */
1064 0x0008, /* « - 171 */
1065 0x0048, /* ¬ - 172 */
1066 0x0408, /* - 173 */
1067 0x0008, /* ® - 174 */
1068 0x0448, /* ¯ - 175 */
1069 0x0008, /* ° - 176 */
1070 0x0008, /* ± - 177 */
1071 0x0000, /* ² - 178 */
1072 0x0000, /* ³ - 179 */
1073 0x0408, /* ´ - 180 */
1074 0x0008, /* µ - 181 */
1075 0x0008, /* ¶ - 182 */
1076 0x0008, /* · - 183 */
1077 0x0408, /* ¸ - 184 */
1078 0x0000, /* ¹ - 185 */
1079 0x0400, /* º - 186 */
1080 0x0008, /* » - 187 */
1081 0x0000, /* ¼ - 188 */
1082 0x0000, /* ½ - 189 */
1083 0x0000, /* ¾ - 190 */
1084 0x0008, /* ¿ - 191 */
1085 0x8003, /* À - 192 */
1086 0x8003, /* Á - 193 */
1087 0x8003, /* Â - 194 */
1088 0x8003, /* Ã - 195 */
1089 0x8003, /* Ä - 196 */
1090 0x8003, /* Å - 197 */
1091 0x8000, /* Æ - 198 */
1092 0x8003, /* Ç - 199 */
1093 0x8003, /* È - 200 */
1094 0x8003, /* É - 201 */
1095 0x8003, /* Ê - 202 */
1096 0x8003, /* Ë - 203 */
1097 0x8003, /* Ì - 204 */
1098 0x8003, /* Í - 205 */
1099 0x8003, /* Î - 206 */
1100 0x8003, /* Ï - 207 */
1101 0x8000, /* Ð - 208 */
1102 0x8003, /* Ñ - 209 */
1103 0x8003, /* Ò - 210 */
1104 0x8003, /* Ó - 211 */
1105 0x8003, /* Ô - 212 */
1106 0x8003, /* Õ - 213 */
1107 0x8003, /* Ö - 214 */
1108 0x0008, /* × - 215 */
1109 0x8003, /* Ø - 216 */
1110 0x8003, /* Ù - 217 */
1111 0x8003, /* Ú - 218 */
1112 0x8003, /* Û - 219 */
1113 0x8003, /* Ü - 220 */
1114 0x8003, /* Ý - 221 */
1115 0x8000, /* Þ - 222 */
1116 0x8000, /* ß - 223 */
1117 0x8003, /* à - 224 */
1118 0x8003, /* á - 225 */
1119 0x8003, /* â - 226 */
1120 0x8003, /* ã - 227 */
1121 0x8003, /* ä - 228 */
1122 0x8003, /* å - 229 */
1123 0x8000, /* æ - 230 */
1124 0x8003, /* ç - 231 */
1125 0x8003, /* è - 232 */
1126 0x8003, /* é - 233 */
1127 0x8003, /* ê - 234 */
1128 0x8003, /* ë - 235 */
1129 0x8003, /* ì - 236 */
1130 0x8003, /* í - 237 */
1131 0x8003, /* î - 238 */
1132 0x8003, /* ï - 239 */
1133 0x8000, /* ð - 240 */
1134 0x8003, /* ñ - 241 */
1135 0x8003, /* ò - 242 */
1136 0x8003, /* ó - 243 */
1137 0x8003, /* ô - 244 */
1138 0x8003, /* õ - 245 */
1139 0x8003, /* ö - 246 */
1140 0x0008, /* ÷ - 247 */
1141 0x8003, /* ø - 248 */
1142 0x8003, /* ù - 249 */
1143 0x8003, /* ú - 250 */
1144 0x8003, /* û - 251 */
1145 0x8003, /* ü - 252 */
1146 0x8003, /* ý - 253 */
1147 0x8000, /* þ - 254 */
1148 0x8003 /* ÿ - 255 */
1151 /******************************************************************************
1152 * GetStringTypeA [KERNEL32.396]
1154 BOOL WINAPI
GetStringTypeA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1155 INT cchSrc
,LPWORD chartype
)
1157 return GetStringTypeExA(locale
,dwInfoType
,src
,cchSrc
,chartype
);
1160 /******************************************************************************
1161 * GetStringTypeExA [KERNEL32.397]
1163 * FIXME: Ignores the locale.
1165 BOOL WINAPI
GetStringTypeExA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1166 INT cchSrc
,LPWORD chartype
)
1170 if ((src
==NULL
) || (chartype
==NULL
) || (src
==(LPSTR
)chartype
))
1172 SetLastError(ERROR_INVALID_PARAMETER
);
1177 cchSrc
=lstrlenA(src
)+1;
1179 switch (dwInfoType
) {
1181 for (i
=0;i
<cchSrc
;i
++)
1184 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1185 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1186 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1187 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1188 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1189 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1190 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1191 /* FIXME: isblank() is a GNU extension */
1192 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1193 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1199 for (i
=0;i
<cchSrc
;i
++)
1201 chartype
[i
]=(WORD
)CT_CType2_LUT
[i
];
1206 for (i
=0;i
<cchSrc
;i
++)
1208 chartype
[i
]=OLE2NLS_CT_CType3_LUT
[i
];
1213 ERR("Unknown dwInfoType:%ld\n",dwInfoType
);
1218 /******************************************************************************
1219 * GetStringTypeW [KERNEL32.399]
1222 * Yes, this is missing LCID locale. MS fault.
1224 BOOL WINAPI
GetStringTypeW(DWORD dwInfoType
,LPCWSTR src
,INT cchSrc
,
1227 return GetStringTypeExW(0/*defaultlocale*/,dwInfoType
,src
,cchSrc
,chartype
);
1230 /******************************************************************************
1231 * GetStringTypeExW [KERNEL32.398]
1233 * FIXME: unicode chars are assumed chars
1235 BOOL WINAPI
GetStringTypeExW(LCID locale
,DWORD dwInfoType
,LPCWSTR src
,
1236 INT cchSrc
,LPWORD chartype
)
1242 cchSrc
=lstrlenW(src
)+1;
1244 switch (dwInfoType
) {
1246 FIXME("CT_CTYPE2 not supported.\n");
1249 FIXME("CT_CTYPE3 not supported.\n");
1253 for (i
=0;i
<cchSrc
;i
++) {
1255 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1256 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1257 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1258 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1259 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1260 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1261 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1262 /* FIXME: isblank() is a GNU extension */
1263 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1264 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1270 /***********************************************************************
1271 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1273 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
1278 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
)
, LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1281 /***********************************************************************
1282 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1284 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
1289 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
)
, LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1293 static const unsigned char LCM_Unicode_LUT
[] = {
1326 7 , 28, /* ! - 33 */
1327 7 , 29, /* " - 34 */ /* " */
1328 7 , 31, /* # - 35 */
1329 7 , 33, /* $ - 36 */
1330 7 , 35, /* % - 37 */
1331 7 , 37, /* & - 38 */
1332 6 , 128, /* ' - 39 */
1333 7 , 39, /* ( - 40 */
1334 7 , 42, /* ) - 41 */
1335 7 , 45, /* * - 42 */
1337 7 , 47, /* , - 44 */
1338 6 , 130, /* - - 45 */
1339 7 , 51, /* . - 46 */
1340 7 , 53, /* / - 47 */
1341 12 , 3, /* 0 - 48 */
1342 12 , 33, /* 1 - 49 */
1343 12 , 51, /* 2 - 50 */
1344 12 , 70, /* 3 - 51 */
1345 12 , 88, /* 4 - 52 */
1346 12 , 106, /* 5 - 53 */
1347 12 , 125, /* 6 - 54 */
1348 12 , 144, /* 7 - 55 */
1349 12 , 162, /* 8 - 56 */
1350 12 , 180, /* 9 - 57 */
1351 7 , 55, /* : - 58 */
1352 7 , 58, /* ; - 59 */
1353 8 , 14, /* < - 60 */
1354 8 , 18, /* = - 61 */
1355 8 , 20, /* > - 62 */
1356 7 , 60, /* ? - 63 */
1357 7 , 62, /* @ - 64 */
1358 14 , 2, /* A - 65 */
1359 14 , 9, /* B - 66 */
1360 14 , 10, /* C - 67 */
1361 14 , 26, /* D - 68 */
1362 14 , 33, /* E - 69 */
1363 14 , 35, /* F - 70 */
1364 14 , 37, /* G - 71 */
1365 14 , 44, /* H - 72 */
1366 14 , 50, /* I - 73 */
1367 14 , 53, /* J - 74 */
1368 14 , 54, /* K - 75 */
1369 14 , 72, /* L - 76 */
1370 14 , 81, /* M - 77 */
1371 14 , 112, /* N - 78 */
1372 14 , 124, /* O - 79 */
1373 14 , 126, /* P - 80 */
1374 14 , 137, /* Q - 81 */
1375 14 , 138, /* R - 82 */
1376 14 , 145, /* S - 83 */
1377 14 , 153, /* T - 84 */
1378 14 , 159, /* U - 85 */
1379 14 , 162, /* V - 86 */
1380 14 , 164, /* W - 87 */
1381 14 , 166, /* X - 88 */
1382 14 , 167, /* Y - 89 */
1383 14 , 169, /* Z - 90 */
1384 7 , 63, /* [ - 91 */
1385 7 , 65, /* \ - 92 */
1386 7 , 66, /* ] - 93 */
1387 7 , 67, /* ^ - 94 */
1388 7 , 68, /* _ - 95 */
1389 7 , 72, /* ` - 96 */
1390 14 , 2, /* a - 97 */
1391 14 , 9, /* b - 98 */
1392 14 , 10, /* c - 99 */
1393 14 , 26, /* d - 100 */
1394 14 , 33, /* e - 101 */
1395 14 , 35, /* f - 102 */
1396 14 , 37, /* g - 103 */
1397 14 , 44, /* h - 104 */
1398 14 , 50, /* i - 105 */
1399 14 , 53, /* j - 106 */
1400 14 , 54, /* k - 107 */
1401 14 , 72, /* l - 108 */
1402 14 , 81, /* m - 109 */
1403 14 , 112, /* n - 110 */
1404 14 , 124, /* o - 111 */
1405 14 , 126, /* p - 112 */
1406 14 , 137, /* q - 113 */
1407 14 , 138, /* r - 114 */
1408 14 , 145, /* s - 115 */
1409 14 , 153, /* t - 116 */
1410 14 , 159, /* u - 117 */
1411 14 , 162, /* v - 118 */
1412 14 , 164, /* w - 119 */
1413 14 , 166, /* x - 120 */
1414 14 , 167, /* y - 121 */
1415 14 , 169, /* z - 122 */
1416 7 , 74, /* { - 123 */
1417 7 , 76, /* | - 124 */
1418 7 , 78, /* } - 125 */
1419 7 , 80, /* ~ - 126 */
1420 6 , 29, /* \x7f - 127 */
1421 6 , 30, /* € - 128 */
1422 6 , 31, /* � - 129 */
1423 7 , 123, /* ‚ - 130 */
1424 14 , 35, /* ƒ - 131 */
1425 7 , 127, /* „ - 132 */
1426 10 , 21, /* … - 133 */
1427 10 , 15, /* † - 134 */
1428 10 , 16, /* ‡ - 135 */
1429 7 , 67, /* ˆ - 136 */
1430 10 , 22, /* ‰ - 137 */
1431 14 , 145, /* Š - 138 */
1432 7 , 136, /* ‹ - 139 */
1433 14 + 16 , 124, /* Œ - 140 */
1434 6 , 43, /* � - 141 */
1435 6 , 44, /* Ž - 142 */
1436 6 , 45, /* � - 143 */
1437 6 , 46, /* � - 144 */
1438 7 , 121, /* ‘ - 145 */
1439 7 , 122, /* ’ - 146 */
1440 7 , 125, /* “ - 147 */
1441 7 , 126, /* ” - 148 */
1442 10 , 17, /* • - 149 */
1443 6 , 137, /* – - 150 */
1444 6 , 139, /* — - 151 */
1445 7 , 93, /* ˜ - 152 */
1446 14 , 156, /* ™ - 153 */
1447 14 , 145, /* š - 154 */
1448 7 , 137, /* › - 155 */
1449 14 + 16 , 124, /* œ - 156 */
1450 6 , 59, /* � - 157 */
1451 6 , 60, /* ž - 158 */
1452 14 , 167, /* Ÿ - 159 */
1454 7 , 81, /* ¡ - 161 */
1455 10 , 2, /* ¢ - 162 */
1456 10 , 3, /* £ - 163 */
1457 10 , 4, /* ¤ - 164 */
1458 10 , 5, /* ¥ - 165 */
1459 7 , 82, /* ¦ - 166 */
1460 10 , 6, /* § - 167 */
1461 7 , 83, /* ¨ - 168 */
1462 10 , 7, /* © - 169 */
1463 14 , 2, /* ª - 170 */
1464 8 , 24, /* « - 171 */
1465 10 , 8, /* ¬ - 172 */
1466 6 , 131, /* - 173 */
1467 10 , 9, /* ® - 174 */
1468 7 , 84, /* ¯ - 175 */
1469 10 , 10, /* ° - 176 */
1470 8 , 23, /* ± - 177 */
1471 12 , 51, /* ² - 178 */
1472 12 , 70, /* ³ - 179 */
1473 7 , 85, /* ´ - 180 */
1474 10 , 11, /* µ - 181 */
1475 10 , 12, /* ¶ - 182 */
1476 10 , 13, /* · - 183 */
1477 7 , 86, /* ¸ - 184 */
1478 12 , 33, /* ¹ - 185 */
1479 14 , 124, /* º - 186 */
1480 8 , 26, /* » - 187 */
1481 12 , 21, /* ¼ - 188 */
1482 12 , 25, /* ½ - 189 */
1483 12 , 29, /* ¾ - 190 */
1484 7 , 87, /* ¿ - 191 */
1485 14 , 2, /* À - 192 */
1486 14 , 2, /* Á - 193 */
1487 14 , 2, /* Â - 194 */
1488 14 , 2, /* Ã - 195 */
1489 14 , 2, /* Ä - 196 */
1490 14 , 2, /* Å - 197 */
1491 14 + 16 , 2, /* Æ - 198 */
1492 14 , 10, /* Ç - 199 */
1493 14 , 33, /* È - 200 */
1494 14 , 33, /* É - 201 */
1495 14 , 33, /* Ê - 202 */
1496 14 , 33, /* Ë - 203 */
1497 14 , 50, /* Ì - 204 */
1498 14 , 50, /* Í - 205 */
1499 14 , 50, /* Î - 206 */
1500 14 , 50, /* Ï - 207 */
1501 14 , 26, /* Ð - 208 */
1502 14 , 112, /* Ñ - 209 */
1503 14 , 124, /* Ò - 210 */
1504 14 , 124, /* Ó - 211 */
1505 14 , 124, /* Ô - 212 */
1506 14 , 124, /* Õ - 213 */
1507 14 , 124, /* Ö - 214 */
1508 8 , 28, /* × - 215 */
1509 14 , 124, /* Ø - 216 */
1510 14 , 159, /* Ù - 217 */
1511 14 , 159, /* Ú - 218 */
1512 14 , 159, /* Û - 219 */
1513 14 , 159, /* Ü - 220 */
1514 14 , 167, /* Ý - 221 */
1515 14 + 32 , 153, /* Þ - 222 */
1516 14 + 48 , 145, /* ß - 223 */
1517 14 , 2, /* à - 224 */
1518 14 , 2, /* á - 225 */
1519 14 , 2, /* â - 226 */
1520 14 , 2, /* ã - 227 */
1521 14 , 2, /* ä - 228 */
1522 14 , 2, /* å - 229 */
1523 14 + 16 , 2, /* æ - 230 */
1524 14 , 10, /* ç - 231 */
1525 14 , 33, /* è - 232 */
1526 14 , 33, /* é - 233 */
1527 14 , 33, /* ê - 234 */
1528 14 , 33, /* ë - 235 */
1529 14 , 50, /* ì - 236 */
1530 14 , 50, /* í - 237 */
1531 14 , 50, /* î - 238 */
1532 14 , 50, /* ï - 239 */
1533 14 , 26, /* ð - 240 */
1534 14 , 112, /* ñ - 241 */
1535 14 , 124, /* ò - 242 */
1536 14 , 124, /* ó - 243 */
1537 14 , 124, /* ô - 244 */
1538 14 , 124, /* õ - 245 */
1539 14 , 124, /* ö - 246 */
1540 8 , 29, /* ÷ - 247 */
1541 14 , 124, /* ø - 248 */
1542 14 , 159, /* ù - 249 */
1543 14 , 159, /* ú - 250 */
1544 14 , 159, /* û - 251 */
1545 14 , 159, /* ü - 252 */
1546 14 , 167, /* ý - 253 */
1547 14 + 32 , 153, /* þ - 254 */
1548 14 , 167 /* ÿ - 255 */ };
1550 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1552 #define LCM_Diacritic_Start 131
1554 static const unsigned char LCM_Diacritic_LUT
[] = {
1682 /******************************************************************************
1683 * OLE2NLS_isPunctuation [INTERNAL]
1685 static int OLE2NLS_isPunctuation(unsigned char c
)
1687 /* "punctuation character" in this context is a character which is
1688 considered "less important" during word sort comparison.
1689 See LCMapString implementation for the precise definition
1690 of "less important". */
1692 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1695 /******************************************************************************
1696 * OLE2NLS_isNonSpacing [INTERNAL]
1698 static int OLE2NLS_isNonSpacing(unsigned char c
)
1700 /* This function is used by LCMapStringA. Characters
1701 for which it returns true are ignored when mapping a
1702 string with NORM_IGNORENONSPACE */
1703 return ((c
==136) || (c
==170) || (c
==186));
1706 /******************************************************************************
1707 * OLE2NLS_isSymbol [INTERNAL]
1709 static int OLE2NLS_isSymbol(unsigned char c
)
1711 /* This function is used by LCMapStringA. Characters
1712 for which it returns true are ignored when mapping a
1713 string with NORM_IGNORESYMBOLS */
1714 return ( (c
!=0) && !IsCharAlphaNumericA(c
) );
1717 /******************************************************************************
1718 * identity [Internal]
1720 static int identity(int c
)
1725 /*************************************************************************
1726 * LCMapStringA [KERNEL32.492]
1728 * Convert a string, or generate a sort key from it.
1730 * If (mapflags & LCMAP_SORTKEY), the function will generate
1731 * a sort key for the source string. Else, it will convert it
1732 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1736 * Success : length of the result string.
1739 * If called with scrlen = -1, the function will compute the length
1740 * of the 0-terminated string strsrc by itself.
1742 * If called with dstlen = 0, returns the buffer length that
1743 * would be required.
1745 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1746 * as if they are equal.
1747 * In the only code page implemented so far, there may not be
1748 * wide characters in strings passed to LCMapStringA,
1749 * so there is nothing to be done for this flag.
1751 INT WINAPI
LCMapStringA(
1752 LCID lcid
/* locale identifier created with MAKELCID;
1753 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1754 predefined values. */,
1755 DWORD mapflags
/* flags */,
1756 LPCSTR srcstr
/* source buffer */,
1757 INT srclen
/* source length */,
1758 LPSTR dststr
/* destination buffer */,
1759 INT dstlen
/* destination buffer length */)
1763 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1764 lcid
,mapflags
,srcstr
,srclen
,dststr
,dstlen
);
1766 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1768 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr
, dststr
);
1769 SetLastError(ERROR_INVALID_PARAMETER
);
1773 srclen
= lstrlenA(srcstr
) + 1 ; /* (include final '\0') */
1775 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1779 NORM_IGNORENONSPACE | \
1781 NORM_IGNOREWIDTH | \
1782 NORM_IGNOREKANATYPE)
1783 /* FIXME: as long as we don't support Kanakana nor Hirigana
1784 * characters, we can support NORM_IGNOREKANATYPE
1786 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1788 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1789 "unimplemented flags: 0x%08lx\n",
1796 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1800 if ( !(mapflags
& LCMAP_SORTKEY
) )
1803 int (*f
)(int) = identity
;
1804 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1805 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1807 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1809 /* For some values of mapflags, the length of the resulting
1810 string is not known at this point. Windows does map the string
1811 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1815 /* Compute required length */
1816 for (i
=j
=0; i
< srclen
; i
++)
1818 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1819 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1831 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1835 if (mapflags
& LCMAP_UPPERCASE
)
1837 else if (mapflags
& LCMAP_LOWERCASE
)
1839 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1840 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1842 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1843 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1845 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1852 /* FIXME: This function completely ignores the "lcid" parameter. */
1853 /* else ... (mapflags & LCMAP_SORTKEY) */
1857 int diacritic_len
=0;
1858 int delayed_punctuation_len
=0;
1859 char *case_component
;
1860 char *diacritic_component
;
1861 char *delayed_punctuation_component
;
1863 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1865 /* compute how much room we will need */
1866 for (i
=0;i
<srclen
;i
++)
1869 unsigned char source_char
= srcstr
[i
];
1870 if (source_char
!='\0')
1872 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
1875 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
1876 unicode_len
++; /* double letter */
1880 delayed_punctuation_len
++;
1884 if (isupper(source_char
))
1885 case_len
=unicode_len
;
1887 ofs
= source_char
- LCM_Diacritic_Start
;
1888 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
1889 diacritic_len
=unicode_len
;
1892 if (mapflags
& NORM_IGNORECASE
)
1894 if (mapflags
& NORM_IGNORENONSPACE
)
1897 room
= 2 * unicode_len
/* "unicode" component */
1898 + diacritic_len
/* "diacritic" component */
1899 + case_len
/* "case" component */
1900 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
1901 + 4 /* four '\1' separators */
1902 + 1 ; /* terminal '\0' */
1905 else if (dstlen
<room
)
1907 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1911 /*FIXME the Pointercheck should not be nessesary */
1912 if (IsBadWritePtr (dststr
,room
))
1913 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
1914 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1918 /* locate each component, write separators */
1919 diacritic_component
= dststr
+ 2*unicode_len
;
1920 *diacritic_component
++ = '\1';
1921 case_component
= diacritic_component
+ diacritic_len
;
1922 *case_component
++ = '\1';
1923 delayed_punctuation_component
= case_component
+ case_len
;
1924 *delayed_punctuation_component
++ = '\1';
1925 *delayed_punctuation_component
++ = '\1';
1927 /* read source string char by char, write
1928 corresponding weight in each component. */
1929 for (i
=0,count
=0;i
<srclen
;i
++)
1931 unsigned char source_char
=srcstr
[i
];
1932 if (source_char
!='\0')
1935 type
= LCM_Unicode_LUT
[-2+2*source_char
];
1936 longcode
= type
>> 4;
1938 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
1940 UINT16 encrypted_location
= (1<<15) + 7 + 4*count
;
1941 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
1942 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
1943 /* big-endian is used here because it lets string comparison be
1944 compatible with numerical comparison */
1946 *delayed_punctuation_component
++ = type
;
1947 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
1948 /* assumption : a punctuation character is never a
1949 double or accented letter */
1953 dststr
[2*count
] = type
;
1954 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
1958 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1959 if (count
<diacritic_len
)
1960 diacritic_component
[count
] = 2; /* assumption: a double letter
1961 is never accented */
1964 dststr
[2*count
] = type
;
1965 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
1966 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1967 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1968 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1972 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1973 if (count
<diacritic_len
)
1975 int ofs
= source_char
- LCM_Diacritic_Start
;
1976 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
1982 dststr
[room
-1] = '\0';
1987 /*************************************************************************
1988 * LCMapStringW [KERNEL32.493]
1990 * Convert a string, or generate a sort key from it.
1994 * See LCMapStringA for documentation
1996 INT WINAPI
LCMapStringW(
1997 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
2002 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2003 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
2005 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
2007 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
2008 SetLastError(ERROR_INVALID_PARAMETER
);
2012 srclen
= lstrlenW(srcstr
)+1;
2014 /* FIXME: Both this function and it's companion LCMapStringA()
2015 * completely ignore the "lcid" parameter. In place of the "lcid"
2016 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2017 * environment variable prior to invoking this function. */
2018 if (mapflags
& LCMAP_SORTKEY
)
2020 /* Possible values of LC_COLLATE. */
2021 char *lc_collate_default
= 0; /* value prior to this function */
2022 char *lc_collate_env
= 0; /* value retrieved from the environment */
2024 /* General purpose index into strings of any type. */
2027 /* Lengths of various strings where the length is measured in
2028 * wide characters for wide character strings and in bytes for
2029 * native strings. The lengths include the NULL terminator. */
2030 size_t returned_len
= 0;
2031 size_t src_native_len
= 0;
2032 size_t dst_native_len
= 0;
2033 size_t dststr_libc_len
= 0;
2035 /* Native (character set determined by locale) versions of the
2036 * strings source and destination strings. */
2037 LPSTR src_native
= 0;
2038 LPSTR dst_native
= 0;
2040 /* Version of the source and destination strings using the
2041 * "wchar_t" Unicode data type needed by various libc functions. */
2042 wchar_t *srcstr_libc
= 0;
2043 wchar_t *dststr_libc
= 0;
2045 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2046 srclen
* sizeof(wchar_t))))
2048 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2049 srclen
* sizeof(wchar_t));
2050 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2054 /* Convert source string to a libc Unicode string. */
2055 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
2057 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
2060 /* src_native should contain at most 3 bytes for each
2061 * multibyte characters in the original srcstr string. */
2062 src_native_len
= 3 * srclen
;
2063 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
2066 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
2067 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2068 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2072 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2073 * current value is backed up so it can be restored after the
2074 * last LC_COLLATE sensitive function returns.
2076 * Even though the locale is adjusted for a minimum amount of
2077 * time a race condition exists where other threads may be
2078 * affected if they invoke LC_COLLATE sensitive functions. One
2079 * possible solution is to wrap all LC_COLLATE sensitive Wine
2080 * functions, like LCMapStringW(), in a mutex.
2082 * Another enhancement to the following would be to set the
2083 * LC_COLLATE locale category as a function of the "lcid"
2084 * parameter instead of the "LC_COLLATE" environment variable. */
2085 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
2087 ERR("Unable to query the LC_COLLATE catagory\n");
2088 SetLastError(ERROR_INVALID_PARAMETER
);
2089 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2090 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2094 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
2096 ERR("Unable to inherit the LC_COLLATE locale category from the "
2097 "environment. The \"LC_COLLATE\" environment variable is "
2098 "\"%s\".\n", getenv("LC_COLLATE") ?
2099 getenv("LC_COLLATE") : "<unset>");
2100 SetLastError(ERROR_INVALID_PARAMETER
);
2101 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2102 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2106 TRACE("lc_collate_default = %s\n", lc_collate_default
);
2107 TRACE("lc_collate_env = %s\n", lc_collate_env
);
2109 /* Convert the libc Unicode string to a native multibyte character
2111 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
2112 if(returned_len
== 0)
2114 LPSTR srcstr_ascii
= (LPSTR
)HEAP_strdupWtoA(GetProcessHeap(),
2116 ERR("wcstombs failed. The string specified (%s) may contains an "
2117 "invalid character.\n", srcstr_ascii
);
2118 SetLastError(ERROR_INVALID_PARAMETER
);
2119 if(srcstr_ascii
) HeapFree(GetProcessHeap(), 0, srcstr_ascii
);
2120 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2121 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2122 setlocale(LC_COLLATE
, lc_collate_default
);
2125 else if(returned_len
> src_native_len
)
2127 src_native
[src_native_len
- 1] = 0;
2128 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2129 "than expected (%d bytes).\n", src_native
, returned_len
,
2132 /* Since this is an internal error I'm not sure what the correct
2134 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2136 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2137 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2138 setlocale(LC_COLLATE
, lc_collate_default
);
2141 src_native_len
= returned_len
;
2143 TRACE("src_native = %s src_native_len = %d\n",
2144 src_native
, src_native_len
);
2146 /* dst_native seems to contain at most 4 bytes for each byte in
2147 * the original src_native string. Change if need be since this
2148 * isn't documented by the strxfrm() man page. */
2149 dst_native_len
= 4 * src_native_len
;
2150 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
2152 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
2153 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2154 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2155 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2156 setlocale(LC_COLLATE
, lc_collate_default
);
2160 /* The actual translation is done by the following call to
2161 * strxfrm(). The surrounding code could have been simplified
2162 * by calling wcsxfrm() instead except that wcsxfrm() is not
2163 * available on older Linux systems (RedHat 4.1 with
2166 * Also, it is possible that the translation could be done by
2167 * various tables as it is done in LCMapStringA(). However, I'm
2168 * not sure what those tables are. */
2169 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
2171 if(returned_len
> dst_native_len
)
2173 dst_native
[dst_native_len
- 1] = 0;
2174 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2175 "than expected (%d bytes).\n", dst_native
, returned_len
,
2178 /* Since this is an internal error I'm not sure what the correct
2180 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2182 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2183 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2184 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2185 setlocale(LC_COLLATE
, lc_collate_default
);
2188 dst_native_len
= returned_len
;
2190 TRACE("dst_native = %s dst_native_len = %d\n",
2191 dst_native
, dst_native_len
);
2193 dststr_libc_len
= dst_native_len
;
2194 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2195 dststr_libc_len
* sizeof(wchar_t))))
2197 ERR("Unable to allocate %d bytes for dststr_libc\n",
2198 dststr_libc_len
* sizeof(wchar_t));
2199 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2200 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2201 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2202 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2203 setlocale(LC_COLLATE
, lc_collate_default
);
2207 /* Convert the native multibyte string to a libc Unicode string. */
2208 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
2210 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2211 * function has returned. */
2212 setlocale(LC_COLLATE
, lc_collate_default
);
2214 if(returned_len
== 0)
2216 ERR("mbstowcs failed. The native version of the translated string "
2217 "(%s) may contain an invalid character.\n", dst_native
);
2218 SetLastError(ERROR_INVALID_PARAMETER
);
2219 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2220 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2221 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2222 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2227 if(returned_len
> dstlen
)
2229 ERR("mbstowcs returned a string that was longer (%d chars) "
2230 "than the buffer provided (%d chars).\n", returned_len
,
2232 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2233 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2234 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2235 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2236 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2239 dstlen
= returned_len
;
2241 /* Convert a libc Unicode string to the destination string. */
2242 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
2244 dststr
[str_idx
] = dststr_libc
[str_idx
];
2246 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2247 *(((int *)dststr
) + 0),
2248 *(((int *)dststr
) + 1),
2249 *(((int *)dststr
) + 2),
2250 *(((int *)dststr
) + 3));
2254 dstlen
= returned_len
;
2256 TRACE("dstlen (return) = %d\n", dstlen
);
2257 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2258 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2259 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2260 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2265 int (*f
)(int)=identity
;
2271 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2275 if (mapflags
& LCMAP_UPPERCASE
)
2277 else if (mapflags
& LCMAP_LOWERCASE
)
2279 for (i
=0; i
< srclen
; i
++)
2280 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
2286 /***********************************************************************
2287 * OLE2NLS_EstimateMappingLength
2289 * Estimates the number of characters required to hold the string
2290 * computed by LCMapStringA.
2292 * The size is always over-estimated, with a fixed limit on the
2293 * amount of estimation error.
2295 * Note that len == -1 is not permitted.
2297 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
2298 LPCSTR str
, DWORD len
)
2300 /* Estimate only for small strings to keep the estimation error from
2301 * becoming too large. */
2302 if (len
< 128) return len
* 8 + 5;
2303 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
2306 /******************************************************************************
2307 * CompareStringA [KERNEL32.143]
2308 * Compares two strings using locale
2312 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2317 * Defaults to a word sort, but uses a string sort if
2318 * SORT_STRINGSORT is set.
2319 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2323 * This implementation ignores the locale
2327 * Quite inefficient.
2329 UINT WINAPI
CompareStringA(
2330 DWORD lcid
, /* locale ID */
2331 DWORD fdwStyle
, /* comparison-style options */
2332 LPCSTR s1
, /* first string */
2333 DWORD l1
, /* length of first string */
2334 LPCSTR s2
, /* second string */
2335 DWORD l2
) /* length of second string */
2337 int mapstring_flags
;
2341 TRACE("%s and %s\n",
2342 debugstr_a (s1
), debugstr_a (s2
));
2344 if ( (s1
==NULL
) || (s2
==NULL
) )
2346 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1
, s2
);
2347 SetLastError(ERROR_INVALID_PARAMETER
);
2351 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2352 FIXME("IGNORESYMBOLS not supported\n");
2354 if (l1
== -1) l1
= lstrlenA(s1
);
2355 if (l2
== -1) l2
= lstrlenA(s2
);
2357 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
2358 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
2359 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
2361 if ((len1
==0)||(len2
==0))
2362 return 0; /* something wrong happened */
2364 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
2366 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
2367 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
2369 ERR("Bug in LCmapStringA.\n");
2374 /* strcmp doesn't necessarily return -1, 0, or 1 */
2375 result
= strcmp(sk1
,sk2
);
2377 HeapFree(GetProcessHeap(),0,sk1
);
2384 /* must be greater, if we reach this point */
2388 /******************************************************************************
2389 * CompareStringW [KERNEL32.144]
2390 * This implementation ignores the locale
2391 * FIXME : Does only string sort. Should
2392 * be reimplemented the same way as CompareStringA.
2394 UINT WINAPI
CompareStringW(DWORD lcid
, DWORD fdwStyle
,
2395 LPCWSTR s1
, DWORD l1
, LPCWSTR s2
,DWORD l2
)
2398 if(fdwStyle
& NORM_IGNORENONSPACE
)
2399 FIXME("IGNORENONSPACE not supprted\n");
2400 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2401 FIXME("IGNORESYMBOLS not supported\n");
2403 /* Is strcmp defaulting to string sort or to word sort?? */
2404 /* FIXME: Handle NORM_STRINGSORT */
2405 l1
= (l1
==-1)?lstrlenW(s1
):l1
;
2406 l2
= (l2
==-1)?lstrlenW(s2
):l2
;
2407 len
= l1
<l2
? l1
:l2
;
2408 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
2409 /* not equal, return 1 or 3 */
2410 if(ret
!=0) return ret
+2;
2411 /* same len, return 2 */
2412 if(l1
==l2
) return 2;
2413 /* the longer one is lexically greater */
2414 return (l1
<l2
)? 1 : 3;
2417 /******************************************************************************
2418 * OLE_GetFormatA [Internal]
2421 * If datelen == 0, it should return the reguired string length.
2423 This function implements stuff for GetDateFormat() and
2426 d single-digit (no leading zero) day (of month)
2427 dd two-digit day (of month)
2428 ddd short day-of-week name
2429 dddd long day-of-week name
2430 M single-digit month
2432 MMM short month name
2433 MMMM full month name
2434 y two-digit year, no leading 0
2436 yyyy four-digit year
2438 h hours with no leading zero (12-hour)
2439 hh hours with full two digits
2440 H hours with no leading zero (24-hour)
2441 HH hours with full two digits
2442 m minutes with no leading zero
2443 mm minutes with full two digits
2444 s seconds with no leading zero
2445 ss seconds with full two digits
2446 t time marker (A or P)
2447 tt time marker (AM, PM)
2448 '' used to quote literal characters
2449 '' (within a quoted string) indicates a literal '
2451 These functions REQUIRE valid locale, date, and format.
2453 static INT
OLE_GetFormatA(LCID locale
,
2457 LPCSTR _format
, /*in*/
2462 int count
, type
, inquote
, Overflow
;
2468 const char * _dgfmt
[] = { "%d", "%02d" };
2469 const char ** dgfmt
= _dgfmt
- 1;
2471 /* report, for debugging */
2472 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2473 locale
, flags
, tflags
,
2474 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2475 _format
, _format
, date
, datelen
);
2478 FIXME("datelen = 0, returning 255\n");
2482 /* initalize state variables and output buffer */
2484 count
= 0; inquote
= 0; Overflow
= 0;
2486 date
[0] = buf
[0] = '\0';
2488 strcpy(format
,_format
);
2490 /* alter the formatstring, while it works for all languages now in wine
2491 its possible that it fails when the time looks like ss:mm:hh as example*/
2492 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2493 { if ((pos
= strstr ( format
, ":mm")))
2494 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2497 if (tflags
& (TIME_NOSECONDS
))
2498 { if ((pos
= strstr ( format
, ":ss")))
2499 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2503 for (inpos
= 0;; inpos
++) {
2504 /* 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]); */
2506 if (format
[inpos
] == '\'') {
2507 if (format
[inpos
+1] == '\'') {
2509 date
[outpos
++] = '\'';
2512 continue; /* we did nothing to the output */
2514 } else if (format
[inpos
] == '\0') {
2515 date
[outpos
++] = '\0';
2516 if (outpos
> datelen
) Overflow
= 1;
2519 date
[outpos
++] = format
[inpos
];
2520 if (outpos
> datelen
) {
2522 date
[outpos
-1] = '\0'; /* this is the last place where
2523 it's safe to write */
2527 } else if ( (count
&& (format
[inpos
] != type
))
2529 || (count
== 2 && strchr("ghHmst", type
)) )
2533 GetLocaleInfoA(locale
,
2535 + xtime
->wDayOfWeek
- 1,
2537 } else if (count
== 3) {
2538 GetLocaleInfoA(locale
,
2539 LOCALE_SABBREVDAYNAME1
2540 + xtime
->wDayOfWeek
- 1,
2543 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2545 } else if (type
== 'M') {
2547 GetLocaleInfoA(locale
,
2548 LOCALE_SABBREVMONTHNAME1
2549 + xtime
->wMonth
- 1,
2551 } else if (count
== 4) {
2552 GetLocaleInfoA(locale
,
2554 + xtime
->wMonth
- 1,
2557 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2559 } else if (type
== 'y') {
2561 sprintf(buf
, "%d", xtime
->wYear
);
2562 } else if (count
== 3) {
2564 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2566 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2568 } else if (type
== 'g') {
2570 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2574 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2576 } else if (type
== 'h') {
2577 /* gives us hours 1:00 -- 12:00 */
2578 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2579 } else if (type
== 'H') {
2581 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2582 } else if ( type
== 'm') {
2583 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2584 } else if ( type
== 's') {
2585 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2586 } else if (type
== 't') {
2588 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2589 } else if (count
== 2) {
2590 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2591 GetLocaleInfoA(locale
,
2593 ? LOCALE_S1159
: LOCALE_S2359
,
2598 /* we need to check the next char in the format string
2599 again, no matter what happened */
2602 /* add the contents of buf to the output */
2603 buflen
= strlen(buf
);
2604 if (outpos
+ buflen
< datelen
) {
2605 date
[outpos
] = '\0'; /* for strcat to hook onto */
2609 date
[outpos
] = '\0';
2610 strncat(date
, buf
, datelen
- outpos
);
2611 date
[datelen
- 1] = '\0';
2612 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2613 WARN("insufficient buffer\n");
2617 /* reset the variables we used to keep track of this item */
2620 } else if (format
[inpos
] == '\0') {
2621 /* we can't check for this at the loop-head, because
2622 that breaks the printing of the last format-item */
2623 date
[outpos
] = '\0';
2626 /* continuing a code for an item */
2629 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2630 type
= format
[inpos
];
2633 } else if (format
[inpos
] == '\'') {
2637 date
[outpos
++] = format
[inpos
];
2639 /* now deal with a possible buffer overflow */
2640 if (outpos
>= datelen
) {
2641 date
[datelen
- 1] = '\0';
2642 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2648 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2651 /* finish it off with a string terminator */
2654 if (outpos
> datelen
-1) outpos
= datelen
-1;
2655 date
[outpos
] = '\0';
2657 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2662 /******************************************************************************
2663 * OLE_GetFormatW [INTERNAL]
2665 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2668 LPWSTR output
, INT outlen
)
2671 int count
, type
=0, inquote
;
2672 int Overflow
; /* loop check */
2675 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2676 WCHAR arg2
[] = {'%','0','2','d',0};
2678 int datevars
=0, timevars
=0;
2684 /* make a debug report */
2685 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2686 "%p with max len %d\n",
2687 locale
, flags
, tflags
,
2688 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2689 debugstr_w(format
), format
, output
, outlen
);
2692 FIXME("outlen = 0, returning 255\n");
2696 /* initialize state variables */
2699 inquote
= Overflow
= 0;
2700 /* this is really just a sanity check */
2701 output
[0] = buf
[0] = 0;
2703 /* this loop is the core of the function */
2704 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2706 if (format
[inpos
] == (WCHAR
) '\'') {
2707 if (format
[inpos
+1] == '\'') {
2709 output
[outpos
++] = '\'';
2714 } else if (format
[inpos
] == 0) {
2715 output
[outpos
++] = 0;
2716 if (outpos
> outlen
) Overflow
= 1;
2717 break; /* normal exit (within a quote) */
2719 output
[outpos
++] = format
[inpos
]; /* copy input */
2720 if (outpos
> outlen
) {
2722 output
[outpos
-1] = 0;
2726 } else if ( (count
&& (format
[inpos
] != type
))
2727 || ( (count
==4 && type
=='y') ||
2728 (count
==4 && type
=='M') ||
2729 (count
==4 && type
=='d') ||
2730 (count
==2 && type
=='g') ||
2731 (count
==2 && type
=='h') ||
2732 (count
==2 && type
=='H') ||
2733 (count
==2 && type
=='m') ||
2734 (count
==2 && type
=='s') ||
2735 (count
==2 && type
=='t') ) ) {
2738 GetLocaleInfoW(locale
,
2739 LOCALE_SDAYNAME1
+ xtime
->wDayOfWeek
-1,
2740 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2741 } else if (count
== 3) {
2742 GetLocaleInfoW(locale
,
2743 LOCALE_SABBREVDAYNAME1
+
2744 xtime
->wDayOfWeek
-1,
2745 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2747 wsnprintfW(buf
, 5, argarr
[count
], xtime
->wDay
);
2749 } else if (type
== 'M') {
2751 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2752 xtime
->wMonth
-1, buf
,
2753 sizeof(buf
)/sizeof(WCHAR
) );
2754 } else if (count
== 3) {
2755 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2756 xtime
->wMonth
-1, buf
,
2757 sizeof(buf
)/sizeof(WCHAR
) );
2759 wsnprintfW(buf
, 5, argarr
[count
], xtime
->wMonth
);
2761 } else if (type
== 'y') {
2763 wsnprintfW(buf
, 6, argarr
[1] /* "%d" */,
2765 } else if (count
== 3) {
2766 lstrcpynAtoW(buf
, "yyy", 5);
2768 wsnprintfW(buf
, 6, argarr
[count
],
2769 xtime
->wYear
% 100);
2771 } else if (type
== 'g') {
2773 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2774 lstrcpynAtoW(buf
, "AD", 5);
2776 /* Win API sez we copy it verbatim */
2777 lstrcpynAtoW(buf
, "g", 5);
2779 } else if (type
== 'h') {
2780 /* hours 1:00-12:00 --- is this right? */
2781 wsnprintfW(buf
, 5, argarr
[count
],
2782 (xtime
->wHour
-1)%12 +1);
2783 } else if (type
== 'H') {
2784 wsnprintfW(buf
, 5, argarr
[count
],
2786 } else if (type
== 'm' ) {
2787 wsnprintfW(buf
, 5, argarr
[count
],
2789 } else if (type
== 's' ) {
2790 wsnprintfW(buf
, 5, argarr
[count
],
2792 } else if (type
== 't') {
2793 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2794 LOCALE_S1159
: LOCALE_S2359
,
2801 /* no matter what happened, we need to check this next
2802 character the next time we loop through */
2805 /* cat buf onto the output */
2806 outlen
= lstrlenW(buf
);
2807 if (outpos
+ buflen
< outlen
) {
2808 lstrcpyW( output
+ outpos
, buf
);
2811 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2813 break; /* Abnormal exit */
2816 /* reset the variables we used this time */
2819 } else if (format
[inpos
] == 0) {
2820 /* we can't check for this at the beginning, because that
2821 would keep us from printing a format spec that ended the
2824 break; /* NORMAL EXIT */
2826 /* how we keep track of the middle of a format spec */
2829 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2830 format
[inpos
]=='M' ||
2831 format
[inpos
]=='y' ||
2832 format
[inpos
]=='g') ) ||
2833 (timevars
&& (format
[inpos
]=='H' ||
2834 format
[inpos
]=='h' ||
2835 format
[inpos
]=='m' ||
2836 format
[inpos
]=='s' ||
2837 format
[inpos
]=='t') ) ) {
2838 type
= format
[inpos
];
2841 } else if (format
[inpos
] == '\'') {
2845 /* unquoted literals */
2846 output
[outpos
++] = format
[inpos
];
2851 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2852 WARN(" buffer overflow\n");
2855 /* final string terminator and sanity check */
2857 if (outpos
> outlen
-1) outpos
= outlen
-1;
2858 output
[outpos
] = '0';
2860 TRACE(" returning %s\n", debugstr_w(output
));
2862 return (!Overflow
) ? outlen
: 0;
2867 /******************************************************************************
2868 * GetDateFormatA [KERNEL32.310]
2869 * Makes an ASCII string of the date
2871 * This function uses format to format the date, or, if format
2872 * is NULL, uses the default for the locale. format is a string
2873 * of literal fields and characters as follows:
2875 * - d single-digit (no leading zero) day (of month)
2876 * - dd two-digit day (of month)
2877 * - ddd short day-of-week name
2878 * - dddd long day-of-week name
2879 * - M single-digit month
2880 * - MM two-digit month
2881 * - MMM short month name
2882 * - MMMM full month name
2883 * - y two-digit year, no leading 0
2884 * - yy two-digit year
2885 * - yyyy four-digit year
2889 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
2891 LPCSTR format
, LPSTR date
,INT datelen
)
2894 char format_buf
[40];
2897 LPSYSTEMTIME thistime
;
2901 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2902 locale
,flags
,xtime
,format
,date
,datelen
);
2905 locale
= LOCALE_SYSTEM_DEFAULT
;
2908 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
2909 thislocale
= GetSystemDefaultLCID();
2910 } else if (locale
== LOCALE_USER_DEFAULT
) {
2911 thislocale
= GetUserDefaultLCID();
2913 thislocale
= locale
;
2916 if (xtime
== NULL
) {
2923 if (format
== NULL
) {
2924 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
2926 : LOCALE_SSHORTDATE
),
2927 format_buf
, sizeof(format_buf
));
2928 thisformat
= format_buf
;
2930 thisformat
= format
;
2934 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
2939 "GetDateFormatA() returning %d, with data=%s\n",
2944 /******************************************************************************
2945 * GetDateFormatW [KERNEL32.311]
2946 * Makes a Unicode string of the date
2948 * Acts the same as GetDateFormatA(), except that it's Unicode.
2949 * Accepts & returns sizes as counts of Unicode characters.
2952 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
2955 LPWSTR date
, INT datelen
)
2957 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
2959 FIXME("STUB (should call OLE_GetFormatW)\n");
2960 lstrcpynW(date
, datearr
, datelen
);
2961 return ( datelen
< 9) ? datelen
: 9;
2966 /**************************************************************************
2967 * EnumDateFormatsA (KERNEL32.198)
2969 BOOL WINAPI
EnumDateFormatsA(
2970 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2972 LCID Loc
= GetUserDefaultLCID();
2973 if(!lpDateFmtEnumProc
)
2975 SetLastError(ERROR_INVALID_PARAMETER
);
2982 case 0x00000407: /* (Loc,"de_DE") */
2986 case DATE_SHORTDATE
:
2987 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2988 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
2989 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2990 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2993 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
2994 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
2995 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
2998 FIXME("Unknown date format (%ld)\n", dwFlags
);
2999 SetLastError(ERROR_INVALID_PARAMETER
);
3004 case 0x0000040c: /* (Loc,"fr_FR") */
3008 case DATE_SHORTDATE
:
3009 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3010 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3011 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3012 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3015 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
3016 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
3017 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3020 FIXME("Unknown date format (%ld)\n", dwFlags
);
3021 SetLastError(ERROR_INVALID_PARAMETER
);
3026 case 0x00000c0c: /* (Loc,"fr_CA") */
3030 case DATE_SHORTDATE
:
3031 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3032 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3033 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
3034 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3037 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
3038 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
3041 FIXME("Unknown date format (%ld)\n", dwFlags
);
3042 SetLastError(ERROR_INVALID_PARAMETER
);
3047 case 0x00000809: /* (Loc,"en_UK") */
3051 case DATE_SHORTDATE
:
3052 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3053 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3054 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3055 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3058 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3059 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3062 FIXME("Unknown date format (%ld)\n", dwFlags
);
3063 SetLastError(ERROR_INVALID_PARAMETER
);
3068 case 0x00000c09: /* (Loc,"en_AU") */
3072 case DATE_SHORTDATE
:
3073 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3074 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3075 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3078 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
3079 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3082 FIXME("Unknown date format (%ld)\n", dwFlags
);
3083 SetLastError(ERROR_INVALID_PARAMETER
);
3088 case 0x00001009: /* (Loc,"en_CA") */
3092 case DATE_SHORTDATE
:
3093 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3094 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3095 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3096 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
3099 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
3100 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
3103 FIXME("Unknown date format (%ld)\n", dwFlags
);
3104 SetLastError(ERROR_INVALID_PARAMETER
);
3109 case 0x00001409: /* (Loc,"en_NZ") */
3113 case DATE_SHORTDATE
:
3114 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3115 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3116 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3119 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3120 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
3123 FIXME("Unknown date format (%ld)\n", dwFlags
);
3124 SetLastError(ERROR_INVALID_PARAMETER
);
3129 case 0x00001809: /* (Loc,"en_IE") */
3133 case DATE_SHORTDATE
:
3134 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3135 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3136 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3139 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3140 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3143 FIXME("Unknown date format (%ld)\n", dwFlags
);
3144 SetLastError(ERROR_INVALID_PARAMETER
);
3149 case 0x00001c09: /* (Loc,"en_ZA") */
3153 case DATE_SHORTDATE
:
3154 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3157 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3160 FIXME("Unknown date format (%ld)\n", dwFlags
);
3161 SetLastError(ERROR_INVALID_PARAMETER
);
3166 case 0x00002009: /* (Loc,"en_JM") */
3170 case DATE_SHORTDATE
:
3171 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3174 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
3175 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
3176 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
3177 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
3180 FIXME("Unknown date format (%ld)\n", dwFlags
);
3181 SetLastError(ERROR_INVALID_PARAMETER
);
3186 case 0x00002809: /* (Loc,"en_BZ") */
3187 case 0x00002c09: /* (Loc,"en_TT") */
3191 case DATE_SHORTDATE
:
3192 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3195 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
3198 FIXME("Unknown date format (%ld)\n", dwFlags
);
3199 SetLastError(ERROR_INVALID_PARAMETER
);
3204 default: /* default to US English "en_US" */
3208 case DATE_SHORTDATE
:
3209 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
3210 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
3211 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
3212 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
3213 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3214 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
3217 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
3218 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
3219 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
3220 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
3223 FIXME("Unknown date format (%ld)\n", dwFlags
);
3224 SetLastError(ERROR_INVALID_PARAMETER
);
3231 /**************************************************************************
3232 * EnumDateFormatsW (KERNEL32.199)
3234 BOOL WINAPI
EnumDateFormatsW(
3235 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3237 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
3238 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3242 /**************************************************************************
3243 * EnumTimeFormatsA (KERNEL32.210)
3245 BOOL WINAPI
EnumTimeFormatsA(
3246 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3248 LCID Loc
= GetUserDefaultLCID();
3249 if(!lpTimeFmtEnumProc
)
3251 SetLastError(ERROR_INVALID_PARAMETER
);
3256 FIXME("Unknown time format (%ld)\n", dwFlags
);
3261 case 0x00000407: /* (Loc,"de_DE") */
3263 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3264 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3265 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3266 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
3267 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
3271 case 0x0000040c: /* (Loc,"fr_FR") */
3272 case 0x00000c0c: /* (Loc,"fr_CA") */
3274 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
3275 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3276 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3277 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3278 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
3282 case 0x00000809: /* (Loc,"en_UK") */
3283 case 0x00000c09: /* (Loc,"en_AU") */
3284 case 0x00001409: /* (Loc,"en_NZ") */
3285 case 0x00001809: /* (Loc,"en_IE") */
3287 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3288 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3289 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3293 case 0x00001c09: /* (Loc,"en_ZA") */
3294 case 0x00002809: /* (Loc,"en_BZ") */
3295 case 0x00002c09: /* (Loc,"en_TT") */
3297 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3298 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3302 default: /* default to US style "en_US" */
3304 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3305 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3306 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3307 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3313 /**************************************************************************
3314 * EnumTimeFormatsW (KERNEL32.211)
3316 BOOL WINAPI
EnumTimeFormatsW(
3317 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3319 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
3320 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3324 /**************************************************************************
3325 * This function is used just locally !
3326 * Description: Inverts a string.
3328 static void OLE_InvertString(char* string
)
3330 char sTmpArray
[128];
3333 for (counter
= strlen(string
); counter
> 0; counter
--)
3335 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
3338 memcpy(sTmpArray
+ i
, "\0", 1);
3339 strcpy(string
, sTmpArray
);
3342 /***************************************************************************************
3343 * This function is used just locally !
3344 * Description: Test if the given string (psNumber) is valid or not.
3345 * The valid characters are the following:
3346 * - Characters '0' through '9'.
3347 * - One decimal point (dot) if the number is a floating-point value.
3348 * - A minus sign in the first character position if the number is
3350 * If the function succeeds, psBefore/psAfter will point to the string
3351 * on the right/left of the decimal symbol. pbNegative indicates if the
3352 * number is negative.
3354 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
3356 char sNumberSet
[] = "0123456789";
3357 BOOL bInDecimal
= FALSE
;
3359 /* Test if we do have a minus sign */
3360 if ( *pInput
== '-' )
3363 pInput
++; /* Jump to the next character. */
3366 while(*pInput
!= '\0')
3368 /* Do we have a valid numeric character */
3369 if ( strchr(sNumberSet
, *pInput
) != NULL
)
3371 if (bInDecimal
== TRUE
)
3372 *psAfter
++ = *pInput
;
3374 *psBefore
++ = *pInput
;
3378 /* Is this a decimal point (dot) */
3379 if ( *pInput
== '.' )
3381 /* Is it the first time we find it */
3382 if ((bInDecimal
== FALSE
))
3385 return -1; /* ERROR: Invalid parameter */
3389 /* It's neither a numeric character, nor a decimal point.
3390 * Thus, return an error.
3398 /* Add an End of Line character to the output buffers */
3405 /**************************************************************************
3406 * This function is used just locally !
3407 * Description: A number could be formatted using different numbers
3408 * of "digits in group" (example: 4;3;2;0).
3409 * The first parameter of this function is an array
3410 * containing the rule to be used. It's format is the following:
3411 * |NDG|DG1|DG2|...|0|
3412 * where NDG is the number of used "digits in group" and DG1, DG2,
3413 * are the corresponding "digits in group".
3414 * Thus, this function returns the grouping value in the array
3415 * pointed by the second parameter.
3417 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3419 char sData
[2], sRuleSize
[2];
3420 INT nData
, nRuleSize
;
3422 memcpy(sRuleSize
, sRule
, 1);
3423 memcpy(sRuleSize
+1, "\0", 1);
3424 nRuleSize
= atoi(sRuleSize
);
3426 if (index
> 0 && index
< nRuleSize
)
3428 memcpy(sData
, sRule
+index
, 1);
3429 memcpy(sData
+1, "\0", 1);
3430 nData
= atoi(sData
);
3435 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3436 memcpy(sData
+1, "\0", 1);
3437 nData
= atoi(sData
);
3443 /**************************************************************************
3444 * GetNumberFormatA (KERNEL32.355)
3446 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3447 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3448 LPSTR lpNumberStr
, int cchNumber
)
3450 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3451 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3452 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3453 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3454 char *pStr
= NULL
, *pTmpStr
= NULL
;
3455 LCID systemDefaultLCID
;
3456 BOOL bNegative
= FALSE
;
3465 strncpy(sNumber
, lpvalue
, 128);
3466 sNumber
[127] = '\0';
3468 /* Make sure we have a valid input string, get the number
3469 * of digits before and after the decimal symbol, and check
3470 * if this is a negative number.
3472 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3474 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3475 nDigits
= strlen(sDigitsAfterDecimal
);
3479 SetLastError(ERROR_INVALID_PARAMETER
);
3483 /* Which source will we use to format the string */
3484 used_operation
= RETURN_ERROR
;
3485 if (lpFormat
!= NULL
)
3488 used_operation
= USE_PARAMETER
;
3492 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3493 used_operation
= USE_LOCALEINFO
;
3495 used_operation
= USE_SYSTEMDEFAULT
;
3498 /* Load the fields we need */
3499 switch(used_operation
)
3501 case USE_LOCALEINFO
:
3502 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3503 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3504 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3505 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3506 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3507 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3510 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3511 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3512 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3513 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3514 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3515 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3517 case USE_SYSTEMDEFAULT
:
3518 systemDefaultLCID
= GetSystemDefaultLCID();
3519 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3520 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3521 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3522 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3523 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3524 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3527 SetLastError(ERROR_INVALID_PARAMETER
);
3531 nNumberDigits
= atoi(sNumberDigits
);
3533 /* Remove the ";" */
3536 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3538 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3540 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3545 sprintf(sBuffer
, "%d", i
);
3546 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3547 memcpy(sRule
+ j
, "\0", 1);
3549 /* First, format the digits before the decimal. */
3550 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3552 /* Working on an inverted string is easier ! */
3553 OLE_InvertString(sDigitsBeforeDecimal
);
3555 nStep
= nCounter
= i
= j
= 0;
3557 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3559 /* Here, we will loop until we reach the end of the string.
3560 * An internal counter (j) is used in order to know when to
3561 * insert the "digit group symbol".
3563 while (nNumberDecimal
> 0)
3565 i
= nCounter
+ nStep
;
3566 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3572 if (nRuleIndex
< sRule
[0])
3574 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3575 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3576 nStep
+= strlen(sDigitGroupSymbol
);
3582 memcpy(sDestination
+ i
+1, "\0", 1);
3583 /* Get the string in the right order ! */
3584 OLE_InvertString(sDestination
);
3588 nLZ
= atoi(sILZero
);
3591 /* Use 0.xxx instead of .xxx */
3592 memcpy(sDestination
, "0", 1);
3593 memcpy(sDestination
+1, "\0", 1);
3596 memcpy(sDestination
, "\0", 1);
3600 /* Second, format the digits after the decimal. */
3602 nCounter
= nNumberDigits
;
3603 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3605 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3606 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3607 j
= strlen(sDigitsAfterDecimal
);
3608 if (j
< nNumberDigits
)
3609 nCounter
= nNumberDigits
-j
;
3611 for (i
=0;i
<nCounter
;i
++)
3612 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3613 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3615 i
= strlen(sDestination
);
3616 j
= strlen(sDigitsAfterDecimal
);
3617 /* Finally, construct the resulting formatted string. */
3619 for (nCounter
=0; nCounter
<i
; nCounter
++)
3620 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3622 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3625 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3626 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3628 /* Is it a negative number */
3629 if (bNegative
== TRUE
)
3631 i
= atoi(sNegNumber
);
3632 pStr
= sDestination
;
3638 while (*sNumber
!= '\0')
3639 *pStr
++ = *pTmpStr
++;
3644 while (*pTmpStr
!= '\0')
3645 *pStr
++ = *pTmpStr
++;
3650 while (*pTmpStr
!= '\0')
3651 *pStr
++ = *pTmpStr
++;
3654 while (*pTmpStr
!= '\0')
3655 *pStr
++ = *pTmpStr
++;
3659 while (*pTmpStr
!= '\0')
3660 *pStr
++ = *pTmpStr
++;
3665 while (*pTmpStr
!= '\0')
3666 *pStr
++ = *pTmpStr
++;
3671 strcpy(sDestination
, sNumber
);
3673 /* If cchNumber is zero, then returns the number of bytes or characters
3674 * required to hold the formatted number string
3677 retVal
= strlen(sDestination
) + 1;
3680 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3681 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3682 retVal
= strlen(lpNumberStr
);
3688 /**************************************************************************
3689 * GetNumberFormatW (KERNEL32.xxx)
3691 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3692 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3693 LPWSTR lpNumberStr
, int cchNumber
)
3695 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue
));
3697 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3698 return cchNumber
? lstrlenW( lpNumberStr
) : 0;
3701 /**************************************************************************
3702 * GetCurrencyFormatA (KERNEL32.302)
3704 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3705 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3706 LPSTR lpCurrencyStr
, int cchCurrency
)
3708 UINT nPosOrder
, nNegOrder
;
3710 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3711 char *pDestination
= sDestination
;
3712 char sNumberFormated
[128];
3713 char *pNumberFormated
= sNumberFormated
;
3714 LCID systemDefaultLCID
;
3715 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3724 NUMBERFMTA numberFmt
;
3726 /* Which source will we use to format the string */
3727 used_operation
= RETURN_ERROR
;
3728 if (lpFormat
!= NULL
)
3731 used_operation
= USE_PARAMETER
;
3735 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3736 used_operation
= USE_LOCALEINFO
;
3738 used_operation
= USE_SYSTEMDEFAULT
;
3741 /* Load the fields we need */
3742 switch(used_operation
)
3744 case USE_LOCALEINFO
:
3745 /* Specific to CURRENCYFMTA*/
3746 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3747 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3748 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3750 nPosOrder
= atoi(sPosOrder
);
3751 nNegOrder
= atoi(sNegOrder
);
3754 /* Specific to CURRENCYFMTA*/
3755 nNegOrder
= lpFormat
->NegativeOrder
;
3756 nPosOrder
= lpFormat
->PositiveOrder
;
3757 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3759 case USE_SYSTEMDEFAULT
:
3760 systemDefaultLCID
= GetSystemDefaultLCID();
3761 /* Specific to CURRENCYFMTA*/
3762 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3763 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3764 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3766 nPosOrder
= atoi(sPosOrder
);
3767 nNegOrder
= atoi(sNegOrder
);
3770 SetLastError(ERROR_INVALID_PARAMETER
);
3774 /* Construct a temporary number format structure */
3775 if (lpFormat
!= NULL
)
3777 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3778 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3779 numberFmt
.Grouping
= lpFormat
->Grouping
;
3780 numberFmt
.NegativeOrder
= 0;
3781 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3782 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3783 bValidFormat
= TRUE
;
3786 /* Make a call to GetNumberFormatA() */
3787 if (*lpvalue
== '-')
3789 bIsPositive
= FALSE
;
3790 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3795 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3801 /* construct the formatted string */
3806 case 0: /* Prefix, no separation */
3807 strcpy (pDestination
, sCurrencySymbol
);
3808 strcat (pDestination
, pNumberFormated
);
3810 case 1: /* Suffix, no separation */
3811 strcpy (pDestination
, pNumberFormated
);
3812 strcat (pDestination
, sCurrencySymbol
);
3814 case 2: /* Prefix, 1 char separation */
3815 strcpy (pDestination
, sCurrencySymbol
);
3816 strcat (pDestination
, " ");
3817 strcat (pDestination
, pNumberFormated
);
3819 case 3: /* Suffix, 1 char separation */
3820 strcpy (pDestination
, pNumberFormated
);
3821 strcat (pDestination
, " ");
3822 strcat (pDestination
, sCurrencySymbol
);
3825 SetLastError(ERROR_INVALID_PARAMETER
);
3829 else /* negative number */
3833 case 0: /* format: ($1.1) */
3834 strcpy (pDestination
, "(");
3835 strcat (pDestination
, sCurrencySymbol
);
3836 strcat (pDestination
, pNumberFormated
);
3837 strcat (pDestination
, ")");
3839 case 1: /* format: -$1.1 */
3840 strcpy (pDestination
, "-");
3841 strcat (pDestination
, sCurrencySymbol
);
3842 strcat (pDestination
, pNumberFormated
);
3844 case 2: /* format: $-1.1 */
3845 strcpy (pDestination
, sCurrencySymbol
);
3846 strcat (pDestination
, "-");
3847 strcat (pDestination
, pNumberFormated
);
3849 case 3: /* format: $1.1- */
3850 strcpy (pDestination
, sCurrencySymbol
);
3851 strcat (pDestination
, pNumberFormated
);
3852 strcat (pDestination
, "-");
3854 case 4: /* format: (1.1$) */
3855 strcpy (pDestination
, "(");
3856 strcat (pDestination
, pNumberFormated
);
3857 strcat (pDestination
, sCurrencySymbol
);
3858 strcat (pDestination
, ")");
3860 case 5: /* format: -1.1$ */
3861 strcpy (pDestination
, "-");
3862 strcat (pDestination
, pNumberFormated
);
3863 strcat (pDestination
, sCurrencySymbol
);
3865 case 6: /* format: 1.1-$ */
3866 strcpy (pDestination
, pNumberFormated
);
3867 strcat (pDestination
, "-");
3868 strcat (pDestination
, sCurrencySymbol
);
3870 case 7: /* format: 1.1$- */
3871 strcpy (pDestination
, pNumberFormated
);
3872 strcat (pDestination
, sCurrencySymbol
);
3873 strcat (pDestination
, "-");
3875 case 8: /* format: -1.1 $ */
3876 strcpy (pDestination
, "-");
3877 strcat (pDestination
, pNumberFormated
);
3878 strcat (pDestination
, " ");
3879 strcat (pDestination
, sCurrencySymbol
);
3881 case 9: /* format: -$ 1.1 */
3882 strcpy (pDestination
, "-");
3883 strcat (pDestination
, sCurrencySymbol
);
3884 strcat (pDestination
, " ");
3885 strcat (pDestination
, pNumberFormated
);
3887 case 10: /* format: 1.1 $- */
3888 strcpy (pDestination
, pNumberFormated
);
3889 strcat (pDestination
, " ");
3890 strcat (pDestination
, sCurrencySymbol
);
3891 strcat (pDestination
, "-");
3893 case 11: /* format: $ 1.1- */
3894 strcpy (pDestination
, sCurrencySymbol
);
3895 strcat (pDestination
, " ");
3896 strcat (pDestination
, pNumberFormated
);
3897 strcat (pDestination
, "-");
3899 case 12: /* format: $ -1.1 */
3900 strcpy (pDestination
, sCurrencySymbol
);
3901 strcat (pDestination
, " ");
3902 strcat (pDestination
, "-");
3903 strcat (pDestination
, pNumberFormated
);
3905 case 13: /* format: 1.1- $ */
3906 strcpy (pDestination
, pNumberFormated
);
3907 strcat (pDestination
, "-");
3908 strcat (pDestination
, " ");
3909 strcat (pDestination
, sCurrencySymbol
);
3911 case 14: /* format: ($ 1.1) */
3912 strcpy (pDestination
, "(");
3913 strcat (pDestination
, sCurrencySymbol
);
3914 strcat (pDestination
, " ");
3915 strcat (pDestination
, pNumberFormated
);
3916 strcat (pDestination
, ")");
3918 case 15: /* format: (1.1 $) */
3919 strcpy (pDestination
, "(");
3920 strcat (pDestination
, pNumberFormated
);
3921 strcat (pDestination
, " ");
3922 strcat (pDestination
, sCurrencySymbol
);
3923 strcat (pDestination
, ")");
3926 SetLastError(ERROR_INVALID_PARAMETER
);
3931 if (cchCurrency
== 0)
3932 return strlen(pDestination
) + 1;
3936 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
3937 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
3938 return strlen(lpCurrencyStr
);
3942 /**************************************************************************
3943 * GetCurrencyFormatW (KERNEL32.303)
3945 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
3946 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
3947 LPWSTR lpCurrencyStr
, int cchCurrency
)
3949 FIXME("This API function is NOT implemented !\n");
3953 /******************************************************************************
3954 * OLE2NLS_CheckLocale [intern]
3956 static LCID
OLE2NLS_CheckLocale (LCID locale
)
3959 { locale
= LOCALE_SYSTEM_DEFAULT
;
3962 if (locale
== LOCALE_SYSTEM_DEFAULT
)
3963 { return GetSystemDefaultLCID();
3965 else if (locale
== LOCALE_USER_DEFAULT
)
3966 { return GetUserDefaultLCID();
3972 /******************************************************************************
3973 * GetTimeFormatA [KERNEL32.422]
3974 * Makes an ASCII string of the time
3976 * Formats date according to format, or locale default if format is
3977 * NULL. The format consists of literal characters and fields as follows:
3979 * h hours with no leading zero (12-hour)
3980 * hh hours with full two digits
3981 * H hours with no leading zero (24-hour)
3982 * HH hours with full two digits
3983 * m minutes with no leading zero
3984 * mm minutes with full two digits
3985 * s seconds with no leading zero
3986 * ss seconds with full two digits
3987 * t time marker (A or P)
3988 * tt time marker (AM, PM)
3992 GetTimeFormatA(LCID locale
, /* in */
3993 DWORD flags
, /* in */
3994 LPSYSTEMTIME xtime
, /* in */
3995 LPCSTR format
, /* in */
3996 LPSTR timestr
, /* out */
3997 INT timelen
/* in */)
3998 { char format_buf
[40];
4001 LPSYSTEMTIME thistime
;
4003 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4006 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
4008 thislocale
= OLE2NLS_CheckLocale ( locale
);
4010 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4011 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4014 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4017 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4018 { thislocale
= GetSystemDefaultLCID();
4020 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
4021 thisformat
= format_buf
;
4024 { thisformat
= format
;
4027 if (xtime
== NULL
) /* NULL means use the current local time*/
4034 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4040 /******************************************************************************
4041 * GetTimeFormatW [KERNEL32.423]
4042 * Makes a Unicode string of the time
4045 GetTimeFormatW(LCID locale
, /* in */
4046 DWORD flags
, /* in */
4047 LPSYSTEMTIME xtime
, /* in */
4048 LPCWSTR format
, /* in */
4049 LPWSTR timestr
, /* out */
4050 INT timelen
/* in */)
4051 { WCHAR format_buf
[40];
4054 LPSYSTEMTIME thistime
;
4056 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4059 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
4060 xtime
,debugstr_w(format
),timestr
,timelen
);
4062 thislocale
= OLE2NLS_CheckLocale ( locale
);
4064 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4065 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4068 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4071 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4072 { thislocale
= GetSystemDefaultLCID();
4074 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
4075 thisformat
= format_buf
;
4078 { thisformat
= format
;
4081 if (xtime
== NULL
) /* NULL means use the current local time*/
4082 { GetSystemTime(&t
);
4089 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4094 /******************************************************************************
4095 * EnumCalendarInfoA [KERNEL32.196]
4097 BOOL WINAPI
EnumCalendarInfoA(
4098 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
4100 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);