2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
17 #include "wine/unicode.h"
24 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(string
);
29 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
30 * MUST contain all #defines from winnls.h
31 * last entry has NULL name, 0 id.
33 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
34 static const struct tagLOCALE_NAME2ID
{
38 LOCALE_ENTRY(ILANGUAGE
),
39 LOCALE_ENTRY(SLANGUAGE
),
40 LOCALE_ENTRY(SENGLANGUAGE
),
41 LOCALE_ENTRY(SABBREVLANGNAME
),
42 LOCALE_ENTRY(SNATIVELANGNAME
),
43 LOCALE_ENTRY(ICOUNTRY
),
44 LOCALE_ENTRY(SCOUNTRY
),
45 LOCALE_ENTRY(SENGCOUNTRY
),
46 LOCALE_ENTRY(SABBREVCTRYNAME
),
47 LOCALE_ENTRY(SNATIVECTRYNAME
),
48 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
49 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
50 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
51 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
52 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
54 LOCALE_ENTRY(IMEASURE
),
55 LOCALE_ENTRY(SDECIMAL
),
56 LOCALE_ENTRY(STHOUSAND
),
57 LOCALE_ENTRY(SGROUPING
),
58 LOCALE_ENTRY(IDIGITS
),
60 LOCALE_ENTRY(INEGNUMBER
),
61 LOCALE_ENTRY(SNATIVEDIGITS
),
62 LOCALE_ENTRY(SCURRENCY
),
63 LOCALE_ENTRY(SINTLSYMBOL
),
64 LOCALE_ENTRY(SMONDECIMALSEP
),
65 LOCALE_ENTRY(SMONTHOUSANDSEP
),
66 LOCALE_ENTRY(SMONGROUPING
),
67 LOCALE_ENTRY(ICURRDIGITS
),
68 LOCALE_ENTRY(IINTLCURRDIGITS
),
69 LOCALE_ENTRY(ICURRENCY
),
70 LOCALE_ENTRY(INEGCURR
),
73 LOCALE_ENTRY(SSHORTDATE
),
74 LOCALE_ENTRY(SLONGDATE
),
75 LOCALE_ENTRY(STIMEFORMAT
),
79 LOCALE_ENTRY(ITIMEMARKPOSN
),
80 LOCALE_ENTRY(ICENTURY
),
81 LOCALE_ENTRY(ITLZERO
),
82 LOCALE_ENTRY(IDAYLZERO
),
83 LOCALE_ENTRY(IMONLZERO
),
86 LOCALE_ENTRY(ICALENDARTYPE
),
87 LOCALE_ENTRY(IOPTIONALCALENDAR
),
88 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
89 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
90 LOCALE_ENTRY(SDAYNAME1
),
91 LOCALE_ENTRY(SDAYNAME2
),
92 LOCALE_ENTRY(SDAYNAME3
),
93 LOCALE_ENTRY(SDAYNAME4
),
94 LOCALE_ENTRY(SDAYNAME5
),
95 LOCALE_ENTRY(SDAYNAME6
),
96 LOCALE_ENTRY(SDAYNAME7
),
97 LOCALE_ENTRY(SABBREVDAYNAME1
),
98 LOCALE_ENTRY(SABBREVDAYNAME2
),
99 LOCALE_ENTRY(SABBREVDAYNAME3
),
100 LOCALE_ENTRY(SABBREVDAYNAME4
),
101 LOCALE_ENTRY(SABBREVDAYNAME5
),
102 LOCALE_ENTRY(SABBREVDAYNAME6
),
103 LOCALE_ENTRY(SABBREVDAYNAME7
),
104 LOCALE_ENTRY(SMONTHNAME1
),
105 LOCALE_ENTRY(SMONTHNAME2
),
106 LOCALE_ENTRY(SMONTHNAME3
),
107 LOCALE_ENTRY(SMONTHNAME4
),
108 LOCALE_ENTRY(SMONTHNAME5
),
109 LOCALE_ENTRY(SMONTHNAME6
),
110 LOCALE_ENTRY(SMONTHNAME7
),
111 LOCALE_ENTRY(SMONTHNAME8
),
112 LOCALE_ENTRY(SMONTHNAME9
),
113 LOCALE_ENTRY(SMONTHNAME10
),
114 LOCALE_ENTRY(SMONTHNAME11
),
115 LOCALE_ENTRY(SMONTHNAME12
),
116 LOCALE_ENTRY(SMONTHNAME13
),
117 LOCALE_ENTRY(SABBREVMONTHNAME1
),
118 LOCALE_ENTRY(SABBREVMONTHNAME2
),
119 LOCALE_ENTRY(SABBREVMONTHNAME3
),
120 LOCALE_ENTRY(SABBREVMONTHNAME4
),
121 LOCALE_ENTRY(SABBREVMONTHNAME5
),
122 LOCALE_ENTRY(SABBREVMONTHNAME6
),
123 LOCALE_ENTRY(SABBREVMONTHNAME7
),
124 LOCALE_ENTRY(SABBREVMONTHNAME8
),
125 LOCALE_ENTRY(SABBREVMONTHNAME9
),
126 LOCALE_ENTRY(SABBREVMONTHNAME10
),
127 LOCALE_ENTRY(SABBREVMONTHNAME11
),
128 LOCALE_ENTRY(SABBREVMONTHNAME12
),
129 LOCALE_ENTRY(SABBREVMONTHNAME13
),
130 LOCALE_ENTRY(SPOSITIVESIGN
),
131 LOCALE_ENTRY(SNEGATIVESIGN
),
132 LOCALE_ENTRY(IPOSSIGNPOSN
),
133 LOCALE_ENTRY(INEGSIGNPOSN
),
134 LOCALE_ENTRY(IPOSSYMPRECEDES
),
135 LOCALE_ENTRY(IPOSSEPBYSPACE
),
136 LOCALE_ENTRY(INEGSYMPRECEDES
),
137 LOCALE_ENTRY(INEGSEPBYSPACE
),
138 LOCALE_ENTRY(FONTSIGNATURE
),
139 LOCALE_ENTRY(SISO639LANGNAME
),
140 LOCALE_ENTRY(SISO3166CTRYNAME
),
144 static char *GetLocaleSubkeyName( DWORD lctype
);
146 /***********************************************************************
147 * GetUserDefaultLCID [KERNEL32.425]
149 LCID WINAPI
GetUserDefaultLCID(void)
151 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
154 /***********************************************************************
155 * GetSystemDefaultLCID [KERNEL32.400]
157 LCID WINAPI
GetSystemDefaultLCID(void)
159 return GetUserDefaultLCID();
162 /***********************************************************************
163 * GetUserDefaultLangID [KERNEL32.426]
165 LANGID WINAPI
GetUserDefaultLangID(void)
167 /* caching result, if defined from environment, which should (?) not change during a WINE session */
168 static LANGID userLCID
= 0;
173 char *lang
,*country
,*charset
,*dialect
,*next
;
175 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
176 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
177 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
178 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
179 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
181 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
184 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
185 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
190 next
=strchr(lang
,':'); if (next
) *next
++='\0';
191 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
192 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
193 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
195 userLCID
= MAIN_GetLanguageID(lang
, country
, charset
, dialect
);
198 } while (lang
&& !userLCID
);
202 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
204 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
210 /***********************************************************************
211 * GetSystemDefaultLangID [KERNEL32.401]
213 LANGID WINAPI
GetSystemDefaultLangID(void)
215 return GetUserDefaultLangID();
218 /******************************************************************************
219 * ConvertDefaultLocale [KERNEL32.147]
221 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
223 { case LOCALE_SYSTEM_DEFAULT
:
224 return GetSystemDefaultLCID();
225 case LOCALE_USER_DEFAULT
:
226 return GetUserDefaultLCID();
228 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
230 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
233 /* Enhanced version of LoadStringW.
234 * It takes LanguageId to find and load language dependant resources.
235 * Resource is copied as is: "binary" strings are not truncated.
236 * Return: length of resource + 1 to distinguish absent resources
237 * from the resources with zero length.
239 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
247 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
250 hmem
= LoadResource(hModule
, hrsrc
);
253 p
= LockResource(hmem
);
254 string_num
= res_id
& 0x000f;
255 for(i
= 0; i
< string_num
; i
++)
258 TRACE("strlen = %d\n", (int)*p
);
260 if (buffer
== NULL
) return *p
;
261 i
= min(buflen
- 1, *p
);
263 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
264 buffer
[i
] = (WCHAR
) 0;
267 buffer
[0] = (WCHAR
) 0;
271 TRACE("\"%s\" loaded!\n", debugstr_w(buffer
));
275 /******************************************************************************
276 * GetLocaleInfoA [KERNEL32.342]
279 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
281 * MS online documentation states that the string returned is NULL terminated
282 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
283 * terminated string".
285 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
287 LPCSTR retString
= NULL
;
291 DWORD dwBufferSize
=128;
294 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
296 if (len
&& (! buf
) ) {
297 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
301 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
)
303 lcid
= GetSystemDefaultLCID();
305 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
307 lcid
= GetUserDefaultLCID();
310 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
311 from the registry. Instead, use system default values. */
312 NoUserOverride
= (LCType
& LOCALE_NOUSEROVERRIDE
) != 0;
314 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
316 /* First, check if it's in the registry. */
317 /* All user customized values are stored in the registry by SetLocaleInfo */
318 if ( !NoUserOverride
&& (pacKey
= GetLocaleSubkeyName(LCType
)) )
323 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
325 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
326 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
328 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
329 &dwBufferSize
) == ERROR_SUCCESS
)
331 retString
= acBuffer
;
338 /* If not in the registry, get it from the NLS entries. */
343 /* check if language is registered in the kernel32 resources */
344 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid
),
345 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
346 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
347 retString
= acBuffer
;
352 /* if not found report a most descriptive error */
355 /* If we are through all of this, retLen should not be zero anymore.
356 If it is, the value is not supported */
358 while (locale_name2id
[i
].name
!=NULL
) {
359 if (LCType
== locale_name2id
[i
].id
) {
360 retString
= locale_name2id
[i
].name
;
366 FIXME("Unkown LC type %lX\n", LCType
);
368 FIXME("'%s' is not defined for your language (%04X).\n"
369 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
370 "and submit patch for inclusion into the next Wine release.\n",
371 retString
, LOWORD(lcid
));
372 SetLastError(ERROR_INVALID_PARAMETER
);
376 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
377 if (LCType
== LOCALE_FONTSIGNATURE
) {
379 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
380 memcpy(buf
, retString
, len
);
383 return sizeof(FONTSIGNATURE
);
385 /* if len=0 return only the length, don't touch the buffer*/
387 lstrcpynA(buf
,retString
,len
);
388 return strlen(buf
) + 1;
390 return strlen(retString
)+1;
393 /******************************************************************************
394 * GetLocaleInfoW [KERNEL32.343]
397 * MS documentation states that len "specifies the size, in bytes (ANSI version)
398 * or characters (Unicode version), of" wbuf. Thus the number returned is
399 * the same between GetLocaleInfoW and GetLocaleInfoA.
401 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
405 if (len
&& (! wbuf
) )
406 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
410 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
411 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
413 if (wlen
&& len
) /* if len=0 return only the length*/
414 lstrcpynAtoW(wbuf
,abuf
,len
);
416 HeapFree(GetProcessHeap(),0,abuf
);
420 /******************************************************************************
422 * GetLocaleSubkeyName [helper function]
424 * - For use with the registry.
425 * - Gets the registry subkey name for a given lctype.
427 static char *GetLocaleSubkeyName( DWORD lctype
)
433 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
434 * the values are stored in the registry, confirmed under Windows,
435 * for the ones that actually assign pacKey. Cases that aren't finished
436 * have not been confirmed, so that must be done before they can be
439 case LOCALE_SDATE
: /* The date separator. */
442 case LOCALE_ICURRDIGITS
:
443 pacKey
= "iCurrDigits";
445 case LOCALE_SDECIMAL
:
448 case LOCALE_ICURRENCY
:
449 pacKey
= "iCurrency";
451 case LOCALE_SGROUPING
:
452 pacKey
= "sGrouping";
460 /* case LOCALE_ICALENDARTYPE: */
461 /* case LOCALE_IFIRSTDAYOFWEEK: */
462 /* case LOCALE_IFIRSTWEEKOFYEAR: */
463 /* case LOCALE_SYEARMONTH : */
464 /* case LOCALE_SPOSITIVESIGN : */
465 /* case LOCALE_IPAPERSIZE: */
467 case LOCALE_SLONGDATE
:
468 pacKey
= "sLongDate";
470 case LOCALE_SMONDECIMALSEP
:
471 pacKey
= "sMonDecimalSep";
473 case LOCALE_SMONGROUPING
:
474 pacKey
= "sMonGrouping";
476 case LOCALE_IMEASURE
:
479 case LOCALE_SMONTHOUSANDSEP
:
480 pacKey
= "sMonThousandSep";
482 case LOCALE_INEGCURR
:
485 case LOCALE_SNEGATIVESIGN
:
486 pacKey
= "sNegativeSign";
488 case LOCALE_INEGNUMBER
:
489 pacKey
= "iNegNumber";
491 case LOCALE_SSHORTDATE
:
492 pacKey
= "sShortDate";
494 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
503 case LOCALE_ITIME
: /* Time format specifier. */
506 case LOCALE_STHOUSAND
:
507 pacKey
= "sThousand";
509 case LOCALE_S1159
: /* AM */
515 case LOCALE_S2359
: /* PM */
518 case LOCALE_STIMEFORMAT
:
519 pacKey
= "sTimeFormat";
521 case LOCALE_SCURRENCY
:
522 pacKey
= "sCurrency";
525 /* The following are not listed under MSDN as supported,
526 * but seem to be used and also stored in the registry.
532 case LOCALE_SCOUNTRY
:
535 case LOCALE_ICOUNTRY
:
538 case LOCALE_SLANGUAGE
:
539 pacKey
= "sLanguage";
549 /******************************************************************************
550 * SetLocaleInfoA [KERNEL32.656]
552 BOOL16 WINAPI
SetLocaleInfoA(DWORD lcid
, DWORD lctype
, LPCSTR data
)
558 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
560 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
561 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
562 &hKey
) == ERROR_SUCCESS
)
564 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
565 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
567 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
574 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
579 /******************************************************************************
580 * IsValidLocale [KERNEL32.489]
582 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
584 /* check if language is registered in the kernel32 resources */
585 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
591 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
592 LPCWSTR name
, WORD LangID
, LONG lParam
)
596 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
597 sprintf(bufA
, "%08X", (UINT
)LangID
);
598 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
599 return lpfnLocaleEnum(bufW
);
602 /******************************************************************************
603 * EnumSystemLocalesW [KERNEL32.209]
605 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
608 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
610 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
611 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
612 (LONG
)lpfnLocaleEnum
);
617 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
618 LPCSTR name
, WORD LangID
, LONG lParam
)
621 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
622 sprintf(bufA
, "%08X", (UINT
)LangID
);
623 return lpfnLocaleEnum(bufA
);
626 /******************************************************************************
627 * EnumSystemLocalesA [KERNEL32.208]
629 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
632 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
634 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
635 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
636 (LONG
)lpfnLocaleEnum
);
641 static const unsigned char CT_CType2_LUT
[] = {
642 C2_NOTAPPLICABLE
, /* - 0 */
643 C2_NOTAPPLICABLE
, /* - 1 */
644 C2_NOTAPPLICABLE
, /* - 2 */
645 C2_NOTAPPLICABLE
, /* - 3 */
646 C2_NOTAPPLICABLE
, /* - 4 */
647 C2_NOTAPPLICABLE
, /* - 5 */
648 C2_NOTAPPLICABLE
, /* - 6 */
649 C2_NOTAPPLICABLE
, /* - 7 */
650 C2_NOTAPPLICABLE
, /* - 8 */
651 C2_SEGMENTSEPARATOR
, /* - 9 */
652 C2_NOTAPPLICABLE
, /* - 10 */
653 C2_NOTAPPLICABLE
, /* - 11 */
654 C2_NOTAPPLICABLE
, /* - 12 */
655 C2_NOTAPPLICABLE
, /* - 13 */
656 C2_NOTAPPLICABLE
, /* - 14 */
657 C2_NOTAPPLICABLE
, /* - 15 */
658 C2_NOTAPPLICABLE
, /* - 16 */
659 C2_NOTAPPLICABLE
, /* - 17 */
660 C2_NOTAPPLICABLE
, /* - 18 */
661 C2_NOTAPPLICABLE
, /* - 19 */
662 C2_NOTAPPLICABLE
, /* - 20 */
663 C2_NOTAPPLICABLE
, /* - 21 */
664 C2_NOTAPPLICABLE
, /* - 22 */
665 C2_NOTAPPLICABLE
, /* - 23 */
666 C2_NOTAPPLICABLE
, /* - 24 */
667 C2_NOTAPPLICABLE
, /* - 25 */
668 C2_NOTAPPLICABLE
, /* - 26 */
669 C2_NOTAPPLICABLE
, /* - 27 */
670 C2_NOTAPPLICABLE
, /* - 28 */
671 C2_NOTAPPLICABLE
, /* - 29 */
672 C2_NOTAPPLICABLE
, /* - 30 */
673 C2_NOTAPPLICABLE
, /* - 31 */
674 C2_WHITESPACE
, /* - 32 */
675 C2_OTHERNEUTRAL
, /* ! - 33 */
676 C2_OTHERNEUTRAL
, /* " - 34 */ /* " */
677 C2_EUROPETERMINATOR
, /* # - 35 */
678 C2_EUROPETERMINATOR
, /* $ - 36 */
679 C2_EUROPETERMINATOR
, /* % - 37 */
680 C2_LEFTTORIGHT
, /* & - 38 */
681 C2_OTHERNEUTRAL
, /* ' - 39 */
682 C2_OTHERNEUTRAL
, /* ( - 40 */
683 C2_OTHERNEUTRAL
, /* ) - 41 */
684 C2_OTHERNEUTRAL
, /* * - 42 */
685 C2_EUROPETERMINATOR
, /* + - 43 */
686 C2_COMMONSEPARATOR
, /* , - 44 */
687 C2_EUROPETERMINATOR
, /* - - 45 */
688 C2_EUROPESEPARATOR
, /* . - 46 */
689 C2_EUROPESEPARATOR
, /* / - 47 */
690 C2_EUROPENUMBER
, /* 0 - 48 */
691 C2_EUROPENUMBER
, /* 1 - 49 */
692 C2_EUROPENUMBER
, /* 2 - 50 */
693 C2_EUROPENUMBER
, /* 3 - 51 */
694 C2_EUROPENUMBER
, /* 4 - 52 */
695 C2_EUROPENUMBER
, /* 5 - 53 */
696 C2_EUROPENUMBER
, /* 6 - 54 */
697 C2_EUROPENUMBER
, /* 7 - 55 */
698 C2_EUROPENUMBER
, /* 8 - 56 */
699 C2_EUROPENUMBER
, /* 9 - 57 */
700 C2_COMMONSEPARATOR
, /* : - 58 */
701 C2_OTHERNEUTRAL
, /* ; - 59 */
702 C2_OTHERNEUTRAL
, /* < - 60 */
703 C2_OTHERNEUTRAL
, /* = - 61 */
704 C2_OTHERNEUTRAL
, /* > - 62 */
705 C2_OTHERNEUTRAL
, /* ? - 63 */
706 C2_LEFTTORIGHT
, /* @ - 64 */
707 C2_LEFTTORIGHT
, /* A - 65 */
708 C2_LEFTTORIGHT
, /* B - 66 */
709 C2_LEFTTORIGHT
, /* C - 67 */
710 C2_LEFTTORIGHT
, /* D - 68 */
711 C2_LEFTTORIGHT
, /* E - 69 */
712 C2_LEFTTORIGHT
, /* F - 70 */
713 C2_LEFTTORIGHT
, /* G - 71 */
714 C2_LEFTTORIGHT
, /* H - 72 */
715 C2_LEFTTORIGHT
, /* I - 73 */
716 C2_LEFTTORIGHT
, /* J - 74 */
717 C2_LEFTTORIGHT
, /* K - 75 */
718 C2_LEFTTORIGHT
, /* L - 76 */
719 C2_LEFTTORIGHT
, /* M - 77 */
720 C2_LEFTTORIGHT
, /* N - 78 */
721 C2_LEFTTORIGHT
, /* O - 79 */
722 C2_LEFTTORIGHT
, /* P - 80 */
723 C2_LEFTTORIGHT
, /* Q - 81 */
724 C2_LEFTTORIGHT
, /* R - 82 */
725 C2_LEFTTORIGHT
, /* S - 83 */
726 C2_LEFTTORIGHT
, /* T - 84 */
727 C2_LEFTTORIGHT
, /* U - 85 */
728 C2_LEFTTORIGHT
, /* V - 86 */
729 C2_LEFTTORIGHT
, /* W - 87 */
730 C2_LEFTTORIGHT
, /* X - 88 */
731 C2_LEFTTORIGHT
, /* Y - 89 */
732 C2_LEFTTORIGHT
, /* Z - 90 */
733 C2_OTHERNEUTRAL
, /* [ - 91 */
734 C2_OTHERNEUTRAL
, /* \ - 92 */
735 C2_OTHERNEUTRAL
, /* ] - 93 */
736 C2_OTHERNEUTRAL
, /* ^ - 94 */
737 C2_OTHERNEUTRAL
, /* _ - 95 */
738 C2_OTHERNEUTRAL
, /* ` - 96 */
739 C2_LEFTTORIGHT
, /* a - 97 */
740 C2_LEFTTORIGHT
, /* b - 98 */
741 C2_LEFTTORIGHT
, /* c - 99 */
742 C2_LEFTTORIGHT
, /* d - 100 */
743 C2_LEFTTORIGHT
, /* e - 101 */
744 C2_LEFTTORIGHT
, /* f - 102 */
745 C2_LEFTTORIGHT
, /* g - 103 */
746 C2_LEFTTORIGHT
, /* h - 104 */
747 C2_LEFTTORIGHT
, /* i - 105 */
748 C2_LEFTTORIGHT
, /* j - 106 */
749 C2_LEFTTORIGHT
, /* k - 107 */
750 C2_LEFTTORIGHT
, /* l - 108 */
751 C2_LEFTTORIGHT
, /* m - 109 */
752 C2_LEFTTORIGHT
, /* n - 110 */
753 C2_LEFTTORIGHT
, /* o - 111 */
754 C2_LEFTTORIGHT
, /* p - 112 */
755 C2_LEFTTORIGHT
, /* q - 113 */
756 C2_LEFTTORIGHT
, /* r - 114 */
757 C2_LEFTTORIGHT
, /* s - 115 */
758 C2_LEFTTORIGHT
, /* t - 116 */
759 C2_LEFTTORIGHT
, /* u - 117 */
760 C2_LEFTTORIGHT
, /* v - 118 */
761 C2_LEFTTORIGHT
, /* w - 119 */
762 C2_LEFTTORIGHT
, /* x - 120 */
763 C2_LEFTTORIGHT
, /* y - 121 */
764 C2_LEFTTORIGHT
, /* z - 122 */
765 C2_OTHERNEUTRAL
, /* { - 123 */
766 C2_OTHERNEUTRAL
, /* | - 124 */
767 C2_OTHERNEUTRAL
, /* } - 125 */
768 C2_OTHERNEUTRAL
, /* ~ - 126 */
769 C2_NOTAPPLICABLE
, /* \x7f - 127 */
770 C2_NOTAPPLICABLE
, /* € - 128 */
771 C2_NOTAPPLICABLE
, /* � - 129 */
772 C2_OTHERNEUTRAL
, /* ‚ - 130 */
773 C2_LEFTTORIGHT
, /* ƒ - 131 */
774 C2_OTHERNEUTRAL
, /* „ - 132 */
775 C2_OTHERNEUTRAL
, /* … - 133 */
776 C2_OTHERNEUTRAL
, /* † - 134 */
777 C2_OTHERNEUTRAL
, /* ‡ - 135 */
778 C2_LEFTTORIGHT
, /* ˆ - 136 */
779 C2_EUROPETERMINATOR
, /* ‰ - 137 */
780 C2_LEFTTORIGHT
, /* Š - 138 */
781 C2_OTHERNEUTRAL
, /* ‹ - 139 */
782 C2_LEFTTORIGHT
, /* Œ - 140 */
783 C2_NOTAPPLICABLE
, /* � - 141 */
784 C2_NOTAPPLICABLE
, /* Ž - 142 */
785 C2_NOTAPPLICABLE
, /* � - 143 */
786 C2_NOTAPPLICABLE
, /* � - 144 */
787 C2_OTHERNEUTRAL
, /* ‘ - 145 */
788 C2_OTHERNEUTRAL
, /* ’ - 146 */
789 C2_OTHERNEUTRAL
, /* “ - 147 */
790 C2_OTHERNEUTRAL
, /* ” - 148 */
791 C2_OTHERNEUTRAL
, /* • - 149 */
792 C2_OTHERNEUTRAL
, /* – - 150 */
793 C2_OTHERNEUTRAL
, /* — - 151 */
794 C2_LEFTTORIGHT
, /* ˜ - 152 */
795 C2_OTHERNEUTRAL
, /* ™ - 153 */
796 C2_LEFTTORIGHT
, /* š - 154 */
797 C2_OTHERNEUTRAL
, /* › - 155 */
798 C2_LEFTTORIGHT
, /* œ - 156 */
799 C2_NOTAPPLICABLE
, /* � - 157 */
800 C2_NOTAPPLICABLE
, /* ž - 158 */
801 C2_LEFTTORIGHT
, /* Ÿ - 159 */
802 C2_WHITESPACE
, /* - 160 */
803 C2_OTHERNEUTRAL
, /* ¡ - 161 */
804 C2_EUROPETERMINATOR
, /* ¢ - 162 */
805 C2_EUROPETERMINATOR
, /* £ - 163 */
806 C2_EUROPETERMINATOR
, /* ¤ - 164 */
807 C2_EUROPETERMINATOR
, /* ¥ - 165 */
808 C2_OTHERNEUTRAL
, /* ¦ - 166 */
809 C2_OTHERNEUTRAL
, /* § - 167 */
810 C2_OTHERNEUTRAL
, /* ¨ - 168 */
811 C2_OTHERNEUTRAL
, /* © - 169 */
812 C2_OTHERNEUTRAL
, /* ª - 170 */
813 C2_OTHERNEUTRAL
, /* « - 171 */
814 C2_OTHERNEUTRAL
, /* ¬ - 172 */
815 C2_OTHERNEUTRAL
, /* - 173 */
816 C2_OTHERNEUTRAL
, /* ® - 174 */
817 C2_OTHERNEUTRAL
, /* ¯ - 175 */
818 C2_EUROPETERMINATOR
, /* ° - 176 */
819 C2_EUROPETERMINATOR
, /* ± - 177 */
820 C2_EUROPENUMBER
, /* ² - 178 */
821 C2_EUROPENUMBER
, /* ³ - 179 */
822 C2_OTHERNEUTRAL
, /* ´ - 180 */
823 C2_OTHERNEUTRAL
, /* µ - 181 */
824 C2_OTHERNEUTRAL
, /* ¶ - 182 */
825 C2_OTHERNEUTRAL
, /* · - 183 */
826 C2_OTHERNEUTRAL
, /* ¸ - 184 */
827 C2_EUROPENUMBER
, /* ¹ - 185 */
828 C2_OTHERNEUTRAL
, /* º - 186 */
829 C2_OTHERNEUTRAL
, /* » - 187 */
830 C2_OTHERNEUTRAL
, /* ¼ - 188 */
831 C2_OTHERNEUTRAL
, /* ½ - 189 */
832 C2_OTHERNEUTRAL
, /* ¾ - 190 */
833 C2_OTHERNEUTRAL
, /* ¿ - 191 */
834 C2_LEFTTORIGHT
, /* À - 192 */
835 C2_LEFTTORIGHT
, /* Á - 193 */
836 C2_LEFTTORIGHT
, /* Â - 194 */
837 C2_LEFTTORIGHT
, /* Ã - 195 */
838 C2_LEFTTORIGHT
, /* Ä - 196 */
839 C2_LEFTTORIGHT
, /* Å - 197 */
840 C2_LEFTTORIGHT
, /* Æ - 198 */
841 C2_LEFTTORIGHT
, /* Ç - 199 */
842 C2_LEFTTORIGHT
, /* È - 200 */
843 C2_LEFTTORIGHT
, /* É - 201 */
844 C2_LEFTTORIGHT
, /* Ê - 202 */
845 C2_LEFTTORIGHT
, /* Ë - 203 */
846 C2_LEFTTORIGHT
, /* Ì - 204 */
847 C2_LEFTTORIGHT
, /* Í - 205 */
848 C2_LEFTTORIGHT
, /* Î - 206 */
849 C2_LEFTTORIGHT
, /* Ï - 207 */
850 C2_LEFTTORIGHT
, /* Ð - 208 */
851 C2_LEFTTORIGHT
, /* Ñ - 209 */
852 C2_LEFTTORIGHT
, /* Ò - 210 */
853 C2_LEFTTORIGHT
, /* Ó - 211 */
854 C2_LEFTTORIGHT
, /* Ô - 212 */
855 C2_LEFTTORIGHT
, /* Õ - 213 */
856 C2_LEFTTORIGHT
, /* Ö - 214 */
857 C2_OTHERNEUTRAL
, /* × - 215 */
858 C2_LEFTTORIGHT
, /* Ø - 216 */
859 C2_LEFTTORIGHT
, /* Ù - 217 */
860 C2_LEFTTORIGHT
, /* Ú - 218 */
861 C2_LEFTTORIGHT
, /* Û - 219 */
862 C2_LEFTTORIGHT
, /* Ü - 220 */
863 C2_LEFTTORIGHT
, /* Ý - 221 */
864 C2_LEFTTORIGHT
, /* Þ - 222 */
865 C2_LEFTTORIGHT
, /* ß - 223 */
866 C2_LEFTTORIGHT
, /* à - 224 */
867 C2_LEFTTORIGHT
, /* á - 225 */
868 C2_LEFTTORIGHT
, /* â - 226 */
869 C2_LEFTTORIGHT
, /* ã - 227 */
870 C2_LEFTTORIGHT
, /* ä - 228 */
871 C2_LEFTTORIGHT
, /* å - 229 */
872 C2_LEFTTORIGHT
, /* æ - 230 */
873 C2_LEFTTORIGHT
, /* ç - 231 */
874 C2_LEFTTORIGHT
, /* è - 232 */
875 C2_LEFTTORIGHT
, /* é - 233 */
876 C2_LEFTTORIGHT
, /* ê - 234 */
877 C2_LEFTTORIGHT
, /* ë - 235 */
878 C2_LEFTTORIGHT
, /* ì - 236 */
879 C2_LEFTTORIGHT
, /* í - 237 */
880 C2_LEFTTORIGHT
, /* î - 238 */
881 C2_LEFTTORIGHT
, /* ï - 239 */
882 C2_LEFTTORIGHT
, /* ð - 240 */
883 C2_LEFTTORIGHT
, /* ñ - 241 */
884 C2_LEFTTORIGHT
, /* ò - 242 */
885 C2_LEFTTORIGHT
, /* ó - 243 */
886 C2_LEFTTORIGHT
, /* ô - 244 */
887 C2_LEFTTORIGHT
, /* õ - 245 */
888 C2_LEFTTORIGHT
, /* ö - 246 */
889 C2_OTHERNEUTRAL
, /* ÷ - 247 */
890 C2_LEFTTORIGHT
, /* ø - 248 */
891 C2_LEFTTORIGHT
, /* ù - 249 */
892 C2_LEFTTORIGHT
, /* ú - 250 */
893 C2_LEFTTORIGHT
, /* û - 251 */
894 C2_LEFTTORIGHT
, /* ü - 252 */
895 C2_LEFTTORIGHT
, /* ý - 253 */
896 C2_LEFTTORIGHT
, /* þ - 254 */
897 C2_LEFTTORIGHT
/* ÿ - 255 */
900 const WORD OLE2NLS_CT_CType3_LUT
[] = {
935 0x0448, /* " - 34 */ /* " */
1000 0x8040, /* c - 99 */
1001 0x8040, /* d - 100 */
1002 0x8040, /* e - 101 */
1003 0x8040, /* f - 102 */
1004 0x8040, /* g - 103 */
1005 0x8040, /* h - 104 */
1006 0x8040, /* i - 105 */
1007 0x8040, /* j - 106 */
1008 0x8040, /* k - 107 */
1009 0x8040, /* l - 108 */
1010 0x8040, /* m - 109 */
1011 0x8040, /* n - 110 */
1012 0x8040, /* o - 111 */
1013 0x8040, /* p - 112 */
1014 0x8040, /* q - 113 */
1015 0x8040, /* r - 114 */
1016 0x8040, /* s - 115 */
1017 0x8040, /* t - 116 */
1018 0x8040, /* u - 117 */
1019 0x8040, /* v - 118 */
1020 0x8040, /* w - 119 */
1021 0x8040, /* x - 120 */
1022 0x8040, /* y - 121 */
1023 0x8040, /* z - 122 */
1024 0x0048, /* { - 123 */
1025 0x0048, /* | - 124 */
1026 0x0048, /* } - 125 */
1027 0x0448, /* ~ - 126 */
1028 0x0000, /* \x7f - 127 */
1029 0x0000, /* € - 128 */
1030 0x0000, /* � - 129 */
1031 0x0008, /* ‚ - 130 */
1032 0x8000, /* ƒ - 131 */
1033 0x0008, /* „ - 132 */
1034 0x0008, /* … - 133 */
1035 0x0008, /* † - 134 */
1036 0x0008, /* ‡ - 135 */
1037 0x0001, /* ˆ - 136 */
1038 0x0008, /* ‰ - 137 */
1039 0x8003, /* Š - 138 */
1040 0x0008, /* ‹ - 139 */
1041 0x8000, /* Œ - 140 */
1042 0x0000, /* � - 141 */
1043 0x0000, /* Ž - 142 */
1044 0x0000, /* � - 143 */
1045 0x0000, /* � - 144 */
1046 0x0088, /* ‘ - 145 */
1047 0x0088, /* ’ - 146 */
1048 0x0088, /* “ - 147 */
1049 0x0088, /* ” - 148 */
1050 0x0008, /* • - 149 */
1051 0x0400, /* – - 150 */
1052 0x0400, /* — - 151 */
1053 0x0408, /* ˜ - 152 */
1054 0x0000, /* ™ - 153 */
1055 0x8003, /* š - 154 */
1056 0x0008, /* › - 155 */
1057 0x8000, /* œ - 156 */
1058 0x0000, /* � - 157 */
1059 0x0000, /* ž - 158 */
1060 0x8003, /* Ÿ - 159 */
1062 0x0008, /* ¡ - 161 */
1063 0x0048, /* ¢ - 162 */
1064 0x0048, /* £ - 163 */
1065 0x0008, /* ¤ - 164 */
1066 0x0048, /* ¥ - 165 */
1067 0x0048, /* ¦ - 166 */
1068 0x0008, /* § - 167 */
1069 0x0408, /* ¨ - 168 */
1070 0x0008, /* © - 169 */
1071 0x0400, /* ª - 170 */
1072 0x0008, /* « - 171 */
1073 0x0048, /* ¬ - 172 */
1074 0x0408, /* - 173 */
1075 0x0008, /* ® - 174 */
1076 0x0448, /* ¯ - 175 */
1077 0x0008, /* ° - 176 */
1078 0x0008, /* ± - 177 */
1079 0x0000, /* ² - 178 */
1080 0x0000, /* ³ - 179 */
1081 0x0408, /* ´ - 180 */
1082 0x0008, /* µ - 181 */
1083 0x0008, /* ¶ - 182 */
1084 0x0008, /* · - 183 */
1085 0x0408, /* ¸ - 184 */
1086 0x0000, /* ¹ - 185 */
1087 0x0400, /* º - 186 */
1088 0x0008, /* » - 187 */
1089 0x0000, /* ¼ - 188 */
1090 0x0000, /* ½ - 189 */
1091 0x0000, /* ¾ - 190 */
1092 0x0008, /* ¿ - 191 */
1093 0x8003, /* À - 192 */
1094 0x8003, /* Á - 193 */
1095 0x8003, /* Â - 194 */
1096 0x8003, /* Ã - 195 */
1097 0x8003, /* Ä - 196 */
1098 0x8003, /* Å - 197 */
1099 0x8000, /* Æ - 198 */
1100 0x8003, /* Ç - 199 */
1101 0x8003, /* È - 200 */
1102 0x8003, /* É - 201 */
1103 0x8003, /* Ê - 202 */
1104 0x8003, /* Ë - 203 */
1105 0x8003, /* Ì - 204 */
1106 0x8003, /* Í - 205 */
1107 0x8003, /* Î - 206 */
1108 0x8003, /* Ï - 207 */
1109 0x8000, /* Ð - 208 */
1110 0x8003, /* Ñ - 209 */
1111 0x8003, /* Ò - 210 */
1112 0x8003, /* Ó - 211 */
1113 0x8003, /* Ô - 212 */
1114 0x8003, /* Õ - 213 */
1115 0x8003, /* Ö - 214 */
1116 0x0008, /* × - 215 */
1117 0x8003, /* Ø - 216 */
1118 0x8003, /* Ù - 217 */
1119 0x8003, /* Ú - 218 */
1120 0x8003, /* Û - 219 */
1121 0x8003, /* Ü - 220 */
1122 0x8003, /* Ý - 221 */
1123 0x8000, /* Þ - 222 */
1124 0x8000, /* ß - 223 */
1125 0x8003, /* à - 224 */
1126 0x8003, /* á - 225 */
1127 0x8003, /* â - 226 */
1128 0x8003, /* ã - 227 */
1129 0x8003, /* ä - 228 */
1130 0x8003, /* å - 229 */
1131 0x8000, /* æ - 230 */
1132 0x8003, /* ç - 231 */
1133 0x8003, /* è - 232 */
1134 0x8003, /* é - 233 */
1135 0x8003, /* ê - 234 */
1136 0x8003, /* ë - 235 */
1137 0x8003, /* ì - 236 */
1138 0x8003, /* í - 237 */
1139 0x8003, /* î - 238 */
1140 0x8003, /* ï - 239 */
1141 0x8000, /* ð - 240 */
1142 0x8003, /* ñ - 241 */
1143 0x8003, /* ò - 242 */
1144 0x8003, /* ó - 243 */
1145 0x8003, /* ô - 244 */
1146 0x8003, /* õ - 245 */
1147 0x8003, /* ö - 246 */
1148 0x0008, /* ÷ - 247 */
1149 0x8003, /* ø - 248 */
1150 0x8003, /* ù - 249 */
1151 0x8003, /* ú - 250 */
1152 0x8003, /* û - 251 */
1153 0x8003, /* ü - 252 */
1154 0x8003, /* ý - 253 */
1155 0x8000, /* þ - 254 */
1156 0x8003 /* ÿ - 255 */
1159 /******************************************************************************
1160 * GetStringTypeA [KERNEL32.396]
1162 BOOL WINAPI
GetStringTypeA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1163 INT cchSrc
,LPWORD chartype
)
1165 return GetStringTypeExA(locale
,dwInfoType
,src
,cchSrc
,chartype
);
1168 /******************************************************************************
1169 * GetStringTypeExA [KERNEL32.397]
1171 * FIXME: Ignores the locale.
1173 BOOL WINAPI
GetStringTypeExA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1174 INT cchSrc
,LPWORD chartype
)
1178 if ((src
==NULL
) || (chartype
==NULL
) || (src
==(LPSTR
)chartype
))
1180 SetLastError(ERROR_INVALID_PARAMETER
);
1185 cchSrc
=lstrlenA(src
)+1;
1187 switch (dwInfoType
) {
1189 for (i
=0;i
<cchSrc
;i
++)
1192 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1193 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1194 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1195 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1196 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1197 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1198 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1199 /* FIXME: isblank() is a GNU extension */
1200 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1201 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1207 for (i
=0;i
<cchSrc
;i
++)
1209 chartype
[i
]=(WORD
)CT_CType2_LUT
[i
];
1214 for (i
=0;i
<cchSrc
;i
++)
1216 chartype
[i
]=OLE2NLS_CT_CType3_LUT
[i
];
1221 ERR("Unknown dwInfoType:%ld\n",dwInfoType
);
1226 /******************************************************************************
1227 * GetStringTypeW [KERNEL32.399]
1230 * Yes, this is missing LCID locale. MS fault.
1232 BOOL WINAPI
GetStringTypeW(DWORD dwInfoType
,LPCWSTR src
,INT cchSrc
,
1235 return GetStringTypeExW(0/*defaultlocale*/,dwInfoType
,src
,cchSrc
,chartype
);
1238 /******************************************************************************
1239 * GetStringTypeExW [KERNEL32.398]
1241 * FIXME: unicode chars are assumed chars
1243 BOOL WINAPI
GetStringTypeExW(LCID locale
,DWORD dwInfoType
,LPCWSTR src
,
1244 INT cchSrc
,LPWORD chartype
)
1250 cchSrc
=lstrlenW(src
)+1;
1252 switch (dwInfoType
) {
1254 FIXME("CT_CTYPE2 not supported.\n");
1257 FIXME("CT_CTYPE3 not supported.\n");
1261 for (i
=0;i
<cchSrc
;i
++) {
1263 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1264 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1265 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1266 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1267 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1268 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1269 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1270 /* FIXME: isblank() is a GNU extension */
1271 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1272 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1278 /***********************************************************************
1279 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1281 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
1286 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1289 /***********************************************************************
1290 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1292 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
1297 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1301 static const unsigned char LCM_Unicode_LUT
[] = {
1334 7 , 28, /* ! - 33 */
1335 7 , 29, /* " - 34 */ /* " */
1336 7 , 31, /* # - 35 */
1337 7 , 33, /* $ - 36 */
1338 7 , 35, /* % - 37 */
1339 7 , 37, /* & - 38 */
1340 6 , 128, /* ' - 39 */
1341 7 , 39, /* ( - 40 */
1342 7 , 42, /* ) - 41 */
1343 7 , 45, /* * - 42 */
1345 7 , 47, /* , - 44 */
1346 6 , 130, /* - - 45 */
1347 7 , 51, /* . - 46 */
1348 7 , 53, /* / - 47 */
1349 12 , 3, /* 0 - 48 */
1350 12 , 33, /* 1 - 49 */
1351 12 , 51, /* 2 - 50 */
1352 12 , 70, /* 3 - 51 */
1353 12 , 88, /* 4 - 52 */
1354 12 , 106, /* 5 - 53 */
1355 12 , 125, /* 6 - 54 */
1356 12 , 144, /* 7 - 55 */
1357 12 , 162, /* 8 - 56 */
1358 12 , 180, /* 9 - 57 */
1359 7 , 55, /* : - 58 */
1360 7 , 58, /* ; - 59 */
1361 8 , 14, /* < - 60 */
1362 8 , 18, /* = - 61 */
1363 8 , 20, /* > - 62 */
1364 7 , 60, /* ? - 63 */
1365 7 , 62, /* @ - 64 */
1366 14 , 2, /* A - 65 */
1367 14 , 9, /* B - 66 */
1368 14 , 10, /* C - 67 */
1369 14 , 26, /* D - 68 */
1370 14 , 33, /* E - 69 */
1371 14 , 35, /* F - 70 */
1372 14 , 37, /* G - 71 */
1373 14 , 44, /* H - 72 */
1374 14 , 50, /* I - 73 */
1375 14 , 53, /* J - 74 */
1376 14 , 54, /* K - 75 */
1377 14 , 72, /* L - 76 */
1378 14 , 81, /* M - 77 */
1379 14 , 112, /* N - 78 */
1380 14 , 124, /* O - 79 */
1381 14 , 126, /* P - 80 */
1382 14 , 137, /* Q - 81 */
1383 14 , 138, /* R - 82 */
1384 14 , 145, /* S - 83 */
1385 14 , 153, /* T - 84 */
1386 14 , 159, /* U - 85 */
1387 14 , 162, /* V - 86 */
1388 14 , 164, /* W - 87 */
1389 14 , 166, /* X - 88 */
1390 14 , 167, /* Y - 89 */
1391 14 , 169, /* Z - 90 */
1392 7 , 63, /* [ - 91 */
1393 7 , 65, /* \ - 92 */
1394 7 , 66, /* ] - 93 */
1395 7 , 67, /* ^ - 94 */
1396 7 , 68, /* _ - 95 */
1397 7 , 72, /* ` - 96 */
1398 14 , 2, /* a - 97 */
1399 14 , 9, /* b - 98 */
1400 14 , 10, /* c - 99 */
1401 14 , 26, /* d - 100 */
1402 14 , 33, /* e - 101 */
1403 14 , 35, /* f - 102 */
1404 14 , 37, /* g - 103 */
1405 14 , 44, /* h - 104 */
1406 14 , 50, /* i - 105 */
1407 14 , 53, /* j - 106 */
1408 14 , 54, /* k - 107 */
1409 14 , 72, /* l - 108 */
1410 14 , 81, /* m - 109 */
1411 14 , 112, /* n - 110 */
1412 14 , 124, /* o - 111 */
1413 14 , 126, /* p - 112 */
1414 14 , 137, /* q - 113 */
1415 14 , 138, /* r - 114 */
1416 14 , 145, /* s - 115 */
1417 14 , 153, /* t - 116 */
1418 14 , 159, /* u - 117 */
1419 14 , 162, /* v - 118 */
1420 14 , 164, /* w - 119 */
1421 14 , 166, /* x - 120 */
1422 14 , 167, /* y - 121 */
1423 14 , 169, /* z - 122 */
1424 7 , 74, /* { - 123 */
1425 7 , 76, /* | - 124 */
1426 7 , 78, /* } - 125 */
1427 7 , 80, /* ~ - 126 */
1428 6 , 29, /* \x7f - 127 */
1429 6 , 30, /* € - 128 */
1430 6 , 31, /* � - 129 */
1431 7 , 123, /* ‚ - 130 */
1432 14 , 35, /* ƒ - 131 */
1433 7 , 127, /* „ - 132 */
1434 10 , 21, /* … - 133 */
1435 10 , 15, /* † - 134 */
1436 10 , 16, /* ‡ - 135 */
1437 7 , 67, /* ˆ - 136 */
1438 10 , 22, /* ‰ - 137 */
1439 14 , 145, /* Š - 138 */
1440 7 , 136, /* ‹ - 139 */
1441 14 + 16 , 124, /* Œ - 140 */
1442 6 , 43, /* � - 141 */
1443 6 , 44, /* Ž - 142 */
1444 6 , 45, /* � - 143 */
1445 6 , 46, /* � - 144 */
1446 7 , 121, /* ‘ - 145 */
1447 7 , 122, /* ’ - 146 */
1448 7 , 125, /* “ - 147 */
1449 7 , 126, /* ” - 148 */
1450 10 , 17, /* • - 149 */
1451 6 , 137, /* – - 150 */
1452 6 , 139, /* — - 151 */
1453 7 , 93, /* ˜ - 152 */
1454 14 , 156, /* ™ - 153 */
1455 14 , 145, /* š - 154 */
1456 7 , 137, /* › - 155 */
1457 14 + 16 , 124, /* œ - 156 */
1458 6 , 59, /* � - 157 */
1459 6 , 60, /* ž - 158 */
1460 14 , 167, /* Ÿ - 159 */
1462 7 , 81, /* ¡ - 161 */
1463 10 , 2, /* ¢ - 162 */
1464 10 , 3, /* £ - 163 */
1465 10 , 4, /* ¤ - 164 */
1466 10 , 5, /* ¥ - 165 */
1467 7 , 82, /* ¦ - 166 */
1468 10 , 6, /* § - 167 */
1469 7 , 83, /* ¨ - 168 */
1470 10 , 7, /* © - 169 */
1471 14 , 2, /* ª - 170 */
1472 8 , 24, /* « - 171 */
1473 10 , 8, /* ¬ - 172 */
1474 6 , 131, /* - 173 */
1475 10 , 9, /* ® - 174 */
1476 7 , 84, /* ¯ - 175 */
1477 10 , 10, /* ° - 176 */
1478 8 , 23, /* ± - 177 */
1479 12 , 51, /* ² - 178 */
1480 12 , 70, /* ³ - 179 */
1481 7 , 85, /* ´ - 180 */
1482 10 , 11, /* µ - 181 */
1483 10 , 12, /* ¶ - 182 */
1484 10 , 13, /* · - 183 */
1485 7 , 86, /* ¸ - 184 */
1486 12 , 33, /* ¹ - 185 */
1487 14 , 124, /* º - 186 */
1488 8 , 26, /* » - 187 */
1489 12 , 21, /* ¼ - 188 */
1490 12 , 25, /* ½ - 189 */
1491 12 , 29, /* ¾ - 190 */
1492 7 , 87, /* ¿ - 191 */
1493 14 , 2, /* À - 192 */
1494 14 , 2, /* Á - 193 */
1495 14 , 2, /* Â - 194 */
1496 14 , 2, /* Ã - 195 */
1497 14 , 2, /* Ä - 196 */
1498 14 , 2, /* Å - 197 */
1499 14 + 16 , 2, /* Æ - 198 */
1500 14 , 10, /* Ç - 199 */
1501 14 , 33, /* È - 200 */
1502 14 , 33, /* É - 201 */
1503 14 , 33, /* Ê - 202 */
1504 14 , 33, /* Ë - 203 */
1505 14 , 50, /* Ì - 204 */
1506 14 , 50, /* Í - 205 */
1507 14 , 50, /* Î - 206 */
1508 14 , 50, /* Ï - 207 */
1509 14 , 26, /* Ð - 208 */
1510 14 , 112, /* Ñ - 209 */
1511 14 , 124, /* Ò - 210 */
1512 14 , 124, /* Ó - 211 */
1513 14 , 124, /* Ô - 212 */
1514 14 , 124, /* Õ - 213 */
1515 14 , 124, /* Ö - 214 */
1516 8 , 28, /* × - 215 */
1517 14 , 124, /* Ø - 216 */
1518 14 , 159, /* Ù - 217 */
1519 14 , 159, /* Ú - 218 */
1520 14 , 159, /* Û - 219 */
1521 14 , 159, /* Ü - 220 */
1522 14 , 167, /* Ý - 221 */
1523 14 + 32 , 153, /* Þ - 222 */
1524 14 + 48 , 145, /* ß - 223 */
1525 14 , 2, /* à - 224 */
1526 14 , 2, /* á - 225 */
1527 14 , 2, /* â - 226 */
1528 14 , 2, /* ã - 227 */
1529 14 , 2, /* ä - 228 */
1530 14 , 2, /* å - 229 */
1531 14 + 16 , 2, /* æ - 230 */
1532 14 , 10, /* ç - 231 */
1533 14 , 33, /* è - 232 */
1534 14 , 33, /* é - 233 */
1535 14 , 33, /* ê - 234 */
1536 14 , 33, /* ë - 235 */
1537 14 , 50, /* ì - 236 */
1538 14 , 50, /* í - 237 */
1539 14 , 50, /* î - 238 */
1540 14 , 50, /* ï - 239 */
1541 14 , 26, /* ð - 240 */
1542 14 , 112, /* ñ - 241 */
1543 14 , 124, /* ò - 242 */
1544 14 , 124, /* ó - 243 */
1545 14 , 124, /* ô - 244 */
1546 14 , 124, /* õ - 245 */
1547 14 , 124, /* ö - 246 */
1548 8 , 29, /* ÷ - 247 */
1549 14 , 124, /* ø - 248 */
1550 14 , 159, /* ù - 249 */
1551 14 , 159, /* ú - 250 */
1552 14 , 159, /* û - 251 */
1553 14 , 159, /* ü - 252 */
1554 14 , 167, /* ý - 253 */
1555 14 + 32 , 153, /* þ - 254 */
1556 14 , 167 /* ÿ - 255 */ };
1558 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1560 #define LCM_Diacritic_Start 131
1562 static const unsigned char LCM_Diacritic_LUT
[] = {
1690 /******************************************************************************
1691 * OLE2NLS_isPunctuation [INTERNAL]
1693 static int OLE2NLS_isPunctuation(unsigned char c
)
1695 /* "punctuation character" in this context is a character which is
1696 considered "less important" during word sort comparison.
1697 See LCMapString implementation for the precise definition
1698 of "less important". */
1700 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1703 /******************************************************************************
1704 * OLE2NLS_isNonSpacing [INTERNAL]
1706 static int OLE2NLS_isNonSpacing(unsigned char c
)
1708 /* This function is used by LCMapStringA. Characters
1709 for which it returns true are ignored when mapping a
1710 string with NORM_IGNORENONSPACE */
1711 return ((c
==136) || (c
==170) || (c
==186));
1714 /******************************************************************************
1715 * OLE2NLS_isSymbol [INTERNAL]
1717 static int OLE2NLS_isSymbol(unsigned char c
)
1719 /* This function is used by LCMapStringA. Characters
1720 for which it returns true are ignored when mapping a
1721 string with NORM_IGNORESYMBOLS */
1722 return ( (c
!=0) && !IsCharAlphaNumericA(c
) );
1725 /******************************************************************************
1726 * identity [Internal]
1728 static int identity(int c
)
1733 /*************************************************************************
1734 * LCMapStringA [KERNEL32.492]
1736 * Convert a string, or generate a sort key from it.
1738 * If (mapflags & LCMAP_SORTKEY), the function will generate
1739 * a sort key for the source string. Else, it will convert it
1740 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1744 * Success : length of the result string.
1747 * If called with scrlen = -1, the function will compute the length
1748 * of the 0-terminated string strsrc by itself.
1750 * If called with dstlen = 0, returns the buffer length that
1751 * would be required.
1753 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1754 * as if they are equal.
1755 * In the only code page implemented so far, there may not be
1756 * wide characters in strings passed to LCMapStringA,
1757 * so there is nothing to be done for this flag.
1759 INT WINAPI
LCMapStringA(
1760 LCID lcid
/* locale identifier created with MAKELCID;
1761 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1762 predefined values. */,
1763 DWORD mapflags
/* flags */,
1764 LPCSTR srcstr
/* source buffer */,
1765 INT srclen
/* source length */,
1766 LPSTR dststr
/* destination buffer */,
1767 INT dstlen
/* destination buffer length */)
1771 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1772 lcid
,mapflags
,srcstr
,srclen
,dststr
,dstlen
);
1774 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1776 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr
, dststr
);
1777 SetLastError(ERROR_INVALID_PARAMETER
);
1781 srclen
= lstrlenA(srcstr
) + 1 ; /* (include final '\0') */
1783 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1787 NORM_IGNORENONSPACE | \
1789 NORM_IGNOREWIDTH | \
1790 NORM_IGNOREKANATYPE)
1791 /* FIXME: as long as we don't support Kanakana nor Hirigana
1792 * characters, we can support NORM_IGNOREKANATYPE
1794 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1796 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1797 "unimplemented flags: 0x%08lx\n",
1804 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1808 if ( !(mapflags
& LCMAP_SORTKEY
) )
1811 int (*f
)(int) = identity
;
1812 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1813 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1815 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1817 /* For some values of mapflags, the length of the resulting
1818 string is not known at this point. Windows does map the string
1819 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1823 /* Compute required length */
1824 for (i
=j
=0; i
< srclen
; i
++)
1826 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1827 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1839 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1843 if (mapflags
& LCMAP_UPPERCASE
)
1845 else if (mapflags
& LCMAP_LOWERCASE
)
1847 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1848 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1850 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1851 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1853 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1860 /* FIXME: This function completely ignores the "lcid" parameter. */
1861 /* else ... (mapflags & LCMAP_SORTKEY) */
1865 int diacritic_len
=0;
1866 int delayed_punctuation_len
=0;
1867 char *case_component
;
1868 char *diacritic_component
;
1869 char *delayed_punctuation_component
;
1871 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1873 /* compute how much room we will need */
1874 for (i
=0;i
<srclen
;i
++)
1877 unsigned char source_char
= srcstr
[i
];
1878 if (source_char
!='\0')
1880 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
1883 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
1884 unicode_len
++; /* double letter */
1888 delayed_punctuation_len
++;
1892 if (isupper(source_char
))
1893 case_len
=unicode_len
;
1895 ofs
= source_char
- LCM_Diacritic_Start
;
1896 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
1897 diacritic_len
=unicode_len
;
1900 if (mapflags
& NORM_IGNORECASE
)
1902 if (mapflags
& NORM_IGNORENONSPACE
)
1905 room
= 2 * unicode_len
/* "unicode" component */
1906 + diacritic_len
/* "diacritic" component */
1907 + case_len
/* "case" component */
1908 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
1909 + 4 /* four '\1' separators */
1910 + 1 ; /* terminal '\0' */
1913 else if (dstlen
<room
)
1915 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1919 /*FIXME the Pointercheck should not be nessesary */
1920 if (IsBadWritePtr (dststr
,room
))
1921 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
1922 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1926 /* locate each component, write separators */
1927 diacritic_component
= dststr
+ 2*unicode_len
;
1928 *diacritic_component
++ = '\1';
1929 case_component
= diacritic_component
+ diacritic_len
;
1930 *case_component
++ = '\1';
1931 delayed_punctuation_component
= case_component
+ case_len
;
1932 *delayed_punctuation_component
++ = '\1';
1933 *delayed_punctuation_component
++ = '\1';
1935 /* read source string char by char, write
1936 corresponding weight in each component. */
1937 for (i
=0,count
=0;i
<srclen
;i
++)
1939 unsigned char source_char
=srcstr
[i
];
1940 if (source_char
!='\0')
1943 type
= LCM_Unicode_LUT
[-2+2*source_char
];
1944 longcode
= type
>> 4;
1946 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
1948 UINT16 encrypted_location
= (1<<15) + 7 + 4*count
;
1949 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
1950 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
1951 /* big-endian is used here because it lets string comparison be
1952 compatible with numerical comparison */
1954 *delayed_punctuation_component
++ = type
;
1955 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
1956 /* assumption : a punctuation character is never a
1957 double or accented letter */
1961 dststr
[2*count
] = type
;
1962 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
1966 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1967 if (count
<diacritic_len
)
1968 diacritic_component
[count
] = 2; /* assumption: a double letter
1969 is never accented */
1972 dststr
[2*count
] = type
;
1973 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
1974 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1975 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1976 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1980 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1981 if (count
<diacritic_len
)
1983 int ofs
= source_char
- LCM_Diacritic_Start
;
1984 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
1990 dststr
[room
-1] = '\0';
1995 /*************************************************************************
1996 * LCMapStringW [KERNEL32.493]
1998 * Convert a string, or generate a sort key from it.
2002 * See LCMapStringA for documentation
2004 INT WINAPI
LCMapStringW(
2005 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
2010 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2011 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
2013 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
2015 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
2016 SetLastError(ERROR_INVALID_PARAMETER
);
2020 srclen
= lstrlenW(srcstr
)+1;
2022 /* FIXME: Both this function and it's companion LCMapStringA()
2023 * completely ignore the "lcid" parameter. In place of the "lcid"
2024 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2025 * environment variable prior to invoking this function. */
2026 if (mapflags
& LCMAP_SORTKEY
)
2028 /* Possible values of LC_COLLATE. */
2029 char *lc_collate_default
= 0; /* value prior to this function */
2030 char *lc_collate_env
= 0; /* value retrieved from the environment */
2032 /* General purpose index into strings of any type. */
2035 /* Lengths of various strings where the length is measured in
2036 * wide characters for wide character strings and in bytes for
2037 * native strings. The lengths include the NULL terminator. */
2038 size_t returned_len
= 0;
2039 size_t src_native_len
= 0;
2040 size_t dst_native_len
= 0;
2041 size_t dststr_libc_len
= 0;
2043 /* Native (character set determined by locale) versions of the
2044 * strings source and destination strings. */
2045 LPSTR src_native
= 0;
2046 LPSTR dst_native
= 0;
2048 /* Version of the source and destination strings using the
2049 * "wchar_t" Unicode data type needed by various libc functions. */
2050 wchar_t *srcstr_libc
= 0;
2051 wchar_t *dststr_libc
= 0;
2053 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2054 srclen
* sizeof(wchar_t))))
2056 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2057 srclen
* sizeof(wchar_t));
2058 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2062 /* Convert source string to a libc Unicode string. */
2063 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
2065 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
2068 /* src_native should contain at most 3 bytes for each
2069 * multibyte characters in the original srcstr string. */
2070 src_native_len
= 3 * srclen
;
2071 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
2074 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
2075 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2076 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2080 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2081 * current value is backed up so it can be restored after the
2082 * last LC_COLLATE sensitive function returns.
2084 * Even though the locale is adjusted for a minimum amount of
2085 * time a race condition exists where other threads may be
2086 * affected if they invoke LC_COLLATE sensitive functions. One
2087 * possible solution is to wrap all LC_COLLATE sensitive Wine
2088 * functions, like LCMapStringW(), in a mutex.
2090 * Another enhancement to the following would be to set the
2091 * LC_COLLATE locale category as a function of the "lcid"
2092 * parameter instead of the "LC_COLLATE" environment variable. */
2093 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
2095 ERR("Unable to query the LC_COLLATE catagory\n");
2096 SetLastError(ERROR_INVALID_PARAMETER
);
2097 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2098 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2102 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
2104 ERR("Unable to inherit the LC_COLLATE locale category from the "
2105 "environment. The \"LC_COLLATE\" environment variable is "
2106 "\"%s\".\n", getenv("LC_COLLATE") ?
2107 getenv("LC_COLLATE") : "<unset>");
2108 SetLastError(ERROR_INVALID_PARAMETER
);
2109 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2110 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2114 TRACE("lc_collate_default = %s\n", lc_collate_default
);
2115 TRACE("lc_collate_env = %s\n", lc_collate_env
);
2117 /* Convert the libc Unicode string to a native multibyte character
2119 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
2120 if(returned_len
== 0)
2122 LPSTR srcstr_ascii
= (LPSTR
)HEAP_strdupWtoA(GetProcessHeap(),
2124 ERR("wcstombs failed. The string specified (%s) may contains an "
2125 "invalid character.\n", srcstr_ascii
);
2126 SetLastError(ERROR_INVALID_PARAMETER
);
2127 if(srcstr_ascii
) HeapFree(GetProcessHeap(), 0, srcstr_ascii
);
2128 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2129 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2130 setlocale(LC_COLLATE
, lc_collate_default
);
2133 else if(returned_len
> src_native_len
)
2135 src_native
[src_native_len
- 1] = 0;
2136 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2137 "than expected (%d bytes).\n", src_native
, returned_len
,
2140 /* Since this is an internal error I'm not sure what the correct
2142 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2144 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2145 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2146 setlocale(LC_COLLATE
, lc_collate_default
);
2149 src_native_len
= returned_len
;
2151 TRACE("src_native = %s src_native_len = %d\n",
2152 src_native
, src_native_len
);
2154 /* dst_native seems to contain at most 4 bytes for each byte in
2155 * the original src_native string. Change if need be since this
2156 * isn't documented by the strxfrm() man page. */
2157 dst_native_len
= 4 * src_native_len
;
2158 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
2160 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
2161 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2162 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2163 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2164 setlocale(LC_COLLATE
, lc_collate_default
);
2168 /* The actual translation is done by the following call to
2169 * strxfrm(). The surrounding code could have been simplified
2170 * by calling wcsxfrm() instead except that wcsxfrm() is not
2171 * available on older Linux systems (RedHat 4.1 with
2174 * Also, it is possible that the translation could be done by
2175 * various tables as it is done in LCMapStringA(). However, I'm
2176 * not sure what those tables are. */
2177 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
2179 if(returned_len
> dst_native_len
)
2181 dst_native
[dst_native_len
- 1] = 0;
2182 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2183 "than expected (%d bytes).\n", dst_native
, returned_len
,
2186 /* Since this is an internal error I'm not sure what the correct
2188 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2190 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2191 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2192 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2193 setlocale(LC_COLLATE
, lc_collate_default
);
2196 dst_native_len
= returned_len
;
2198 TRACE("dst_native = %s dst_native_len = %d\n",
2199 dst_native
, dst_native_len
);
2201 dststr_libc_len
= dst_native_len
;
2202 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2203 dststr_libc_len
* sizeof(wchar_t))))
2205 ERR("Unable to allocate %d bytes for dststr_libc\n",
2206 dststr_libc_len
* sizeof(wchar_t));
2207 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2208 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2209 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2210 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2211 setlocale(LC_COLLATE
, lc_collate_default
);
2215 /* Convert the native multibyte string to a libc Unicode string. */
2216 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
2218 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2219 * function has returned. */
2220 setlocale(LC_COLLATE
, lc_collate_default
);
2222 if(returned_len
== 0)
2224 ERR("mbstowcs failed. The native version of the translated string "
2225 "(%s) may contain an invalid character.\n", dst_native
);
2226 SetLastError(ERROR_INVALID_PARAMETER
);
2227 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2228 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2229 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2230 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2235 if(returned_len
> dstlen
)
2237 ERR("mbstowcs returned a string that was longer (%d chars) "
2238 "than the buffer provided (%d chars).\n", returned_len
,
2240 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2241 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2242 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2243 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2244 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2247 dstlen
= returned_len
;
2249 /* Convert a libc Unicode string to the destination string. */
2250 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
2252 dststr
[str_idx
] = dststr_libc
[str_idx
];
2254 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2255 *(((int *)dststr
) + 0),
2256 *(((int *)dststr
) + 1),
2257 *(((int *)dststr
) + 2),
2258 *(((int *)dststr
) + 3));
2262 dstlen
= returned_len
;
2264 TRACE("dstlen (return) = %d\n", dstlen
);
2265 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2266 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2267 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2268 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2273 int (*f
)(int)=identity
;
2279 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2283 if (mapflags
& LCMAP_UPPERCASE
)
2285 else if (mapflags
& LCMAP_LOWERCASE
)
2287 for (i
=0; i
< srclen
; i
++)
2288 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
2294 /***********************************************************************
2295 * OLE2NLS_EstimateMappingLength
2297 * Estimates the number of characters required to hold the string
2298 * computed by LCMapStringA.
2300 * The size is always over-estimated, with a fixed limit on the
2301 * amount of estimation error.
2303 * Note that len == -1 is not permitted.
2305 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
2306 LPCSTR str
, DWORD len
)
2308 /* Estimate only for small strings to keep the estimation error from
2309 * becoming too large. */
2310 if (len
< 128) return len
* 8 + 5;
2311 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
2314 /******************************************************************************
2315 * CompareStringA [KERNEL32.143]
2316 * Compares two strings using locale
2320 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2325 * Defaults to a word sort, but uses a string sort if
2326 * SORT_STRINGSORT is set.
2327 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2331 * This implementation ignores the locale
2335 * Quite inefficient.
2337 UINT WINAPI
CompareStringA(
2338 DWORD lcid
, /* locale ID */
2339 DWORD fdwStyle
, /* comparison-style options */
2340 LPCSTR s1
, /* first string */
2341 DWORD l1
, /* length of first string */
2342 LPCSTR s2
, /* second string */
2343 DWORD l2
) /* length of second string */
2345 int mapstring_flags
;
2349 TRACE("%s and %s\n",
2350 debugstr_a (s1
), debugstr_a (s2
));
2352 if ( (s1
==NULL
) || (s2
==NULL
) )
2354 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1
, s2
);
2355 SetLastError(ERROR_INVALID_PARAMETER
);
2359 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2360 FIXME("IGNORESYMBOLS not supported\n");
2362 if (l1
== -1) l1
= lstrlenA(s1
);
2363 if (l2
== -1) l2
= lstrlenA(s2
);
2365 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
2366 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
2367 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
2369 if ((len1
==0)||(len2
==0))
2370 return 0; /* something wrong happened */
2372 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
2374 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
2375 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
2377 ERR("Bug in LCmapStringA.\n");
2382 /* strcmp doesn't necessarily return -1, 0, or 1 */
2383 result
= strcmp(sk1
,sk2
);
2385 HeapFree(GetProcessHeap(),0,sk1
);
2392 /* must be greater, if we reach this point */
2396 /******************************************************************************
2397 * CompareStringW [KERNEL32.144]
2398 * This implementation ignores the locale
2399 * FIXME : Does only string sort. Should
2400 * be reimplemented the same way as CompareStringA.
2402 UINT WINAPI
CompareStringW(DWORD lcid
, DWORD fdwStyle
,
2403 LPCWSTR s1
, DWORD l1
, LPCWSTR s2
,DWORD l2
)
2406 if(fdwStyle
& NORM_IGNORENONSPACE
)
2407 FIXME("IGNORENONSPACE not supprted\n");
2408 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2409 FIXME("IGNORESYMBOLS not supported\n");
2411 /* Is strcmp defaulting to string sort or to word sort?? */
2412 /* FIXME: Handle NORM_STRINGSORT */
2413 l1
= (l1
==-1)?lstrlenW(s1
):l1
;
2414 l2
= (l2
==-1)?lstrlenW(s2
):l2
;
2415 len
= l1
<l2
? l1
:l2
;
2416 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
2417 /* not equal, return 1 or 3 */
2418 if(ret
!=0) return ret
+2;
2419 /* same len, return 2 */
2420 if(l1
==l2
) return 2;
2421 /* the longer one is lexically greater */
2422 return (l1
<l2
)? 1 : 3;
2425 /******************************************************************************
2426 * OLE_GetFormatA [Internal]
2429 * If datelen == 0, it should return the reguired string length.
2431 This function implements stuff for GetDateFormat() and
2434 d single-digit (no leading zero) day (of month)
2435 dd two-digit day (of month)
2436 ddd short day-of-week name
2437 dddd long day-of-week name
2438 M single-digit month
2440 MMM short month name
2441 MMMM full month name
2442 y two-digit year, no leading 0
2444 yyyy four-digit year
2446 h hours with no leading zero (12-hour)
2447 hh hours with full two digits
2448 H hours with no leading zero (24-hour)
2449 HH hours with full two digits
2450 m minutes with no leading zero
2451 mm minutes with full two digits
2452 s seconds with no leading zero
2453 ss seconds with full two digits
2454 t time marker (A or P)
2455 tt time marker (AM, PM)
2456 '' used to quote literal characters
2457 '' (within a quoted string) indicates a literal '
2459 These functions REQUIRE valid locale, date, and format.
2461 static INT
OLE_GetFormatA(LCID locale
,
2465 LPCSTR _format
, /*in*/
2470 int count
, type
, inquote
, Overflow
;
2476 const char * _dgfmt
[] = { "%d", "%02d" };
2477 const char ** dgfmt
= _dgfmt
- 1;
2479 /* report, for debugging */
2480 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2481 locale
, flags
, tflags
,
2482 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2483 _format
, _format
, date
, datelen
);
2486 FIXME("datelen = 0, returning 255\n");
2490 /* initalize state variables and output buffer */
2492 count
= 0; inquote
= 0; Overflow
= 0;
2494 date
[0] = buf
[0] = '\0';
2496 strcpy(format
,_format
);
2498 /* alter the formatstring, while it works for all languages now in wine
2499 its possible that it fails when the time looks like ss:mm:hh as example*/
2500 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2501 { if ((pos
= strstr ( format
, ":mm")))
2502 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2505 if (tflags
& (TIME_NOSECONDS
))
2506 { if ((pos
= strstr ( format
, ":ss")))
2507 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2511 for (inpos
= 0;; inpos
++) {
2512 /* 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]); */
2514 if (format
[inpos
] == '\'') {
2515 if (format
[inpos
+1] == '\'') {
2517 date
[outpos
++] = '\'';
2520 continue; /* we did nothing to the output */
2522 } else if (format
[inpos
] == '\0') {
2523 date
[outpos
++] = '\0';
2524 if (outpos
> datelen
) Overflow
= 1;
2527 date
[outpos
++] = format
[inpos
];
2528 if (outpos
> datelen
) {
2530 date
[outpos
-1] = '\0'; /* this is the last place where
2531 it's safe to write */
2535 } else if ( (count
&& (format
[inpos
] != type
))
2537 || (count
== 2 && strchr("ghHmst", type
)) )
2541 GetLocaleInfoA(locale
,
2543 + xtime
->wDayOfWeek
- 1,
2545 } else if (count
== 3) {
2546 GetLocaleInfoA(locale
,
2547 LOCALE_SABBREVDAYNAME1
2548 + xtime
->wDayOfWeek
- 1,
2551 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2553 } else if (type
== 'M') {
2555 GetLocaleInfoA(locale
,
2556 LOCALE_SABBREVMONTHNAME1
2557 + xtime
->wMonth
- 1,
2559 } else if (count
== 4) {
2560 GetLocaleInfoA(locale
,
2562 + xtime
->wMonth
- 1,
2565 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2567 } else if (type
== 'y') {
2569 sprintf(buf
, "%d", xtime
->wYear
);
2570 } else if (count
== 3) {
2572 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2574 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2576 } else if (type
== 'g') {
2578 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2582 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2584 } else if (type
== 'h') {
2585 /* gives us hours 1:00 -- 12:00 */
2586 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2587 } else if (type
== 'H') {
2589 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2590 } else if ( type
== 'm') {
2591 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2592 } else if ( type
== 's') {
2593 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2594 } else if (type
== 't') {
2596 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2597 } else if (count
== 2) {
2598 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2599 GetLocaleInfoA(locale
,
2601 ? LOCALE_S1159
: LOCALE_S2359
,
2606 /* we need to check the next char in the format string
2607 again, no matter what happened */
2610 /* add the contents of buf to the output */
2611 buflen
= strlen(buf
);
2612 if (outpos
+ buflen
< datelen
) {
2613 date
[outpos
] = '\0'; /* for strcat to hook onto */
2617 date
[outpos
] = '\0';
2618 strncat(date
, buf
, datelen
- outpos
);
2619 date
[datelen
- 1] = '\0';
2620 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2621 WARN("insufficient buffer\n");
2625 /* reset the variables we used to keep track of this item */
2628 } else if (format
[inpos
] == '\0') {
2629 /* we can't check for this at the loop-head, because
2630 that breaks the printing of the last format-item */
2631 date
[outpos
] = '\0';
2634 /* continuing a code for an item */
2637 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2638 type
= format
[inpos
];
2641 } else if (format
[inpos
] == '\'') {
2645 date
[outpos
++] = format
[inpos
];
2647 /* now deal with a possible buffer overflow */
2648 if (outpos
>= datelen
) {
2649 date
[datelen
- 1] = '\0';
2650 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2656 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2659 /* finish it off with a string terminator */
2662 if (outpos
> datelen
-1) outpos
= datelen
-1;
2663 date
[outpos
] = '\0';
2665 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2670 /******************************************************************************
2671 * OLE_GetFormatW [INTERNAL]
2673 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2676 LPWSTR output
, INT outlen
)
2679 int count
, type
=0, inquote
;
2680 int Overflow
; /* loop check */
2683 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2684 WCHAR arg2
[] = {'%','0','2','d',0};
2686 int datevars
=0, timevars
=0;
2692 /* make a debug report */
2693 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2694 "%p with max len %d\n",
2695 locale
, flags
, tflags
,
2696 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2697 debugstr_w(format
), format
, output
, outlen
);
2700 FIXME("outlen = 0, returning 255\n");
2704 /* initialize state variables */
2707 inquote
= Overflow
= 0;
2708 /* this is really just a sanity check */
2709 output
[0] = buf
[0] = 0;
2711 /* this loop is the core of the function */
2712 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2714 if (format
[inpos
] == (WCHAR
) '\'') {
2715 if (format
[inpos
+1] == '\'') {
2717 output
[outpos
++] = '\'';
2722 } else if (format
[inpos
] == 0) {
2723 output
[outpos
++] = 0;
2724 if (outpos
> outlen
) Overflow
= 1;
2725 break; /* normal exit (within a quote) */
2727 output
[outpos
++] = format
[inpos
]; /* copy input */
2728 if (outpos
> outlen
) {
2730 output
[outpos
-1] = 0;
2734 } else if ( (count
&& (format
[inpos
] != type
))
2735 || ( (count
==4 && type
=='y') ||
2736 (count
==4 && type
=='M') ||
2737 (count
==4 && type
=='d') ||
2738 (count
==2 && type
=='g') ||
2739 (count
==2 && type
=='h') ||
2740 (count
==2 && type
=='H') ||
2741 (count
==2 && type
=='m') ||
2742 (count
==2 && type
=='s') ||
2743 (count
==2 && type
=='t') ) ) {
2746 GetLocaleInfoW(locale
,
2747 LOCALE_SDAYNAME1
+ xtime
->wDayOfWeek
-1,
2748 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2749 } else if (count
== 3) {
2750 GetLocaleInfoW(locale
,
2751 LOCALE_SABBREVDAYNAME1
+
2752 xtime
->wDayOfWeek
-1,
2753 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2755 wsnprintfW(buf
, 5, argarr
[count
], xtime
->wDay
);
2757 } else if (type
== 'M') {
2759 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2760 xtime
->wMonth
-1, buf
,
2761 sizeof(buf
)/sizeof(WCHAR
) );
2762 } else if (count
== 3) {
2763 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2764 xtime
->wMonth
-1, buf
,
2765 sizeof(buf
)/sizeof(WCHAR
) );
2767 wsnprintfW(buf
, 5, argarr
[count
], xtime
->wMonth
);
2769 } else if (type
== 'y') {
2771 wsnprintfW(buf
, 6, argarr
[1] /* "%d" */,
2773 } else if (count
== 3) {
2774 lstrcpynAtoW(buf
, "yyy", 5);
2776 wsnprintfW(buf
, 6, argarr
[count
],
2777 xtime
->wYear
% 100);
2779 } else if (type
== 'g') {
2781 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2782 lstrcpynAtoW(buf
, "AD", 5);
2784 /* Win API sez we copy it verbatim */
2785 lstrcpynAtoW(buf
, "g", 5);
2787 } else if (type
== 'h') {
2788 /* hours 1:00-12:00 --- is this right? */
2789 wsnprintfW(buf
, 5, argarr
[count
],
2790 (xtime
->wHour
-1)%12 +1);
2791 } else if (type
== 'H') {
2792 wsnprintfW(buf
, 5, argarr
[count
],
2794 } else if (type
== 'm' ) {
2795 wsnprintfW(buf
, 5, argarr
[count
],
2797 } else if (type
== 's' ) {
2798 wsnprintfW(buf
, 5, argarr
[count
],
2800 } else if (type
== 't') {
2801 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2802 LOCALE_S1159
: LOCALE_S2359
,
2809 /* no matter what happened, we need to check this next
2810 character the next time we loop through */
2813 /* cat buf onto the output */
2814 outlen
= lstrlenW(buf
);
2815 if (outpos
+ buflen
< outlen
) {
2816 lstrcpyW( output
+ outpos
, buf
);
2819 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2821 break; /* Abnormal exit */
2824 /* reset the variables we used this time */
2827 } else if (format
[inpos
] == 0) {
2828 /* we can't check for this at the beginning, because that
2829 would keep us from printing a format spec that ended the
2832 break; /* NORMAL EXIT */
2834 /* how we keep track of the middle of a format spec */
2837 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2838 format
[inpos
]=='M' ||
2839 format
[inpos
]=='y' ||
2840 format
[inpos
]=='g') ) ||
2841 (timevars
&& (format
[inpos
]=='H' ||
2842 format
[inpos
]=='h' ||
2843 format
[inpos
]=='m' ||
2844 format
[inpos
]=='s' ||
2845 format
[inpos
]=='t') ) ) {
2846 type
= format
[inpos
];
2849 } else if (format
[inpos
] == '\'') {
2853 /* unquoted literals */
2854 output
[outpos
++] = format
[inpos
];
2859 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2860 WARN(" buffer overflow\n");
2863 /* final string terminator and sanity check */
2865 if (outpos
> outlen
-1) outpos
= outlen
-1;
2866 output
[outpos
] = '0';
2868 TRACE(" returning %s\n", debugstr_w(output
));
2870 return (!Overflow
) ? outlen
: 0;
2875 /******************************************************************************
2876 * GetDateFormatA [KERNEL32.310]
2877 * Makes an ASCII string of the date
2879 * This function uses format to format the date, or, if format
2880 * is NULL, uses the default for the locale. format is a string
2881 * of literal fields and characters as follows:
2883 * - d single-digit (no leading zero) day (of month)
2884 * - dd two-digit day (of month)
2885 * - ddd short day-of-week name
2886 * - dddd long day-of-week name
2887 * - M single-digit month
2888 * - MM two-digit month
2889 * - MMM short month name
2890 * - MMMM full month name
2891 * - y two-digit year, no leading 0
2892 * - yy two-digit year
2893 * - yyyy four-digit year
2897 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
2899 LPCSTR format
, LPSTR date
,INT datelen
)
2902 char format_buf
[40];
2905 LPSYSTEMTIME thistime
;
2909 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2910 locale
,flags
,xtime
,format
,date
,datelen
);
2913 locale
= LOCALE_SYSTEM_DEFAULT
;
2916 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
2917 thislocale
= GetSystemDefaultLCID();
2918 } else if (locale
== LOCALE_USER_DEFAULT
) {
2919 thislocale
= GetUserDefaultLCID();
2921 thislocale
= locale
;
2924 if (xtime
== NULL
) {
2931 if (format
== NULL
) {
2932 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
2934 : LOCALE_SSHORTDATE
),
2935 format_buf
, sizeof(format_buf
));
2936 thisformat
= format_buf
;
2938 thisformat
= format
;
2942 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
2947 "GetDateFormatA() returning %d, with data=%s\n",
2952 /******************************************************************************
2953 * GetDateFormatW [KERNEL32.311]
2954 * Makes a Unicode string of the date
2956 * Acts the same as GetDateFormatA(), except that it's Unicode.
2957 * Accepts & returns sizes as counts of Unicode characters.
2960 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
2963 LPWSTR date
, INT datelen
)
2965 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
2967 FIXME("STUB (should call OLE_GetFormatW)\n");
2968 lstrcpynW(date
, datearr
, datelen
);
2969 return ( datelen
< 9) ? datelen
: 9;
2974 /**************************************************************************
2975 * EnumDateFormatsA (KERNEL32.198)
2977 BOOL WINAPI
EnumDateFormatsA(
2978 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2980 LCID Loc
= GetUserDefaultLCID();
2981 if(!lpDateFmtEnumProc
)
2983 SetLastError(ERROR_INVALID_PARAMETER
);
2990 case 0x00000407: /* (Loc,"de_DE") */
2994 case DATE_SHORTDATE
:
2995 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2996 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
2997 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2998 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3001 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
3002 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
3003 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
3006 FIXME("Unknown date format (%ld)\n", dwFlags
);
3007 SetLastError(ERROR_INVALID_PARAMETER
);
3012 case 0x0000040c: /* (Loc,"fr_FR") */
3016 case DATE_SHORTDATE
:
3017 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3018 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3019 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3020 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3023 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
3024 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
3025 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3028 FIXME("Unknown date format (%ld)\n", dwFlags
);
3029 SetLastError(ERROR_INVALID_PARAMETER
);
3034 case 0x00000c0c: /* (Loc,"fr_CA") */
3038 case DATE_SHORTDATE
:
3039 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3040 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3041 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
3042 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3045 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
3046 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
3049 FIXME("Unknown date format (%ld)\n", dwFlags
);
3050 SetLastError(ERROR_INVALID_PARAMETER
);
3055 case 0x00000809: /* (Loc,"en_UK") */
3059 case DATE_SHORTDATE
:
3060 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3061 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3062 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3063 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3066 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3067 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3070 FIXME("Unknown date format (%ld)\n", dwFlags
);
3071 SetLastError(ERROR_INVALID_PARAMETER
);
3076 case 0x00000c09: /* (Loc,"en_AU") */
3080 case DATE_SHORTDATE
:
3081 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3082 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3083 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3086 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
3087 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3090 FIXME("Unknown date format (%ld)\n", dwFlags
);
3091 SetLastError(ERROR_INVALID_PARAMETER
);
3096 case 0x00001009: /* (Loc,"en_CA") */
3100 case DATE_SHORTDATE
:
3101 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3102 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3103 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3104 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
3107 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
3108 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
3111 FIXME("Unknown date format (%ld)\n", dwFlags
);
3112 SetLastError(ERROR_INVALID_PARAMETER
);
3117 case 0x00001409: /* (Loc,"en_NZ") */
3121 case DATE_SHORTDATE
:
3122 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3123 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3124 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3127 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3128 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
3131 FIXME("Unknown date format (%ld)\n", dwFlags
);
3132 SetLastError(ERROR_INVALID_PARAMETER
);
3137 case 0x00001809: /* (Loc,"en_IE") */
3141 case DATE_SHORTDATE
:
3142 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3143 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3144 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3147 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3148 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3151 FIXME("Unknown date format (%ld)\n", dwFlags
);
3152 SetLastError(ERROR_INVALID_PARAMETER
);
3157 case 0x00001c09: /* (Loc,"en_ZA") */
3161 case DATE_SHORTDATE
:
3162 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3165 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3168 FIXME("Unknown date format (%ld)\n", dwFlags
);
3169 SetLastError(ERROR_INVALID_PARAMETER
);
3174 case 0x00002009: /* (Loc,"en_JM") */
3178 case DATE_SHORTDATE
:
3179 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3182 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
3183 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
3184 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
3185 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
3188 FIXME("Unknown date format (%ld)\n", dwFlags
);
3189 SetLastError(ERROR_INVALID_PARAMETER
);
3194 case 0x00002809: /* (Loc,"en_BZ") */
3195 case 0x00002c09: /* (Loc,"en_TT") */
3199 case DATE_SHORTDATE
:
3200 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3203 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
3206 FIXME("Unknown date format (%ld)\n", dwFlags
);
3207 SetLastError(ERROR_INVALID_PARAMETER
);
3212 default: /* default to US English "en_US" */
3216 case DATE_SHORTDATE
:
3217 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
3218 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
3219 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
3220 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
3221 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3222 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
3225 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
3226 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
3227 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
3228 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
3231 FIXME("Unknown date format (%ld)\n", dwFlags
);
3232 SetLastError(ERROR_INVALID_PARAMETER
);
3239 /**************************************************************************
3240 * EnumDateFormatsW (KERNEL32.199)
3242 BOOL WINAPI
EnumDateFormatsW(
3243 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3245 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
3246 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3250 /**************************************************************************
3251 * EnumTimeFormatsA (KERNEL32.210)
3253 BOOL WINAPI
EnumTimeFormatsA(
3254 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3256 LCID Loc
= GetUserDefaultLCID();
3257 if(!lpTimeFmtEnumProc
)
3259 SetLastError(ERROR_INVALID_PARAMETER
);
3264 FIXME("Unknown time format (%ld)\n", dwFlags
);
3269 case 0x00000407: /* (Loc,"de_DE") */
3271 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3272 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3273 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3274 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
3275 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
3279 case 0x0000040c: /* (Loc,"fr_FR") */
3280 case 0x00000c0c: /* (Loc,"fr_CA") */
3282 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
3283 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3284 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3285 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3286 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
3290 case 0x00000809: /* (Loc,"en_UK") */
3291 case 0x00000c09: /* (Loc,"en_AU") */
3292 case 0x00001409: /* (Loc,"en_NZ") */
3293 case 0x00001809: /* (Loc,"en_IE") */
3295 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3296 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3297 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3301 case 0x00001c09: /* (Loc,"en_ZA") */
3302 case 0x00002809: /* (Loc,"en_BZ") */
3303 case 0x00002c09: /* (Loc,"en_TT") */
3305 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3306 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3310 default: /* default to US style "en_US" */
3312 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3313 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3314 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3315 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3321 /**************************************************************************
3322 * EnumTimeFormatsW (KERNEL32.211)
3324 BOOL WINAPI
EnumTimeFormatsW(
3325 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3327 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
3328 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3332 /**************************************************************************
3333 * This function is used just locally !
3334 * Description: Inverts a string.
3336 static void OLE_InvertString(char* string
)
3338 char sTmpArray
[128];
3341 for (counter
= strlen(string
); counter
> 0; counter
--)
3343 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
3346 memcpy(sTmpArray
+ i
, "\0", 1);
3347 strcpy(string
, sTmpArray
);
3350 /***************************************************************************************
3351 * This function is used just locally !
3352 * Description: Test if the given string (psNumber) is valid or not.
3353 * The valid characters are the following:
3354 * - Characters '0' through '9'.
3355 * - One decimal point (dot) if the number is a floating-point value.
3356 * - A minus sign in the first character position if the number is
3358 * If the function succeeds, psBefore/psAfter will point to the string
3359 * on the right/left of the decimal symbol. pbNegative indicates if the
3360 * number is negative.
3362 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
3364 char sNumberSet
[] = "0123456789";
3365 BOOL bInDecimal
= FALSE
;
3367 /* Test if we do have a minus sign */
3368 if ( *pInput
== '-' )
3371 pInput
++; /* Jump to the next character. */
3374 while(*pInput
!= '\0')
3376 /* Do we have a valid numeric character */
3377 if ( strchr(sNumberSet
, *pInput
) != NULL
)
3379 if (bInDecimal
== TRUE
)
3380 *psAfter
++ = *pInput
;
3382 *psBefore
++ = *pInput
;
3386 /* Is this a decimal point (dot) */
3387 if ( *pInput
== '.' )
3389 /* Is it the first time we find it */
3390 if ((bInDecimal
== FALSE
))
3393 return -1; /* ERROR: Invalid parameter */
3397 /* It's neither a numeric character, nor a decimal point.
3398 * Thus, return an error.
3406 /* Add an End of Line character to the output buffers */
3413 /**************************************************************************
3414 * This function is used just locally !
3415 * Description: A number could be formatted using different numbers
3416 * of "digits in group" (example: 4;3;2;0).
3417 * The first parameter of this function is an array
3418 * containing the rule to be used. It's format is the following:
3419 * |NDG|DG1|DG2|...|0|
3420 * where NDG is the number of used "digits in group" and DG1, DG2,
3421 * are the corresponding "digits in group".
3422 * Thus, this function returns the grouping value in the array
3423 * pointed by the second parameter.
3425 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3427 char sData
[2], sRuleSize
[2];
3428 INT nData
, nRuleSize
;
3430 memcpy(sRuleSize
, sRule
, 1);
3431 memcpy(sRuleSize
+1, "\0", 1);
3432 nRuleSize
= atoi(sRuleSize
);
3434 if (index
> 0 && index
< nRuleSize
)
3436 memcpy(sData
, sRule
+index
, 1);
3437 memcpy(sData
+1, "\0", 1);
3438 nData
= atoi(sData
);
3443 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3444 memcpy(sData
+1, "\0", 1);
3445 nData
= atoi(sData
);
3451 /**************************************************************************
3452 * GetNumberFormatA (KERNEL32.355)
3454 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3455 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3456 LPSTR lpNumberStr
, int cchNumber
)
3458 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3459 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3460 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3461 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3462 char *pStr
= NULL
, *pTmpStr
= NULL
;
3463 LCID systemDefaultLCID
;
3464 BOOL bNegative
= FALSE
;
3473 strncpy(sNumber
, lpvalue
, 128);
3474 sNumber
[127] = '\0';
3476 /* Make sure we have a valid input string, get the number
3477 * of digits before and after the decimal symbol, and check
3478 * if this is a negative number.
3480 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3482 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3483 nDigits
= strlen(sDigitsAfterDecimal
);
3487 SetLastError(ERROR_INVALID_PARAMETER
);
3491 /* Which source will we use to format the string */
3492 used_operation
= RETURN_ERROR
;
3493 if (lpFormat
!= NULL
)
3496 used_operation
= USE_PARAMETER
;
3500 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3501 used_operation
= USE_LOCALEINFO
;
3503 used_operation
= USE_SYSTEMDEFAULT
;
3506 /* Load the fields we need */
3507 switch(used_operation
)
3509 case USE_LOCALEINFO
:
3510 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3511 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3512 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3513 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3514 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3515 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3518 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3519 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3520 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3521 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3522 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3523 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3525 case USE_SYSTEMDEFAULT
:
3526 systemDefaultLCID
= GetSystemDefaultLCID();
3527 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3528 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3529 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3530 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3531 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3532 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3535 SetLastError(ERROR_INVALID_PARAMETER
);
3539 nNumberDigits
= atoi(sNumberDigits
);
3541 /* Remove the ";" */
3544 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3546 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3548 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3553 sprintf(sBuffer
, "%d", i
);
3554 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3555 memcpy(sRule
+ j
, "\0", 1);
3557 /* First, format the digits before the decimal. */
3558 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3560 /* Working on an inverted string is easier ! */
3561 OLE_InvertString(sDigitsBeforeDecimal
);
3563 nStep
= nCounter
= i
= j
= 0;
3565 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3567 /* Here, we will loop until we reach the end of the string.
3568 * An internal counter (j) is used in order to know when to
3569 * insert the "digit group symbol".
3571 while (nNumberDecimal
> 0)
3573 i
= nCounter
+ nStep
;
3574 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3580 if (nRuleIndex
< sRule
[0])
3582 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3583 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3584 nStep
+= strlen(sDigitGroupSymbol
);
3590 memcpy(sDestination
+ i
+1, "\0", 1);
3591 /* Get the string in the right order ! */
3592 OLE_InvertString(sDestination
);
3596 nLZ
= atoi(sILZero
);
3599 /* Use 0.xxx instead of .xxx */
3600 memcpy(sDestination
, "0", 1);
3601 memcpy(sDestination
+1, "\0", 1);
3604 memcpy(sDestination
, "\0", 1);
3608 /* Second, format the digits after the decimal. */
3610 nCounter
= nNumberDigits
;
3611 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3613 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3614 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3615 j
= strlen(sDigitsAfterDecimal
);
3616 if (j
< nNumberDigits
)
3617 nCounter
= nNumberDigits
-j
;
3619 for (i
=0;i
<nCounter
;i
++)
3620 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3621 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3623 i
= strlen(sDestination
);
3624 j
= strlen(sDigitsAfterDecimal
);
3625 /* Finally, construct the resulting formatted string. */
3627 for (nCounter
=0; nCounter
<i
; nCounter
++)
3628 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3630 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3633 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3634 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3636 /* Is it a negative number */
3637 if (bNegative
== TRUE
)
3639 i
= atoi(sNegNumber
);
3640 pStr
= sDestination
;
3646 while (*sNumber
!= '\0')
3647 *pStr
++ = *pTmpStr
++;
3652 while (*pTmpStr
!= '\0')
3653 *pStr
++ = *pTmpStr
++;
3658 while (*pTmpStr
!= '\0')
3659 *pStr
++ = *pTmpStr
++;
3662 while (*pTmpStr
!= '\0')
3663 *pStr
++ = *pTmpStr
++;
3667 while (*pTmpStr
!= '\0')
3668 *pStr
++ = *pTmpStr
++;
3673 while (*pTmpStr
!= '\0')
3674 *pStr
++ = *pTmpStr
++;
3679 strcpy(sDestination
, sNumber
);
3681 /* If cchNumber is zero, then returns the number of bytes or characters
3682 * required to hold the formatted number string
3685 retVal
= strlen(sDestination
) + 1;
3688 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3689 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3690 retVal
= strlen(lpNumberStr
);
3696 /**************************************************************************
3697 * GetNumberFormatW (KERNEL32.xxx)
3699 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3700 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3701 LPWSTR lpNumberStr
, int cchNumber
)
3703 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue
));
3705 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3706 return cchNumber
? lstrlenW( lpNumberStr
) : 0;
3709 /**************************************************************************
3710 * GetCurrencyFormatA (KERNEL32.302)
3712 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3713 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3714 LPSTR lpCurrencyStr
, int cchCurrency
)
3716 UINT nPosOrder
, nNegOrder
;
3718 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3719 char *pDestination
= sDestination
;
3720 char sNumberFormated
[128];
3721 char *pNumberFormated
= sNumberFormated
;
3722 LCID systemDefaultLCID
;
3723 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3732 NUMBERFMTA numberFmt
;
3734 /* Which source will we use to format the string */
3735 used_operation
= RETURN_ERROR
;
3736 if (lpFormat
!= NULL
)
3739 used_operation
= USE_PARAMETER
;
3743 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3744 used_operation
= USE_LOCALEINFO
;
3746 used_operation
= USE_SYSTEMDEFAULT
;
3749 /* Load the fields we need */
3750 switch(used_operation
)
3752 case USE_LOCALEINFO
:
3753 /* Specific to CURRENCYFMTA*/
3754 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3755 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3756 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3758 nPosOrder
= atoi(sPosOrder
);
3759 nNegOrder
= atoi(sNegOrder
);
3762 /* Specific to CURRENCYFMTA*/
3763 nNegOrder
= lpFormat
->NegativeOrder
;
3764 nPosOrder
= lpFormat
->PositiveOrder
;
3765 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3767 case USE_SYSTEMDEFAULT
:
3768 systemDefaultLCID
= GetSystemDefaultLCID();
3769 /* Specific to CURRENCYFMTA*/
3770 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3771 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3772 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3774 nPosOrder
= atoi(sPosOrder
);
3775 nNegOrder
= atoi(sNegOrder
);
3778 SetLastError(ERROR_INVALID_PARAMETER
);
3782 /* Construct a temporary number format structure */
3783 if (lpFormat
!= NULL
)
3785 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3786 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3787 numberFmt
.Grouping
= lpFormat
->Grouping
;
3788 numberFmt
.NegativeOrder
= 0;
3789 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3790 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3791 bValidFormat
= TRUE
;
3794 /* Make a call to GetNumberFormatA() */
3795 if (*lpvalue
== '-')
3797 bIsPositive
= FALSE
;
3798 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3803 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3809 /* construct the formatted string */
3814 case 0: /* Prefix, no separation */
3815 strcpy (pDestination
, sCurrencySymbol
);
3816 strcat (pDestination
, pNumberFormated
);
3818 case 1: /* Suffix, no separation */
3819 strcpy (pDestination
, pNumberFormated
);
3820 strcat (pDestination
, sCurrencySymbol
);
3822 case 2: /* Prefix, 1 char separation */
3823 strcpy (pDestination
, sCurrencySymbol
);
3824 strcat (pDestination
, " ");
3825 strcat (pDestination
, pNumberFormated
);
3827 case 3: /* Suffix, 1 char separation */
3828 strcpy (pDestination
, pNumberFormated
);
3829 strcat (pDestination
, " ");
3830 strcat (pDestination
, sCurrencySymbol
);
3833 SetLastError(ERROR_INVALID_PARAMETER
);
3837 else /* negative number */
3841 case 0: /* format: ($1.1) */
3842 strcpy (pDestination
, "(");
3843 strcat (pDestination
, sCurrencySymbol
);
3844 strcat (pDestination
, pNumberFormated
);
3845 strcat (pDestination
, ")");
3847 case 1: /* format: -$1.1 */
3848 strcpy (pDestination
, "-");
3849 strcat (pDestination
, sCurrencySymbol
);
3850 strcat (pDestination
, pNumberFormated
);
3852 case 2: /* format: $-1.1 */
3853 strcpy (pDestination
, sCurrencySymbol
);
3854 strcat (pDestination
, "-");
3855 strcat (pDestination
, pNumberFormated
);
3857 case 3: /* format: $1.1- */
3858 strcpy (pDestination
, sCurrencySymbol
);
3859 strcat (pDestination
, pNumberFormated
);
3860 strcat (pDestination
, "-");
3862 case 4: /* format: (1.1$) */
3863 strcpy (pDestination
, "(");
3864 strcat (pDestination
, pNumberFormated
);
3865 strcat (pDestination
, sCurrencySymbol
);
3866 strcat (pDestination
, ")");
3868 case 5: /* format: -1.1$ */
3869 strcpy (pDestination
, "-");
3870 strcat (pDestination
, pNumberFormated
);
3871 strcat (pDestination
, sCurrencySymbol
);
3873 case 6: /* format: 1.1-$ */
3874 strcpy (pDestination
, pNumberFormated
);
3875 strcat (pDestination
, "-");
3876 strcat (pDestination
, sCurrencySymbol
);
3878 case 7: /* format: 1.1$- */
3879 strcpy (pDestination
, pNumberFormated
);
3880 strcat (pDestination
, sCurrencySymbol
);
3881 strcat (pDestination
, "-");
3883 case 8: /* format: -1.1 $ */
3884 strcpy (pDestination
, "-");
3885 strcat (pDestination
, pNumberFormated
);
3886 strcat (pDestination
, " ");
3887 strcat (pDestination
, sCurrencySymbol
);
3889 case 9: /* format: -$ 1.1 */
3890 strcpy (pDestination
, "-");
3891 strcat (pDestination
, sCurrencySymbol
);
3892 strcat (pDestination
, " ");
3893 strcat (pDestination
, pNumberFormated
);
3895 case 10: /* format: 1.1 $- */
3896 strcpy (pDestination
, pNumberFormated
);
3897 strcat (pDestination
, " ");
3898 strcat (pDestination
, sCurrencySymbol
);
3899 strcat (pDestination
, "-");
3901 case 11: /* format: $ 1.1- */
3902 strcpy (pDestination
, sCurrencySymbol
);
3903 strcat (pDestination
, " ");
3904 strcat (pDestination
, pNumberFormated
);
3905 strcat (pDestination
, "-");
3907 case 12: /* format: $ -1.1 */
3908 strcpy (pDestination
, sCurrencySymbol
);
3909 strcat (pDestination
, " ");
3910 strcat (pDestination
, "-");
3911 strcat (pDestination
, pNumberFormated
);
3913 case 13: /* format: 1.1- $ */
3914 strcpy (pDestination
, pNumberFormated
);
3915 strcat (pDestination
, "-");
3916 strcat (pDestination
, " ");
3917 strcat (pDestination
, sCurrencySymbol
);
3919 case 14: /* format: ($ 1.1) */
3920 strcpy (pDestination
, "(");
3921 strcat (pDestination
, sCurrencySymbol
);
3922 strcat (pDestination
, " ");
3923 strcat (pDestination
, pNumberFormated
);
3924 strcat (pDestination
, ")");
3926 case 15: /* format: (1.1 $) */
3927 strcpy (pDestination
, "(");
3928 strcat (pDestination
, pNumberFormated
);
3929 strcat (pDestination
, " ");
3930 strcat (pDestination
, sCurrencySymbol
);
3931 strcat (pDestination
, ")");
3934 SetLastError(ERROR_INVALID_PARAMETER
);
3939 if (cchCurrency
== 0)
3940 return strlen(pDestination
) + 1;
3944 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
3945 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
3946 return strlen(lpCurrencyStr
);
3950 /**************************************************************************
3951 * GetCurrencyFormatW (KERNEL32.303)
3953 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
3954 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
3955 LPWSTR lpCurrencyStr
, int cchCurrency
)
3957 FIXME("This API function is NOT implemented !\n");
3961 /******************************************************************************
3962 * OLE2NLS_CheckLocale [intern]
3964 static LCID
OLE2NLS_CheckLocale (LCID locale
)
3967 { locale
= LOCALE_SYSTEM_DEFAULT
;
3970 if (locale
== LOCALE_SYSTEM_DEFAULT
)
3971 { return GetSystemDefaultLCID();
3973 else if (locale
== LOCALE_USER_DEFAULT
)
3974 { return GetUserDefaultLCID();
3980 /******************************************************************************
3981 * GetTimeFormatA [KERNEL32.422]
3982 * Makes an ASCII string of the time
3984 * Formats date according to format, or locale default if format is
3985 * NULL. The format consists of literal characters and fields as follows:
3987 * h hours with no leading zero (12-hour)
3988 * hh hours with full two digits
3989 * H hours with no leading zero (24-hour)
3990 * HH hours with full two digits
3991 * m minutes with no leading zero
3992 * mm minutes with full two digits
3993 * s seconds with no leading zero
3994 * ss seconds with full two digits
3995 * t time marker (A or P)
3996 * tt time marker (AM, PM)
4000 GetTimeFormatA(LCID locale
, /* in */
4001 DWORD flags
, /* in */
4002 LPSYSTEMTIME xtime
, /* in */
4003 LPCSTR format
, /* in */
4004 LPSTR timestr
, /* out */
4005 INT timelen
/* in */)
4006 { char format_buf
[40];
4009 LPSYSTEMTIME thistime
;
4011 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4014 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
4016 thislocale
= OLE2NLS_CheckLocale ( locale
);
4018 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4019 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4022 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4025 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4026 { thislocale
= GetSystemDefaultLCID();
4028 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
4029 thisformat
= format_buf
;
4032 { thisformat
= format
;
4035 if (xtime
== NULL
) /* NULL means use the current local time*/
4042 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4048 /******************************************************************************
4049 * GetTimeFormatW [KERNEL32.423]
4050 * Makes a Unicode string of the time
4053 GetTimeFormatW(LCID locale
, /* in */
4054 DWORD flags
, /* in */
4055 LPSYSTEMTIME xtime
, /* in */
4056 LPCWSTR format
, /* in */
4057 LPWSTR timestr
, /* out */
4058 INT timelen
/* in */)
4059 { WCHAR format_buf
[40];
4062 LPSYSTEMTIME thistime
;
4064 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4067 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
4068 xtime
,debugstr_w(format
),timestr
,timelen
);
4070 thislocale
= OLE2NLS_CheckLocale ( locale
);
4072 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4073 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4076 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4079 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4080 { thislocale
= GetSystemDefaultLCID();
4082 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
4083 thisformat
= format_buf
;
4086 { thisformat
= format
;
4089 if (xtime
== NULL
) /* NULL means use the current local time*/
4090 { GetSystemTime(&t
);
4097 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4102 /******************************************************************************
4103 * EnumCalendarInfoA [KERNEL32.196]
4105 BOOL WINAPI
EnumCalendarInfoA(
4106 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
4108 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);