parseVersion parses version string Returns: major, minor, patch, isCanary, canaryNumber
(version string)
| 274 | // parseVersion parses version string |
| 275 | // Returns: major, minor, patch, isCanary, canaryNumber |
| 276 | func parseVersion(version string) (int, int, int, bool, int) { |
| 277 | // Remove "v" prefix |
| 278 | version = strings.TrimPrefix(version, "v") |
| 279 | |
| 280 | // Check if it's a canary version |
| 281 | isCanary := strings.Contains(version, "canary") |
| 282 | canaryNum := 0 |
| 283 | |
| 284 | // Regular expression to match version number |
| 285 | // Format: 14.3.0-canary.77 or 15.0.1 |
| 286 | re := regexp.MustCompile(`^(\d+)\.(\d+)\.(\d+)(?:-canary\.(\d+))?`) |
| 287 | matches := re.FindStringSubmatch(version) |
| 288 | |
| 289 | if len(matches) < 4 { |
| 290 | return 0, 0, 0, false, 0 |
| 291 | } |
| 292 | |
| 293 | major, _ := strconv.Atoi(matches[1]) |
| 294 | minor, _ := strconv.Atoi(matches[2]) |
| 295 | patch, _ := strconv.Atoi(matches[3]) |
| 296 | |
| 297 | if len(matches) > 4 && matches[4] != "" { |
| 298 | canaryNum, _ = strconv.Atoi(matches[4]) |
| 299 | } |
| 300 | |
| 301 | return major, minor, patch, isCanary, canaryNum |
| 302 | } |
no outgoing calls