File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -148,13 +148,14 @@ inline char toUpper(char x) {
148
148
return x;
149
149
}
150
150
151
- inline std::string utohexstr (uint64_t X, bool LowerCase = false ) {
151
+ inline std::string utohexstr (uint64_t X, bool LowerCase = false ,
152
+ unsigned Width = 0 ) {
152
153
char Buffer[17 ];
153
154
char *BufPtr = std::end (Buffer);
154
155
155
156
if (X == 0 ) *--BufPtr = ' 0' ;
156
157
157
- while (X ) {
158
+ for ( unsigned i = 0 ; Width ? (i < Width) : X; ++i ) {
158
159
unsigned char Mod = static_cast <unsigned char >(X) & 15 ;
159
160
*--BufPtr = hexdigit (Mod, LowerCase);
160
161
X >>= 4 ;
Original file line number Diff line number Diff line change @@ -96,6 +96,12 @@ TEST(StringExtrasTest, ToAndFromHex) {
96
96
EXPECT_FALSE (tryGetFromHex (InvalidStr, IgnoredOutput));
97
97
}
98
98
99
+ TEST (StringExtrasTest, UINT64ToHex) {
100
+ EXPECT_EQ (utohexstr (0xA0u ), " A0" );
101
+ EXPECT_EQ (utohexstr (0xA0u , false , 4 ), " 00A0" );
102
+ EXPECT_EQ (utohexstr (0xA0u , false , 8 ), " 000000A0" );
103
+ }
104
+
99
105
TEST (StringExtrasTest, to_float) {
100
106
float F;
101
107
EXPECT_TRUE (to_float (" 4.7" , F));
You can’t perform that action at this time.
0 commit comments