Giter Club home page Giter Club logo

cpp-semver's Introduction

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;
}

To build:

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

Or build with optional PEGTL parser: (to cross test, or to quickly evaluate any grammar change for development purpose.)

> 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.

cpp-semver's People

Contributors

gpbeta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.