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 size = str.size();
92 const double coeff =
stod(std::string(str.data(), str.size()), &cur);
95 while (cur<size && isspace(str[cur])) ++cur;
101 auto result = [coeff,&
exp,&unit,&value]() {
103 if (
v < std::numeric_limits<T>::max()) {
110 if (cur==size)
return result();
112 switch (toupper(str[cur])) {
113 case 'B':
exp = 0;
break;
114 case 'K':
exp = 3;
break;
115 case 'M':
exp = 6;
break;
116 case 'G':
exp = 9;
break;
117 case 'T':
exp = 12;
break;
118 case 'E':
exp = 15;
break;
119 case 'Z':
exp = 18;
break;
120 case 'Y':
exp = 21;
break;
127 if (cur<size && toupper(str[cur]) ==
'I') {
132 if (cur==size)
return result();
135 switch (toupper(str[cur])) {
138 case '\t': ++cur;
break;
140 case '\0':
return result();
double pow(double, double)
Namespace for new ROOT classes and functions.
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,...
double stod(std::string_view str, size_t *pos)
basic_string_view< char > string_view