2 Print Library worker functions.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Module Name: PrintLibInternal.c
17 #include "PrintLibInternal.h"
19 static CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
22 BasePrintLibFillBuffer (
31 for (Index
= 0; Index
< Length
; Index
++) {
32 *Buffer
= (CHAR8
) Character
;
33 *(Buffer
+ 1) = (CHAR8
) (Character
>> 8);
40 Print worker function that prints a Value as a decimal number in Buffer.
42 @param Buffer Location to place the Unicode or ASCII string of Value.
44 @param Value Value to convert to a Decimal or Hexidecimal string in Buffer.
46 @param Flags Flags to use in printing string, see file header for details.
48 @param Precision Minimum number of digits to return in the ASCII string
50 @return Number of characters printed.
55 BasePrintLibValueToString (
65 // Loop to convert one digit at a time in reverse order
70 Value
= (INT64
)DivU64x32Remainder ((UINT64
)Value
, (UINT32
)Radix
, &Remainder
);
71 *(Buffer
++) = mHexStr
[Remainder
];
78 BasePrintLibConvertValueToString (
86 CHAR8
*OriginalBuffer
;
87 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
92 OriginalBuffer
= Buffer
;
94 if (Width
== 0 || (Flags
& COMMA_TYPE
) != 0) {
95 Flags
&= (~PREFIX_ZERO
);
98 if (Width
== 0 || Width
> (MAXIMUM_VALUE_CHARACTERS
- 1)) {
99 Width
= MAXIMUM_VALUE_CHARACTERS
- 1;
104 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, '-', Increment
);
107 Count
= BasePrintLibValueToString (ValueBuffer
, Value
, 10);
109 if ((Flags
& PREFIX_ZERO
) != 0) {
110 Buffer
= BasePrintLibFillBuffer (Buffer
, Width
- Count
, '0', Increment
);
113 Digits
= 3 - (Count
% 3);
114 for (Index
= 0; Index
< Count
; Index
++) {
115 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ValueBuffer
[Count
- Index
], Increment
);
116 if ((Flags
& COMMA_TYPE
) != 0) {
120 if ((Index
+ 1) < Count
) {
121 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ',', Increment
);
127 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, 0, Increment
);
129 return ((Buffer
- OriginalBuffer
) / Increment
);
134 UnicodeValueToString (
135 IN OUT CHAR16
*Buffer
,
141 return BasePrintLibConvertValueToString ((CHAR8
*)Buffer
, Flags
, Value
, Width
, 2);
146 IN OUT CHAR8
*Buffer
,
152 return BasePrintLibConvertValueToString ((CHAR8
*)Buffer
, Flags
, Value
, Width
, 1);