]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/String/PrintLibInternal.c
3 Copyright (c) 2004-2006 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Print Library worker functions.
23 #include <Common/UefiBaseTypes.h>
24 #include <Library/PrintLib.h>
26 #include "CommonLib.h"
27 #include "PrintLibInternal.h"
29 static CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
32 BasePrintLibFillBuffer (
41 for (Index
= 0; Index
< Length
; Index
++) {
42 *Buffer
= (CHAR8
) Character
;
43 *(Buffer
+ 1) = (CHAR8
) (Character
>> 8);
50 Print worker function that prints a Value as a decimal number in Buffer.
52 @param Buffer Location to place the Unicode or ASCII string of Value.
54 @param Value Value to convert to a Decimal or Hexidecimal string in Buffer.
56 @param Flags Flags to use in printing string, see file header for details.
58 @param Precision Minimum number of digits to return in the ASCII string
60 @return Number of characters printed.
65 BasePrintLibValueToString (
75 // Loop to convert one digit at a time in reverse order
80 // Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);
81 Remainder
= (UINT64
)Value
% (UINT32
)Radix
;
82 Value
= (UINT64
)Value
/ (UINT32
)Radix
;
83 *(Buffer
++) = mHexStr
[Remainder
];
90 BasePrintLibConvertValueToString (
98 CHAR8
*OriginalBuffer
;
99 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
104 OriginalBuffer
= Buffer
;
106 if (Width
== 0 || (Flags
& COMMA_TYPE
) != 0) {
107 Flags
&= (~PREFIX_ZERO
);
110 if (Width
== 0 || Width
> (MAXIMUM_VALUE_CHARACTERS
- 1)) {
111 Width
= MAXIMUM_VALUE_CHARACTERS
- 1;
116 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, '-', Increment
);
119 Count
= BasePrintLibValueToString (ValueBuffer
, Value
, 10);
121 if ((Flags
& PREFIX_ZERO
) != 0) {
122 Buffer
= BasePrintLibFillBuffer (Buffer
, Width
- Count
, '0', Increment
);
125 Digits
= 3 - (Count
% 3);
126 for (Index
= 0; Index
< Count
; Index
++) {
127 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ValueBuffer
[Count
- Index
], Increment
);
128 if ((Flags
& COMMA_TYPE
) != 0) {
132 if ((Index
+ 1) < Count
) {
133 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, ',', Increment
);
139 Buffer
= BasePrintLibFillBuffer (Buffer
, 1, 0, Increment
);
141 return ((Buffer
- OriginalBuffer
) / Increment
);