private static void VerifyRegex(VimRegexConverter converter)
        {
            // we compile the regex because Iris itself will compile it when the time really comes. So, just to be paranoid, we compile it here
            RegexOptions options = RegexOptions.Compiled;

            if (!converter.HasBackReference)
            {
                options |= RegexOptions.ExplicitCapture;
            }

            new Regex(converter.ConvertedRegex, options);
        }
Exemple #2
0
        public static string TestRegexConversion(string vimRegex, string expectedDotnetRegex)
        {
            ArgumentValidator.ThrowIfNullOrEmpty(vimRegex, "vimRegex");
            ArgumentValidator.ThrowIfNullOrEmpty(expectedDotnetRegex, "expectedDotnetRegex");

            VimRegexConverter regexScanner = new VimRegexConverter(vimRegex, ConversionOptions.DefaultMultiLine);

            Console.WriteLine(regexScanner.ConvertedRegex);
            Assert.AreEqual(expectedDotnetRegex, regexScanner.ConvertedRegex);

            return regexScanner.ConvertedRegex;
        }
        private Pattern PatternFromMatch(Match m, bool excludeNl)
        {
            string vimRegex  = m.Groups["pattern"].Value;
            string delimiter = m.Groups["delimiter"].Value;

            if (delimiter != "+")
            {
                vimRegex = vimRegex.Replace("\\" + delimiter, delimiter);
            }

            VimRegexConverter converter;

            if (this.m_ignoreCase)
            {
                converter = new VimRegexConverter(vimRegex, ConversionOptions.CaseInsensitiveMultiline);
            }
            else
            {
                converter = new VimRegexConverter(vimRegex, ConversionOptions.DefaultMultiLine);
            }

            if (this.m_verifyRegexes)
            {
                VerifyRegex(converter);
            }

            Pattern p = new Pattern(converter.ConvertedRegex);

            p.HasBackReference   = converter.HasBackReference;
            p.HasMatchStartGroup = converter.HasMatchStartGroup;
            p.HasMatchEndGroup   = converter.HasMatchEndGroup;
            p.CntExternalGroups  = converter.CntExternalGroups;
            p.LastExternalMatch  = converter.LastExternalMatch;
            p.EatNewLine         = !excludeNl && converter.MatchesMagicDollar;

            string offsetstring = m.Groups["offsets"].Value;

            if (!string.IsNullOrEmpty(offsetstring))
            {
                string[] offsets = offsetstring.Split(',');
                Array.ForEach(offsets, (string offset) => AddOffset(p, offset));
            }

            return(p);
        }
        private static string ConvertRegexesInGroupNames(string names)
        {
            if (!StringExtensions.HasMagicRegexChars(names))
            {
                return(names);
            }

            List <string> convertedNames = new List <string>();

            foreach (string groupName in names.Split(','))
            {
                if (!StringExtensions.HasMagicRegexChars(groupName))
                {
                    convertedNames.Add(groupName);
                }
                else
                {
                    convertedNames.Add(VimRegexConverter.ConvertRegex(groupName, ConversionOptions.DefaultMultiLine));
                }
            }

            return(string.Join(",", convertedNames.ToArray()));
        }
Exemple #5
0
        private Pattern PatternFromMatch(Match m, bool excludeNl)
        {
            string vimRegex = m.Groups["pattern"].Value;
            string delimiter = m.Groups["delimiter"].Value;

            if (delimiter != "+") {
                vimRegex = vimRegex.Replace("\\" + delimiter, delimiter);
            }

            VimRegexConverter converter;

            if (this.m_ignoreCase) {
                converter = new VimRegexConverter(vimRegex, ConversionOptions.CaseInsensitiveMultiline);
            } else {
                converter = new VimRegexConverter(vimRegex, ConversionOptions.DefaultMultiLine);
            }

            if (this.m_verifyRegexes) {
                VerifyRegex(converter);
            }

            Pattern p = new Pattern(converter.ConvertedRegex);

            p.HasBackReference = converter.HasBackReference;
            p.HasMatchStartGroup = converter.HasMatchStartGroup;
            p.HasMatchEndGroup = converter.HasMatchEndGroup;
            p.CntExternalGroups = converter.CntExternalGroups;
            p.LastExternalMatch = converter.LastExternalMatch;
            p.EatNewLine = !excludeNl && converter.MatchesMagicDollar;

            string offsetstring = m.Groups["offsets"].Value;

            if(!string.IsNullOrEmpty(offsetstring)) {
                string[] offsets = offsetstring.Split(',');
                Array.ForEach(offsets, (string offset) => AddOffset(p, offset));
            }

            return p;
        }
Exemple #6
0
        private static void VerifyRegex(VimRegexConverter converter)
        {
            // we compile the regex because Iris itself will compile it when the time really comes. So, just to be paranoid, we compile it here
            RegexOptions options = RegexOptions.Compiled;

            if (!converter.HasBackReference) {
                options |= RegexOptions.ExplicitCapture;
            }

            new Regex(converter.ConvertedRegex, options);
        }