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 (
33 Size = (NlsLeadByteInfo[AnsiChar] == 0) ? 1 : 2;
36 RtlMultiByteToUnicodeN (&UnicodeChar,
48 RtlAnsiStringToUnicodeSize (
49 IN PANSI_STRING AnsiString
54 RtlMultiByteToUnicodeSize (&Size,
64 RtlAnsiStringToUnicodeString(
65 IN OUT PUNICODE_STRING DestinationString,
66 IN PANSI_STRING SourceString,
67 IN BOOLEAN AllocateDestinationString
73 if (NlsMbCodePageTag == TRUE)
74 Length = RtlAnsiStringToUnicodeSize (SourceString);
76 Length = SourceString->Length * sizeof(WCHAR);
79 return STATUS_INVALID_PARAMETER_2;
81 if (AllocateDestinationString == TRUE)
83 DestinationString->MaximumLength = Length + sizeof(WCHAR);
84 DestinationString->Buffer =
85 RtlAllocateHeap (RtlGetProcessHeap (),
87 DestinationString->MaximumLength);
88 if (DestinationString->Buffer == NULL)
89 return STATUS_NO_MEMORY;
93 if (Length + sizeof(WCHAR) > DestinationString->MaximumLength)
95 DPRINT("STATUS_BUFFER_TOO_SMALL\n");
96 return STATUS_BUFFER_TOO_SMALL;
99 DestinationString->Length = Length;
101 RtlZeroMemory (DestinationString->Buffer,
102 DestinationString->Length);
104 Status = RtlMultiByteToUnicodeN (DestinationString->Buffer,
105 DestinationString->Length,
107 SourceString->Buffer,
108 SourceString->Length);
109 if (!NT_SUCCESS(Status))
111 if (AllocateDestinationString)
113 RtlFreeHeap (RtlGetProcessHeap (),
115 DestinationString->Buffer);
120 DestinationString->Buffer[Length / sizeof(WCHAR)] = 0;
122 return STATUS_SUCCESS;
128 RtlAppendAsciizToString (
129 IN OUT PSTRING Destination,
137 return STATUS_SUCCESS;
139 Length = strlen (Source);
140 if (Destination->Length + Length >= Destination->MaximumLength)
141 return STATUS_BUFFER_TOO_SMALL;
143 Ptr = Destination->Buffer + Destination->Length;
150 Destination->Length += Length;
152 return STATUS_SUCCESS;
158 RtlAppendStringToString (
159 IN OUT PSTRING Destination,
165 if (Source->Length == 0)
166 return STATUS_SUCCESS;
168 if (Destination->Length + Source->Length >= Destination->MaximumLength)
169 return STATUS_BUFFER_TOO_SMALL;
171 Ptr = Destination->Buffer + Destination->Length;
175 Ptr += Source->Length;
178 Destination->Length += Source->Length;
180 return STATUS_SUCCESS;
186 RtlAppendUnicodeStringToString (
187 IN OUT PUNICODE_STRING Destination,
188 IN PUNICODE_STRING Source
195 if ((Source->Length + Destination->Length) >= Destination->MaximumLength)
196 return STATUS_BUFFER_TOO_SMALL;
198 Src = Source->Buffer;
199 Dest = Destination->Buffer + (Destination->Length / sizeof (WCHAR));
200 for (i = 0; i < (Source->Length / sizeof(WCHAR)); i++)
208 Destination->Length += Source->Length;
210 return STATUS_SUCCESS;
215 RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
223 slen = wcslen(Source) * sizeof(WCHAR);
225 if (Destination->Length + slen >= Destination->MaximumLength)
226 return(STATUS_BUFFER_TOO_SMALL);
229 Dest = Destination->Buffer + (Destination->Length / sizeof(WCHAR));
231 for (i = 0; i < (slen / sizeof(WCHAR)); i++)
239 Destination->Length += slen;
241 return(STATUS_SUCCESS);
263 if ((*String == 'x') && isxdigit (String[1]))
271 if (!isxdigit (*String))
272 return STATUS_INVALID_PARAMETER;
274 while (isxdigit (*String) &&
275 (Val = isdigit (*String) ? * String - '0' : (islower (*String)
276 ? toupper (*String) : *String) - 'A' + 10) < Base)
278 *Value = *Value * Base + Val;
282 return STATUS_SUCCESS;
291 IN BOOLEAN CaseInsensitive
298 if (String1 && String2)
300 len1 = String1->Length;
301 len2 = String2->Length;
302 s1 = String1->Buffer;
303 s2 = String2->Buffer;
311 c1 = len1-- ? RtlUpperChar (*s1++) : 0;
312 c2 = len2-- ? RtlUpperChar (*s2++) : 0;
313 if (!c1 || !c2 || c1 != c2)
321 c1 = len1-- ? *s1++ : 0;
322 c2 = len2-- ? *s2++ : 0;
323 if (!c1 || !c2 || c1 != c2)
336 RtlCompareUnicodeString (
337 IN PUNICODE_STRING String1,
338 IN PUNICODE_STRING String2,
339 IN BOOLEAN CaseInsensitive
346 if (String1 && String2)
348 len1 = String1->Length / sizeof(WCHAR);
349 len2 = String2->Length / sizeof(WCHAR);
350 s1 = String1->Buffer;
351 s2 = String2->Buffer;
359 c1 = len1-- ? RtlUpcaseUnicodeChar (*s1++) : 0;
360 c2 = len2-- ? RtlUpcaseUnicodeChar (*s2++) : 0;
361 if (!c1 || !c2 || c1 != c2)
369 c1 = len1-- ? *s1++ : 0;
370 c2 = len2-- ? *s2++ : 0;
371 if (!c1 || !c2 || c1 != c2)
385 IN OUT PSTRING DestinationString,
386 IN PSTRING SourceString
392 if (SourceString == NULL)
394 DestinationString->Length = 0;
398 copylen = min (DestinationString->MaximumLength - sizeof(CHAR),
399 SourceString->Length);
400 Src = SourceString->Buffer;
401 Dest = DestinationString->Buffer;
403 for (i = 0; i < copylen; i++)
411 DestinationString->Length = copylen;
417 RtlCopyUnicodeString (
418 IN OUT PUNICODE_STRING DestinationString,
419 IN PUNICODE_STRING SourceString
425 if (SourceString == NULL)
427 DestinationString->Length = 0;
431 copylen = min (DestinationString->MaximumLength - sizeof(WCHAR),
432 SourceString->Length);
433 Src = SourceString->Buffer;
434 Dest = DestinationString->Buffer;
436 for (i = 0; i < (copylen / sizeof (WCHAR)); i++)
444 DestinationString->Length = copylen;
450 RtlCreateUnicodeString (
451 IN OUT PUNICODE_STRING Destination,
457 Length = (wcslen (Source) + 1) * sizeof(WCHAR);
459 Destination->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
462 if (Destination->Buffer == NULL)
465 memmove (Destination->Buffer,
469 Destination->MaximumLength = Length;
470 Destination->Length = Length - sizeof (WCHAR);
477 RtlCreateUnicodeStringFromAsciiz (OUT PUNICODE_STRING Destination,
480 ANSI_STRING AnsiString;
483 RtlInitAnsiString (&AnsiString,
486 Status = RtlAnsiStringToUnicodeString (Destination,
490 return NT_SUCCESS(Status);
496 RtlDowncaseUnicodeString (
497 IN OUT PUNICODE_STRING DestinationString,
498 IN PUNICODE_STRING SourceString,
499 IN BOOLEAN AllocateDestinationString
505 if (AllocateDestinationString == TRUE)
507 DestinationString->MaximumLength = SourceString->Length + sizeof(WCHAR);
508 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
510 SourceString->Length + sizeof(WCHAR));
514 if (SourceString->Length >= DestinationString->MaximumLength)
515 return STATUS_BUFFER_TOO_SMALL;
517 DestinationString->Length = SourceString->Length;
519 Src = SourceString->Buffer;
520 Dest = DestinationString->Buffer;
521 for (i=0; i < SourceString->Length / sizeof(WCHAR); i++)
527 else if (*Src <= L'Z')
529 *Dest = (*Src + (L'a' - L'A'));
533 /* FIXME: characters above 'Z' */
542 return STATUS_SUCCESS;
548 RtlEqualComputerName (
549 IN PUNICODE_STRING ComputerName1,
550 IN PUNICODE_STRING ComputerName2
553 return RtlEqualDomainName (ComputerName1,
561 IN PUNICODE_STRING DomainName1,
562 IN PUNICODE_STRING DomainName2
565 OEM_STRING OemString1;
566 OEM_STRING OemString2;
569 RtlUpcaseUnicodeStringToOemString (&OemString1,
572 RtlUpcaseUnicodeStringToOemString (&OemString2,
576 Result = RtlEqualString (&OemString1,
580 RtlFreeOemString (&OemString1);
581 RtlFreeOemString (&OemString2);
592 IN BOOLEAN CaseInsensitive
599 if (String1->Length != String2->Length)
602 p1 = String1->Buffer;
603 p2 = String2->Buffer;
604 for (i = 0; i < String1->Length; i++)
606 if (CaseInsensitive == TRUE)
608 c1 = RtlUpperChar (*p1);
609 c2 = RtlUpperChar (*p2);
630 RtlEqualUnicodeString (
631 IN PUNICODE_STRING String1,
632 IN PUNICODE_STRING String2,
633 IN BOOLEAN CaseInsensitive
640 if (String1->Length != String2->Length)
643 pw1 = String1->Buffer;
644 pw2 = String2->Buffer;
646 for (i = 0; i < String1->Length / sizeof(WCHAR); i++)
648 if (CaseInsensitive == TRUE)
650 wc1 = RtlUpcaseUnicodeChar (*pw1);
651 wc2 = RtlUpcaseUnicodeChar (*pw2);
672 RtlEraseUnicodeString (
673 IN PUNICODE_STRING String
676 if (String->Buffer == NULL)
679 if (String->MaximumLength == 0)
682 memset (String->Buffer,
684 String->MaximumLength);
693 IN PANSI_STRING AnsiString
696 if (AnsiString->Buffer == NULL)
699 RtlFreeHeap (RtlGetProcessHeap (),
703 AnsiString->Buffer = NULL;
704 AnsiString->Length = 0;
705 AnsiString->MaximumLength = 0;
712 IN POEM_STRING OemString
715 if (OemString->Buffer == NULL)
718 RtlFreeHeap (RtlGetProcessHeap (),
722 OemString->Buffer = NULL;
723 OemString->Length = 0;
724 OemString->MaximumLength = 0;
730 RtlFreeUnicodeString (
731 IN PUNICODE_STRING UnicodeString
734 if (UnicodeString->Buffer == NULL)
737 RtlFreeHeap (RtlGetProcessHeap (),
739 UnicodeString->Buffer);
741 UnicodeString->Buffer = NULL;
742 UnicodeString->Length = 0;
743 UnicodeString->MaximumLength = 0;
750 IN OUT PANSI_STRING DestinationString,
756 if(SourceString==NULL)
758 DestinationString->Length = 0;
759 DestinationString->MaximumLength = 0;
763 DestSize = strlen ((const char *)SourceString);
764 DestinationString->Length = DestSize;
765 DestinationString->MaximumLength = DestSize + 1;
767 DestinationString->Buffer = (PCHAR)SourceString;
774 IN OUT PSTRING DestinationString,
780 if (SourceString == NULL)
782 DestinationString->Length = 0;
783 DestinationString->MaximumLength = 0;
787 DestSize = strlen((const char *)SourceString);
788 DestinationString->Length = DestSize;
789 DestinationString->MaximumLength = DestSize + sizeof(CHAR);
791 DestinationString->Buffer = (PCHAR)SourceString;
797 RtlInitUnicodeString (
798 IN OUT PUNICODE_STRING DestinationString,
799 IN PCWSTR SourceString
804 if (SourceString==NULL)
806 DestinationString->Length=0;
807 DestinationString->MaximumLength=0;
811 DestSize = wcslen((PWSTR)SourceString) * sizeof(WCHAR);
812 DestinationString->Length = DestSize;
813 DestinationString->MaximumLength = DestSize + sizeof(WCHAR);
815 DestinationString->Buffer = (PWSTR)SourceString;
839 if ((Radix != 2) && (Radix != 8) &&
840 (Radix != 10) && (Radix != 16))
841 return STATUS_INVALID_PARAMETER;
844 while (v || tp == temp)
855 if (tp - temp >= Length)
856 return STATUS_BUFFER_TOO_SMALL;
863 return STATUS_SUCCESS;
869 RtlIntegerToUnicodeString (
871 IN ULONG Base, /* optional */
872 IN OUT PUNICODE_STRING String
875 ANSI_STRING AnsiString;
879 Status = RtlIntegerToChar (Value,
883 if (!NT_SUCCESS(Status))
886 AnsiString.Buffer = Buffer;
887 AnsiString.Length = strlen (Buffer);
888 AnsiString.MaximumLength = 33;
890 Status = RtlAnsiStringToUnicodeString (String,
900 RtlLargeIntegerToChar (
901 IN PLARGE_INTEGER Value,
909 ULONGLONG v = Value->QuadPart;
918 if ((Radix != 2) && (Radix != 8) &&
919 (Radix != 10) && (Radix != 16))
920 return STATUS_INVALID_PARAMETER;
923 while (v || tp == temp)
934 if (tp - temp >= Length)
935 return STATUS_BUFFER_TOO_SMALL;
942 return STATUS_SUCCESS;
948 RtlOemStringToUnicodeSize (
949 IN POEM_STRING OemString
954 RtlMultiByteToUnicodeSize (&Size,
964 RtlOemStringToUnicodeString (
965 IN OUT PUNICODE_STRING DestinationString,
966 IN POEM_STRING SourceString,
967 IN BOOLEAN AllocateDestinationString
973 if (NlsMbCodePageTag == TRUE)
974 Length = RtlAnsiStringToUnicodeSize (SourceString);
976 Length = SourceString->Length * sizeof(WCHAR);
979 return STATUS_INVALID_PARAMETER_2;
981 if (AllocateDestinationString == TRUE)
983 DestinationString->MaximumLength = Length + sizeof(WCHAR);
984 DestinationString->Buffer =
985 RtlAllocateHeap (RtlGetProcessHeap (),
987 DestinationString->MaximumLength);
988 if (DestinationString->Buffer == NULL)
989 return STATUS_NO_MEMORY;
993 if (Length + sizeof(WCHAR) > DestinationString->MaximumLength)
995 DPRINT("STATUS_BUFFER_TOO_SMALL\n");
996 return STATUS_BUFFER_TOO_SMALL;
999 DestinationString->Length = Length;
1001 RtlZeroMemory (DestinationString->Buffer,
1002 DestinationString->Length);
1004 Status = RtlOemToUnicodeN (DestinationString->Buffer,
1005 DestinationString->Length,
1007 SourceString->Buffer,
1008 SourceString->Length);
1009 if (!NT_SUCCESS(Status))
1011 if (AllocateDestinationString)
1013 RtlFreeHeap (RtlGetProcessHeap (),
1015 DestinationString->Buffer);
1020 DestinationString->Buffer[Length / sizeof(WCHAR)] = 0;
1022 return STATUS_SUCCESS;
1029 PANSI_STRING String1,
1030 PANSI_STRING String2,
1031 BOOLEAN CaseInsensitive
1038 if (String2->Length < String1->Length)
1041 Length = String1->Length;
1042 pc1 = String1->Buffer;
1043 pc2 = String2->Buffer;
1047 if (CaseInsensitive)
1051 if (RtlUpperChar (*pc1++) != RtlUpperChar (*pc2++))
1059 if (*pc1++ != *pc2++)
1071 RtlPrefixUnicodeString (
1072 PUNICODE_STRING String1,
1073 PUNICODE_STRING String2,
1074 BOOLEAN CaseInsensitive
1081 if (String2->Length < String1->Length)
1084 Length = String1->Length / 2;
1085 pc1 = String1->Buffer;
1086 pc2 = String2->Buffer;
1090 if (CaseInsensitive)
1094 if (RtlUpcaseUnicodeChar (*pc1++)
1095 != RtlUpcaseUnicodeChar (*pc2++))
1103 if( *pc1++ != *pc2++ )
1115 RtlUnicodeStringToAnsiSize (
1116 IN PUNICODE_STRING UnicodeString
1121 RtlUnicodeToMultiByteSize (&Size,
1122 UnicodeString->Buffer,
1123 UnicodeString->Length);
1125 return Size+1; //NB: incl. nullterm
1131 RtlUnicodeStringToAnsiString (
1132 IN OUT PANSI_STRING DestinationString,
1133 IN PUNICODE_STRING SourceString,
1134 IN BOOLEAN AllocateDestinationString
1140 if (NlsMbCodePageTag == TRUE)
1141 Length = RtlUnicodeStringToAnsiSize (SourceString);
1143 Length = SourceString->Length / sizeof(WCHAR);
1145 if (AllocateDestinationString == TRUE)
1147 DestinationString->MaximumLength = Length + sizeof(CHAR);
1148 DestinationString->Buffer =
1149 RtlAllocateHeap (RtlGetProcessHeap (),
1151 DestinationString->MaximumLength);
1152 if (DestinationString->Buffer == NULL)
1153 return STATUS_NO_MEMORY;
1157 if (Length >= DestinationString->MaximumLength)
1158 return STATUS_BUFFER_TOO_SMALL;
1160 DestinationString->Length = Length;
1162 RtlZeroMemory (DestinationString->Buffer,
1163 DestinationString->Length);
1165 Status = RtlUnicodeToMultiByteN (DestinationString->Buffer,
1166 DestinationString->Length,
1168 SourceString->Buffer,
1169 SourceString->Length);
1170 if (!NT_SUCCESS(Status))
1172 if (AllocateDestinationString == TRUE)
1174 RtlFreeHeap (RtlGetProcessHeap (),
1176 DestinationString->Buffer);
1181 DestinationString->Buffer[Length] = 0;
1183 return STATUS_SUCCESS;
1189 RtlUnicodeStringToInteger (
1190 IN PUNICODE_STRING String,
1199 BOOLEAN addneg = FALSE;
1202 Str = String->Buffer;
1204 for (i = 0; i < String->Length / sizeof(WCHAR); i++)
1211 else if (*Str == L'o')
1216 else if (*Str == L'd')
1221 else if (*Str == L'x')
1226 else if (*Str == L'+')
1230 else if (*Str == L'-')
1235 else if ((*Str > L'1') && (Base == 2))
1237 return STATUS_INVALID_PARAMETER;
1239 else if (((*Str > L'7') || (*Str < L'0')) && (Base == 8))
1241 return STATUS_INVALID_PARAMETER;
1243 else if (((*Str > L'9') || (*Str < L'0')) && (Base == 10))
1245 return STATUS_INVALID_PARAMETER;
1247 else if ((((*Str > L'9') || (*Str < L'0')) ||
1248 ((towupper (*Str) > L'F') ||
1249 (towupper (*Str) < L'A'))) && (Base == 16))
1251 return STATUS_INVALID_PARAMETER;
1257 Str = String->Buffer + lenmin;
1262 while (iswxdigit (*Str) &&
1263 (Val = iswdigit (*Str) ? *Str - L'0' : (iswlower (*Str)
1264 ? toupper (*Str) : *Str) - L'A' + 10) < Base)
1266 *Value = *Value * Base + Val;
1273 return STATUS_SUCCESS;
1279 RtlUnicodeStringToOemSize (
1280 IN PUNICODE_STRING UnicodeString
1285 RtlUnicodeToMultiByteSize (&Size,
1286 UnicodeString->Buffer,
1287 UnicodeString->Length);
1289 return Size+1; //NB: incl. nullterm
1295 RtlUnicodeStringToCountedOemString (
1296 IN OUT POEM_STRING DestinationString,
1297 IN PUNICODE_STRING SourceString,
1298 IN BOOLEAN AllocateDestinationString
1305 if (NlsMbOemCodePageTag == TRUE)
1306 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1308 Length = SourceString->Length / sizeof(WCHAR) + 1;
1310 if (Length > 0x0000FFFF)
1311 return STATUS_INVALID_PARAMETER_2;
1313 DestinationString->Length = (WORD)(Length - 1);
1315 if (AllocateDestinationString)
1317 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1320 if (DestinationString->Buffer == NULL)
1321 return STATUS_NO_MEMORY;
1323 RtlZeroMemory (DestinationString->Buffer,
1325 DestinationString->MaximumLength = (WORD)Length;
1329 if (Length > DestinationString->MaximumLength)
1331 if (DestinationString->MaximumLength == 0)
1332 return STATUS_BUFFER_OVERFLOW;
1333 DestinationString->Length =
1334 DestinationString->MaximumLength - 1;
1338 Status = RtlUnicodeToOemN (DestinationString->Buffer,
1339 DestinationString->Length,
1341 SourceString->Buffer,
1342 SourceString->Length);
1343 if (!NT_SUCCESS(Status))
1345 if (AllocateDestinationString)
1347 RtlFreeHeap (RtlGetProcessHeap (),
1349 DestinationString->Buffer);
1354 DestinationString->Buffer[Size] = 0;
1356 return STATUS_SUCCESS;
1362 RtlUnicodeStringToOemString (
1363 IN OUT POEM_STRING DestinationString,
1364 IN PUNICODE_STRING SourceString,
1365 IN BOOLEAN AllocateDestinationString
1372 if (NlsMbOemCodePageTag == TRUE)
1373 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1375 Length = SourceString->Length / sizeof(WCHAR) + 1;
1377 if (Length > 0x0000FFFF)
1378 return STATUS_INVALID_PARAMETER_2;
1380 DestinationString->Length = (WORD)(Length - 1);
1382 if (AllocateDestinationString)
1384 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1387 if (DestinationString->Buffer == NULL)
1388 return STATUS_NO_MEMORY;
1390 RtlZeroMemory (DestinationString->Buffer,
1392 DestinationString->MaximumLength = (WORD)Length;
1396 if (Length > DestinationString->MaximumLength)
1398 if (DestinationString->MaximumLength == 0)
1399 return STATUS_BUFFER_OVERFLOW;
1400 DestinationString->Length =
1401 DestinationString->MaximumLength - 1;
1405 Status = RtlUnicodeToOemN (DestinationString->Buffer,
1406 DestinationString->Length,
1408 SourceString->Buffer,
1409 SourceString->Length);
1410 if (!NT_SUCCESS(Status))
1412 if (AllocateDestinationString)
1414 RtlFreeHeap (RtlGetProcessHeap (),
1416 DestinationString->Buffer);
1421 DestinationString->Buffer[Size] = 0;
1423 return STATUS_SUCCESS;
1429 RtlUpcaseUnicodeChar (
1437 return (Source - (L'a' - L'A'));
1439 /* FIXME: characters above 'z' */
1447 RtlUpcaseUnicodeString (
1448 IN OUT PUNICODE_STRING DestinationString,
1449 IN PUNICODE_STRING SourceString,
1450 IN BOOLEAN AllocateDestinationString
1456 if (AllocateDestinationString == TRUE)
1458 DestinationString->MaximumLength=SourceString->Length+sizeof(WCHAR);
1459 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1461 SourceString->Length + sizeof(WCHAR));
1462 if (DestinationString->Buffer == NULL)
1463 return STATUS_NO_MEMORY;
1467 if (SourceString->Length >= DestinationString->MaximumLength)
1468 return STATUS_BUFFER_TOO_SMALL;
1470 DestinationString->Length = SourceString->Length;
1472 Src = SourceString->Buffer;
1473 Dest = DestinationString->Buffer;
1474 for (i = 0; i < SourceString->Length / sizeof(WCHAR); i++)
1476 *Dest = RtlUpcaseUnicodeChar (*Src);
1482 return STATUS_SUCCESS;
1488 RtlUpcaseUnicodeStringToAnsiString (
1489 IN OUT PANSI_STRING DestinationString,
1490 IN PUNICODE_STRING SourceString,
1491 IN BOOLEAN AllocateDestinationString
1498 if (NlsMbCodePageTag == TRUE)
1499 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1501 Length = SourceString->Length / sizeof(WCHAR) + 1;
1503 if (Length > 0x0000FFFF)
1504 return STATUS_INVALID_PARAMETER_2;
1506 DestinationString->Length = (WORD)(Length - 1);
1508 if (AllocateDestinationString == TRUE)
1510 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1512 DestinationString->MaximumLength);
1513 if (DestinationString->Buffer == NULL)
1514 return STATUS_NO_MEMORY;
1516 RtlZeroMemory (DestinationString->Buffer,
1518 DestinationString->MaximumLength = (WORD)Length;
1522 if (Length > DestinationString->MaximumLength)
1524 if (!DestinationString->MaximumLength)
1525 return STATUS_BUFFER_OVERFLOW;
1526 DestinationString->Length =
1527 DestinationString->MaximumLength - 1;
1531 Status = RtlUpcaseUnicodeToMultiByteN (DestinationString->Buffer,
1532 DestinationString->Length,
1534 SourceString->Buffer,
1535 SourceString->Length);
1536 if (!NT_SUCCESS(Status))
1538 if (AllocateDestinationString)
1540 RtlFreeHeap (RtlGetProcessHeap (),
1542 DestinationString->Buffer);
1547 DestinationString->Buffer[Size] = 0;
1549 return STATUS_SUCCESS;
1555 RtlUpcaseUnicodeStringToCountedOemString (
1556 IN OUT POEM_STRING DestinationString,
1557 IN PUNICODE_STRING SourceString,
1558 IN BOOLEAN AllocateDestinationString
1565 if (NlsMbCodePageTag == TRUE)
1566 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1568 Length = SourceString->Length / sizeof(WCHAR) + 1;
1570 if (Length > 0x0000FFFF)
1571 return STATUS_INVALID_PARAMETER_2;
1573 DestinationString->Length = (WORD)(Length - 1);
1575 if (AllocateDestinationString == TRUE)
1577 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1580 if (DestinationString->Buffer == NULL)
1581 return STATUS_NO_MEMORY;
1583 RtlZeroMemory (DestinationString->Buffer,
1585 DestinationString->MaximumLength = (WORD)Length;
1589 if (Length > DestinationString->MaximumLength)
1591 if (DestinationString->MaximumLength == 0)
1592 return STATUS_BUFFER_OVERFLOW;
1593 DestinationString->Length =
1594 DestinationString->MaximumLength - 1;
1598 Status = RtlUpcaseUnicodeToOemN (DestinationString->Buffer,
1599 DestinationString->Length,
1601 SourceString->Buffer,
1602 SourceString->Length);
1603 if (!NT_SUCCESS(Status))
1605 if (AllocateDestinationString)
1607 RtlFreeHeap (RtlGetProcessHeap (),
1609 DestinationString->Buffer);
1614 DestinationString->Buffer[Size] = 0;
1616 return STATUS_SUCCESS;
1622 RtlUpcaseUnicodeStringToOemString (
1623 IN OUT POEM_STRING DestinationString,
1624 IN PUNICODE_STRING SourceString,
1625 IN BOOLEAN AllocateDestinationString
1632 if (NlsMbOemCodePageTag == TRUE)
1633 Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
1635 Length = SourceString->Length / sizeof(WCHAR) + 1;
1637 if (Length > 0x0000FFFF)
1638 return STATUS_INVALID_PARAMETER_2;
1640 DestinationString->Length = (WORD)(Length - 1);
1642 if (AllocateDestinationString == TRUE)
1644 DestinationString->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
1647 if (DestinationString->Buffer == NULL)
1648 return STATUS_NO_MEMORY;
1650 RtlZeroMemory (DestinationString->Buffer,
1652 DestinationString->MaximumLength = (WORD)Length;
1656 if (Length > DestinationString->MaximumLength)
1658 if (DestinationString->MaximumLength == 0)
1659 return STATUS_BUFFER_OVERFLOW;
1660 DestinationString->Length =
1661 DestinationString->MaximumLength - 1;
1665 Status = RtlUpcaseUnicodeToOemN (DestinationString->Buffer,
1666 DestinationString->Length,
1668 SourceString->Buffer,
1669 SourceString->Length);
1670 if (!NT_SUCCESS(Status))
1672 if (AllocateDestinationString)
1674 RtlFreeHeap (RtlGetProcessHeap (),
1676 DestinationString->Buffer);
1681 DestinationString->Buffer[Size] = 0;
1683 return STATUS_SUCCESS;
1696 if (NlsMbCodePageTag == FALSE)
1698 /* single-byte code page */
1700 Unicode = (WCHAR)Source;
1702 Unicode = NlsAnsiToUnicodeData[Source];
1705 /* upcase conversion */
1706 Unicode = RtlUpcaseUnicodeChar (Unicode);
1708 /* unicode -> ansi */
1709 Destination = (CHAR)Unicode;
1711 Destination = NlsUnicodeToAnsiData[Unicode];
1716 /* single-byte code page */
1717 /* FIXME: implement the multi-byte stuff!! */
1718 Destination = Source;
1728 IN OUT PSTRING DestinationString,
1729 IN PSTRING SourceString
1737 Length = min(SourceString->Length, DestinationString->MaximumLength - 1);
1739 Src = SourceString->Buffer;
1740 Dest = DestinationString->Buffer;
1741 for (i = 0; i < Length; i++)
1743 *Dest = RtlUpperChar (*Src);
1749 DestinationString->Length = SourceString->Length;
1755 RtlxAnsiStringToUnicodeSize (
1756 IN PANSI_STRING AnsiString
1759 return RtlAnsiStringToUnicodeSize (AnsiString);
1765 RtlxOemStringToUnicodeSize (
1766 IN POEM_STRING OemString
1769 return RtlAnsiStringToUnicodeSize ((PANSI_STRING)OemString);
1775 RtlxUnicodeStringToAnsiSize (
1776 IN PUNICODE_STRING UnicodeString
1779 return RtlUnicodeStringToAnsiSize (UnicodeString);
1785 RtlxUnicodeStringToOemSize (
1786 IN PUNICODE_STRING UnicodeString
1789 return RtlUnicodeStringToAnsiSize (UnicodeString);