MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / toString

Method toString

JUCE/modules/juce_core/maths/juce_BigInteger.cpp:1085–1130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1083}
1084
1085String BigInteger::toString (const int base, const int minimumNumCharacters) const
1086{
1087 String s;
1088 auto v = *this;
1089
1090 if (base == 2 || base == 8 || base == 16)
1091 {
1092 auto bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
1093 static const char hexDigits[] = "0123456789abcdef";
1094
1095 for (;;)
1096 {
1097 auto remainder = v.getBitRangeAsInt (0, bits);
1098 v >>= bits;
1099
1100 if (remainder == 0 && v.isZero())
1101 break;
1102
1103 s = String::charToString ((juce_wchar) (uint8) hexDigits [remainder]) + s;
1104 }
1105 }
1106 else if (base == 10)
1107 {
1108 const BigInteger ten (10);
1109 BigInteger remainder;
1110
1111 for (;;)
1112 {
1113 v.divideBy (ten, remainder);
1114
1115 if (remainder.isZero() && v.isZero())
1116 break;
1117
1118 s = String (remainder.getBitRangeAsInt (0, 8)) + s;
1119 }
1120 }
1121 else
1122 {
1123 jassertfalse; // can't do the specified base!
1124 return {};
1125 }
1126
1127 s = s.paddedLeft ('0', minimumNumCharacters);
1128
1129 return isNegative() ? "-" + s : s;
1130}
1131
1132void BigInteger::parseString (StringRef text, const int base)
1133{

Callers 1

Calls 5

divideByMethod · 0.80
paddedLeftMethod · 0.80
StringFunction · 0.50
getBitRangeAsIntMethod · 0.45
isZeroMethod · 0.45

Tested by

no test coverage detected