1 /* Copyright (C) 1995, 1996, 1999, 2000, 2004, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "libguile/_scm.h"
25 #include "libguile/chars.h"
26 #include "libguile/strings.h"
27 #include "libguile/symbols.h"
29 #include "libguile/validate.h"
30 #include "libguile/strorder.h"
31 #include "libguile/srfi-13.h"
34 SCM_C_INLINE_KEYWORD
static SCM
35 srfi13_cmp (SCM s1
, SCM s2
, SCM (*cmp
) (SCM
, SCM
, SCM
, SCM
, SCM
, SCM
))
37 if (scm_is_true (cmp (s1
, s2
,
38 SCM_UNDEFINED
, SCM_UNDEFINED
,
39 SCM_UNDEFINED
, SCM_UNDEFINED
)))
45 static SCM
scm_i_string_equal_p (SCM s1
, SCM s2
, SCM rest
);
46 SCM_DEFINE (scm_i_string_equal_p
, "string=?", 0, 2, 1,
47 (SCM s1
, SCM s2
, SCM rest
),
48 "Lexicographic equality predicate; return @code{#t} if the two\n"
49 "strings are the same length and contain the same characters in\n"
50 "the same positions, otherwise return @code{#f}.\n"
52 "The procedure @code{string-ci=?} treats upper and lower case\n"
53 "letters as though they were the same character, but\n"
54 "@code{string=?} treats upper and lower case as distinct\n"
56 #define FUNC_NAME s_scm_i_string_equal_p
58 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
60 while (!scm_is_null (rest
))
62 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_eq
)))
66 rest
= scm_cdr (rest
);
68 return srfi13_cmp (s1
, s2
, scm_string_eq
);
72 SCM
scm_string_equal_p (SCM s1
, SCM s2
)
73 #define FUNC_NAME s_scm_i_string_equal_p
75 return srfi13_cmp (s1
, s2
, scm_string_eq
);
79 static SCM
scm_i_string_ci_equal_p (SCM s1
, SCM s2
, SCM rest
);
80 SCM_DEFINE (scm_i_string_ci_equal_p
, "string-ci=?", 0, 2, 1,
81 (SCM s1
, SCM s2
, SCM rest
),
82 "Case-insensitive string equality predicate; return @code{#t} if\n"
83 "the two strings are the same length and their component\n"
84 "characters match (ignoring case) at each position; otherwise\n"
86 #define FUNC_NAME s_scm_i_string_ci_equal_p
88 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
90 while (!scm_is_null (rest
))
92 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_eq
)))
96 rest
= scm_cdr (rest
);
98 return srfi13_cmp (s1
, s2
, scm_string_ci_eq
);
102 SCM
scm_string_ci_equal_p (SCM s1
, SCM s2
)
103 #define FUNC_NAME s_scm_i_string_ci_equal_p
105 return srfi13_cmp (s1
, s2
, scm_string_ci_eq
);
109 static SCM
scm_i_string_less_p (SCM s1
, SCM s2
, SCM rest
);
110 SCM_DEFINE (scm_i_string_less_p
, "string<?", 0, 2, 1,
111 (SCM s1
, SCM s2
, SCM rest
),
112 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
113 "is lexicographically less than @var{s2}.")
114 #define FUNC_NAME s_scm_i_string_less_p
116 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
118 while (!scm_is_null (rest
))
120 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_lt
)))
124 rest
= scm_cdr (rest
);
126 return srfi13_cmp (s1
, s2
, scm_string_lt
);
130 SCM
scm_string_less_p (SCM s1
, SCM s2
)
131 #define FUNC_NAME s_scm_i_string_less_p
133 return srfi13_cmp (s1
, s2
, scm_string_lt
);
137 static SCM
scm_i_string_leq_p (SCM s1
, SCM s2
, SCM rest
);
138 SCM_DEFINE (scm_i_string_leq_p
, "string<=?", 0, 2, 1,
139 (SCM s1
, SCM s2
, SCM rest
),
140 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
141 "is lexicographically less than or equal to @var{s2}.")
142 #define FUNC_NAME s_scm_i_string_leq_p
144 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
146 while (!scm_is_null (rest
))
148 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_le
)))
152 rest
= scm_cdr (rest
);
154 return srfi13_cmp (s1
, s2
, scm_string_le
);
158 SCM
scm_string_leq_p (SCM s1
, SCM s2
)
159 #define FUNC_NAME s_scm_i_string_leq_p
161 return srfi13_cmp (s1
, s2
, scm_string_le
);
165 static SCM
scm_i_string_gr_p (SCM s1
, SCM s2
, SCM rest
);
166 SCM_DEFINE (scm_i_string_gr_p
, "string>?", 0, 2, 1,
167 (SCM s1
, SCM s2
, SCM rest
),
168 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
169 "is lexicographically greater than @var{s2}.")
170 #define FUNC_NAME s_scm_i_string_gr_p
172 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
174 while (!scm_is_null (rest
))
176 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_gt
)))
180 rest
= scm_cdr (rest
);
182 return srfi13_cmp (s1
, s2
, scm_string_gt
);
186 SCM
scm_string_gr_p (SCM s1
, SCM s2
)
187 #define FUNC_NAME s_scm_i_string_gr_p
189 return srfi13_cmp (s1
, s2
, scm_string_gt
);
193 static SCM
scm_i_string_geq_p (SCM s1
, SCM s2
, SCM rest
);
194 SCM_DEFINE (scm_i_string_geq_p
, "string>=?", 0, 2, 1,
195 (SCM s1
, SCM s2
, SCM rest
),
196 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
197 "is lexicographically greater than or equal to @var{s2}.")
198 #define FUNC_NAME s_scm_i_string_geq_p
200 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
202 while (!scm_is_null (rest
))
204 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ge
)))
208 rest
= scm_cdr (rest
);
210 return srfi13_cmp (s1
, s2
, scm_string_ge
);
214 SCM
scm_string_geq_p (SCM s1
, SCM s2
)
215 #define FUNC_NAME s_scm_i_string_geq_p
217 return srfi13_cmp (s1
, s2
, scm_string_ge
);
221 static SCM
scm_i_string_ci_less_p (SCM s1
, SCM s2
, SCM rest
);
222 SCM_DEFINE (scm_i_string_ci_less_p
, "string-ci<?", 0, 2, 1,
223 (SCM s1
, SCM s2
, SCM rest
),
224 "Case insensitive lexicographic ordering predicate; return\n"
225 "@code{#t} if @var{s1} is lexicographically less than @var{s2}\n"
226 "regardless of case.")
227 #define FUNC_NAME s_scm_i_string_ci_less_p
229 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
231 while (!scm_is_null (rest
))
233 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_lt
)))
237 rest
= scm_cdr (rest
);
239 return srfi13_cmp (s1
, s2
, scm_string_ci_lt
);
243 SCM
scm_string_ci_less_p (SCM s1
, SCM s2
)
244 #define FUNC_NAME s_scm_i_string_ci_less_p
246 return srfi13_cmp (s1
, s2
, scm_string_ci_lt
);
250 static SCM
scm_i_string_ci_leq_p (SCM s1
, SCM s2
, SCM rest
);
251 SCM_DEFINE (scm_i_string_ci_leq_p
, "string-ci<=?", 0, 2, 1,
252 (SCM s1
, SCM s2
, SCM rest
),
253 "Case insensitive lexicographic ordering predicate; return\n"
254 "@code{#t} if @var{s1} is lexicographically less than or equal\n"
255 "to @var{s2} regardless of case.")
256 #define FUNC_NAME s_scm_i_string_ci_leq_p
258 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
260 while (!scm_is_null (rest
))
262 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_le
)))
266 rest
= scm_cdr (rest
);
268 return srfi13_cmp (s1
, s2
, scm_string_ci_le
);
272 SCM
scm_string_ci_leq_p (SCM s1
, SCM s2
)
273 #define FUNC_NAME s_scm_i_string_ci_leq_p
275 return srfi13_cmp (s1
, s2
, scm_string_ci_le
);
279 static SCM
scm_i_string_ci_gr_p (SCM s1
, SCM s2
, SCM rest
);
280 SCM_DEFINE (scm_i_string_ci_gr_p
, "string-ci>?", 0, 2, 1,
281 (SCM s1
, SCM s2
, SCM rest
),
282 "Case insensitive lexicographic ordering predicate; return\n"
283 "@code{#t} if @var{s1} is lexicographically greater than\n"
284 "@var{s2} regardless of case.")
285 #define FUNC_NAME s_scm_i_string_ci_gr_p
287 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
289 while (!scm_is_null (rest
))
291 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_gt
)))
295 rest
= scm_cdr (rest
);
297 return srfi13_cmp (s1
, s2
, scm_string_ci_gt
);
301 SCM
scm_string_ci_gr_p (SCM s1
, SCM s2
)
302 #define FUNC_NAME s_scm_i_string_ci_gr_p
304 return srfi13_cmp (s1
, s2
, scm_string_ci_gt
);
308 static SCM
scm_i_string_ci_geq_p (SCM s1
, SCM s2
, SCM rest
);
309 SCM_DEFINE (scm_i_string_ci_geq_p
, "string-ci>=?", 0, 2, 1,
310 (SCM s1
, SCM s2
, SCM rest
),
311 "Case insensitive lexicographic ordering predicate; return\n"
312 "@code{#t} if @var{s1} is lexicographically greater than or\n"
313 "equal to @var{s2} regardless of case.")
314 #define FUNC_NAME s_scm_i_string_ci_geq_p
316 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
318 while (!scm_is_null (rest
))
320 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_ge
)))
324 rest
= scm_cdr (rest
);
326 return srfi13_cmp (s1
, s2
, scm_string_ci_ge
);
330 SCM
scm_string_ci_geq_p (SCM s1
, SCM s2
)
331 #define FUNC_NAME s_scm_i_string_ci_geq_p
333 return srfi13_cmp (s1
, s2
, scm_string_ci_ge
);
342 #include "libguile/strorder.x"