Skip to content

Conversation

@katzoded
Copy link

No description provided.

…ulong (ulong can be 32 bits in case it is not built with LP64.

2. add test to verify the max values of 64bits
… ulong (ulong can be 32 bits in case it is not built with LP64.

    2. add test to verify the max values of 64bits
… ulong (ulong can be 32 bits in case it is not built with LP64.

    2. add test to verify the max values of 64bits
@linear
Copy link

linear bot commented Apr 11, 2023

@katzoded katzoded requested a review from ekampf April 11, 2023 04:10
@katzoded katzoded requested a review from stablebits April 11, 2023 04:11
const std::string prerelease_allowed_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-";
const std::string version_pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
const std::string loose_version_pattern = "^v?(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
const std::string version_pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we change regex? Where are these new patterns coming from?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same regex, Oded just broke it into lines to make it easier to read the major.minor.patch parts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logan is right, I just broke the regex into those parts as defined in standard.

patch = patch_m.matched ? std::stoul(patch_m) : 0;
major = (BuildIdentifierPart) parse_build_identifier_part(major_m);
minor = minor_m.matched ? (BuildIdentifierPart) parse_build_identifier_part(minor_m) : 0;
patch = patch_m.matched ? (BuildIdentifierPart) parse_build_identifier_part(patch_m) : 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_buld_identifier_part() already returns BuildIdentifierPart so we don't need these type casts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, good catch... its a leftovers

namespace semver
{

typedef uint64_t BuildIdentifierPart;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: using is considered to be more in line with modern C++ than typedef. e.g. using BuildIdentifierPart = uint64_t;.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea was to allow users of this class to define the size of BuildIdentifierPart before the include (if someone wants a smaller size)

but for some reason I couldn't make it work...
I'll change it to using


inline BuildIdentifierPart parse_build_identifier_part(const std::string& version_part)
{
return (BuildIdentifierPart)std::stoull(version_part);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: static_cast<BuildIdentifierPart>(...) is also more like modern C++ ))

namespace semver
{

typedef uint64_t BuildIdentifierPart;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea was to allow users of this class to define the size of BuildIdentifierPart before the include (if someone wants a smaller size)

but for some reason I couldn't make it work...
I'll change it to using

const std::string prerelease_allowed_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-";
const std::string version_pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
const std::string loose_version_pattern = "^v?(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
const std::string version_pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logan is right, I just broke the regex into those parts as defined in standard.

const std::string version_pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
const std::string loose_version_pattern = "^v?(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
const std::string version_pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)"
"(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))"
Copy link
Author

@katzoded katzoded Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Twingate/sdwan,
maybe you can help me understand this regex and if it complies with RFC ABNF .

<pre-release identifier> ::= <alphanumeric identifier>
                           | <numeric identifier>

I would do something much easier on this one (?:-[a-zA-Z0-9\.]*), although I tried to modify it and it didn't go that easy for the tests!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually the regex it taken from RFC

patch = patch_m.matched ? std::stoul(patch_m) : 0;
major = (BuildIdentifierPart) parse_build_identifier_part(major_m);
minor = minor_m.matched ? (BuildIdentifierPart) parse_build_identifier_part(minor_m) : 0;
patch = patch_m.matched ? (BuildIdentifierPart) parse_build_identifier_part(patch_m) : 0;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, good catch... its a leftovers

namespace semver
{

using BuildIdentifierPart = uint64_t;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw., this code is using variable_name style, not VariableStyle, for naming variables, functions, and types. It's better to use the same style when modifying existing code so that code looks consistent.

@katzoded katzoded merged commit f614975 into main Apr 11, 2023
@katzoded katzoded deleted the feature/ok/sdwan-252-authz-version-semver branch April 11, 2023 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants