当前位置: 首页>>代码示例>>C#>>正文


C# Match.Copy方法代码示例

本文整理汇总了C#中Match.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# Match.Copy方法的具体用法?C# Match.Copy怎么用?C# Match.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Match的用法示例。


在下文中一共展示了Match.Copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Find

        /// <summary>Searches for a match, beginning from a specified position.</summary>
        /// <param name="text">The text to match against.</param>
        /// <param name="startIndex">The starting position.</param>
        /// <param name="anchored">Set to <c>true</c> to force matches to start from <paramref name="startIndex"/>.</param>
        /// <returns>Result of the search.</returns>
        internal Match Find(string text, int startIndex, bool anchored)
        {
            int length = text.Length;
            if (Anchored) anchored = true;
            Stack<Match> avail = new Stack<Match>();
            Queue<Match> active = new Queue<Match>(nTransitions);

            Match best = new Match(this, text, anchored);
            Match start = new Match(this, text, anchored);
            start.StateID = 0;
            start.Position = startIndex;
            if (!anchored) Scan(start);
            do
            {
                Match current;
                if (active.Count == 0 || active.Peek().Position > start.Position)
                    current = start;
                else
                    current = active.Dequeue();
                Transition[] trans = States[current.StateID];
                for (int i = 0; i < trans.Length; i++)
                {
                    if (Evaluate(current, trans[i].instruction, trans[i].target, true))
                    {
                        // don't duplicate work or run past the end of text
                        if (current.Position <= length && !active.Contains(current, sameFinal))
                        {
                            Match next;
                            if (avail.Count == 0)
                                next = new Match(this, text, anchored);
                            else
                                next = avail.Pop();
                            next.Copy(current);
                            active.Enqueue(next);
                        }
                    }
                    else if (Match.PosixPriority(current, best) > 0)
                        best.Copy(current);

                    Unevaluate(current);
                }
                if (current != start)
                    avail.Push(current);
                else if (anchored || best.IsSuccess)
                    start.Position = length;
                else
                {
                    start.Position++;
                    Scan(start);
                }
            } while (active.Count > 0 || start.Position < length);

            return best;
        }
开发者ID:MichaelBrazier,项目名称:brasswork-regex,代码行数:59,代码来源:NFA.cs


注:本文中的Match.Copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。