1 /* $Id: nls.c,v 1.7 2003/03/16 13:07:02 chorns 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>
31 NlsMbCodePageTag
= FALSE
;
34 NlsMbOemCodePageTag
= FALSE
;
37 NlsLeadByteInfo
= 0; /* ? */
40 NlsOemLeadByteInfo
= 0;
46 NlsOemCodePage
= 0; /* not exported */
49 PWCHAR NlsAnsiToUnicodeTable
= NULL
;
50 PWCHAR NlsOemToUnicodeTable
= NULL
;
52 PCHAR NlsUnicodeToAnsiTable
= NULL
;
53 PCHAR NlsUnicodeToOemTable
= NULL
;
55 PWCHAR NlsUnicodeUpcaseTable
= NULL
;
56 PWCHAR NlsUnicodeLowercaseTable
= NULL
;
60 /* FUNCTIONS *****************************************************************/
64 * RtlInitCodePageTable
66 * RtlResetRtlTranslations
70 * RtlConsoleMultiByteToUnicodeN@24
75 RtlCustomCPToUnicodeN (
76 PRTL_NLS_DATA NlsData
,
86 if (NlsData
->DbcsFlag
== FALSE
)
88 /* single-byte code page */
89 if (CustomSize
> (UnicodeSize
/ sizeof(WCHAR
)))
90 Size
= UnicodeSize
/ sizeof(WCHAR
);
94 if (ResultSize
!= NULL
)
95 *ResultSize
= Size
* sizeof(WCHAR
);
97 for (i
= 0; i
< Size
; i
++)
99 *UnicodeString
= NlsData
->MultiByteToUnicode
[(int)*CustomString
];
106 /* multi-byte code page */
111 return STATUS_SUCCESS
;
117 RtlGetDefaultCodePage (
118 PUSHORT AnsiCodePage
,
122 *AnsiCodePage
= NlsAnsiCodePage
;
123 *OemCodePage
= NlsOemCodePage
;
129 RtlMultiByteToUnicodeN (
130 PWCHAR UnicodeString
,
140 if (NlsMbCodePageTag
== FALSE
)
142 /* single-byte code page */
143 if (MbSize
> (UnicodeSize
/ sizeof(WCHAR
)))
144 Size
= UnicodeSize
/ sizeof(WCHAR
);
148 if (ResultSize
!= NULL
)
149 *ResultSize
= Size
* sizeof(WCHAR
);
151 for (i
= 0; i
< Size
; i
++)
153 *UnicodeString
= *MbString
;
155 *UnicodeString
= NlsAnsiToUnicodeTable
[*MbString
];
164 /* multi-byte code page */
169 return STATUS_SUCCESS
;
175 RtlMultiByteToUnicodeSize (
181 if (NlsMbCodePageTag
== FALSE
)
183 /* single-byte code page */
184 *UnicodeSize
= MbSize
* sizeof (WCHAR
);
188 /* multi-byte code page */
193 return STATUS_SUCCESS
;
200 PWCHAR UnicodeString
,
210 if (NlsMbOemCodePageTag
== FALSE
)
212 /* single-byte code page */
213 if (OemSize
> (UnicodeSize
/ sizeof(WCHAR
)))
214 Size
= UnicodeSize
/ sizeof(WCHAR
);
218 if (ResultSize
!= NULL
)
219 *ResultSize
= Size
* sizeof(WCHAR
);
221 for (i
= 0; i
< Size
; i
++)
223 *UnicodeString
= *OemString
;
225 *UnicodeString
= NlsOemToUnicodeTable
[*OemString
];
234 /* multi-byte code page */
239 return STATUS_SUCCESS
;
245 RtlUnicodeToCustomCPN (
246 PRTL_NLS_DATA NlsData
,
250 PWCHAR UnicodeString
,
257 if (NlsData
->DbcsFlag
== 0)
259 /* single-byte code page */
260 if (UnicodeSize
> (CustomSize
* sizeof(WCHAR
)))
263 Size
= UnicodeSize
/ sizeof(WCHAR
);
265 if (ResultSize
!= NULL
)
268 for (i
= 0; i
< Size
; i
++)
270 *CustomString
= NlsData
->UnicodeToMultiByte
[*UnicodeString
];
277 /* multi-byte code page */
282 return STATUS_SUCCESS
;
288 RtlUnicodeToMultiByteN (
292 PWCHAR UnicodeString
,
299 if (NlsMbCodePageTag
== FALSE
)
301 /* single-byte code page */
302 if (UnicodeSize
> (MbSize
* sizeof(WCHAR
)))
305 Size
= UnicodeSize
/ sizeof(WCHAR
);
307 if (ResultSize
!= NULL
)
310 for (i
= 0; i
< Size
; i
++)
312 *MbString
= *UnicodeString
;
314 *MbString
= UnicodeToAnsiTable
[*UnicodeString
];
323 /* multi-byte code page */
328 return STATUS_SUCCESS
;
334 RtlUnicodeToMultiByteSize (
336 PWCHAR UnicodeString
,
340 if (NlsMbCodePageTag
== FALSE
)
342 /* single-byte code page */
343 *MbSize
= UnicodeSize
/ sizeof (WCHAR
);
347 /* multi-byte code page */
353 return STATUS_SUCCESS
;
363 PWCHAR UnicodeString
,
370 if (NlsMbOemCodePageTag
== FALSE
)
372 /* single-byte code page */
373 if (UnicodeSize
> (OemSize
* sizeof(WCHAR
)))
376 Size
= UnicodeSize
/ sizeof(WCHAR
);
378 if (ResultSize
!= NULL
)
381 for (i
= 0; i
< Size
; i
++)
383 *OemString
= *UnicodeString
;
385 *OemString
= UnicodeToOemTable
[*UnicodeString
];
394 /* multi-byte code page */
399 return STATUS_SUCCESS
;
405 RtlUpcaseUnicodeToCustomCPN (
406 PRTL_NLS_DATA NlsData
,
410 PWCHAR UnicodeString
,
418 if (NlsData
->DbcsFlag
== 0)
420 /* single-byte code page */
421 if (UnicodeSize
> (CustomSize
* sizeof(WCHAR
)))
424 Size
= UnicodeSize
/ sizeof(WCHAR
);
426 if (ResultSize
!= NULL
)
429 for (i
= 0; i
< Size
; i
++)
431 *CustomString
= NlsData
->UnicodeToMultiByte
[*UnicodeString
];
433 UpcaseChar
= NlsUnicodeUpcaseTable
[*UnicodeString
];
434 *CustomString
= NlsData
->UnicodeToMultiByte
[UpcaseChar
];
442 /* multi-byte code page */
447 return STATUS_SUCCESS
;
453 RtlUpcaseUnicodeToMultiByteN (
457 PWCHAR UnicodeString
,
465 if (NLS_MB_CODE_PAGE_TAG
== FALSE
)
467 /* single-byte code page */
468 if (UnicodeSize
> (MbSize
* sizeof(WCHAR
)))
471 Size
= UnicodeSize
/ sizeof(WCHAR
);
473 if (ResultSize
!= NULL
)
476 for (i
= 0; i
< Size
; i
++)
478 *MbString
= *UnicodeString
;
480 UpcaseChar
= NlsUnicodeUpcaseTable
[*UnicodeString
];
481 *MbString
= NlsUnicodeToAnsiTable
[UpcaseChar
];
490 /* multi-byte code page */
495 return STATUS_SUCCESS
;
501 RtlUpcaseUnicodeToOemN (
505 PWCHAR UnicodeString
,
513 if (NLS_MB_OEM_CODE_PAGE_TAG
== FALSE
)
515 /* single-byte code page */
516 if (UnicodeSize
> (OemSize
* sizeof(WCHAR
)))
519 Size
= UnicodeSize
/ sizeof(WCHAR
);
521 if (ResultSize
!= NULL
)
524 for (i
= 0; i
< Size
; i
++)
526 *OemString
= *UnicodeString
;
528 UpcaseChar
= NlsUnicodeUpcaseTable
[*UnicodeString
];
529 *OemString
= UnicodeToOemTable
[UpcaseChar
];
538 /* multi-byte code page */
543 return STATUS_SUCCESS
;