Changeset 6633
- Timestamp:
- May 31, 2007, 5:06:19 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-streams.lisp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-streams.lisp
r6539 r6633 58 58 :io 59 59 :output)) 60 61 ;;; Try to return a string containing characters that're near the 62 ;;; stream's current position, if that makes sense. Return NIL 63 ;;; if it doesn't make sense. 64 (defmethod stream-surrounding-characters ((s stream)) 65 nil) 60 66 61 67 … … 473 479 474 480 475 476 481 (defun %ioblock-surrounding-characters (ioblock) 482 (let* ((inbuf (ioblock-inbuf ioblock))) 483 (when inbuf 484 (let* ((encoding (or (ioblock-encoding ioblock) 485 (get-character-encoding nil))) 486 (size (ash (character-encoding-code-unit-size encoding) -3)) 487 (buffer (io-buffer-buffer inbuf)) 488 (idx (io-buffer-idx inbuf)) 489 (count (io-buffer-count inbuf))) 490 (unless (= count 0) 491 (let* ((start (max (- idx (* 5 size)) 0)) 492 (end (min (+ idx (* 5 size)) count)) 493 (string (make-string (funcall (character-encoding-length-of-vector-encoding-function encoding) buffer start end)))) 494 (funcall (character-encoding-vector-decode-function encoding) 495 buffer 496 start 497 (- end start) 498 string) 499 (if (position #\Replacement_Character string) 500 (string-trim (string #\Replacement_Character) string) 501 string))))))) 502 503 477 504 478 505 … … 3738 3765 (synonym-method interactive-stream-p) 3739 3766 (synonym-method stream-direction) 3740 (synonym-method stream-device direction)) 3767 (synonym-method stream-device direction) 3768 (synonym-method stream-surrounding-characters)) 3741 3769 3742 3770 … … 3797 3825 (two-way-input-method stream-read-list l c) 3798 3826 (two-way-input-method stream-read-vector v start end) 3827 (two-way-input-method stream-surrounding-characters) 3799 3828 (two-way-output-method stream-write-char c) 3800 3829 (two-way-output-method stream-write-byte b) … … 4422 4451 4423 4452 4453 (defmethod stream-surrounding-characters ((s string-input-stream)) 4454 (let* ((ioblock (basic-stream-ioblock s)) 4455 (start (string-input-stream-ioblock-start ioblock)) 4456 (idx (string-input-stream-ioblock-index ioblock)) 4457 (end (string-input-stream-ioblock-end ioblock)) 4458 (string (string-stream-ioblock-string ioblock))) 4459 (subseq string (max (- idx 5) start) (min (+ idx 5) end)))) 4460 4461 4424 4462 (defmethod stream-position ((s string-input-stream) &optional newpos) 4425 4463 (let* ((ioblock (basic-stream-ioblock s)) … … 4705 4743 (when (open-stream-p stream) 4706 4744 (stream-force-output stream)))) 4745 4746 (defmethod stream-surrounding-characters ((stream buffered-character-input-stream-mixin)) 4747 (let* ((ioblock (stream-ioblock stream nil))) 4748 (and ioblock (%ioblock-surrounding-characters ioblock)))) 4749 4750 (defmethod stream-surrounding-characters ((stream basic-character-input-stream)) 4751 (let* ((ioblock (stream-ioblock stream nil))) 4752 (and ioblock (%ioblock-surrounding-characters ioblock)))) 4753 4707 4754 4708 4755 #|
Note:
See TracChangeset
for help on using the changeset viewer.
