Ejemplo n.º 1
0
        public void Match(ref PcreRefMatch match, ReadOnlySpan <char> subject, PcreMatchSettings settings, int startIndex, uint additionalOptions)
        {
            var input = new Native.match_input();

            settings.FillMatchInput(ref input);

            Native.match_result result;
            CalloutInterop.CalloutInteropInfo calloutInterop;

            fixed(char *pSubject = subject)
            fixed(uint *pOVec = match.OutputVector)
            {
                input.code               = _code;
                input.subject            = pSubject;
                input.subject_length     = (uint)subject.Length;
                input.output_vector      = pOVec;
                input.start_index        = (uint)startIndex;
                input.additional_options = additionalOptions;

                if (input.subject == (char *)0 && input.subject_length == 0)
                {
                    input.subject = (char *)1; // PCRE doesn't like null subjects, even if the length is zero
                }
                CalloutInterop.Prepare(subject, this, ref input, out calloutInterop, settings.RefCallout);

                Native.match(ref input, out result);
            }

            AfterMatch(result, ref calloutInterop);

            match.Update(subject, result);
        }
Ejemplo n.º 2
0
        private static void CompareGroups(TestPattern pattern, PcreRefMatch actualMatch, ExpectedMatch expectedMatch)
        {
            var expectedGroups = expectedMatch.Groups.ToList();

            Assert.That(actualMatch.Groups.Count, Is.GreaterThanOrEqualTo(expectedGroups.Count));

            for (var groupIndex = 0; groupIndex < actualMatch.Groups.Count; ++groupIndex)
            {
                var actualGroup   = actualMatch.Groups[groupIndex];
                var expectedGroup = groupIndex < expectedGroups.Count
                    ? expectedGroups[groupIndex]
                    : ExpectedGroup.Unset;

                Assert.That(actualGroup.Success, Is.EqualTo(expectedGroup.IsMatch));

                if (expectedGroup.IsMatch)
                {
                    var expectedValue = pattern.SubjectLiteral
                        ? expectedGroup.Value
                        : expectedGroup.Value.UnescapeGroup();

                    Assert.That(actualGroup.Value.ToString(), Is.EqualTo(expectedValue));
                }
            }
        }
Ejemplo n.º 3
0
        private static List <bool> GetDuplicateNamedGroupsSuccesses(PcreRefMatch match, string groupName)
        {
            var result = new List <bool>();

            foreach (var group in match.GetDuplicateNamedGroups(groupName))
            {
                result.Add(group.Success);
            }

            return(result);
        }
Ejemplo n.º 4
0
 private static void CompareRemainingString(PcreRefMatch actualMatch, ExpectedMatch expectedMatch)
 => Assert.That(actualMatch.Subject.Slice(actualMatch.Index + actualMatch.Length).ToString(), Is.EqualTo(expectedMatch.RemainingString.UnescapeGroup()));
Ejemplo n.º 5
0
 private static void CompareMark(PcreRefMatch actualMatch, ExpectedMatch expectedMatch)
 => Assert.That(actualMatch.Mark.ToString(), Is.EqualTo(expectedMatch.Mark.UnescapeGroup() ?? string.Empty));