Skip to content

Validating versions and version ranges #47

@r3ps4J

Description

@r3ps4J

Hi!

I want to check if a semver version or version range string is valid. With node-semver I'm using valid(v) (for versions) and validRange(range) (for ranges) to do this. See the following Typescript code:

if (!semver.valid(actualVersion)) {
    return false;
}
if (!semver.validRange(requiredVersion)) {
    return false;
}

Can this be done with your library as well in C++?

For versions I think I can make use of the from_string methods and check the return or error, based on the following from the readme file:

// Non-member from string.
semver::version v5 = semver::from_string(s); // constexpr and may throw.
std::optional<version> v6 = semver::from_string_noexcept(s); // constexpr and no throw.

// From string.
semver::version v7;
v7.from_string(s); // constexpr and may throw.
bool success = v7.from_string_noexcept(s); // constexpr and no throw.

But I'm not sure if something similar is possible for version ranges. What would be the best way to recreate my typescript code in C++ using your library?

I'm a bit new to C++, so let me know if you need more info!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions