The FSF has a new address.
[bpt/guile.git] / libguile / strorder.c
1 /* Copyright (C) 1995, 1996, 1999, 2000, 2004 Free Software Foundation, Inc.
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but 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.
12 *
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 02110-1301 USA
16 */
17
18 \f
19
20 #include "libguile/_scm.h"
21 #include "libguile/chars.h"
22 #include "libguile/strings.h"
23 #include "libguile/symbols.h"
24
25 #include "libguile/validate.h"
26 #include "libguile/strorder.h"
27 #include "libguile/srfi-13.h"
28 \f
29
30 SCM_C_INLINE_KEYWORD static SCM
31 srfi13_cmp (SCM s1, SCM s2, SCM (*cmp) (SCM, SCM, SCM, SCM, SCM, SCM))
32 {
33 if (scm_is_true (cmp (s1, s2,
34 SCM_UNDEFINED, SCM_UNDEFINED,
35 SCM_UNDEFINED, SCM_UNDEFINED)))
36 return SCM_BOOL_T;
37 else
38 return SCM_BOOL_F;
39 }
40
41 SCM_DEFINE1 (scm_string_equal_p, "string=?", scm_tc7_rpsubr,
42 (SCM s1, SCM s2),
43 "Lexicographic equality predicate; return @code{#t} if the two\n"
44 "strings are the same length and contain the same characters in\n"
45 "the same positions, otherwise return @code{#f}.\n"
46 "\n"
47 "The procedure @code{string-ci=?} treats upper and lower case\n"
48 "letters as though they were the same character, but\n"
49 "@code{string=?} treats upper and lower case as distinct\n"
50 "characters.")
51 #define FUNC_NAME s_scm_string_equal_p
52 {
53 return srfi13_cmp (s1, s2, scm_string_eq);
54 }
55 #undef FUNC_NAME
56
57 SCM_DEFINE1 (scm_string_ci_equal_p, "string-ci=?", scm_tc7_rpsubr,
58 (SCM s1, SCM s2),
59 "Case-insensitive string equality predicate; return @code{#t} if\n"
60 "the two strings are the same length and their component\n"
61 "characters match (ignoring case) at each position; otherwise\n"
62 "return @code{#f}.")
63 #define FUNC_NAME s_scm_string_ci_equal_p
64 {
65 return srfi13_cmp (s1, s2, scm_string_ci_eq);
66 }
67 #undef FUNC_NAME
68
69 SCM_DEFINE1 (scm_string_less_p, "string<?", scm_tc7_rpsubr,
70 (SCM s1, SCM s2),
71 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
72 "is lexicographically less than @var{s2}.")
73 #define FUNC_NAME s_scm_string_less_p
74 {
75 return srfi13_cmp (s1, s2, scm_string_lt);
76 }
77 #undef FUNC_NAME
78
79 SCM_DEFINE1 (scm_string_leq_p, "string<=?", scm_tc7_rpsubr,
80 (SCM s1, SCM s2),
81 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
82 "is lexicographically less than or equal to @var{s2}.")
83 #define FUNC_NAME s_scm_string_leq_p
84 {
85 return srfi13_cmp (s1, s2, scm_string_le);
86 }
87 #undef FUNC_NAME
88
89 SCM_DEFINE1 (scm_string_gr_p, "string>?", scm_tc7_rpsubr,
90 (SCM s1, SCM s2),
91 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
92 "is lexicographically greater than @var{s2}.")
93 #define FUNC_NAME s_scm_string_gr_p
94 {
95 return srfi13_cmp (s1, s2, scm_string_gt);
96 }
97 #undef FUNC_NAME
98
99 SCM_DEFINE1 (scm_string_geq_p, "string>=?", scm_tc7_rpsubr,
100 (SCM s1, SCM s2),
101 "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
102 "is lexicographically greater than or equal to @var{s2}.")
103 #define FUNC_NAME s_scm_string_geq_p
104 {
105 return srfi13_cmp (s1, s2, scm_string_ge);
106 }
107 #undef FUNC_NAME
108
109 SCM_DEFINE1 (scm_string_ci_less_p, "string-ci<?", scm_tc7_rpsubr,
110 (SCM s1, SCM s2),
111 "Case insensitive lexicographic ordering predicate; return\n"
112 "@code{#t} if @var{s1} is lexicographically less than @var{s2}\n"
113 "regardless of case.")
114 #define FUNC_NAME s_scm_string_ci_less_p
115 {
116 return srfi13_cmp (s1, s2, scm_string_ci_lt);
117 }
118 #undef FUNC_NAME
119
120 SCM_DEFINE1 (scm_string_ci_leq_p, "string-ci<=?", scm_tc7_rpsubr,
121 (SCM s1, SCM s2),
122 "Case insensitive lexicographic ordering predicate; return\n"
123 "@code{#t} if @var{s1} is lexicographically less than or equal\n"
124 "to @var{s2} regardless of case.")
125 #define FUNC_NAME s_scm_string_ci_leq_p
126 {
127 return srfi13_cmp (s1, s2, scm_string_ci_le);
128 }
129 #undef FUNC_NAME
130
131 SCM_DEFINE1 (scm_string_ci_gr_p, "string-ci>?", scm_tc7_rpsubr,
132 (SCM s1, SCM s2),
133 "Case insensitive lexicographic ordering predicate; return\n"
134 "@code{#t} if @var{s1} is lexicographically greater than\n"
135 "@var{s2} regardless of case.")
136 #define FUNC_NAME s_scm_string_ci_gr_p
137 {
138 return srfi13_cmp (s1, s2, scm_string_ci_gt);
139 }
140 #undef FUNC_NAME
141
142 SCM_DEFINE1 (scm_string_ci_geq_p, "string-ci>=?", scm_tc7_rpsubr,
143 (SCM s1, SCM s2),
144 "Case insensitive lexicographic ordering predicate; return\n"
145 "@code{#t} if @var{s1} is lexicographically greater than or\n"
146 "equal to @var{s2} regardless of case.")
147 #define FUNC_NAME s_scm_string_ci_geq_p
148 {
149 return srfi13_cmp (s1, s2, scm_string_ci_ge);
150 }
151 #undef FUNC_NAME
152
153 \f
154
155 void
156 scm_init_strorder ()
157 {
158 #include "libguile/strorder.x"
159 }
160
161
162 /*
163 Local Variables:
164 c-file-style: "gnu"
165 End:
166 */