void print(raw_ostream &OS, bool isSigned) const;
/// Converts an APInt to a string and append it to Str. Str is commonly a
- /// SmallString.
+ /// SmallString. If Radix > 10, UpperCase determine the case of letter
+ /// digits.
void toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
- bool formatAsCLiteral = false) const;
+ bool formatAsCLiteral = false, bool UpperCase = true) const;
/// Considers the APInt to be unsigned and converts it into a string in the
/// radix given. The radix can be 2, 8, 10 16, or 36.
this->negate();
}
-void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
- bool Signed, bool formatAsCLiteral) const {
+void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
+ bool formatAsCLiteral, bool UpperCase) const {
assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
Radix == 36) &&
"Radix should be 2, 8, 10, 16, or 36!");
return;
}
- static const char Digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ static const char BothDigits[] = "0123456789abcdefghijklmnopqrstuvwxyz"
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ const char *Digits = BothDigits + (UpperCase ? 36 : 0);
if (isSingleWord()) {
char Buffer[65];
APInt(8, 255, isSigned).toString(S, 10, isSigned, true);
EXPECT_EQ(std::string(S), "255");
S.clear();
+ APInt(8, 255, isSigned).toString(S, 16, isSigned, true, /*UpperCase=*/false);
+ EXPECT_EQ(std::string(S), "0xff");
+ S.clear();
APInt(8, 255, isSigned).toString(S, 16, isSigned, true);
EXPECT_EQ(std::string(S), "0xFF");
S.clear();