Example #1
0
        public CodePatternMatch FirstMatchInResourcesSegment(MemoryAddress start, int length, string pattern)
        {
            if (start < Resources.Start ||
                start >= Resources.Start + Resources.Size)
            {
                throw new ArgumentOutOfRangeException(nameof(start));
            }
            if (length <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }
            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            return(CodePattern.Parse(pattern).Matches(Resources.Start, ResourcesBuffer, start, length).First());
        }
Example #2
0
 public IEnumerable <CodePatternMatch> MatchesInTextSegment(string pattern)
 {
     return(CodePattern.Parse(pattern)
            .Matches(Text.Start, TextBuffer));
 }
Example #3
0
 public CodePatternMatch FirstMatchInDataSegment(string pattern)
 {
     return(CodePattern.Parse(pattern)
            .Matches(Data.Start, DataBuffer)
            .First());
 }
Example #4
0
        public static CodePattern Parse(string pattern)
        {
            var bp      = new StringBuilder(pattern.Length);
            var marker  = default(string);
            var markers = new Lazy <List <CodePatternMarker> >();
            var op      = new Range(0, 0);
            var ops     = new List <Range>();

            foreach (var c in pattern)
            {
                if (c == '{')
                {
                    if (marker != null)
                    {
                        throw new FormatException();
                    }
                    marker = "";
                }
                else if (marker != null)
                {
                    if (c == '}')
                    {
                        var position = bp.Length;
                        if ((position & 1) != 0)
                        {
                            throw new FormatException();
                        }
                        markers.Value.Add(new CodePatternMarker {
                            Name = marker, Position = position / 2
                        });
                        marker = null;
                    }
                    else
                    {
                        marker += c;
                    }
                }
                else if (IsClean(c))
                {
                    bp.Append(c);
                }
                else if (c == '|')
                {
                    var position = bp.Length;
                    if (op != default(Range))
                    {
                        if ((position & 1) != 0)
                        {
                            throw new FormatException();
                        }
                        op.Size = position / 2 - op.Start;
                        ops.Add(op);
                    }
                    op = new Range(position / 2, 0);
                }
            }
            if (marker != null)
            {
                throw new FormatException();
            }
            if (op != default(Range))
            {
                var position = bp.Length;
                if ((position & 1) != 0)
                {
                    throw new FormatException();
                }
                op.Size = position / 2 - op.Start;
                ops.Add(op);
            }

            var binary = BinaryPattern.Parse(bp.ToString());
            var x      = new CodePattern {
                Markers = markers.IsValueCreated ? markers.Value : null, Binary = binary, Operations = ops
            };

            return(x);
        }