Beispiel #1
0
        /**
         * {@code findAllUTF8Submatch} is the <a href='#all'>All</a> version of {@link #findUTF8Submatch};
         * it returns a list of up to {@code n} successive matches of the expression, as defined by the <a
         * href='#all'>All</a> description above.
         *
         * <p>
         * A return value of null indicates no match.
         */
        // This is visible for testing.
        public List <byte[][]> findAllUTF8Submatch(byte[] b, int n)
        {
            List <byte[][]> result = new List <byte[][]>();

            allMatches(
                MachineInput.fromUTF8(b),
                n,
                (int[] match) => {
                byte[][] slice = new byte[match.Length / 2][];
                for (int j = 0; j < slice.Length; ++j)
                {
                    if (match[2 * j] >= 0)
                    {
                        slice[j] = Utils.subarray(b, match[2 * j], match[2 * j + 1]);
                    }
                }
                result.Add(slice);
            });
            if (!result.Any())
            {
                return(null);
            }

            return(result);
        }
Beispiel #2
0
        /**
         * Returns a two-element array of integers defining the location of the leftmost match in
         * {@code b} of this regular expression. The match itself is at {@code b[loc[0]...loc[1]]}.
         *
         * <p>
         * A return value of null indicates no match.
         */
        // This is visible for testing.
        public int[] findUTF8Index(byte[] b)
        {
            int[] a = doExecute(MachineInput.fromUTF8(b), 0, UNANCHORED, 2);
            if (a == null)
            {
                return(null);
            }

            return(Utils.subarray(a, 0, 2));
        }
Beispiel #3
0
        /**
         * {@code findAllUTF8SubmatchIndex} is the <a href='#all'>All</a> version of
         * {@link #findUTF8SubmatchIndex}; it returns a list of up to {@code n} successive matches of the
         * expression, as defined by the <a href='#all'>All</a> description above.
         *
         * <p>
         * A return value of null indicates no match.
         */
        // This is visible for testing.
        public List <int[]> findAllUTF8SubmatchIndex(byte[] b, int n)
        {
            List <int[]> result = new List <int[]>();

            allMatches(
                MachineInput.fromUTF8(b),
                n,
                (int[] match) => {
                result.Add(match);
            });
            if (!result.Any())
            {
                return(null);
            }

            return(result);
        }
Beispiel #4
0
        /**
         * {@code findAllUTF8()} is the <a href='#all'>All</a> version of {@link #findUTF8}; it returns a
         * list of up to {@code n} successive matches of the expression, as defined by the <a
         * href='#all'>All</a> description above.
         *
         * <p>
         * A return value of null indicates no match.
         *
         * TODO(adonovan): think about defining a byte slice view class, like a read-only Go slice backed
         * by |b|.
         */
        // This is visible for testing.
        public List <byte[]> findAllUTF8(byte[] b, int n)
        {
            List <byte[]> result = new List <byte[]>();

            allMatches(
                MachineInput.fromUTF8(b),
                n,
                (int[] match) => {
                result.Add(Utils.subarray(b, match[0], match[1]));
            });
            if (!result.Any())
            {
                return(null);
            }

            return(result);
        }
Beispiel #5
0
        /**
         * Returns an array of arrays the text of the leftmost match of the regular expression in
         * {@code b} and the matches, if any, of its subexpressions, as defined by the <a
         * href='#submatch'>Submatch</a> description above.
         *
         * <p>
         * A return value of null indicates no match.
         */
        // This is visible for testing.
        public byte[][] findUTF8Submatch(byte[] b)
        {
            int[] a = doExecute(MachineInput.fromUTF8(b), 0, UNANCHORED, prog.numCap);
            if (a == null)
            {
                return(null);
            }

            byte[][] ret = new byte[1 + numSubexp][];
            for (int i = 0; i < ret.Length; i++)
            {
                if (2 * i < a.Length && a[2 * i] >= 0)
                {
                    ret[i] = Utils.subarray(b, a[2 * i], a[2 * i + 1]);
                }
            }

            return(ret);
        }
Beispiel #6
0
 /**
  * Returns an array holding the index pairs identifying the leftmost match of this regular
  * expression in {@code b} and the matches, if any, of its subexpressions, as defined by the the
  * <a href='#submatch'>Submatch</a> and <a href='#index'>Index</a> descriptions above.
  *
  * <p>
  * A return value of null indicates no match.
  */
 // This is visible for testing.
 public int[] findUTF8SubmatchIndex(byte[] b)
 {
     return(pad(doExecute(MachineInput.fromUTF8(b), 0, UNANCHORED, prog.numCap)));
 }
Beispiel #7
0
 /**
  * Returns true iff this regexp matches the UTF-8 byte array {@code b}.
  */
 // This is visible for testing.
 bool matchUTF8(byte[] b)
 {
     return(doExecute(MachineInput.fromUTF8(b), 0, UNANCHORED, 0) != null);
 }