MCPcopy Create free account
hub / github.com/cutelyst/cutelyst / durationFromString

Method durationFromString

Cutelyst/utils.cpp:302–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300}
301
302std::chrono::microseconds Utils::durationFromString(QStringView str, bool *ok)
303{
304 QList<std::pair<QString, QString>> parts;
305 QString digitPart;
306 QString unitPart;
307 bool valid = true;
308 // NOLINTBEGIN(bugprone-branch-clone)
309 for (const QChar ch : str) {
310 if (ch >= u'0' && ch <= u'9') {
311 if (digitPart.isEmpty() && unitPart.isEmpty()) {
312 // we are at the beginning of a new part
313 digitPart.append(ch);
314 } else if (digitPart.isEmpty() && !unitPart.isEmpty()) {
315 // wrong order
316 valid = false;
317 break;
318 } else if (!digitPart.isEmpty() && unitPart.isEmpty()) {
319 // we are still in the digit part
320 digitPart.append(ch);
321 } else if (!digitPart.isEmpty() && !unitPart.isEmpty()) {
322 // we start a new part
323 parts.emplace_back(digitPart, unitPart);
324 digitPart.clear();
325 unitPart.clear();
326 digitPart.append(ch);
327 }
328 } else if ((ch >= u'a' && ch <= u'z') || ch == u'M') {
329 if (digitPart.isEmpty() && unitPart.isEmpty()) {
330 // something is wrong with a digitless unit
331 valid = false;
332 break;
333 } else if (digitPart.isEmpty() && !unitPart.isEmpty()) {
334 // it should not be possible to be here
335 valid = false;
336 break;
337 } else if (!digitPart.isEmpty() && unitPart.isEmpty()) {
338 // we start adding the unit
339 unitPart.append(ch);
340 } else if (!digitPart.isEmpty() && !unitPart.isEmpty()) {
341 // normal operation
342 unitPart.append(ch);
343 }
344 }
345 }
346 // NOLINTEND(bugprone-branch-clone)
347
348 if (!valid) {
349 if (ok) {
350 *ok = false;
351 }
352 return std::chrono::microseconds::zero();
353 }
354
355 if (!digitPart.isEmpty()) {
356 parts.emplace_back(digitPart, unitPart);
357 }
358
359 if (parts.empty()) {

Callers

nothing calls this directly

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected