Changeset 189 for trunk


Ignore:
Timestamp:
04/22/07 08:12:22 (18 years ago)
Author:
Erik Huelsmann
Message:

Move 2 utility routines.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/protocol.lisp

    r188 r189  
    335335  (loop while (read-message connection)))
    336336
    337 (defun try-decode-line (line external-formats)
    338   (loop for external-format in external-formats
    339         for decoded = nil
    340         for error = nil
    341         do (multiple-value-setq (decoded error)
    342              (handler-case
    343               (flexi-streams:with-input-from-sequence (in line)
    344                 (let* ((ex-fmt (external-format-fixup external-format))
    345                        (flexi (flexi-streams:make-flexi-stream
    346                                in
    347                                ;; :element-type 'character
    348                                :external-format ex-fmt)))
    349                   (read-line flexi nil nil)))
    350               (flexi-streams:flexi-stream-encoding-error ()
    351                   nil)))
    352         if decoded
    353         do (return decoded)))
    354 
    355 (defun read-protocol-line (connection)
    356   "Reads a line from the input network stream, returning a
    357 character array with the input read."
    358   (multiple-value-bind
    359       (buf buf-len)
    360       ;; Note: we cannot use read-line here (or any other
    361       ;; character based functions), since they may cause
    362       ;; (at this time unwanted) character conversion
    363       (read-sequence-until (network-stream connection)
    364                            (make-array 1024
    365                                        :element-type '(unsigned-byte 8)
    366                                        :fill-pointer t)
    367                            '(10))
    368     (when (< 0 buf-len)
    369       (setf (fill-pointer buf)
    370             ;; remove all trailing CR and LF characters
    371             ;; (This allows non-conforming clients to send CRCRLF
    372             ;;  as a line separator too).
    373             (or (position-if #'(lambda (x) (member x '(10 13)))
    374                              buf :from-end t :end buf-len)
    375                 buf-len))
    376       (try-decode-line buf *default-incoming-external-formats*))))
    377337
    378338(defmethod read-irc-message ((connection connection))
  • TabularUnified trunk/utility.lisp

    r188 r189  
    106106    (setf (getf (cdr new-format) :eol-style) :crlf)
    107107    new-format))
     108
     109(defun try-decode-line (line external-formats)
     110  (loop for external-format in external-formats
     111        for decoded = nil
     112        for error = nil
     113        do (multiple-value-setq (decoded error)
     114             (handler-case
     115              (flexi-streams:with-input-from-sequence (in line)
     116                (let* ((ex-fmt (external-format-fixup external-format))
     117                       (flexi (flexi-streams:make-flexi-stream
     118                               in
     119                               ;; :element-type 'character
     120                               :external-format ex-fmt)))
     121                  (read-line flexi nil nil)))
     122              (flexi-streams:flexi-stream-encoding-error ()
     123                  nil)))
     124        if decoded
     125        do (return decoded)))
    108126
    109127(defun read-byte-no-hang (stream &optional eof-error-p eof-value)
     
    140158                 (= limit-cur limit-max))
    141159          do (return (values target (1+ targ-cur) nil)))))
     160
     161(defun read-protocol-line (connection)
     162  "Reads a line from the input network stream, returning a
     163character array with the input read."
     164  (multiple-value-bind
     165      (buf buf-len)
     166      ;; Note: we cannot use read-line here (or any other
     167      ;; character based functions), since they may cause
     168      ;; (at this time unwanted) character conversion
     169      (read-sequence-until (network-stream connection)
     170                           (make-array 1024
     171                                       :element-type '(unsigned-byte 8)
     172                                       :fill-pointer t)
     173                           '(10))
     174    (when (< 0 buf-len)
     175      (setf (fill-pointer buf)
     176            ;; remove all trailing CR and LF characters
     177            ;; (This allows non-conforming clients to send CRCRLF
     178            ;;  as a line separator too).
     179            (or (position-if #'(lambda (x) (member x '(10 13)))
     180                             buf :from-end t :end buf-len)
     181                buf-len))
     182      (try-decode-line buf *default-incoming-external-formats*))))
     183
    142184
    143185(defun substring (string start &optional end)
Note: See TracChangeset for help on using the changeset viewer.