コード例 #1
0
ファイル: RepeatElement.cs プロジェクト: jaenudin86/Meta.Net
        /**
         * Returns the length of the maximum number of elements matching
         * the string starting at the specified position. This method
         * allows no backtracking, i.e. no skips..
         *
         * @param m              the matcher being used
         * @param buffer         the input character buffer to match
         * @param start          the starting position
         * @param count          the start count, normally zero (0)
         *
         * @return the length of the longest matching string, or
         *         -1 if no match was found
         *
         * @throws IOException if an I/O error occurred
         */
        private int MatchPossessive(Matcher m,
                                    ReaderBuffer buffer,
                                    int start,
                                    int count)
        {
            int length    = 0;
            int subLength = 1;

            // Match as many elements as possible
            while (subLength > 0 && count < max)
            {
                subLength = elem.Match(m, buffer, start + length, 0);
                if (subLength >= 0)
                {
                    count++;
                    length += subLength;
                }
            }

            // Return result
            if (min <= count && count <= max)
            {
                return(length);
            }
            else
            {
                return(-1);
            }
        }
コード例 #2
0
        /**
         * Returns the length of a matching string starting at the
         * specified position. The number of matches to skip can also be
         * specified, but numbers higher than zero (0) cause a failed
         * match for any element that doesn't attempt to combine other
         * elements.
         *
         * @param m              the matcher being used
         * @param buffer         the input character buffer to match
         * @param start          the starting position
         * @param skip           the number of matches to skip
         *
         * @return the length of the longest matching string, or
         *         -1 if no match was found
         *
         * @throws IOException if an I/O error occurred
         */
        public override int Match(Matcher m,
                                  ReaderBuffer buffer,
                                  int start,
                                  int skip)
        {
            int length1 = -1;
            int length2 = 0;
            int skip1   = 0;
            int skip2   = 0;

            while (skip >= 0)
            {
                length1 = elem1.Match(m, buffer, start, skip1);
                if (length1 < 0)
                {
                    return(-1);
                }
                length2 = elem2.Match(m, buffer, start + length1, skip2);
                if (length2 < 0)
                {
                    skip1++;
                    skip2 = 0;
                }
                else
                {
                    skip2++;
                    skip--;
                }
            }

            return(length1 + length2);
        }
コード例 #3
0
 /**
  * Attempts to find a match starting at the specified position
  * in the string.
  *
  * @param pos            the starting position of the match
  *
  * @return true if a match was found, or
  *         false otherwise
  *
  * @throws IOException if an I/O error occurred while reading
  *             an input stream
  */
 public bool MatchFrom(int pos)
 {
     Reset();
     start  = pos;
     length = element.Match(this, buffer, start, 0);
     return(length >= 0);
 }
コード例 #4
0
        /**
         * Returns the length of a matching string starting at the
         * specified position. The number of matches to skip can also
         * be specified, but numbers higher than zero (0) cause a
         * failed match for any element that doesn't attempt to
         * combine other elements.
         *
         * @param m              the matcher being used
         * @param buffer         the input character buffer to match
         * @param start          the starting position
         * @param skip           the number of matches to skip
         *
         * @return the length of the longest matching string, or
         *         -1 if no match was found
         *
         * @throws IOException if an I/O error occurred
         */
        public override int Match(Matcher m,
                                  ReaderBuffer buffer,
                                  int start,
                                  int skip)
        {
            int length  = 0;
            int length1 = -1;
            int length2 = -1;
            int skip1   = 0;
            int skip2   = 0;

            while (length >= 0 && skip1 + skip2 <= skip)
            {
                length1 = elem1.Match(m, buffer, start, skip1);
                length2 = elem2.Match(m, buffer, start, skip2);
                if (length1 >= length2)
                {
                    length = length1;
                    skip1++;
                }
                else
                {
                    length = length2;
                    skip2++;
                }
            }
            return(length);
        }