Beispiel #1
0
        /// <returns>Matched size. 0 means no match.</returns>
        public static int MatchOption(OptionInfo I,
                                      string str,
                                      bool ignoreCase)
        {
            foreach (var pre in I.Prefixes)
            {
                if (pre != null)
                {
                    if (str.StartsWith(pre))
                    {
                        string rest = str.Substring(pre.Length);

                        bool matched = ignoreCase
                                               ? rest.StartsWith(I.Name,
                                                                 StringComparison.InvariantCultureIgnoreCase)
                                               : rest.StartsWith(I.Name);
                        if (matched)
                        {
                            return(pre.Length + I.Name.Length);
                        }
                    }
                }
            }

            return(0);
        }
Beispiel #2
0
        // Returns true if one of the Prefixes + In.Names matches Option
        public static bool OptionMatches(OptionInfo In,
                                         string option)
        {
            if (In.Values != null && In.Prefixes != null)
            {
                for (uint I = 0; In.Prefixes[I] != null; I++)
                {
                    if (option == In.Prefixes[I] + In.Name)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        /// Add Values to Option's Values class
        ///
        /// \param [in] Option - Prefix + Name of the flag which Values will be
        ///  changed. For example, "-analyzer-checker".
        /// \param [in] Values - String of Values seperated by ",", such as
        ///  "foo, bar..", where foo and bar is the argument which the Option flag
        ///  takes
        ///
        /// <returns>true in success, and false in fail.</returns>
        public bool AddValues(string option,
                              string values)
        {
            for (int I = _firstSearchableIndex, e = _optionInfos.Count; I < e; I++)
            {
                OptionInfo In = _optionInfos[I];
                if (OptionMatches(In,
                                  option))
                {
                    In.Values = values;
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        public Option(OptionInfo info,
                      OptionTable owner)
        {
            Info  = info;
            Owner = owner;

            // Multi-level aliases are not supported. This just simplifies option
            // tracking, it is not an inherent limitation.
            Contract.Assert((Info == null || !GetAlias().IsValid() || !GetAlias().GetAlias().IsValid()),
                            "Multi-level aliases are not supported.");

            if (Info != null &&
                GetAliasArgs() != null)
            {
                Contract.Assert(GetAlias().IsValid(),
                                "Only alias options can have alias args.");
                Contract.Assert(GetKind() == OptionKind.FlagClass,
                                "Only Flag aliases can have alias args.");
                Contract.Assert(GetAlias().GetKind() != OptionKind.FlagClass,
                                "Cannot provide alias args to a flag option.");
            }
        }