MCPcopy Create free account
hub / github.com/Kitware/CMake / ParseSimpleVersion

Function ParseSimpleVersion

Source/cmPackageInfoReader.cxx:410–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408}
409
410cm::optional<cmPackageInfoReader::Pep440Version> ParseSimpleVersion(
411 std::string const& version)
412{
413 if (version.empty()) {
414 return cm::nullopt;
415 }
416
417 cmPackageInfoReader::Pep440Version result;
418 result.Simple = true;
419
420 cm::string_view remnant{ version };
421 for (;;) {
422 // Find the next part separator.
423 std::string::size_type const n = remnant.find_first_of(".+-"_s);
424 if (n == 0) {
425 // The part is an empty string.
426 return cm::nullopt;
427 }
428
429 // Extract the part as a number.
430 cm::string_view const part = remnant.substr(0, n);
431 std::string::size_type const l = part.size();
432 std::string::size_type p;
433 unsigned long const value = std::stoul(std::string{ part }, &p);
434 if (p != l || value > std::numeric_limits<unsigned>::max()) {
435 // The part was not a valid number or is too big.
436 return cm::nullopt;
437 }
438 result.ReleaseComponents.push_back(static_cast<unsigned>(value));
439
440 // Have we consumed the entire input?
441 if (n == std::string::npos) {
442 return { std::move(result) };
443 }
444
445 // Lop off the current part.
446 char const sep = remnant[n];
447 remnant = remnant.substr(n + 1);
448 if (sep == '+' || sep == '-') {
449 // If we hit the local label, we're done.
450 result.LocalLabel = remnant;
451 return { std::move(result) };
452 }
453
454 // We just consumed a '.'; check that there's more.
455 if (remnant.empty()) {
456 // A trailing part separator is not allowed.
457 return cm::nullopt;
458 }
459
460 // Continue with the remaining input.
461 }
462
463 // Unreachable.
464}
465
466} // namespace
467

Callers 1

ParseVersionMethod · 0.85

Calls 6

moveFunction · 0.85
find_first_ofMethod · 0.80
push_backMethod · 0.80
emptyMethod · 0.45
substrMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…