Validates a dot-separated pre-release or build identifier segment. Each identifier is [0-9A-Za-z-]+. Numeric identifiers must not have leading zeros.
| 203 | // Each identifier is [0-9A-Za-z-]+. |
| 204 | // Numeric identifiers must not have leading zeros. |
| 205 | bool isPreReleaseOrBuild(std::string_view V, bool CheckLeadingZeros) { |
| 206 | if (V.empty()) |
| 207 | return false; |
| 208 | size_t Start = 0; |
| 209 | while (Start < V.size()) { |
| 210 | size_t DotPos = V.find('.', Start); |
| 211 | std::string_view Ident = |
| 212 | (DotPos == V.npos) ? V.substr(Start) : V.substr(Start, DotPos - Start); |
| 213 | if (Ident.empty()) |
| 214 | return false; |
| 215 | for (char C : Ident) { |
| 216 | if (!isalnum(C) && C != '-') |
| 217 | return false; |
| 218 | } |
| 219 | if (CheckLeadingZeros) { |
| 220 | bool AllDigits = std::all_of(Ident.begin(), Ident.end(), |
| 221 | [](char C) { return isdigit(C); }); |
| 222 | if (AllDigits && Ident.size() > 1 && Ident[0] == '0') |
| 223 | return false; |
| 224 | } |
| 225 | if (DotPos == V.npos) |
| 226 | break; |
| 227 | Start = DotPos + 1; |
| 228 | } |
| 229 | return true; |
| 230 | } |
| 231 | |
| 232 | // MAJOR.MINOR.PATCH[-prerelease][+build] per semver.org 2.0 |
| 233 | bool isValidSemver(std::string_view V) { |