Example #1
0
        private void ReplacePart(string originalRegex, int selectionStart, int selectionLength, string replacement, FSharpOption <string> groupName, string sampleValue)
        {
            var result = RegexModifier.substitute(
                originalRegex,
                selectionStart,
                selectionLength,
                replacement,
                groupName,
                sampleValue
                );

            switch (result)
            {
            case RegexModifier.SubstitutionResult.Failure failure:
            {
                MessageBox.Show(failure.Item.Message);
                return;
            }

            case RegexModifier.SubstitutionResult.Success success:
            {
                textBoxGroupReplacement.Text = string.Empty;
                textBoxGroupName.Text        = string.Empty;
                richTextBoxRegex.Text        = success.Item.NewRegex;
                return;
            }

            default: throw new NotImplementedException();
            }
        }
        public static void Find(string param)
        {
            Dictionary <string, FileInfoWrapper> result = list;

            string nameParam = Regex.Match(param, @"-n=[^\s]+").Value;

            if (!string.IsNullOrEmpty(nameParam))
            {
                string bareParam = param.Remove(0, param.IndexOf('=') + 1);
                string paramN    = GetParam(param, 'n');
                bareParam = bareParam.Replace(paramN, string.Empty);
                RegexModifier modifier = null;
                if (bareParam == "-f")
                {
                    modifier = (f, s) => (f == s);
                }
                else if (bareParam != "-f" && !string.IsNullOrEmpty(bareParam))
                {
                    throw new ArgumentException("Unknown parameter modifier to -n=[regex]. Did you mean '-f'?");
                }
                else
                {
                    modifier = (f, s) => true;
                }
                result = FindBy(s =>
                {
                    var match = Regex.Match(s.Key, GetParam(param, 'n'));
                    return(match.Success && modifier(match.Value, s.Key));
                }
                                , result);
            }

            string extensionParam = Regex.Match(param, @"-e=[^\s]+").Value;

            if (!string.IsNullOrEmpty(extensionParam))
            {
                result = FindBy(s => Regex.Match(s.Value.Extension, GetParam(extensionParam, 'e')).Success, result);
            }

            string atributeParam = Regex.Match(param, @"-a=[^\s]+").Value;

            if (!string.IsNullOrEmpty(atributeParam))
            {
                string name = GetParam(param, 'a');
                result = FindBy((s => Regex.Match(s.Value.Atributes.ToString() + ",", string.Format(@"({0},)", name)).Success), result);
            }

            string dataParam = Regex.Match(param, @"-d=[\w.\-=]+").Value;

            if (!string.IsNullOrEmpty(dataParam))
            {
                result = FindByData(dataParam, result);
            }

            Show(string.Empty, result);
        }