/[flexi-streams]/branches/edi/strings.lisp
ViewVC logotype

Contents of /branches/edi/strings.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61 - (show annotations)
Sun May 25 23:43:22 2008 UTC (5 years, 10 months ago) by eweitz
File size: 4126 byte(s)
Ready for release
1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: FLEXI-STREAMS; Base: 10 -*-
2 ;;; $Header: /usr/local/cvsrep/flexi-streams/strings.lisp,v 1.32 2008/05/25 23:09:13 edi Exp $
3
4 ;;; Copyright (c) 2005-2008, Dr. Edmund Weitz. All rights reserved.
5
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
8 ;;; are met:
9
10 ;;; * Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
12
13 ;;; * Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials
16 ;;; provided with the distribution.
17
18 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
19 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 (in-package :flexi-streams)
31
32 (defun string-to-octets (string &key
33 (external-format :latin1)
34 (start 0) (end (length string)))
35 "Converts the Lisp string STRING from START to END to an array of
36 octets corresponding to the external format designated by
37 EXTERNAL-FORMAT.
38
39 In spite of the name, STRING can be any sequence of characters, but
40 the function is optimized for strings."
41 (declare #.*standard-optimize-settings*)
42 (declare (string string))
43 (setq external-format (maybe-convert-external-format external-format))
44 ;; the external format knows how to do it...
45 (string-to-octets* external-format string start end))
46
47 (defun octets-to-string (sequence &key
48 (external-format :latin1)
49 (start 0) (end (length sequence)))
50 "Converts the Lisp sequence SEQUENCE of octets from START to END to
51 a string using the external format designated by EXTERNAL-FORMAT.
52
53 This function is optimized for the case of SEQUENCE being a vector.
54 Don't use lists if you're in a hurry."
55 (declare #.*standard-optimize-settings*)
56 (declare (fixnum start end))
57 (setq external-format (maybe-convert-external-format external-format))
58 ;; the external format knows how to do it...
59 (octets-to-string* external-format sequence start end))
60
61 (defun octet-length (string &key (external-format :latin1) (start 0) (end (length string)))
62 "Returns the length of the substring of STRING from START to END in
63 octets if encoded using the external format EXTERNAL-FORMAT.
64
65 In spite of the name, STRING can be any sequence of characters, but
66 the function is optimized for strings."
67 (declare #.*standard-optimize-settings*)
68 (declare (fixnum start end) (string string))
69 (setq external-format (maybe-convert-external-format external-format))
70 (compute-number-of-octets external-format string start end))
71
72 (defun char-length (sequence &key (external-format :latin1) (start 0) (end (length sequence)))
73 "Kind of the inverse of OCTET-LENGTH. Returns the length of the
74 subsequence \(of octets) of SEQUENCE from START to END in characters
75 if decoded using the external format EXTERNAL-FORMAT. Note that this
76 function doesn't check for the validity of the data in SEQUENCE.
77
78 This function is optimized for the case of SEQUENCE being a vector.
79 Don't use lists if you're in a hurry."
80 (declare #.*standard-optimize-settings*)
81 (declare (fixnum start end))
82 (setq external-format (maybe-convert-external-format external-format))
83 (compute-number-of-chars external-format sequence start end))

  ViewVC Help
Powered by ViewVC 1.1.5