Skip to content

hrbrmstr/cpp-semver

This branch is 12 commits behind easz/cpp-semver:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Tsungi Lyn
Mar 20, 2018
5e5b265 · Mar 20, 2018

History

33 Commits
Mar 12, 2018
Mar 15, 2018
Mar 19, 2018
Mar 20, 2018
Mar 15, 2018
Mar 12, 2018
Mar 5, 2018
Mar 20, 2018
Mar 18, 2018

Repository files navigation

cpp-semver - Semantic Versioning in C++

Features

API handling string representation

  • semver::valid( v ): return true if the given version or range is syntactically and semantically valid.
  • semver::intersects( range1, range2="*" ): return true if the given version ranges or comparators intersect.
  • semver::satisfies( version, range ): return true if the version satisfies the range.
  • semver::gt( v1, v2 ), semver::gte( v1, v2 ), semver::lt( v1, v2 ), semver::lte( v1, v2 ), semver::eq( v1, v2 ), semver::neq( v1, v2 ), semver::gtr( version, range ), semver::ltr( version, range ): various comparators.
  • semver::prerelease( version ), semver::major( version ), semver::minor( version ), semver::patch( version ): get version parts if possible.

Usage & Demo

// example/demo.cpp

#include "cpp-semver.hpp"
#include <iostream>

int main()
{
  {
    const std::string ver1 = "1.0.0 || 1.5 - 3.0";
    const std::string ver2 = ">1.1 <2.0";

    const bool intersected = semver::intersects(ver1, ver2);

    std::cout << "\"" << ver1
      << "\" and \"" << ver2
      << "\" are " << (intersected ? "" : "not ")
      << "intersected." << std::endl;
  }

  {
    const std::string comp = "<1.* >2.2";

    const bool intersected = semver::intersects(comp);

    std::cout << "\"" << comp
      << "\" is " << (intersected ? "" : "not ")
      << "intersected." << std::endl;
  }

  return 0;
}

Build with zero-dependency:

> g++ -std=c++11 -Iinclude example/demo.cpp

Or build with PEGTL:

> git submodule update --init --recursive
> g++ -std=c++11 -D USE_PEGTL -Iinclude -IPEGTL/include example/demo.cpp

The result:

> ./a.out
"1.0.0 || 1.5 - 3.0" and ">1.1 <2.0" are intersected.
"<1.* >2.2" is not intersected.

About

semver in c++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 97.1%
  • Makefile 2.9%