;;; -*- Mode: Lisp; Package: CLIMACS-REGEX -*-

;;;  (c) copyright 2005 by
;;;           Nicolas Sceaux (nicolas.sceaux@free.fr)

;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 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
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library 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.

;;; 

(in-package :climacs-regex)

;;;
;;; Specializes some CLIMACS-PPCRE methods for scanning buffers.
;;;

(defmethod climacs-ppcre:sequence-element ((buffer buffer) offset)
  (buffer-object buffer offset))

(defmethod climacs-ppcre:sequence-search ((buffer buffer) pattern 
                                          &key (start 0)
                                               (end (size buffer))
                                               (test #'eql))
  (let ((offset (buffer-search-forward buffer start pattern :test test)))
    (and offset (< offset end) offset)))

(defmethod climacs-ppcre:sequence-length ((buffer buffer))
  (size buffer))

(defmethod climacs-ppcre:sequence-subseq ((buffer buffer) start 
                                           &optional (end (size buffer))
                                           sharedp)
  (declare (ignore sharedp))
  (buffer-sequence buffer start end))

(defmethod climacs-ppcre:scan ((regex-string string) (target-buffer buffer)
                               &key (start 0) (end (size target-buffer)))
  (funcall (create-scanner regex-string) target-buffer start end))

(defmethod climacs-ppcre:scan ((scanner function) (target-buffer buffer)
                               &key (start 0) (end (size target-buffer)))
  (funcall scanner target-buffer start end))

(defmethod climacs-ppcre:scan ((parse-tree t) (target-buffer buffer)
                 &key (start 0) (end (size target-buffer)))
  (funcall (create-scanner parse-tree) target-buffer start end))

;;;
;;; CLIMACS-REGEX API
;;;

