Author: ehuelsmann Date: Fri May 5 17:46:25 2006 New Revision: 149
Modified: trunk/event.lisp trunk/parse-message.lisp trunk/protocol.lisp trunk/utility.lisp Log: More efficient string manipulation. Also remove dependency on #\Return character at the end of each line (making cl-irc windows EOL translating lisp implementation compatible).
Modified: trunk/event.lisp ============================================================================== --- trunk/event.lisp (original) +++ trunk/event.lisp Fri May 5 17:46:25 2006 @@ -82,8 +82,8 @@ (mapcar #'(lambda (x) (let ((eq-pos (position #= x))) (if eq-pos - (list (subseq x 0 eq-pos) - (subseq x (1+ eq-pos))) + (list (substring x 0 eq-pos) + (substring x (1+ eq-pos))) (list x)))) capabilities) (server-capabilities connection)) :initial-value '()))
Modified: trunk/parse-message.lisp ============================================================================== --- trunk/parse-message.lisp (original) +++ trunk/parse-message.lisp Fri May 5 17:46:25 2006 @@ -58,7 +58,7 @@ "Assuming `string' is a valid IRC message this function returns the trailing-argument part of the message. Returns nil if the trailing-argument part is not present." - (cut-between string #: '(#\Return) :start start)) + (cut-between string #: '(#\Return) :start start :cut-to-end t))
(defun combine-arguments-and-trailing (string &key (start 0)) (multiple-value-bind
Modified: trunk/protocol.lisp ============================================================================== --- trunk/protocol.lisp (original) +++ trunk/protocol.lisp Fri May 5 17:46:25 2006 @@ -687,7 +687,7 @@ (second (assoc "PREFIX" (server-capabilities connection) :test #'string=)))) - (subseq nickname 1) + (substring nickname 1) nickname))
(defun normalize-nickname (connection string)
Modified: trunk/utility.lisp ============================================================================== --- trunk/utility.lisp (original) +++ trunk/utility.lisp Fri May 5 17:46:25 2006 @@ -115,10 +115,11 @@ :displaced-index-offset start)))
-(defun cut-between (string start-char end-chars &key (start 0) (cut-extra t)) +(defun cut-between (string start-char end-chars + &key (start 0) (cut-extra t) (cut-to-end nil)) "If `start-char' is not nil, cut string between `start-char' and any of the `end-chars', from `start'. If `start-char' is nil, cut from -`start' until any of the `end-chars'. +`start' until any of the `end-chars' (or sting-end when `cut-to-end' is true).
If `cut-extra' is t, we will cut from start + 1 instead of just `start'. @@ -126,9 +127,10 @@ When there is no string matching the input parameters `start' and nil will be returned, otherwise `end-position' and the string are returned." - (let ((end-position (position-if #'(lambda (char) - (member char end-chars)) - string :start (1+ start))) + (let ((end-position (or (position-if #'(lambda (char) + (member char end-chars)) + string :start (1+ start)) + (when cut-to-end (length string)))) (cut-from (if cut-extra (1+ start) start))) @@ -142,8 +144,11 @@ (substring string cut-from end-position)) (values start nil)))))
-(defun cut-before (string substring end-chars &key (start 0) (cut-extra t)) - "Cut `string' before `substring' or any of the `end-chars', from `start'. +(defun cut-before (string substring end-chars + &key (start 0) (cut-extra t) (cut-to-end nil)) + "Cut `string' before `substring' or any of the `end-chars', from `start', +if none of substring or end-chars are found, until the end of the string +when `cut-to-end' is true.
If `cut-extra' is t, we will cut from start + 1 instead of just `start'. @@ -157,9 +162,10 @@ (substring string (if (and cut-extra (< start end-position)) (1+ start) start) end-position)) - (let ((end-position (position-if #'(lambda (x) - (member x end-chars)) - string :start (1+ start))) + (let ((end-position (or (position-if #'(lambda (x) + (member x end-chars)) + string :start (1+ start)) + (when cut-to-end (length string)))) (cut-from (if cut-extra (1+ start) start))) (if end-position (values end-position @@ -240,8 +246,8 @@ (let ((closing-paren-pos (position #) prefix))) (when (and (eq (elt prefix 0) #( ) closing-paren-pos) - (let ((prefixes (subseq prefix (1+ closing-paren-pos))) - (modes (subseq prefix 1 closing-paren-pos))) + (let ((prefixes (substring prefix (1+ closing-paren-pos))) + (modes (substring prefix 1 closing-paren-pos))) (when (= (length prefixes) (length modes)) (values prefixes modes)))))) @@ -355,7 +361,7 @@ (do ((changes (pop arguments) (pop arguments))) ((null changes) (values ops nil)) (let* ((this-op (char changes 0)) - (modes (subseq changes 1)) + (modes (substring changes 1)) (param-req (if (char= this-op #+) #'mode-desc-param-on-set-p #'mode-desc-param-on-unset-p)))