コード例 #1
0
        internal Int32 AddResult(String rest, Int32 index)
        {
            var restResult = new regexMarkerResult(rest, index, defaultMarker);

            AddResult(restResult);
            return(restResult.index + restResult.length);
        }
コード例 #2
0
        public regexMarkerResult GetResult(String scrambled)
        {
            Match             m   = test.Match(scrambled);
            regexMarkerResult res = new regexMarkerResult(m, marker);

            res.regexMarker = this;
            return(res);
        }
コード例 #3
0
        internal void AddResult(regexMarkerResult res)
        {
            for (Int32 ind = res.index; ind <= res.index + res.length; ind++)
            {
                byAllocation.Add(ind, res);
            }

            byMarker.Add(res.marker, res);
        }
コード例 #4
0
        public List <regexMarkerResult> GetResults(String scrambled)
        {
            List <regexMarkerResult> output = new List <regexMarkerResult>();

            MatchCollection mchs = test.Matches(scrambled);

            foreach (Match m in mchs)
            {
                regexMarkerResult res = new regexMarkerResult(m, marker);
                res.regexMarker = this;
                output.Add(res);
            }
            return(output);
        }
コード例 #5
0
        /// <summary>
        /// Gets the marker results by order of appearance -- taking only first layer
        /// </summary>
        /// <returns></returns>
        public List <regexMarkerResult> GetByOrder()
        {
            List <regexMarkerResult> output = new List <regexMarkerResult>();
            Int32 index = 0;

            regexMarkerResult head = null;

            while (index < length)
            {
                if (byAllocation.ContainsKey(index))
                {
                    var tmp = byAllocation[index].First();
                    output.Add(tmp);
                    index = index + tmp.length;
                }
                else
                {
                    index++;
                }
            }
            return(output);
        }
コード例 #6
0
        /// <summary>
        /// Processes the specified text input into <see cref="regexMarkerResultCollection{T}"/>
        /// </summary>
        /// <param name="input">The input text to be parsed</param>
        /// <returns>Collection with matched results</returns>
        public regexMarkerResultCollection process(String input)
        {
            regexMarkerResultCollection output = new regexMarkerResultCollection();

            String scrambled = input;


            if (SerialMode)
            {
                Boolean matchFound = true;
                do
                {
                    matchFound = false;
                    foreach (var reg in Markers)
                    {
                        if (reg != null)
                        {
                            Match m = reg.test.Match(scrambled);
                            if (m.Success)
                            {
                                regexMarkerResult res = new regexMarkerResult(m, reg.marker);
                                output.AddResult(res);
                                scrambled  = reg.ReplaceMatch(m, scrambled);
                                matchFound = true;
                            }
                        }
                    }
                } while (matchFound);
            }
            else
            {
                foreach (var reg in Markers)
                {
                    if (reg != null)
                    {
                        MatchCollection mchs = reg.test.Matches(scrambled);
                        foreach (Match m in mchs)
                        {
                            regexMarkerResult res = new regexMarkerResult(m, reg.marker);
                            output.AddResult(res);
                        }
                        scrambled = reg.test.Replace(scrambled, reg.replacementGenerator);
                    }
                }
            }



            String[] rest = scrambleCut.Split(scrambled);

            Int32 index = 0;

            regexMarkerResult restResult = null;

            foreach (String rst in rest)
            {
                if (output.byAllocation.ContainsKey(index))
                {
                    index = index + output.byAllocation[index].First().match.Length;
                }
                else
                {
                    index = output.AddResult(rst, index);
                }
            }
            output.length = index;

            return(output);
        }