home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume11
/
test.el
/
part01
/
tst-inequal.el
< prev
next >
Wrap
Lisp/Scheme
|
1987-09-08
|
4KB
|
137 lines
;;; inequal.el -- A number of inequality functions.
;;; See also equal.el
;;; Lorri Menard, Wang Institute of Graduate Studies
;;; Don Zaremba, Wang Institute of Graduate Studies
;;; Copyright 1987 Wang Institute of Graduate Studies
;;;
(provide 'tst-inequal)
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun string-equal-less-white (str1 str2)
" Returns t if the two strings are equal after ignoring whitespace."
(let ()
(string-equal-less-regexp "\\s " str1 str2)
) ; let
) ; line-of-buffer
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun string-equal-less-regexp (regexp str1 str2)
" Returns t if the two strings are equal after ignoring all substrings
that match regexp ."
(let (start1 end1 start2 end2 token1 token2 success more1 more2)
(setq success t more1 t more2 t)
(setq start1 (first-not-regexp regexp str1 0)); move to 1st non-white
(setq start2 (first-not-regexp regexp str2 0)); move to 1st non-white
(while (and more1 more2)
(progn
(setq end1 (string-match regexp str1 start1))
(setq end2 (string-match regexp str2 start2))
(if end1
(progn ; end1 not nil
(setq token1 (substring str1 start1 end1))
(setq start1 (first-not-regexp regexp str1 end1))
(if (not start1) ; check for trailing delimiter only
(setq more1 nil))
); progn
;else
(progn
(setq token1 (substring str1 start1 nil));
(setq more1 nil)
); progn
); if
(if end2
(progn ; end2 not nil
(setq token2 (substring str2 start2 end2))
(setq start2 (first-not-regexp regexp str2 end2))
(if (not start2) ; check for trailing delimiter only
(setq more2 nil))
); progn
;else
(progn
(setq token2 (substring str2 start2 nil));
(setq more2 nil)
); progn
); if
; (send-string-to-terminal "[")
; (send-string-to-terminal token1)
; (send-string-to-terminal "][")
; (send-string-to-terminal token2)
; (send-string-to-terminal "]")
(setq success (string-equal token1 token2))
(if (not success)
(setq more1 nil)) ; if failed then stop the loop
); progn
) ; while
(and (not more1) (not more2) success)
) ; let
) ; string-equal-less-white
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun first-not-regexp (regexp str sindex)
" Returns the index of the first char in string that does not match
regular expression. Returns nil if nothing doesn't match."
(let (fm more string-is-nil)
(setq more t slen)
(setq slen (length str))
(if (equal 0 slen) ; test for a zero length string
nil
; else
(progn
(setq string-is-nil nil)
(setq fm (string-match regexp str sindex)) ; start of match
(if (or (not fm) (< sindex fm)) (setq more nil)) ; found non-regexp
; (debug nil "Before while" fm sindex)
(while more
(progn
(setq sindex (match-end 0))
(if (>= sindex slen)
(progn
(setq string-is-nil t)
(setq more nil)
)
;else
(progn
(setq fm (string-match regexp str sindex))
(if (or (not fm) (< sindex fm)) (setq more nil))
; (debug nil "In while " fm sindex)
); progn
); if
); progn
); while
(if string-is-nil nil sindex)
); progn
); if
) ; let
) ; first-not-regexp
; example hook usage
;
; (setq tst-equ-line-hook 'first-5)
; (setq tst-equ-mark-hook 'great-mark)
;
; example line hook - only compares first 5 chars on a line
;(defun first-5 ()
; (string-equal (substring tst-equ-line1 0 5) (substring tst-equ-line2 0 5))
;)
;example mark hook - only concerned with relative order of marks
;(defun great-mark ()
; (> tst-equ-mark1 tst-equ-mark2)
; )