1 /* Copyright (C) 1995, 1996, 1999, 2000, 2004, 2006, 2008, 2009 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 SCM_DEFINE (scm_i_string_equal_p
, "string=?", 0, 2, 1,
46 (SCM s1
, SCM s2
, SCM rest
),
47 "Lexicographic equality predicate; return @code{#t} if the two\n"
48 "strings are the same length and contain the same characters in\n"
49 "the same positions, otherwise return @code{#f}.\n"
51 "The procedure @code{string-ci=?} treats upper and lower case\n"
52 "letters as though they were the same character, but\n"
53 "@code{string=?} treats upper and lower case as distinct\n"
55 #define FUNC_NAME s_scm_i_string_equal_p
57 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
59 while (!scm_is_null (rest
))
61 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_eq
)))
65 rest
= scm_cdr (rest
);
67 return srfi13_cmp (s1
, s2
, scm_string_eq
);
71 SCM
scm_string_equal_p (SCM s1
, SCM s2
)
72 #define FUNC_NAME s_scm_i_string_equal_p
74 return srfi13_cmp (s1
, s2
, scm_string_eq
);
78 SCM_DEFINE (scm_i_string_ci_equal_p
, "string-ci=?", 0, 2, 1,
79 (SCM s1
, SCM s2
, SCM rest
),
80 "Case-insensitive string equality predicate; return @code{#t} if\n"
81 "the two strings are the same length and their component\n"
82 "characters match (ignoring case) at each position; otherwise\n"
84 #define FUNC_NAME s_scm_i_string_ci_equal_p
86 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
88 while (!scm_is_null (rest
))
90 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_eq
)))
94 rest
= scm_cdr (rest
);
96 return srfi13_cmp (s1
, s2
, scm_string_ci_eq
);
100 SCM
scm_string_ci_equal_p (SCM s1
, SCM s2
)
101 #define FUNC_NAME s_scm_i_string_ci_equal_p
103 return srfi13_cmp (s1
, s2
, scm_string_ci_eq
);
107 SCM_DEFINE (scm_i_string_less_p
, "string<?", 0, 2, 1,
108 (SCM s1
, SCM s2
, SCM rest
),
109 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
110 "is lexicographically less than @var{s2}.")
111 #define FUNC_NAME s_scm_i_string_less_p
113 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
115 while (!scm_is_null (rest
))
117 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_lt
)))
121 rest
= scm_cdr (rest
);
123 return srfi13_cmp (s1
, s2
, scm_string_lt
);
127 SCM
scm_string_less_p (SCM s1
, SCM s2
)
128 #define FUNC_NAME s_scm_i_string_less_p
130 return srfi13_cmp (s1
, s2
, scm_string_lt
);
134 SCM_DEFINE (scm_i_string_leq_p
, "string<=?", 0, 2, 1,
135 (SCM s1
, SCM s2
, SCM rest
),
136 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
137 "is lexicographically less than or equal to @var{s2}.")
138 #define FUNC_NAME s_scm_i_string_leq_p
140 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
142 while (!scm_is_null (rest
))
144 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_le
)))
148 rest
= scm_cdr (rest
);
150 return srfi13_cmp (s1
, s2
, scm_string_le
);
154 SCM
scm_string_leq_p (SCM s1
, SCM s2
)
155 #define FUNC_NAME s_scm_i_string_leq_p
157 return srfi13_cmp (s1
, s2
, scm_string_le
);
161 SCM_DEFINE (scm_i_string_gr_p
, "string>?", 0, 2, 1,
162 (SCM s1
, SCM s2
, SCM rest
),
163 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
164 "is lexicographically greater than @var{s2}.")
165 #define FUNC_NAME s_scm_i_string_gr_p
167 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
169 while (!scm_is_null (rest
))
171 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_gt
)))
175 rest
= scm_cdr (rest
);
177 return srfi13_cmp (s1
, s2
, scm_string_gt
);
181 SCM
scm_string_gr_p (SCM s1
, SCM s2
)
182 #define FUNC_NAME s_scm_i_string_gr_p
184 return srfi13_cmp (s1
, s2
, scm_string_gt
);
188 SCM_DEFINE (scm_i_string_geq_p
, "string>=?", 0, 2, 1,
189 (SCM s1
, SCM s2
, SCM rest
),
190 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
191 "is lexicographically greater than or equal to @var{s2}.")
192 #define FUNC_NAME s_scm_i_string_geq_p
194 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
196 while (!scm_is_null (rest
))
198 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ge
)))
202 rest
= scm_cdr (rest
);
204 return srfi13_cmp (s1
, s2
, scm_string_ge
);
208 SCM
scm_string_geq_p (SCM s1
, SCM s2
)
209 #define FUNC_NAME s_scm_i_string_geq_p
211 return srfi13_cmp (s1
, s2
, scm_string_ge
);
215 SCM_DEFINE (scm_i_string_ci_less_p
, "string-ci<?", 0, 2, 1,
216 (SCM s1
, SCM s2
, SCM rest
),
217 "Case insensitive lexicographic ordering predicate; return\n"
218 "@code{#t} if @var{s1} is lexicographically less than @var{s2}\n"
219 "regardless of case.")
220 #define FUNC_NAME s_scm_i_string_ci_less_p
222 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
224 while (!scm_is_null (rest
))
226 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_lt
)))
230 rest
= scm_cdr (rest
);
232 return srfi13_cmp (s1
, s2
, scm_string_ci_lt
);
236 SCM
scm_string_ci_less_p (SCM s1
, SCM s2
)
237 #define FUNC_NAME s_scm_i_string_ci_less_p
239 return srfi13_cmp (s1
, s2
, scm_string_ci_lt
);
243 SCM_DEFINE (scm_i_string_ci_leq_p
, "string-ci<=?", 0, 2, 1,
244 (SCM s1
, SCM s2
, SCM rest
),
245 "Case insensitive lexicographic ordering predicate; return\n"
246 "@code{#t} if @var{s1} is lexicographically less than or equal\n"
247 "to @var{s2} regardless of case.")
248 #define FUNC_NAME s_scm_i_string_ci_leq_p
250 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
252 while (!scm_is_null (rest
))
254 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_le
)))
258 rest
= scm_cdr (rest
);
260 return srfi13_cmp (s1
, s2
, scm_string_ci_le
);
264 SCM
scm_string_ci_leq_p (SCM s1
, SCM s2
)
265 #define FUNC_NAME s_scm_i_string_ci_leq_p
267 return srfi13_cmp (s1
, s2
, scm_string_ci_le
);
271 SCM_DEFINE (scm_i_string_ci_gr_p
, "string-ci>?", 0, 2, 1,
272 (SCM s1
, SCM s2
, SCM rest
),
273 "Case insensitive lexicographic ordering predicate; return\n"
274 "@code{#t} if @var{s1} is lexicographically greater than\n"
275 "@var{s2} regardless of case.")
276 #define FUNC_NAME s_scm_i_string_ci_gr_p
278 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
280 while (!scm_is_null (rest
))
282 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_gt
)))
286 rest
= scm_cdr (rest
);
288 return srfi13_cmp (s1
, s2
, scm_string_ci_gt
);
292 SCM
scm_string_ci_gr_p (SCM s1
, SCM s2
)
293 #define FUNC_NAME s_scm_i_string_ci_gr_p
295 return srfi13_cmp (s1
, s2
, scm_string_ci_gt
);
299 SCM_DEFINE (scm_i_string_ci_geq_p
, "string-ci>=?", 0, 2, 1,
300 (SCM s1
, SCM s2
, SCM rest
),
301 "Case insensitive lexicographic ordering predicate; return\n"
302 "@code{#t} if @var{s1} is lexicographically greater than or\n"
303 "equal to @var{s2} regardless of case.")
304 #define FUNC_NAME s_scm_i_string_ci_geq_p
306 if (SCM_UNBNDP (s1
) || SCM_UNBNDP (s2
))
308 while (!scm_is_null (rest
))
310 if (scm_is_false (srfi13_cmp (s1
, s2
, scm_string_ci_ge
)))
314 rest
= scm_cdr (rest
);
316 return srfi13_cmp (s1
, s2
, scm_string_ci_ge
);
320 SCM
scm_string_ci_geq_p (SCM s1
, SCM s2
)
321 #define FUNC_NAME s_scm_i_string_ci_geq_p
323 return srfi13_cmp (s1
, s2
, scm_string_ci_ge
);
332 #include "libguile/strorder.x"