Esempio n. 1
0
 public static Diapason <int> Create(string s)
 {
     return(Diapason.CreateInt32(s).SetLimits(1025, 65535));
 }
Esempio n. 2
0
 public static Diapason <int> ToDiapason(this string s, int from, int to)
 {
     return(Diapason.CreateInt32(s).SetLimits(from, to));
 }
Esempio n. 3
0
        private static RulesSet FromLines([NotNull] string[] strings)
        {
            var    list = new List <Rule>(strings.Length);
            string fileName = null, section = null;
            Match  sectionParsed = null;
            IEnumerable <string> sectionNumbered = null;

            foreach (var raw in strings)
            {
                var splitted = SpacesRegex.Split(raw.Trim());
                if (splitted.Length == 0 || splitted[0].Length == 0)
                {
                    continue;
                }

                var path = splitted[0].Split(new [] { '/' }, 3);

                string property = null;
                if (FileNameRegex.IsMatch(path[0]))
                {
                    fileName      = path[0];
                    section       = path.Length >= 2 ? path[1] : null;
                    sectionParsed = null;

                    if (path.Length >= 3)
                    {
                        property = path[2];
                    }
                    else if (splitted.Length == 1)
                    {
                        continue;
                    }
                }
                else
                {
                    property = path[path.Length - 1];
                    if (path.Length > 1)
                    {
                        section       = path[path.Length - 2];
                        sectionParsed = null;
                    }
                    if (path.Length > 2)
                    {
                        fileName = path[path.Length - 3];
                    }
                }

                var type = RuleTypeFromString(splitted.Length == 1 ? "number" : splitted[1]);

                if (type != RuleType.Lut)
                {
                    if (fileName == null || section == null)
                    {
                        Console.Error.WriteLine("Invalid field '{0}/{1}/{2}'", fileName, section, property);
                        continue;
                    }
                }

                var additionalParams = splitted.Skip(2).ToList();
                var extra            = additionalParams.Where(x => x.StartsWith("×") ||
                                                              x.StartsWith("=") || x.StartsWith("≠") ||
                                                              x.StartsWith("<") || x.StartsWith(">") ||
                                                              x.StartsWith("≤") || x.StartsWith("≥")).ToList();
                var actualParams = additionalParams.ApartFrom(extra).ToArray();

                var weight = FlexibleParser.TryParseDouble(extra.FirstOrDefault(x => x.StartsWith("×"))?.Substring(1)) ?? 1d;
                var tests  = extra.Select(GetTest).NonNull().ToArray();

                if (sectionParsed == null && section != null)
                {
                    sectionParsed = Regex.Match(section, @"(.*)\{(.+)\}(.*)");
                    if (sectionParsed.Success)
                    {
                        var prefix  = sectionParsed.Groups[1].Value;
                        var postfix = sectionParsed.Groups[3].Value;
                        sectionNumbered = Diapason.CreateInt32(sectionParsed.Groups[2].Value).SetLimits(0, 100).Select(x => prefix + x + postfix);
                    }
                    else
                    {
                        sectionNumbered = new[] { section };
                    }
                }

                list.AddRange(from s in sectionNumbered ?? new string[0]
                              select new Rule {
                    Type = type, FileName = fileName, Section = s, Property = property, Params = actualParams, Tests = tests, Weight = weight
                });
            }

            return(new RulesSet(list.ToArray()));
        }
Esempio n. 4
0
 public void OptimizationTest()
 {
     Assert.AreEqual(0, Diapason.CreateInt32("112-20").Pieces.Count);
     Assert.AreEqual("12-28, 114-132", Diapason.CreateInt32("12-20, 12-14, 12-28, 114, 114-124, 114-132").Pieces.JoinToString(", "));
     Assert.AreEqual("12-32", Diapason.CreateInt32("12-20, 12-14, 12-28, 14, 14-24, 14-32").Pieces.JoinToString(", "));
 }