3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/rtl/unicode.c
6 * PURPOSE: String functions
7 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
12 #include <ddk/ntddk.h>
13 #include <ntdll/rtl.h>
14 //#include <internal/nls.h>
16 #include <ntos/minmax.h>
18 #include <ntdll/ntdll.h>
20 /* FUNCTIONS *****************************************************************/
24 RtlAnsiCharToUnicodeChar(
32 Size = (NlsLeadByteInfo[AnsiChar] == 0) ? 1 : 2;
35 RtlMultiByteToUnicodeN (&UnicodeChar,
47 RtlAnsiStringToUnicodeSize(
48 IN PANSI_STRING AnsiString)
52 RtlMultiByteToUnicodeSize (&Size,
62 RtlAnsiStringToUnicodeString(
63 IN OUT PUNICODE_STRING DestinationString,
64 IN PANSI_STRING SourceString,
65 IN BOOLEAN AllocateDestinationString)
70 if (NlsMbCodePageTag == TRUE)
71 Length = RtlAnsiStringToUnicodeSize (SourceString);
73 Length = SourceString->Length * sizeof(WCHAR);
76 return STATUS_INVALID_PARAMETER_2;
78 if (AllocateDestinationString == TRUE)
80 DestinationString->MaximumLength = Length + sizeof(WCHAR);
81 DestinationString->Buffer =
82 RtlAllocateHeap (RtlGetProcessHeap (),
84 DestinationString->MaximumLength);
85 if (DestinationString->Buffer == NULL)
86 return STATUS_NO_MEMORY;
90 if (Length + sizeof(WCHAR) > DestinationString->MaximumLength)
92 DPRINT("STATUS_BUFFER_TOO_SMALL\n");
93 return STATUS_BUFFER_TOO_SMALL;
96 DestinationString->Length = Length;
98 RtlZeroMemory (DestinationString->Buffer,
99 DestinationString->Length);
101 Status = RtlMultiByteToUnicodeN (DestinationString->Buffer,
102 DestinationString->Length,
104 SourceString->Buffer,
105 SourceString->Length);
106 if (!NT_SUCCESS(Status))
108 if (AllocateDestinationString)
110 RtlFreeHeap (RtlGetProcessHeap (),
112 DestinationString->Buffer);
117 DestinationString->Buffer[Length / sizeof(WCHAR)] = 0;
119 return STATUS_SUCCESS;
125 RtlAppendAsciizToString(
126 IN OUT PSTRING Destination,
133 return STATUS_SUCCESS;
135 Length = strlen (Source);
136 if (Destination->Length + Length >= Destination->MaximumLength)
137 return STATUS_BUFFER_TOO_SMALL;
139 Ptr = Destination->Buffer + Destination->Length;
146 Destination->Length += Length;
148 return STATUS_SUCCESS;
154 RtlAppendStringToString(
155 IN OUT PSTRING Destination,
160 if (Source->Length == 0)
161 return STATUS_SUCCESS;
163 if (Destination->Length + Source->Length >= Destination->MaximumLength)
164 return STATUS_BUFFER_TOO_SMALL;
166 Ptr = Destination->Buffer + Destination->Length;
170 Ptr += Source->Length;
173 Destination->Length += Source->Length;
175 return STATUS_SUCCESS;
181 RtlAppendUnicodeStringToString(
182 IN OUT PUNICODE_STRING Destination,
183 IN PUNICODE_STRING Source)
189 if ((Source->Length + Destination->Length) >= Destination->MaximumLength)
190 return STATUS_BUFFER_TOO_SMALL;
192 Src = Source->Buffer;
193 Dest = Destination->Buffer + (Destination->Length / sizeof (WCHAR));
194 for (i = 0; i < (Source->Length / sizeof(WCHAR)); i++)
202 Destination->Length += Source->Length;
204 return STATUS_SUCCESS;
209 RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
217 slen = wcslen(Source) * sizeof(WCHAR);
219 if (Destination->Length + slen >= Destination->MaximumLength)
220 return(STATUS_BUFFER_TOO_SMALL);
223 Dest = Destination->Buffer + (Destination->Length / sizeof(WCHAR));
225 for (i = 0; i < (slen / sizeof(WCHAR)); i++)
233 Destination->Length += slen;
235 return(STATUS_SUCCESS);
257 if ((*String == 'x') && isxdigit (String[1]))
265 if (!isxdigit (*String))
266 return STATUS_INVALID_PARAMETER;
268 while (isxdigit (*String) &&
269 (Val = isdigit (*String) ? * String - '0' : (islower (*String)
270 ? toupper (*String) : *String) - 'A' + 10) < Base)
272 *Value = *Value * Base + Val;
276 return STATUS_SUCCESS;
285 IN BOOLEAN CaseInsensitive)
291 if (String1 && String2)
293 len1 = String1->Length;
294 len2 = String2->Length;
295 s1 = String1->Buffer;
296 s2 = String2->Buffer;
304 c1 = len1-- ? RtlUpperChar (*s1++) : 0;
305 c2 = len2-- ? RtlUpperChar (*s2++) : 0;
306 if (!c1 || !c2 || c1 != c2)
314 c1 = len1-- ? *s1++ : 0;
315 c2 = len2-- ? *s2++ : 0;
316 if (!c1 || !c2 || c1 != c2)
329 RtlCompareUnicodeString(
330 IN PUNICODE_STRING String1,
331 IN PUNICODE_STRING String2,
332 IN BOOLEAN CaseInsensitive)
338 if (String1 && String2)
340 len1 = String1->Length / sizeof(WCHAR);
341 len2 = String2->Length / sizeof(WCHAR);
342 s1 = String1->Buffer;
343 s2 = String2->Buffer;
351 c1 = len1-- ? RtlUpcaseUnicodeChar (*s1++) : 0;
352 c2 = len2-- ? RtlUpcaseUnicodeChar (*s2++) : 0;
353 if (!c1 || !c2 || c1 != c2)
361 c1 = len1-- ? *s1++ : 0;
362 c2 = len2-- ? *s2++ : 0;
363 if (!c1 || !c2 || c1 != c2)
377 IN OUT PSTRING DestinationString,
378 IN PSTRING SourceString)
383 if (SourceString == NULL)
385 DestinationString->Length = 0;
389 copylen = min (DestinationString->MaximumLength - sizeof(CHAR),
390 SourceString->Length);
391 Src = SourceString->Buffer;
392 Dest = DestinationString->Buffer;
394 for (i = 0; i < copylen; i++)
402 DestinationString->Length = copylen;
408 RtlCopyUnicodeString(
409 IN OUT PUNICODE_STRING DestinationString,
410 IN PUNICODE_STRING SourceString)
415 if (SourceString == NULL)
417 DestinationString->Length = 0;
421 copylen = min (DestinationString->MaximumLength - sizeof(WCHAR),
422 SourceString->Length);
423 Src = SourceString->Buffer;
424 Dest = DestinationString->Buffer;
426 for (i = 0; i < (copylen / sizeof (WCHAR)); i++)
434 DestinationString->Length = copylen;
440 RtlCreateUnicodeString(
441 IN OUT PUNICODE_STRING Destination,
446 Length = (wcslen (Source) + 1) * sizeof(WCHAR);
448 Destination->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
451 if (Destination->Buffer == NULL)
454 memmove (Destination->Buffer,
458 Destination->MaximumLength = Length;
459 Destination->Length = Length - sizeof (WCHAR);
467 RtlCreateUnicodeStringFromAsciiz(
468 OUT PUNICODE_STRING Destination,
471 ANSI_STRING AnsiString;
474 RtlInitAnsiString (&AnsiString,
477 Status = RtlAnsiStringToUnicodeString (Destination,
481 return NT_SUCCESS(Status);
487 RtlDowncaseUnicodeString(
488 IN OUT PUNICODE_STRING DestinationString,
489 IN PUNICODE_STRING SourceString,
490 IN BOOLEAN AllocateDestinationString)
495 if (AllocateDestinationString == TRUE)
497 DestinationString->MaximumLength = SourceString->Length + sizeof(WCHAR);
498 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
500 SourceString->Length + sizeof(WCHAR));
504 if (SourceString->Length >= DestinationString->MaximumLength)
505 return STATUS_BUFFER_TOO_SMALL;
507 DestinationString->Length = SourceString->Length;
509 Src = SourceString->Buffer;
510 Dest = DestinationString->Buffer;
511 for (i=0; i < SourceString->Length / sizeof(WCHAR); i++)
517 else if (*Src <= L'Z')
519 *Dest = (*Src + (L'a' - L'A'));
523 /* FIXME: characters above 'Z' */
532 return STATUS_SUCCESS;
538 RtlEqualComputerName(
539 IN PUNICODE_STRING ComputerName1,
540 IN PUNICODE_STRING ComputerName2)
542 return RtlEqualDomainName (ComputerName1,
550 IN PUNICODE_STRING DomainName1,
551 IN PUNICODE_STRING DomainName2
554 OEM_STRING OemString1;
555 OEM_STRING OemString2;
558 RtlUpcaseUnicodeStringToOemString (&OemString1,
561 RtlUpcaseUnicodeStringToOemString (&OemString2,
565 Result = RtlEqualString (&OemString1,
569 RtlFreeOemString (&OemString1);
570 RtlFreeOemString (&OemString2);
581 IN BOOLEAN CaseInsensitive)
587 if (String1->Length != String2->Length)
590 p1 = String1->Buffer;
591 p2 = String2->Buffer;
592 for (i = 0; i < String1->Length; i++)
594 if (CaseInsensitive == TRUE)
596 c1 = RtlUpperChar (*p1);
597 c2 = RtlUpperChar (*p2);
618 RtlEqualUnicodeString(
619 IN PUNICODE_STRING String1,
620 IN PUNICODE_STRING String2,
621 IN BOOLEAN CaseInsensitive)
627 if (String1->Length != String2->Length)
630 pw1 = String1->Buffer;
631 pw2 = String2->Buffer;
633 for (i = 0; i < String1->Length / sizeof(WCHAR); i++)
635 if (CaseInsensitive == TRUE)
637 wc1 = RtlUpcaseUnicodeChar (*pw1);
638 wc2 = RtlUpcaseUnicodeChar (*pw2);
659 RtlEraseUnicodeString(
660 IN PUNICODE_STRING String)
662 if (String->Buffer == NULL)
665 if (String->MaximumLength == 0)
668 memset (String->Buffer,
670 String->MaximumLength);
679 IN PANSI_STRING AnsiString)
681 if (AnsiString->Buffer == NULL)
684 RtlFreeHeap (RtlGetProcessHeap (),
688 AnsiString->Buffer = NULL;
689 AnsiString->Length = 0;
690 AnsiString->MaximumLength = 0;
697 IN POEM_STRING OemString)
699 if (OemString->Buffer == NULL)
702 RtlFreeHeap (RtlGetProcessHeap (),
706 OemString->Buffer = NULL;
707 OemString->Length = 0;
708 OemString->MaximumLength = 0;
714 RtlFreeUnicodeString(
715 IN PUNICODE_STRING UnicodeString)
717 if (UnicodeString->Buffer == NULL)
720 RtlFreeHeap (RtlGetProcessHeap (),
722 UnicodeString->Buffer);
724 UnicodeString->Buffer = NULL;
725 UnicodeString->Length = 0;
726 UnicodeString->MaximumLength = 0;
733 IN OUT PANSI_STRING DestinationString,
734 IN PCSZ SourceString)
738 if(SourceString==NULL)
740 DestinationString->Length = 0;
741 DestinationString->MaximumLength = 0;
745 DestSize = strlen ((const char *)SourceString);
746 DestinationString->Length = DestSize;
747 DestinationString->MaximumLength = DestSize + 1;
749 DestinationString->Buffer = (PCHAR)SourceString;
756 IN OUT PSTRING DestinationString,
757 IN PCSZ SourceString)
761 if (SourceString == NULL)
763 DestinationString->Length = 0;
764 DestinationString->MaximumLength = 0;
768 DestSize = strlen((const char *)SourceString);
769 DestinationString->Length = DestSize;
770 DestinationString->MaximumLength = DestSize + sizeof(CHAR);
772 DestinationString->Buffer = (PCHAR)SourceString;
778 RtlInitUnicodeString(
779 IN OUT PUNICODE_STRING DestinationString,
780 IN PCWSTR SourceString)
784 if (SourceString==NULL)
786 DestinationString->Length=0;
787 DestinationString->MaximumLength=0;
791 DestSize = wcslen((PWSTR)SourceString) * sizeof(WCHAR);
792 DestinationString->Length = DestSize;
793 DestinationString->MaximumLength = DestSize + sizeof(WCHAR);
795 DestinationString->Buffer = (PWSTR)SourceString;
818 if ((Radix != 2) && (Radix != 8) &&
819 (Radix != 10) && (Radix != 16))
820 return STATUS_INVALID_PARAMETER;
823 while (v || tp == temp)
834 if (tp - temp >= Length)
835 return STATUS_BUFFER_TOO_SMALL;
842 return STATUS_SUCCESS;
848 RtlIntegerToUnicodeString(
850 IN ULONG Base, /* optional */
851 IN OUT PUNICODE_STRING String)
853 ANSI_STRING AnsiString;
857 Status = RtlIntegerToChar (Value,
861 if (!NT_SUCCESS(Status))
864 AnsiString.Buffer = Buffer;
865 AnsiString.Length = strlen (Buffer);
866 AnsiString.MaximumLength = 33;
868 Status = RtlAnsiStringToUnicodeString (String,
878 RtlLargeIntegerToChar(
879 IN PLARGE_INTEGER Value,
886 ULONGLONG v = Value->QuadPart;
895 if ((Radix != 2) && (Radix != 8) &&
896 (Radix != 10) && (Radix != 16))
897 return STATUS_INVALID_PARAMETER;
900 while (v || tp == temp)
911 if (tp - temp >= Length)
912 return STATUS_BUFFER_TOO_SMALL;
919 return STATUS_SUCCESS;
925 RtlOemStringToUnicodeSize(
926 IN POEM_STRING OemString)
930 RtlMultiByteToUnicodeSize (&Size,
940 RtlOemStringToUnicodeString(
941 IN OUT PUNICODE_STRING DestinationString,
942 IN POEM_STRING SourceString,
943 IN BOOLEAN AllocateDestinationString)
948 if (NlsMbCodePageTag == TRUE)
949 Length = RtlAnsiStringToUnicodeSize (SourceString);
951 Length = SourceString->Length * sizeof(WCHAR);
954 return STATUS_INVALID_PARAMETER_2;
956 if (AllocateDestinationString == TRUE)
958 DestinationString->MaximumLength = Length + sizeof(WCHAR);
959 DestinationString->Buffer =
960 RtlAllocateHeap (RtlGetProcessHeap (),
962 DestinationString->MaximumLength);
963 if (DestinationString->Buffer == NULL)
964 return STATUS_NO_MEMORY;
968 if (Length + sizeof(WCHAR) > DestinationString->MaximumLength)
970 DPRINT("STATUS_BUFFER_TOO_SMALL\n");
971 return STATUS_BUFFER_TOO_SMALL;
974 DestinationString->Length = Length;
976 RtlZeroMemory (DestinationString->Buffer,
977 DestinationString->Length);
979 Status = RtlOemToUnicodeN (DestinationString->Buffer,
980 DestinationString->Length,
982 SourceString->Buffer,
983 SourceString->Length);
984 if (!NT_SUCCESS(Status))
986 if (AllocateDestinationString)
988 RtlFreeHeap (RtlGetProcessHeap (),
990 DestinationString->Buffer);
995 DestinationString->Buffer[Length / sizeof(WCHAR)] = 0;
997 return STATUS_SUCCESS;
1004 PANSI_STRING String1,
1005 PANSI_STRING String2,
1006 BOOLEAN CaseInsensitive)
1012 if (String2->Length < String1->Length)
1015 Length = String1->Length;
1016 pc1 = String1->Buffer;
1017 pc2 = String2->Buffer;
1021 if (CaseInsensitive)
1025 if (RtlUpperChar (*pc1++) != RtlUpperChar (*pc2++))
1033 if (*pc1++ != *pc2++)
1045 RtlPrefixUnicodeString(
1046 PUNICODE_STRING String1,
1047 PUNICODE_STRING String2,
1048 BOOLEAN CaseInsensitive)
1054 if (String2->Length < String1->Length)
1057 Length = String1->Length / 2;
1058 pc1 = String1->Buffer;
1059 pc2 = String2->Buffer;
1063 if (CaseInsensitive)
1067 if (RtlUpcaseUnicodeChar (*pc1++)
1068 != RtlUpcaseUnicodeChar (*pc2++))
1076 if( *pc1++ != *pc2++ )
1088 RtlUnicodeStringToAnsiSize(
1089 IN PUNICODE_STRING UnicodeString)
1093 RtlUnicodeToMultiByteSize (&Size,
1094 UnicodeString->Buffer,
1095 UnicodeString->Length);
1097 return Size+1; //NB: incl. nullterm
1103 RtlUnicodeStringToAnsiString(
1104 IN OUT PANSI_STRING DestinationString,
1105 IN PUNICODE_STRING SourceString,
1106 IN BOOLEAN AllocateDestinationString)
1111 if (NlsMbCodePageTag == TRUE)
1112 Length = RtlUnicodeStringToAnsiSize (SourceString);
1114 Length = SourceString->Length / sizeof(WCHAR);
1116 if (AllocateDestinationString == TRUE)
1118 DestinationString->MaximumLength = Length + sizeof(CHAR);
1119 DestinationString->Buffer =
1120 RtlAllocateHeap (RtlGetProcessHeap (),
1122 DestinationString->MaximumLength);
1123 if (DestinationString->Buffer == NULL)
1124 return STATUS_NO_MEMORY;
1128 if (Length >= DestinationString->MaximumLength)
1129 return STATUS_BUFFER_TOO_SMALL;
1131 DestinationString->Length = Length;
1133 RtlZeroMemory (DestinationString->Buffer,
1134 DestinationString->Length);
1136 Status = RtlUnicodeToMultiByteN (DestinationString->Buffer,
1137 DestinationString->Length,
1139 SourceString->Buffer,
1140 SourceString->Length);
1141 if (!NT_SUCCESS(Status))
1143 if (AllocateDestinationString == TRUE)
1145 RtlFreeHeap (RtlGetProcessHeap (),
1147 DestinationString->Buffer);
1152 DestinationString->Buffer[Length] = 0;
1154 return STATUS_SUCCESS;
1160 RtlUnicodeStringToInteger(
1161 IN PUNICODE_STRING String,
1169 BOOLEAN addneg = FALSE;
1172 Str = String->Buffer;
1174 for (i = 0; i < String->Length / sizeof(WCHAR); i++)
1181 else if (*Str == L'o')
1186 else if (*Str == L'd')
1191 else if (*Str == L'x')
1196 else if (*Str == L'+')
1200 else if (*Str == L'-')
1205 else if ((*Str > L'1') && (Base == 2))
1207 return STATUS_INVALID_PARAMETER;
1209 else if (((*Str > L'7') || (*Str < L'0')) && (Base == 8))
1211 return STATUS_INVALID_PARAMETER;
1213 else if (((*Str > L'9') || (*Str < L'0')) && (Base == 10))
1215 return STATUS_INVALID_PARAMETER;
1217 else if ((((*Str > L'9') || (*Str < L'0')) ||
1218 ((towupper (*Str) > L'F') ||
1219 (towupper (*Str) < L'A'))) && (Base == 16))
1221 return STATUS_INVALID_PARAMETER;
1227 Str = String->Buffer + lenmin;
1232 while (iswxdigit (*Str) &&
1233 (Val = iswdigit (*Str) ? *Str - L'0' : (iswlower (*Str)
1234 ? toupper (*Str) : *Str) - L'A' + 10) < Base)
1236 *Value = *Value * Base + Val;
1243 return STATUS_SUCCESS;
1249 RtlUnicodeStringToOemSize(
1250 IN PUNICODE_STRING UnicodeString)
1254 RtlUnicodeToMultiByteSize (&Size,
1255 UnicodeString->Buffer,
1256 UnicodeString->Length);
1258 return Size+1; //NB: incl. nullterm
1264 RtlUnicodeStringToCountedOemString(
1265 IN OUT POEM_STRING DestinationString,
1266 IN PUNICODE_STRING SourceString,
1267 IN BOOLEAN AllocateDestinationString)
1273 if (NlsMbOemCodePageTag == TRUE)
1274 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1276 Length = SourceString->Length / sizeof(WCHAR) + 1;
1278 if (Length > 0x0000FFFF)
1279 return STATUS_INVALID_PARAMETER_2;
1281 DestinationString->Length = (WORD)(Length - 1);
1283 if (AllocateDestinationString)
1285 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1288 if (DestinationString->Buffer == NULL)
1289 return STATUS_NO_MEMORY;
1291 RtlZeroMemory (DestinationString->Buffer,
1293 DestinationString->MaximumLength = (WORD)Length;
1297 if (Length > DestinationString->MaximumLength)
1299 if (DestinationString->MaximumLength == 0)
1300 return STATUS_BUFFER_OVERFLOW;
1301 DestinationString->Length =
1302 DestinationString->MaximumLength - 1;
1306 Status = RtlUnicodeToOemN (DestinationString->Buffer,
1307 DestinationString->Length,
1309 SourceString->Buffer,
1310 SourceString->Length);
1311 if (!NT_SUCCESS(Status))
1313 if (AllocateDestinationString)
1315 RtlFreeHeap (RtlGetProcessHeap (),
1317 DestinationString->Buffer);
1322 DestinationString->Buffer[Size] = 0;
1324 return STATUS_SUCCESS;
1330 RtlUnicodeStringToOemString(
1331 IN OUT POEM_STRING DestinationString,
1332 IN PUNICODE_STRING SourceString,
1333 IN BOOLEAN AllocateDestinationString)
1339 if (NlsMbOemCodePageTag == TRUE)
1340 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1342 Length = SourceString->Length / sizeof(WCHAR) + 1;
1344 if (Length > 0x0000FFFF)
1345 return STATUS_INVALID_PARAMETER_2;
1347 DestinationString->Length = (WORD)(Length - 1);
1349 if (AllocateDestinationString)
1351 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1354 if (DestinationString->Buffer == NULL)
1355 return STATUS_NO_MEMORY;
1357 RtlZeroMemory (DestinationString->Buffer,
1359 DestinationString->MaximumLength = (WORD)Length;
1363 if (Length > DestinationString->MaximumLength)
1365 if (DestinationString->MaximumLength == 0)
1366 return STATUS_BUFFER_OVERFLOW;
1367 DestinationString->Length =
1368 DestinationString->MaximumLength - 1;
1372 Status = RtlUnicodeToOemN (DestinationString->Buffer,
1373 DestinationString->Length,
1375 SourceString->Buffer,
1376 SourceString->Length);
1377 if (!NT_SUCCESS(Status))
1379 if (AllocateDestinationString)
1381 RtlFreeHeap (RtlGetProcessHeap (),
1383 DestinationString->Buffer);
1388 DestinationString->Buffer[Size] = 0;
1390 return STATUS_SUCCESS;
1396 RtlUpcaseUnicodeChar(IN WCHAR Source)
1402 return (Source - (L'a' - L'A'));
1404 /* FIXME: characters above 'z' */
1412 RtlUpcaseUnicodeString(
1413 IN OUT PUNICODE_STRING DestinationString,
1414 IN PUNICODE_STRING SourceString,
1415 IN BOOLEAN AllocateDestinationString)
1420 if (AllocateDestinationString == TRUE)
1422 DestinationString->MaximumLength=SourceString->Length+sizeof(WCHAR);
1423 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1425 SourceString->Length + sizeof(WCHAR));
1426 if (DestinationString->Buffer == NULL)
1427 return STATUS_NO_MEMORY;
1431 if (SourceString->Length >= DestinationString->MaximumLength)
1432 return STATUS_BUFFER_TOO_SMALL;
1434 DestinationString->Length = SourceString->Length;
1436 Src = SourceString->Buffer;
1437 Dest = DestinationString->Buffer;
1438 for (i = 0; i < SourceString->Length / sizeof(WCHAR); i++)
1440 *Dest = RtlUpcaseUnicodeChar (*Src);
1446 return STATUS_SUCCESS;
1452 RtlUpcaseUnicodeStringToAnsiString(
1453 IN OUT PANSI_STRING DestinationString,
1454 IN PUNICODE_STRING SourceString,
1455 IN BOOLEAN AllocateDestinationString)
1461 if (NlsMbCodePageTag == TRUE)
1462 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1464 Length = SourceString->Length / sizeof(WCHAR) + 1;
1466 if (Length > 0x0000FFFF)
1467 return STATUS_INVALID_PARAMETER_2;
1469 DestinationString->Length = (WORD)(Length - 1);
1471 if (AllocateDestinationString == TRUE)
1473 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1475 DestinationString->MaximumLength);
1476 if (DestinationString->Buffer == NULL)
1477 return STATUS_NO_MEMORY;
1479 RtlZeroMemory (DestinationString->Buffer,
1481 DestinationString->MaximumLength = (WORD)Length;
1485 if (Length > DestinationString->MaximumLength)
1487 if (!DestinationString->MaximumLength)
1488 return STATUS_BUFFER_OVERFLOW;
1489 DestinationString->Length =
1490 DestinationString->MaximumLength - 1;
1494 Status = RtlUpcaseUnicodeToMultiByteN (DestinationString->Buffer,
1495 DestinationString->Length,
1497 SourceString->Buffer,
1498 SourceString->Length);
1499 if (!NT_SUCCESS(Status))
1501 if (AllocateDestinationString)
1503 RtlFreeHeap (RtlGetProcessHeap (),
1505 DestinationString->Buffer);
1510 DestinationString->Buffer[Size] = 0;
1512 return STATUS_SUCCESS;
1518 RtlUpcaseUnicodeStringToCountedOemString(
1519 IN OUT POEM_STRING DestinationString,
1520 IN PUNICODE_STRING SourceString,
1521 IN BOOLEAN AllocateDestinationString)
1527 if (NlsMbCodePageTag == TRUE)
1528 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1530 Length = SourceString->Length / sizeof(WCHAR) + 1;
1532 if (Length > 0x0000FFFF)
1533 return STATUS_INVALID_PARAMETER_2;
1535 DestinationString->Length = (WORD)(Length - 1);
1537 if (AllocateDestinationString == TRUE)
1539 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1542 if (DestinationString->Buffer == NULL)
1543 return STATUS_NO_MEMORY;
1545 RtlZeroMemory (DestinationString->Buffer,
1547 DestinationString->MaximumLength = (WORD)Length;
1551 if (Length > DestinationString->MaximumLength)
1553 if (DestinationString->MaximumLength == 0)
1554 return STATUS_BUFFER_OVERFLOW;
1555 DestinationString->Length =
1556 DestinationString->MaximumLength - 1;
1560 Status = RtlUpcaseUnicodeToOemN (DestinationString->Buffer,
1561 DestinationString->Length,
1563 SourceString->Buffer,
1564 SourceString->Length);
1565 if (!NT_SUCCESS(Status))
1567 if (AllocateDestinationString)
1569 RtlFreeHeap (RtlGetProcessHeap (),
1571 DestinationString->Buffer);
1576 DestinationString->Buffer[Size] = 0;
1578 return STATUS_SUCCESS;
1584 RtlUpcaseUnicodeStringToOemString (
1585 IN OUT POEM_STRING DestinationString,
1586 IN PUNICODE_STRING SourceString,
1587 IN BOOLEAN AllocateDestinationString
1594 if (NlsMbOemCodePageTag == TRUE)
1595 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1597 Length = SourceString->Length / sizeof(WCHAR) + 1;
1599 if (Length > 0x0000FFFF)
1600 return STATUS_INVALID_PARAMETER_2;
1602 DestinationString->Length = (WORD)(Length - 1);
1604 if (AllocateDestinationString == TRUE)
1606 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1609 if (DestinationString->Buffer == NULL)
1610 return STATUS_NO_MEMORY;
1612 RtlZeroMemory (DestinationString->Buffer,
1614 DestinationString->MaximumLength = (WORD)Length;
1618 if (Length > DestinationString->MaximumLength)
1620 if (DestinationString->MaximumLength == 0)
1621 return STATUS_BUFFER_OVERFLOW;
1622 DestinationString->Length =
1623 DestinationString->MaximumLength - 1;
1627 Status = RtlUpcaseUnicodeToOemN (DestinationString->Buffer,
1628 DestinationString->Length,
1630 SourceString->Buffer,
1631 SourceString->Length);
1632 if (!NT_SUCCESS(Status))
1634 if (AllocateDestinationString)
1636 RtlFreeHeap (RtlGetProcessHeap (),
1638 DestinationString->Buffer);
1643 DestinationString->Buffer[Size] = 0;
1645 return STATUS_SUCCESS;
1658 if (NlsMbCodePageTag == FALSE)
1660 /* single-byte code page */
1662 Unicode = (WCHAR)Source;
1664 Unicode = NlsAnsiToUnicodeData[Source];
1667 /* upcase conversion */
1668 Unicode = RtlUpcaseUnicodeChar (Unicode);
1670 /* unicode -> ansi */
1671 Destination = (CHAR)Unicode;
1673 Destination = NlsUnicodeToAnsiData[Unicode];
1678 /* single-byte code page */
1679 /* FIXME: implement the multi-byte stuff!! */
1680 Destination = Source;
1690 IN OUT PSTRING DestinationString,
1691 IN PSTRING SourceString)
1698 Length = min(SourceString->Length, DestinationString->MaximumLength - 1);
1700 Src = SourceString->Buffer;
1701 Dest = DestinationString->Buffer;
1702 for (i = 0; i < Length; i++)
1704 *Dest = RtlUpperChar (*Src);
1710 DestinationString->Length = SourceString->Length;
1716 RtlxAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
1718 return RtlAnsiStringToUnicodeSize(AnsiString);
1724 RtlxOemStringToUnicodeSize(IN POEM_STRING OemString)
1726 return RtlAnsiStringToUnicodeSize((PANSI_STRING)OemString);
1732 RtlxUnicodeStringToAnsiSize(IN PUNICODE_STRING UnicodeString)
1734 return RtlUnicodeStringToAnsiSize(UnicodeString);
1740 RtlxUnicodeStringToOemSize(IN PUNICODE_STRING UnicodeString)
1742 return RtlUnicodeStringToAnsiSize(UnicodeString);