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