| 156 | } |
| 157 | |
| 158 | std::string solidity::util::formatNumberReadable(bigint const& _value, bool _useTruncation) |
| 159 | { |
| 160 | bool const isNegative = _value < 0; |
| 161 | bigint const absValue = isNegative ? (bigint(-1) * _value) : bigint(_value); |
| 162 | std::string const sign = isNegative ? "-" : ""; |
| 163 | |
| 164 | // smaller numbers return as decimal |
| 165 | if (absValue <= 0x1000000) |
| 166 | return sign + absValue.str(); |
| 167 | |
| 168 | if (auto result = tryFormatPowerOfTwo(absValue)) |
| 169 | return {sign + *result}; |
| 170 | else if (auto result = tryFormatPowerOfTwo(absValue + 1)) |
| 171 | return {sign + *result + (isNegative ? " + 1" : " - 1")}; |
| 172 | |
| 173 | std::string str = toHex(toCompactBigEndian(absValue), HexPrefix::Add, HexCase::Mixed); |
| 174 | |
| 175 | if (_useTruncation) |
| 176 | { |
| 177 | // return as interior-truncated hex. |
| 178 | size_t len = str.size(); |
| 179 | |
| 180 | if (len < 24) |
| 181 | return sign + str; |
| 182 | |
| 183 | size_t const initialChars = 6; |
| 184 | size_t const finalChars = 4; |
| 185 | size_t numSkipped = len - initialChars - finalChars; |
| 186 | |
| 187 | return fmt::format( |
| 188 | "{}{}...{{+{} more}}...{}", |
| 189 | sign, |
| 190 | str.substr(0, initialChars), |
| 191 | numSkipped, |
| 192 | str.substr(len-finalChars, len) |
| 193 | ); |
| 194 | } |
| 195 | |
| 196 | return sign + str; |
| 197 | } |
| 198 | |
| 199 | std::string solidity::util::prefixLines( |
| 200 | std::string const& _input, |
nothing calls this directly
no test coverage detected