| 139 | } |
| 140 | |
| 141 | string HumanReadableNumBytes::ToStringWithoutRounding(int64 num_bytes) { |
| 142 | if (num_bytes == kint64min) { |
| 143 | // Special case for number with not representable nagation. |
| 144 | return "-8E"; |
| 145 | } |
| 146 | |
| 147 | const char *neg_str = GetNegStr(&num_bytes); |
| 148 | static const char units[] = "BKMGTPE"; // int64 only goes up to E. |
| 149 | |
| 150 | int64 num_units = num_bytes; |
| 151 | int unit_type = 0; |
| 152 | for (; unit_type < arraysize(units); unit_type++) { |
| 153 | if (num_units % 1024 != 0) { |
| 154 | // Not divisible by the next unit. |
| 155 | break; |
| 156 | } |
| 157 | |
| 158 | int64 next_units = num_units >> 10; |
| 159 | if (next_units == 0) { |
| 160 | // Less than the next unit. |
| 161 | break; |
| 162 | } |
| 163 | |
| 164 | num_units = next_units; |
| 165 | } |
| 166 | return StringPrintf("%s%" PRId64 "%c", neg_str, num_units, units[unit_type]); |
| 167 | } |
| 168 | |
| 169 | string HumanReadableInt::ToString(int64 value) { |
| 170 | string s; |
nothing calls this directly
no test coverage detected