1 /* $Id: nls.c,v 1.4 2000/05/25 15:52:53 ekohl Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/rtl/nls.c
6 * PURPOSE: National Language Support (NLS) functions
8 * 20/08/99 Created by Emanuele Aliberti
9 * 10/11/99 Added translation functions.
12 * Multi-byte code pages are not supported yet. Even single-byte code
13 * pages are not supported properly. Only stupid CHAR->WCHAR and
14 * WCHAR->CHAR (Attention: data loss!!!) translation is done.
17 * 1) Implement code to initialize the translation tables.
18 * 2) Use fixed translation table for translation.
19 * 3) Add loading of translation tables (NLS files).
20 * 4) Implement unicode upcase and downcase handling.
21 * 5) Add multi-byte translation code.
24 #include <ddk/ntddk.h>
25 //#include <internal/nls.h>
29 NlsMbCodePageTag
= FALSE
;
32 NlsMbOemCodePageTag
= FALSE
;
35 NlsLeadByteInfo
= 0; /* ? */
38 NlsOemLeadByteInfo
= 0;
44 NlsOemCodePage
= 0; /* not exported */
47 PWCHAR NlsAnsiToUnicodeTable
= NULL
;
48 PWCHAR NlsOemToUnicodeTable
= NULL
;
50 PCHAR NlsUnicodeToAnsiTable
= NULL
;
51 PCHAR NlsUnicodeToOemTable
= NULL
;
53 PWCHAR NlsUnicodeUpcaseTable
= NULL
;
54 PWCHAR NlsUnicodeLowercaseTable
= NULL
;
58 /* FUNCTIONS *****************************************************************/
62 * RtlInitCodePageTable
64 * RtlResetRtlTranslations
68 * RtlConsoleMultiByteToUnicodeN@24
73 RtlCustomCPToUnicodeN (
74 PRTL_NLS_DATA NlsData
,
84 if (NlsData
->DbcsFlag
== FALSE
)
86 /* single-byte code page */
87 if (CustomSize
> (UnicodeSize
/ sizeof(WCHAR
)))
88 Size
= UnicodeSize
/ sizeof(WCHAR
);
92 if (ResultSize
!= NULL
)
93 *ResultSize
= Size
* sizeof(WCHAR
);
95 for (i
= 0; i
< Size
; i
++)
97 *UnicodeString
= NlsData
->MultiByteToUnicode
[(int)*CustomString
];
104 /* multi-byte code page */
109 return STATUS_SUCCESS
;
115 RtlGetDefaultCodePage (
116 PUSHORT AnsiCodePage
,
120 *AnsiCodePage
= NlsAnsiCodePage
;
121 *OemCodePage
= NlsOemCodePage
;
127 RtlMultiByteToUnicodeN (
128 PWCHAR UnicodeString
,
138 if (NlsMbCodePageTag
== FALSE
)
140 /* single-byte code page */
141 if (MbSize
> (UnicodeSize
/ sizeof(WCHAR
)))
142 Size
= UnicodeSize
/ sizeof(WCHAR
);
146 if (ResultSize
!= NULL
)
147 *ResultSize
= Size
* sizeof(WCHAR
);
149 for (i
= 0; i
< Size
; i
++)
151 *UnicodeString
= *MbString
;
153 *UnicodeString
= NlsAnsiToUnicodeTable
[*MbString
];
162 /* multi-byte code page */
167 return STATUS_SUCCESS
;
173 RtlMultiByteToUnicodeSize (
179 if (NlsMbCodePageTag
== FALSE
)
181 /* single-byte code page */
182 *UnicodeSize
= MbSize
* sizeof (WCHAR
);
186 /* multi-byte code page */
191 return STATUS_SUCCESS
;
198 PWCHAR UnicodeString
,
208 if (NlsMbOemCodePageTag
== FALSE
)
210 /* single-byte code page */
211 if (OemSize
> (UnicodeSize
/ sizeof(WCHAR
)))
212 Size
= UnicodeSize
/ sizeof(WCHAR
);
216 if (ResultSize
!= NULL
)
217 *ResultSize
= Size
* sizeof(WCHAR
);
219 for (i
= 0; i
< Size
; i
++)
221 *UnicodeString
= *OemString
;
223 *UnicodeString
= NlsOemToUnicodeTable
[*OemString
];
232 /* multi-byte code page */
237 return STATUS_SUCCESS
;
243 RtlUnicodeToCustomCPN (
244 PRTL_NLS_DATA NlsData
,
248 PWCHAR UnicodeString
,
255 if (NlsData
->DbcsFlag
== 0)
257 /* single-byte code page */
258 if (UnicodeSize
> (CustomSize
* sizeof(WCHAR
)))
261 Size
= UnicodeSize
/ sizeof(WCHAR
);
263 if (ResultSize
!= NULL
)
266 for (i
= 0; i
< Size
; i
++)
268 *CustomString
= NlsData
->UnicodeToMultiByte
[*UnicodeString
];
275 /* multi-byte code page */
280 return STATUS_SUCCESS
;
286 RtlUnicodeToMultiByteN (
290 PWCHAR UnicodeString
,
297 if (NlsMbCodePageTag
== FALSE
)
299 /* single-byte code page */
300 if (UnicodeSize
> (MbSize
* sizeof(WCHAR
)))
303 Size
= UnicodeSize
/ sizeof(WCHAR
);
305 if (ResultSize
!= NULL
)
308 for (i
= 0; i
< Size
; i
++)
310 *MbString
= *UnicodeString
;
312 *MbString
= UnicodeToAnsiTable
[*UnicodeString
];
321 /* multi-byte code page */
326 return STATUS_SUCCESS
;
332 RtlUnicodeToMultiByteSize (
334 PWCHAR UnicodeString
,
338 if (NlsMbCodePageTag
== FALSE
)
340 /* single-byte code page */
341 *MbSize
= UnicodeSize
/ sizeof (WCHAR
);
345 /* multi-byte code page */
350 return STATUS_SUCCESS
;
360 PWCHAR UnicodeString
,
367 if (NlsMbOemCodePageTag
== FALSE
)
369 /* single-byte code page */
370 if (UnicodeSize
> (OemSize
* sizeof(WCHAR
)))
373 Size
= UnicodeSize
/ sizeof(WCHAR
);
375 if (ResultSize
!= NULL
)
378 for (i
= 0; i
< Size
; i
++)
380 *OemString
= *UnicodeString
;
382 *OemString
= UnicodeToOemTable
[*UnicodeString
];
391 /* multi-byte code page */
396 return STATUS_SUCCESS
;
402 RtlUpcaseUnicodeToCustomCPN (
403 PRTL_NLS_DATA NlsData
,
407 PWCHAR UnicodeString
,
415 if (NlsData
->DbcsFlag
== 0)
417 /* single-byte code page */
418 if (UnicodeSize
> (CustomSize
* sizeof(WCHAR
)))
421 Size
= UnicodeSize
/ sizeof(WCHAR
);
423 if (ResultSize
!= NULL
)
426 for (i
= 0; i
< Size
; i
++)
428 *CustomString
= NlsData
->UnicodeToMultiByte
[*UnicodeString
];
430 UpcaseChar
= NlsUnicodeUpcaseTable
[*UnicodeString
];
431 *CustomString
= NlsData
->UnicodeToMultiByte
[UpcaseChar
];
439 /* multi-byte code page */
444 return STATUS_SUCCESS
;
450 RtlUpcaseUnicodeToMultiByteN (
454 PWCHAR UnicodeString
,
462 if (NLS_MB_CODE_PAGE_TAG
== FALSE
)
464 /* single-byte code page */
465 if (UnicodeSize
> (MbSize
* sizeof(WCHAR
)))
468 Size
= UnicodeSize
/ sizeof(WCHAR
);
470 if (ResultSize
!= NULL
)
473 for (i
= 0; i
< Size
; i
++)
475 *MbString
= *UnicodeString
;
477 UpcaseChar
= NlsUnicodeUpcaseTable
[*UnicodeString
];
478 *MbString
= NlsUnicodeToAnsiTable
[UpcaseChar
];
487 /* multi-byte code page */
492 return STATUS_SUCCESS
;
498 RtlUpcaseUnicodeToOemN (
502 PWCHAR UnicodeString
,
510 if (NLS_MB_OEM_CODE_PAGE_TAG
== FALSE
)
512 /* single-byte code page */
513 if (UnicodeSize
> (OemSize
* sizeof(WCHAR
)))
516 Size
= UnicodeSize
/ sizeof(WCHAR
);
518 if (ResultSize
!= NULL
)
521 for (i
= 0; i
< Size
; i
++)
523 *OemString
= *UnicodeString
;
525 UpcaseChar
= NlsUnicodeUpcaseTable
[*UnicodeString
];
526 *OemString
= UnicodeToOemTable
[UpcaseChar
];
535 /* multi-byte code page */
540 return STATUS_SUCCESS
;