MCPcopy Create free account
hub / github.com/BirolLab/abyss / SIToBytes

Function SIToBytes

Common/StringUtil.h:181–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179}
180
181static inline size_t SIToBytes(std::istringstream& iss)
182{
183 double size;
184 std::string units;
185
186 iss >> size;
187 if (iss.fail()) {
188 // not prefixed by a number
189 return 0;
190 }
191
192 iss >> units;
193 if (iss.fail() && iss.eof()) {
194 // no units given; clear fail flag
195 // and assume bytes
196 iss.clear(std::ios::eofbit);
197 return (size_t)ceil(size);
198 }
199
200 if (units.size() > 1) {
201 // unrecognized multichar suffix
202 iss.setstate(std::ios::failbit);
203 return 0;
204 }
205
206 switch(tolower(units[0])) {
207 case 'k':
208 size *= (size_t)1<<10; break;
209 case 'm':
210 size *= (size_t)1<<20; break;
211 case 'g':
212 size *= (size_t)1<<30; break;
213 default:
214 iss.setstate(std::ios::failbit);
215 return 0;
216 }
217
218 return (size_t)ceil(size);
219}
220
221static inline size_t SIToBytes(const std::string& str)
222{

Callers 7

mainFunction · 0.85
mainFunction · 0.85
TESTFunction · 0.85
buildFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 4

failMethod · 0.80
eofMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68