Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/easz/cpp-semver
semver in c++
https://github.com/easz/cpp-semver
cpp semver
Last synced: 3 months ago
JSON representation
semver in c++
- Host: GitHub
- URL: https://github.com/easz/cpp-semver
- Owner: easz
- License: mit
- Created: 2018-03-05T13:31:43.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T16:10:16.000Z (about 1 year ago)
- Last Synced: 2024-08-01T21:44:09.942Z (6 months ago)
- Topics: cpp, semver
- Language: C++
- Homepage:
- Size: 49.8 KB
- Stars: 29
- Watchers: 2
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## cpp-semver - Semantic Versioning in C++
### Features
* header-only C++11
* parses semver string
* inspired by [Semantic Versioning](https://semver.org/) and [npm-semver](https://docs.npmjs.com/cli/v6/using-npm/semver)
### 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
```c++
// example/demo.cpp#include "cpp-semver.hpp"
#includeint 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.
```