/// <summary> /// Constructs a new RegexString with the given string and <see cref="RegexStringOptions"/> /// </summary> /// <param name="pattern"></param> /// <param name="options"></param> public RegexString(string pattern, RegexStringOptions options) { Options = options; if (!options.HasFlag(RegexStringOptions.PlainText)) { string regexPattern = pattern; if (options.HasFlag(RegexStringOptions.MatchFromStart)) { //'^' is the regex modifier to assert that the match must begin at the start of the string regexPattern = "^" + regexPattern; } if (options.HasFlag(RegexStringOptions.MatchAtEnd)) { //'$' is the regex modifier to assert that the match must end at the end of the string regexPattern = regexPattern + "$"; } _regex = new Regex(regexPattern, !options.HasFlag(RegexStringOptions.CaseSensitive) ? RegexOptions.IgnoreCase : RegexOptions.None); } _matchStart = options.HasFlag(RegexStringOptions.MatchFromStart); _matchEnd = options.HasFlag(RegexStringOptions.MatchAtEnd); _caseSensitive = options.HasFlag(RegexStringOptions.CaseSensitive); _string = _caseSensitive ? pattern : pattern.ToLowerInvariant(); }
/// <summary> /// Constructs a new CommandExecutorAttribute using the given <see cref="RegexString"/>s to match input to the command /// </summary> /// <param name="description">A string describing the command</param> /// <param name="commandMatcher">A required RegexString that input must match for the command to be run</param> /// <param name="matcherOptions">A RegexStringOptions enum defining how the matcher will behave</param> /// <param name="friendlyName">An optional human-readable name for the command</param> public CommandExecutorAttribute(string description, string commandMatcher, RegexStringOptions matcherOptions, string friendlyName = null) { Description = description; CommandMatcher = new RegexString(commandMatcher, matcherOptions); FriendlyName = friendlyName; }
/// <summary> /// Constructs a new SubcommandExecutorAttribute using the given <see cref="RegexString"/>s to match input to the command /// </summary> /// <param name="parentCommand">A string representing the name of the command that executes this subcommand</param> /// <param name="description">A string describing the command</param> /// <param name="commandMatcher">A required RegexString that input must match for the command to be run</param> /// <param name="matcherOptions">A RegexStringOptions enum defining how the matcher will behave</param> /// <param name="friendlyName">An optional human-readable name for the command</param> public SubcommandExecutorAttribute(string parentCommand, string description, string commandMatcher, RegexStringOptions matcherOptions, string friendlyName = null) : base(description, commandMatcher, matcherOptions, friendlyName) { ParentName = parentCommand; }