[flexi-streams-cvs] r43 - in branches/edi: . doc
eweitz at common-lisp.net
eweitz at common-lisp.net
Wed May 21 01:49:43 UTC 2008
Author: eweitz
Date: Tue May 20 21:49:41 2008
New Revision: 43
Modified:
branches/edi/doc/index.html
branches/edi/packages.lisp
branches/edi/strings.lisp
Log:
New function octet-length
Modified: branches/edi/doc/index.html
==============================================================================
--- branches/edi/doc/index.html (original)
+++ branches/edi/doc/index.html Tue May 20 21:49:41 2008
@@ -115,6 +115,7 @@
<ol>
<li><a href="#string-to-octets"><code>string-to-octets</code></a>
<li><a href="#octets-to-string"><code>octets-to-string</code></a>
+ <li><a href="#octet-length"><code>octet-length</code></a>
</ol>
</ol>
<li><a href="#position">File positions</a>
@@ -470,8 +471,8 @@
CL-USER 5 > (make-external-format :ucs-2be)
#<FLEXI-STREAMS::EXTERNAL-FORMAT (:UTF-16 :EOL-STYLE :CRLF :LITTLE-ENDIAN NIL) 2067DBE4>
-CL-USER 6 > (make-external-format :ucs-2be :eol-style :br)
-#<FLEXI-STREAMS::EXTERNAL-FORMAT (:UTF-16 :EOL-STYLE :BR :LITTLE-ENDIAN NIL) 206B54AC>
+CL-USER 6 > (make-external-format :ucs-2be :eol-style :cr)
+#<FLEXI-STREAMS::EXTERNAL-FORMAT (:UTF-16 :EOL-STYLE :CR :LITTLE-ENDIAN NIL) 206B54AC>
</pre>
</blockquote>
@@ -982,7 +983,8 @@
<blockquote><br>
Converts the Lisp string <code><i>string</i></code> from <code><i>start</i></code> to <code><i>end</i></code> to an array of
-<a href="#octet">octets</a> corresponding to the external format designated by <a href="#external-formats">external format</a> <code><i>external-format</i></code>. The defaults for
+<a href="#octet">octets</a> corresponding to the <a href="#external-formats">external
+format</a> designated by <code><i>external-format</i></code>. The defaults for
<code><i>start</i></code> and <code><i>end</i></code>
are <code>0</code> and the length of the string. The default
for <code><i>external-format</i></code> is <code>:LATIN1</code>.
@@ -995,9 +997,25 @@
<blockquote><br> Converts the Lisp
sequence <code><i>sequence</i></code> of <a href="#octet">octets</a>
from <code><i>start</i></code> to <code><i>end</i></code> to string
-using the external format designated
-by <a href="#external-formats">external
-format</a> <code><i>external-format</i></code>. The defaults for
+using the <a href="#external-formats">external format</a> designated
+by <code><i>external-format</i></code>. The defaults for
+<code><i>start</i></code> and <code><i>end</i></code>
+are <code>0</code> and the length of the sequence. The default
+for <code><i>external-format</i></code> is <code>:LATIN1</code>.
+</blockquote>
+
+<p><br>[Function]
+<br><a class=none name="octet-length"><b>octet-length</b> <i>string <tt>&key</tt> external-format start end</i> => <i>length-or-nil</i></a>
+
+<blockquote><br>
+
+Returns the length of the substring of <code><i>string</i></code> from <code><i>start</i></code> to <code><i>end</i></code> in
+<a href="#octet">octets</a> if encoded using
+the <a href="#external-formats">external format</a> designated
+by <code><i>external-format</i></code>. Might return <code>NIL</code>
+if there's no efficient way to compute the length without iterating
+through the whole string.
+The defaults for
<code><i>start</i></code> and <code><i>end</i></code>
are <code>0</code> and the length of the sequence. The default
for <code><i>external-format</i></code> is <code>:LATIN1</code>.
@@ -1042,7 +1060,7 @@
his work on making FLEXI-STREAMS faster.
<p>
-$Header: /usr/local/cvsrep/flexi-streams/doc/index.html,v 1.106 2008/05/21 01:06:45 edi Exp $
+$Header: /usr/local/cvsrep/flexi-streams/doc/index.html,v 1.107 2008/05/21 01:43:45 edi Exp $
<p><a href="http://weitz.de/index.html">BACK TO MY HOMEPAGE</a>
</body>
Modified: branches/edi/packages.lisp
==============================================================================
--- branches/edi/packages.lisp (original)
+++ branches/edi/packages.lisp Tue May 20 21:49:41 2008
@@ -1,5 +1,5 @@
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-USER; Base: 10 -*-
-;;; $Header: /usr/local/cvsrep/flexi-streams/packages.lisp,v 1.34 2008/05/20 23:44:45 edi Exp $
+;;; $Header: /usr/local/cvsrep/flexi-streams/packages.lisp,v 1.35 2008/05/21 01:43:43 edi Exp $
;;; Copyright (c) 2005-2008, Dr. Edmund Weitz. All rights reserved.
@@ -76,6 +76,7 @@
:make-in-memory-output-stream
:make-flexi-stream
:octet
+ :octet-length
:octets-to-string
:output-stream-sequence-length
:peek-byte
Modified: branches/edi/strings.lisp
==============================================================================
--- branches/edi/strings.lisp (original)
+++ branches/edi/strings.lisp Tue May 20 21:49:41 2008
@@ -1,5 +1,5 @@
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: FLEXI-STREAMS; Base: 10 -*-
-;;; $Header: /usr/local/cvsrep/flexi-streams/strings.lisp,v 1.21 2008/05/20 09:04:23 edi Exp $
+;;; $Header: /usr/local/cvsrep/flexi-streams/strings.lisp,v 1.22 2008/05/21 01:43:43 edi Exp $
;;; Copyright (c) 2005-2008, Dr. Edmund Weitz. All rights reserved.
@@ -159,3 +159,15 @@
(incf j))
(setf (fill-pointer string) j)
string))))))))
+
+(defun octet-length (string &key (external-format :latin1) (start 0) (end (length string)))
+ "Returns the length of the substring of STRING from START to END in
+octets if encoded using the external format EXTERNAL-FORMAT. Might
+return NIL if there's no efficient way to compute the length without
+iterating through the whole string."
+ (declare #.*standard-optimize-settings*)
+ (declare (fixnum start end) (string string))
+ (setq external-format (maybe-convert-external-format external-format))
+ (let ((factor (encoding-factor external-format)))
+ (typecase factor
+ (fixnum (* factor (- end start))))))
More information about the Flexi-streams-cvs
mailing list