// -*- c++ -*-

/*
 * jakelib2-regex - Regular Expressions for Jakelib2
 * Copyright (C) 2003 Florian Wolff  (florian@donuz.de)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: Matcher.h,v 1.1 2003/09/24 17:14:54 florian Exp $
 */

#ifndef INCLUDE_JAKELIB2_UTIL_REGEX_MATCHER_H
# define INCLUDE_JAKELIB2_UTIL_REGEX_MATCHER_H

namespace jakelib {
  namespace util {
    namespace regex {

      class Pattern;

      /**
       *
       * 
       * <b>Copyright notice:</b>
       * <pre>Regular expression support is provided by the PCRE library package,
       * which is open source software, written by Philip Hazel, and copyright
       * by the University of Cambridge, England.</pre>
       *
       * @class Matcher
       * @version $Id: Matcher.h,v 1.1 2003/09/24 17:14:54 florian Exp $
       * @author Florian 'Overflo' Wolff (florian@donuz.de)
       */
      class Matcher : public jakelib::lang::Object
      {
        friend class Pattern;

      public:
        ~Matcher();

      protected:
        Matcher(Pattern* pattern, jakelib::lang::String* input);

      public:
        jboolean matches();

        Pattern* pattern();

        /**
         * Returns the number of capturing parenthesis in this expression.
         */
        jint groupCount();

        jboolean find(jint startIndex = 0);

        jakelib::lang::String* group(jint idx = 0);

        jint start(jint idx = 0);

        jint end(jint idx = 0);

        void reset();

        void reset(jakelib::lang::String* input);

        void appendReplacement(jakelib::lang::StringBuffer* buf, jakelib::lang::String* replacement);

        void appendTail(jakelib::lang::StringBuffer* buf);

        jakelib::lang::String* replaceAll(jakelib::lang::String* replacement);

      protected:
        Pattern* _pattern;
        jakelib::lang::String* input;
        int resultsSize;
        int* results;
        jboolean executed;
        int substringCount;
        int appendPosition;
        int previousStartIndex;

        JAKELIB_DECLARE_CLASS(Matcher);
      };
    }
  }
}

#endif

