(scm_string_for_each): Reverse order of first 2 args.
[bpt/guile.git] / srfi / srfi-13.scm
CommitLineData
ca003b26
MG
1;;;; srfi-13.scm --- SRFI-13 procedures for Guile
2;;;;
3;;;; Copyright (C) 2001 Free Software Foundation, Inc.
4;;;;
5;;;; This program is free software; you can redistribute it and/or
6;;;; modify it under the terms of the GNU General Public License as
7;;;; published by the Free Software Foundation; either version 2, or
8;;;; (at your option) any later version.
9;;;;
10;;;; This program is distributed in the hope that it will be useful,
11;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13;;;; General Public License for more details.
14;;;;
15;;;; You should have received a copy of the GNU General Public License
16;;;; along with this software; see the file COPYING. If not, write to
17;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18;;;; Boston, MA 02111-1307 USA
f480396b
MV
19;;;;
20;;;; As a special exception, the Free Software Foundation gives permission
21;;;; for additional uses of the text contained in its release of GUILE.
22;;;;
23;;;; The exception is that, if you link the GUILE library with other files
24;;;; to produce an executable, this does not by itself cause the
25;;;; resulting executable to be covered by the GNU General Public License.
26;;;; Your use of that executable is in no way restricted on account of
27;;;; linking the GUILE library code into it.
28;;;;
29;;;; This exception does not however invalidate any other reasons why
30;;;; the executable file might be covered by the GNU General Public License.
31;;;;
32;;;; This exception applies only to the code released by the
33;;;; Free Software Foundation under the name GUILE. If you copy
34;;;; code from other Free Software Foundation releases into a copy of
35;;;; GUILE, as the General Public License permits, the exception does
36;;;; not apply to the code that you add in this way. To avoid misleading
37;;;; anyone as to the status of such modified files, you must delete
38;;;; this exception notice from them.
39;;;;
40;;;; If you write modifications of your own for GUILE, it is your choice
41;;;; whether to permit this exception to apply to your modifications.
42;;;; If you do not wish that, delete this exception notice.
ca003b26
MG
43
44(define-module (srfi srfi-13))
45
3d968b4e
MV
46(begin-deprecated
47 ;; Prevent `export' from re-exporting core bindings. This behaviour
99f59e93 48 ;; of `export' is deprecated and will disappear in one of the next
3d968b4e
MV
49 ;; releases.
50 (define string->list #f)
51 (define string-copy #f)
52 (define string-fill! #f)
53 (define string-index #f)
54 (define string-upcase #f)
55 (define string-upcase! #f)
56 (define string-downcase #f)
57 (define string-downcase! #f))
58
ca003b26
MG
59(export
60;;; Predicates
61 ;; string? string-null? <= in the core
62 string-any string-every
63
64;;; Constructors
65 ;; make-string string <= in the core
66 string-tabulate
67
68;;; List/string conversion
69 string->list
70 ;; list->string <= in the core
71 reverse-list->string
72 string-join
73
74;;; Selection
75 ;; string-length string-ref <= in the core
76 string-copy
77 substring/shared
78 string-copy!
79 string-take string-take-right
80 string-drop string-drop-right
81 string-pad string-pad-right
82 string-trim string-trim-right
83 string-trim-both
84
85;;; Modification
86 ;; string-set! <= in the core
87 string-fill!
88
89;;; Comparison
90 string-compare string-compare-ci
91 string= string<>
92 string< string>
93 string<= string>=
94 string-ci= string-ci<>
95 string-ci< string-ci>
96 string-ci<= string-ci>=
fafb71de 97 string-hash string-hash-ci
ca003b26
MG
98
99;;; Prefixes/Suffixes
100 string-prefix-length
101 string-prefix-length-ci
102 string-suffix-length
103 string-suffix-length-ci
104 string-prefix?
105 string-prefix-ci?
106 string-suffix?
107 string-suffix-ci?
108
109;;; Searching
110 string-index string-index-right
111 string-skip string-skip-right
112 string-count
113 string-contains string-contains-ci
114
115;;; Alphabetic case mapping
116
117 string-upcase string-upcase!
118 string-downcase string-downcase!
119 string-titlecase string-titlecase!
120
121;;; Reverse/Append
122 string-reverse string-reverse!
123 ;; string-append <= in the core
124 string-append/shared
125 string-concatenate
8dddb4bc 126 string-concatenate-reverse
ca003b26 127 string-concatenate/shared
8dddb4bc 128 string-concatenate-reverse/shared
ca003b26
MG
129
130;;; Fold/Unfold/Map
131 string-map string-map!
132 string-fold
133 string-fold-right
134 string-unfold
135 string-unfold-right
136 string-for-each
137
138;;; Replicate/Rotate
139 xsubstring string-xcopy!
140
141;;; Miscellaneous
142 string-replace
143 string-tokenize
144
145;;; Filtering/Deleting
146 string-filter
147 string-delete
148 )
149
1b2f40b9
MG
150(cond-expand-provide (current-module) '(srfi-13))
151
dd22a80a 152(load-extension "libguile-srfi-srfi-13-14" "scm_init_srfi_13")
ca003b26
MG
153
154(define string-hash
155 (lambda (s . rest)
156 (let ((bound (if (pair? rest)
157 (or (car rest)
158 871)
159 871))
160 (start (if (and (pair? rest) (pair? (cdr rest)))
161 (cadr rest)
162 0))
163 (end (if (and (pair? rest) (pair? (cdr rest)) (pair? (cddr rest)))
164 (caddr rest)
165 (string-length s))))
166 (hash (substring/shared s start end) bound))))
167
168(define string-hash-ci
169 (lambda (s . rest)
170 (let ((bound (if (pair? rest)
171 (or (car rest)
172 871)
173 871))
174 (start (if (and (pair? rest) (pair? (cdr rest)))
175 (cadr rest)
176 0))
177 (end (if (and (pair? rest) (pair? (cdr rest)) (pair? (cddr rest)))
178 (caddr rest)
179 (string-length s))))
180 (hash (string-upcase (substring/shared s start end)) bound))))
1b2f40b9 181