12#ifndef ROOT_StringConv
13#define ROOT_StringConv
18#include "RConfigure.h"
37template <
typename value_type>
44 static const char *
const suffix[][2] =
53 value_type unit = si ? 1000 : 1024;
61 }
else if (bytes > 0) {
63 (
int) (
sizeof(suffix) /
sizeof(suffix[0]) - 1));
66 *units = suffix[
exp][!si];
89 size_t cur, size = str.size();
91 const double coeff = stod(std::string(str.data(), str.size()), &cur);
94 while (cur<size && isspace(str[cur])) ++cur;
97 int exp = 0, unit = 1000;
99 auto result = [coeff,&
exp,&unit,&value]() {
101 if (
v < (
double) std::numeric_limits<T>::max()) {
108 if (cur==size)
return result();
110 switch (toupper(str[cur])) {
111 case 'B':
exp = 0;
break;
112 case 'K':
exp = 3;
break;
113 case 'M':
exp = 6;
break;
114 case 'G':
exp = 9;
break;
115 case 'T':
exp = 12;
break;
116 case 'E':
exp = 15;
break;
117 case 'Z':
exp = 18;
break;
118 case 'Y':
exp = 21;
break;
125 if (cur<size && toupper(str[cur]) ==
'I') {
130 if (cur==size)
return result();
133 switch (toupper(str[cur])) {
136 case '\t': ++cur;
break;
138 case '\0':
return result();
double pow(double, double)
basic_string_view< char > string_view
void ToHumanReadableSize(value_type bytes, Bool_t si, Double_t *coeff, const char **units)
Return the size expressed in 'human readable' format.
EFromHumanReadableSize FromHumanReadableSize(std::string_view str, T &value)
Convert strings like the following into byte counts 5MB, 5 MB, 5M, 3.7GB, 123b, 456kB,...