Refactor RtlpWriteWideStringValue() and RtlpWriteWideStringStringValue() routines

This commit is contained in:
Rafal Kupiec 2024-02-16 17:03:10 +01:00
parent 8ddd6137da
commit a1ec5e410d
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 18 additions and 39 deletions

View File

@ -323,13 +323,13 @@ XTSTATUS
RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context, RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context,
PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, PRTL_PRINT_FORMAT_PROPERTIES FormatProperties,
PCHAR String, PCHAR String,
BOOLEAN Character); SIZE_T StringLength);
XTAPI XTAPI
XTSTATUS XTSTATUS
RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context, RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context,
PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, PRTL_PRINT_FORMAT_PROPERTIES FormatProperties,
PWCHAR String, PWCHAR String,
BOOLEAN Character); SIZE_T StringLength);
#endif /* __XTOSKRNL_RTLI_H */ #endif /* __XTOSKRNL_RTLI_H */

View File

@ -901,7 +901,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context,
if(FormatProperties.VariableType == Unknown) if(FormatProperties.VariableType == Unknown)
{ {
/* Write defined wide character */ /* Write defined wide character */
Status = RtlpWriteWideStringValue(Context, &FormatProperties, &WideCharArg, TRUE); Status = RtlpWriteWideStringValue(Context, &FormatProperties, &WideCharArg, 1);
} }
if(FormatProperties.VariableType == Boolean) if(FormatProperties.VariableType == Boolean)
{ {
@ -920,14 +920,17 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context,
/* Check if using uppercase format */ /* Check if using uppercase format */
if(FormatProperties.PrintUpperCase) if(FormatProperties.PrintUpperCase)
{ {
/* Write 'TRUE' or 'FALSE' depending on argument value */ /* Set uppercase boolean string depending on argument value */
Status = RtlpWriteWideStringValue(Context, &FormatProperties, IntArg ? L"TRUE" : L"FALSE", FALSE); WideStrArg = IntArg ? L"TRUE" : L"FALSE";
} }
else else
{ {
/* Write 'true' or 'false' depending on argument value */ /* Set lowercase boolean string depending on argument value */
Status = RtlpWriteWideStringValue(Context, &FormatProperties, IntArg ? L"true" : L"false", FALSE); WideStrArg = IntArg ? L"true" : L"false";
} }
/* Write formatted boolean string */
Status = RtlpWriteWideStringValue(Context, &FormatProperties, WideStrArg, RtlWideStringLength(WideStrArg, 0));
} }
else if(FormatProperties.VariableType == Char) else if(FormatProperties.VariableType == Char)
{ {
@ -944,7 +947,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context,
} }
/* Write formatted character */ /* Write formatted character */
Status = RtlpWriteWideStringStringValue(Context, &FormatProperties, &CharArg, TRUE); Status = RtlpWriteWideStringStringValue(Context, &FormatProperties, &CharArg, 1);
} }
else if(FormatProperties.VariableType == WideChar) else if(FormatProperties.VariableType == WideChar)
{ {
@ -961,7 +964,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context,
} }
/* Write formatted wide character */ /* Write formatted wide character */
Status = RtlpWriteWideStringValue(Context, &FormatProperties, &WideCharArg, TRUE); Status = RtlpWriteWideStringValue(Context, &FormatProperties, &WideCharArg, 1);
} }
else if(FormatProperties.VariableType == Float) else if(FormatProperties.VariableType == Float)
{ {
@ -1068,7 +1071,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context,
} }
/* Write formatted string value */ /* Write formatted string value */
Status = RtlpWriteWideStringStringValue(Context, &FormatProperties, StrArg, FALSE); Status = RtlpWriteWideStringStringValue(Context, &FormatProperties, StrArg, RtlStringLength(StrArg, 0));
} }
else if(FormatProperties.VariableType == WideString) else if(FormatProperties.VariableType == WideString)
{ {
@ -1086,7 +1089,7 @@ RtlpFormatWideStringArgumentSpecifier(IN PRTL_PRINT_CONTEXT Context,
} }
/* Write formatted wide string value */ /* Write formatted wide string value */
Status = RtlpWriteWideStringValue(Context, &FormatProperties, WideStrArg, FALSE); Status = RtlpWriteWideStringValue(Context, &FormatProperties, WideStrArg, RtlWideStringLength(WideStrArg, 0));
} }
/* Cleanup ArgumentsCopy object */ /* Cleanup ArgumentsCopy object */
@ -1527,11 +1530,10 @@ XTSTATUS
RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context, RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context,
PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, PRTL_PRINT_FORMAT_PROPERTIES FormatProperties,
PCHAR String, PCHAR String,
BOOLEAN Character) SIZE_T StringLength)
{ {
WCHAR WideCharacter[2]; WCHAR WideCharacter[2];
ULONG PaddingLength; ULONG PaddingLength;
SIZE_T StringLength;
XTSTATUS Status; XTSTATUS Status;
/* Check for NULL string */ /* Check for NULL string */
@ -1539,18 +1541,7 @@ RtlpWriteWideStringStringValue(PRTL_PRINT_CONTEXT Context,
{ {
/* Print '(null)' instead */ /* Print '(null)' instead */
String = "(null)"; String = "(null)";
} StringLength = 6;
/* Check if single character is expected */
if(Character)
{
/* Force string length to 1 */
StringLength = 1;
}
else
{
/* Get real string length */
StringLength = RtlStringLength(String, 0);
} }
/* Check if string length exceeds precision limit */ /* Check if string length exceeds precision limit */
@ -1649,10 +1640,9 @@ XTSTATUS
RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context, RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context,
PRTL_PRINT_FORMAT_PROPERTIES FormatProperties, PRTL_PRINT_FORMAT_PROPERTIES FormatProperties,
PWCHAR String, PWCHAR String,
BOOLEAN Character) SIZE_T StringLength)
{ {
ULONG PaddingLength; ULONG PaddingLength;
SIZE_T StringLength;
XTSTATUS Status; XTSTATUS Status;
/* Check for NULL string */ /* Check for NULL string */
@ -1660,18 +1650,7 @@ RtlpWriteWideStringValue(PRTL_PRINT_CONTEXT Context,
{ {
/* Print '(null)' instead */ /* Print '(null)' instead */
String = L"(null)"; String = L"(null)";
} StringLength = 6;
/* Check if single character is expected */
if(Character)
{
/* Force string length to 1 */
StringLength = 1;
}
else
{
/* Get real string length */
StringLength = RtlWideStringLength(String, 0);
} }
/* Check if string length exceeds precision limit */ /* Check if string length exceeds precision limit */