]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePrintLib/PrintLibInternal.c
Minor adjust the logic in BasePrintLib and fix several typos
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLibInternal.c
index d207b8151e145901486dbedd0f0d44c7e5aca317..9fe52f22bc501979d2d0837c7c92b04426fbec74 100644 (file)
@@ -91,42 +91,39 @@ BasePrintLibFillBuffer (
 }\r
 \r
 /**\r
-  Internal function that convert a decimal number to a string in Buffer.\r
+  Internal function that convert a number to a string in Buffer.\r
 \r
-  Print worker function that convert a decimal number to a string in Buffer.\r
+  Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.\r
 \r
-  @param  Buffer    Location to place the Unicode or ASCII string of Value.\r
+  @param  Buffer    Location to place the ASCII string of Value.\r
   @param  Value     Value to convert to a Decimal or Hexadecimal string in Buffer.\r
   @param  Radix     Radix of the value\r
 \r
-  @return Number of characters printed.\r
+  @return A pointer to the end of buffer filled with ASCII string.\r
 \r
 **/\r
-UINTN\r
+CHAR8 *\r
 BasePrintLibValueToString (\r
   IN OUT CHAR8  *Buffer, \r
   IN INT64      Value, \r
   IN UINTN      Radix\r
   )\r
 {\r
-  UINTN   Digits;\r
   UINT32  Remainder;\r
 \r
   //\r
   // Loop to convert one digit at a time in reverse order\r
   //\r
-  *(Buffer++) = 0;\r
-  Digits = 0;\r
+  *Buffer = 0;\r
   do {\r
     Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);\r
-    *(Buffer++) = mHexStr[Remainder];\r
-    Digits++;\r
+    *(++Buffer) = mHexStr[Remainder];\r
   } while (Value != 0);\r
 \r
   //\r
-  // the length of Buffer string converted from Value\r
+  // Return pointer of the end of filled buffer.\r
   //\r
-  return Digits;\r
+  return Buffer;\r
 }\r
 \r
 /**\r
@@ -179,6 +176,7 @@ BasePrintLibConvertValueToString (
   CHAR8  *OriginalBuffer;\r
   CHAR8  *EndBuffer;\r
   CHAR8  ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r
+  CHAR8  *ValueBufferPtr;\r
   UINTN  Count;\r
   UINTN  Digits;\r
   UINTN  Index;\r
@@ -231,7 +229,8 @@ BasePrintLibConvertValueToString (
   // Count the length of the value string.\r
   //\r
   Radix = ((Flags & RADIX_HEX) == 0)? 10 : 16;\r
-  Count = BasePrintLibValueToString (ValueBuffer, Value, Radix);\r
+  ValueBufferPtr = BasePrintLibValueToString (ValueBuffer, Value, Radix);\r
+  Count = ValueBufferPtr - ValueBuffer;\r
   \r
   //\r
   // Append Zero\r
@@ -248,7 +247,7 @@ BasePrintLibConvertValueToString (
     Digits = 3 - Digits;\r
   }\r
   for (Index = 0; Index < Count; Index++) {\r
-    Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ValueBuffer[Count - Index], Increment);\r
+    Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, *ValueBufferPtr--, Increment);\r
     if ((Flags & COMMA_TYPE) != 0) {\r
       Digits++;\r
       if (Digits == 3) {\r
@@ -273,13 +272,13 @@ BasePrintLibConvertValueToString (
   based on a Null-terminated format string and a VA_LIST argument list.\r
 \r
   VSPrint function to process format and place the results in Buffer. Since a \r
-  VA_LIST is used this rountine allows the nesting of Vararg routines. Thus \r
+  VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
   this is the main print working routine.\r
 \r
   @param  Buffer      Character buffer to print the results of the parsing\r
                       of Format into.\r
   @param  BufferSize  Maximum number of characters to put into buffer.\r
-  @param  Flags       Intial flags value.\r
+  @param  Flags       Initial flags value.\r
                       Can only have FORMAT_UNICODE and OUTPUT_UNICODE set.\r
   @param  Format      Null-terminated format string.\r
   @param  Marker      Vararg list consumed by processing Format.\r
@@ -362,8 +361,6 @@ BasePrintLibVSPrint (
     FormatMask = 0xff;\r
   }\r
 \r
-\r
-\r
   //\r
   // Get the first character from the format string\r
   //\r
@@ -526,7 +523,7 @@ BasePrintLibVSPrint (
         //\r
         // Convert Value to a reversed string\r
         //\r
-        Count = BasePrintLibValueToString (ValueBuffer, Value, Radix);\r
+        Count = BasePrintLibValueToString (ValueBuffer, Value, Radix) - ValueBuffer;\r
         if (Value == 0 && Precision == 0) {\r
           Count = 0;\r
         }\r
@@ -793,14 +790,14 @@ BasePrintLibVSPrint (
   based on a Null-terminated format string and variable argument list.\r
 \r
   VSPrint function to process format and place the results in Buffer. Since a \r
-  VA_LIST is used this rountine allows the nesting of Vararg routines. Thus \r
+  VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
   this is the main print working routine\r
 \r
   @param  StartOfBuffer Character buffer to print the results of the parsing\r
                         of Format into.\r
   @param  BufferSize    Maximum number of characters to put into buffer.\r
                         Zero means no limit.\r
-  @param  Flags         Intial flags value.\r
+  @param  Flags         Initial flags value.\r
                         Can only have FORMAT_UNICODE and OUTPUT_UNICODE set\r
   @param  FormatString  Null-terminated format string.\r
   @param  ...           The variable argument list.\r