<commit_before>﻿// Author: <NAME> (Trade/ProgTrade) 2016

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using nUpdate.Core;

namespace nUpdate.Updating
{
    public class UpdateVersion : IComparable<UpdateVersion>
    {
        /// <summary>
        ///     Initializes a new instance of the <see cref="UpdateVersion" />-class.
        /// </summary>
        public UpdateVersion()
            : this(0, 0, 0, 0, DevelopmentalStage.Release, 0)
        {
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="UpdateVersion" />-class.
        /// </summary>
        /// <param name="version">The update version.</param>
        public UpdateVersion(string version)
        {
            Match match = Regex.Match(version,
                @"^(?<Version>((?<VersionNumber>\d+)\.){0,3}(?<VersionNumber>\d+))((-| )?(?<DevStage>(?<Type>[ab]|rc)(\.?(?<DevBuild>\d+))?))?$");
            if (!match.Success || !match.Groups["Version"].Success)
                throw new ArgumentException("The specified version is not valid.");

            Major = int.Parse(match.Groups["VersionNumber"].Captures[0].Value);
            if (match.Groups["VersionNumber"].Captures.Count > 1)
                Minor = int.Parse(match.Groups["VersionNumber"].Captures[1].Value);
            else
                Build = 0;
            Build = match.Groups["VersionNumber"].Captures.Count > 2
                ? int.Parse(match.Groups["VersionNumber"].Captures[2].Value)
                : 0;
            Revision = match.Groups["VersionNumber"].Captures.Count > 3
                ? int.Parse(match.Groups["VersionNumber"].Captures[3].Value)
                : 0;

            if (!match.Groups["DevStage"].Success)
                return;
            var devStage = match.Groups["Type"].Value;
            DevelopmentalStage = devStage == "a"
                ? DevelopmentalStage.Alpha
                : devStage == "b" ? DevelopmentalStage.Beta : DevelopmentalStage.ReleaseCandidate;

            DevelopmentBuild = match.Groups["DevBuild"].Success ? int.Parse(match.Groups["DevBuild"].Value) : 0;
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="UpdateVersion" />-class.
        /// </summary>
        /// <param name="major">The major version.</param><commit_msg>Fix that invalid developmental stages were accepted<commit_after>﻿// Author: <NAME> (Trade/ProgTrade) 2016

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using nUpdate.Core;

namespace nUpdate.Updating
{
    public class UpdateVersion : IComparable<UpdateVersion>
    {
        /// <summary>
        ///     Initializes a new instance of the <see cref="UpdateVersion" />-class.
        /// </summary>
        public UpdateVersion()
            : this(0, 0, 0, 0, DevelopmentalStage.Release, 0)
        {
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="UpdateVersion" />-class.
        /// </summary>
        /// <param name="version">The update version.</param>
        public UpdateVersion(string version)
        {
            Match match = Regex.Match(version,
                @"^(?<Version>((?<VersionNumber>\d+)\.){0,3}(?<VersionNumber>\d+))((-| )?(?<DevStage>(?<Type>[ab]|rc)(\.?(?<DevBuild>\d+))?))?$");
            if (!match.Success || !match.Groups["Version"].Success)
                throw new ArgumentException("The specified version is not valid.");

            Major = int.Parse(match.Groups["VersionNumber"].Captures[0].Value);
            if (match.Groups["VersionNumber"].Captures.Count > 1)
                Minor = int.Parse(match.Groups["VersionNumber"].Captures[1].Value);
            else
                Build = 0;
            Build = match.Groups["VersionNumber"].Captures.Count > 2
                ? int.Parse(match.Groups["VersionNumber"].Captures[2].Value)
                : 0;
            Revision = match.Groups["VersionNumber"].Captures.Count > 3
                ? int.Parse(match.Groups["VersionNumber"].Captures[3].Value)
                : 0;

            if (!match.Groups["DevStage"].Success)
                return;
            var developmentalStage = match.Groups["Type"].Value;
            switch (developmentalStage)
            {
                case "a":
                    DevelopmentalStage = DevelopmentalStage.Alpha;
                    break;
                case "b":
                    DevelopmentalStage = DevelopmentalStage.Beta;
                    break;
                case "rc":
                    DevelopmentalStage = DevelopmentalStage.ReleaseCandidate;
                    break;
                default:
                    throw new ArgumentException("The specified developmental stage is not valid.");
            }

            DevelopmentBuild = match.Groups["DevBuild"].Success ? int.Parse(match.Groups["DevBuild"].Value) : 0;
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="UpdateVersion" />-class.
        /// </summary>
        /// <param name="major">The major version.</param>
{'fraction_non_alphanumeric': 0.14427670552264477, 'fraction_numerical': 0.008408178864895853, 'mean_word_length': 1.9857387335995436, 'pattern_counts': {'":': 3, '<': 45, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1764697', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1352, 'n_words': 282}