1 /* Copyright (C) 1995,1996,1998, 2000, 2001, 2004, 2006, 2008 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
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
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.
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
26 #include "libguile/_scm.h"
27 #include "libguile/validate.h"
29 #include "libguile/chars.h"
30 #include "libguile/srfi-14.h"
34 SCM_DEFINE (scm_char_p, "char?", 1, 0, 0,
36 "Return @code{#t} iff @var{x} is a character, else @code{#f}.")
37 #define FUNC_NAME s_scm_char_p
39 return scm_from_bool (SCM_CHARP(x));
43 SCM_DEFINE1 (scm_char_eq_p, "char=?", scm_tc7_rpsubr,
45 "Return @code{#t} iff @var{x} is the same character as @var{y}, else @code{#f}.")
46 #define FUNC_NAME s_scm_char_eq_p
48 SCM_VALIDATE_CHAR (1, x);
49 SCM_VALIDATE_CHAR (2, y);
50 return scm_from_bool (scm_is_eq (x, y));
55 SCM_DEFINE1 (scm_char_less_p, "char<?", scm_tc7_rpsubr,
57 "Return @code{#t} iff @var{x} is less than @var{y} in the ASCII sequence,\n"
59 #define FUNC_NAME s_scm_char_less_p
61 SCM_VALIDATE_CHAR (1, x);
62 SCM_VALIDATE_CHAR (2, y);
63 return scm_from_bool (SCM_CHAR(x) < SCM_CHAR(y));
67 SCM_DEFINE1 (scm_char_leq_p, "char<=?", scm_tc7_rpsubr,
69 "Return @code{#t} iff @var{x} is less than or equal to @var{y} in the\n"
70 "ASCII sequence, else @code{#f}.")
71 #define FUNC_NAME s_scm_char_leq_p
73 SCM_VALIDATE_CHAR (1, x);
74 SCM_VALIDATE_CHAR (2, y);
75 return scm_from_bool (SCM_CHAR(x) <= SCM_CHAR(y));
79 SCM_DEFINE1 (scm_char_gr_p, "char>?", scm_tc7_rpsubr,
81 "Return @code{#t} iff @var{x} is greater than @var{y} in the ASCII\n"
82 "sequence, else @code{#f}.")
83 #define FUNC_NAME s_scm_char_gr_p
85 SCM_VALIDATE_CHAR (1, x);
86 SCM_VALIDATE_CHAR (2, y);
87 return scm_from_bool (SCM_CHAR(x) > SCM_CHAR(y));
91 SCM_DEFINE1 (scm_char_geq_p, "char>=?", scm_tc7_rpsubr,
93 "Return @code{#t} iff @var{x} is greater than or equal to @var{y} in the\n"
94 "ASCII sequence, else @code{#f}.")
95 #define FUNC_NAME s_scm_char_geq_p
97 SCM_VALIDATE_CHAR (1, x);
98 SCM_VALIDATE_CHAR (2, y);
99 return scm_from_bool (SCM_CHAR(x) >= SCM_CHAR(y));
103 SCM_DEFINE1 (scm_char_ci_eq_p, "char-ci=?", scm_tc7_rpsubr,
105 "Return @code{#t} iff @var{x} is the same character as @var{y} ignoring\n"
106 "case, else @code{#f}.")
107 #define FUNC_NAME s_scm_char_ci_eq_p
109 SCM_VALIDATE_CHAR (1, x);
110 SCM_VALIDATE_CHAR (2, y);
111 return scm_from_bool (scm_c_upcase(SCM_CHAR(x))==scm_c_upcase(SCM_CHAR(y)));
115 SCM_DEFINE1 (scm_char_ci_less_p, "char-ci<?", scm_tc7_rpsubr,
117 "Return @code{#t} iff @var{x} is less than @var{y} in the ASCII sequence\n"
118 "ignoring case, else @code{#f}.")
119 #define FUNC_NAME s_scm_char_ci_less_p
121 SCM_VALIDATE_CHAR (1, x);
122 SCM_VALIDATE_CHAR (2, y);
123 return scm_from_bool ((scm_c_upcase(SCM_CHAR(x))) < scm_c_upcase(SCM_CHAR(y)));
127 SCM_DEFINE1 (scm_char_ci_leq_p, "char-ci<=?", scm_tc7_rpsubr,
129 "Return @code{#t} iff @var{x} is less than or equal to @var{y} in the\n"
130 "ASCII sequence ignoring case, else @code{#f}.")
131 #define FUNC_NAME s_scm_char_ci_leq_p
133 SCM_VALIDATE_CHAR (1, x);
134 SCM_VALIDATE_CHAR (2, y);
135 return scm_from_bool (scm_c_upcase(SCM_CHAR(x)) <= scm_c_upcase(SCM_CHAR(y)));
139 SCM_DEFINE1 (scm_char_ci_gr_p, "char-ci>?", scm_tc7_rpsubr,
141 "Return @code{#t} iff @var{x} is greater than @var{y} in the ASCII\n"
142 "sequence ignoring case, else @code{#f}.")
143 #define FUNC_NAME s_scm_char_ci_gr_p
145 SCM_VALIDATE_CHAR (1, x);
146 SCM_VALIDATE_CHAR (2, y);
147 return scm_from_bool (scm_c_upcase(SCM_CHAR(x)) > scm_c_upcase(SCM_CHAR(y)));
151 SCM_DEFINE1 (scm_char_ci_geq_p, "char-ci>=?", scm_tc7_rpsubr,
153 "Return @code{#t} iff @var{x} is greater than or equal to @var{y} in the\n"
154 "ASCII sequence ignoring case, else @code{#f}.")
155 #define FUNC_NAME s_scm_char_ci_geq_p
157 SCM_VALIDATE_CHAR (1, x);
158 SCM_VALIDATE_CHAR (2, y);
159 return scm_from_bool (scm_c_upcase(SCM_CHAR(x)) >= scm_c_upcase(SCM_CHAR(y)));
164 SCM_DEFINE (scm_char_alphabetic_p, "char-alphabetic?", 1, 0, 0,
166 "Return @code{#t} iff @var{chr} is alphabetic, else @code{#f}.\n")
167 #define FUNC_NAME s_scm_char_alphabetic_p
169 return scm_char_set_contains_p (scm_char_set_letter, chr);
173 SCM_DEFINE (scm_char_numeric_p, "char-numeric?", 1, 0, 0,
175 "Return @code{#t} iff @var{chr} is numeric, else @code{#f}.\n")
176 #define FUNC_NAME s_scm_char_numeric_p
178 return scm_char_set_contains_p (scm_char_set_digit, chr);
182 SCM_DEFINE (scm_char_whitespace_p, "char-whitespace?", 1, 0, 0,
184 "Return @code{#t} iff @var{chr} is whitespace, else @code{#f}.\n")
185 #define FUNC_NAME s_scm_char_whitespace_p
187 return scm_char_set_contains_p (scm_char_set_whitespace, chr);
193 SCM_DEFINE (scm_char_upper_case_p, "char-upper-case?", 1, 0, 0,
195 "Return @code{#t} iff @var{chr} is uppercase, else @code{#f}.\n")
196 #define FUNC_NAME s_scm_char_upper_case_p
198 return scm_char_set_contains_p (scm_char_set_upper_case, chr);
203 SCM_DEFINE (scm_char_lower_case_p, "char-lower-case?", 1, 0, 0,
205 "Return @code{#t} iff @var{chr} is lowercase, else @code{#f}.\n")
206 #define FUNC_NAME s_scm_char_lower_case_p
208 return scm_char_set_contains_p (scm_char_set_lower_case, chr);
214 SCM_DEFINE (scm_char_is_both_p, "char-is-both?", 1, 0, 0,
216 "Return @code{#t} iff @var{chr} is either uppercase or lowercase, else @code{#f}.\n")
217 #define FUNC_NAME s_scm_char_is_both_p
219 if (scm_is_true (scm_char_set_contains_p (scm_char_set_lower_case, chr)))
221 return scm_char_set_contains_p (scm_char_set_upper_case, chr);
228 SCM_DEFINE (scm_char_to_integer, "char->integer", 1, 0, 0,
230 "Return the number corresponding to ordinal position of @var{chr} in the\n"
232 #define FUNC_NAME s_scm_char_to_integer
234 SCM_VALIDATE_CHAR (1, chr);
235 return scm_from_ulong (SCM_CHAR(chr));
241 SCM_DEFINE (scm_integer_to_char, "integer->char", 1, 0, 0,
243 "Return the character at position @var{n} in the ASCII sequence.")
244 #define FUNC_NAME s_scm_integer_to_char
246 return SCM_MAKE_CHAR (scm_to_uchar (n));
251 SCM_DEFINE (scm_char_upcase, "char-upcase", 1, 0, 0,
253 "Return the uppercase character version of @var{chr}.")
254 #define FUNC_NAME s_scm_char_upcase
256 SCM_VALIDATE_CHAR (1, chr);
257 return SCM_MAKE_CHAR (toupper (SCM_CHAR (chr)));
262 SCM_DEFINE (scm_char_downcase, "char-downcase", 1, 0, 0,
264 "Return the lowercase character version of @var{chr}.")
265 #define FUNC_NAME s_scm_char_downcase
267 SCM_VALIDATE_CHAR (1, chr);
268 return SCM_MAKE_CHAR (tolower (SCM_CHAR(chr)));
277 TODO: change name to scm_i_.. ? --hwn
282 scm_c_upcase (unsigned int c)
292 scm_c_downcase (unsigned int c)
304 # if (('\n'=='\025') && (' '=='\100') && ('a'=='\201') && ('A'=='\301'))
306 # endif /* (('\n'=='\025') && (' '=='\100') && ('a'=='\201') && ('A'=='\301')) */
307 # if (('\n'=='\012') && (' '=='\040') && ('a'=='\141') && ('A'=='\101'))
309 # endif /* (('\n'=='\012') && (' '=='\040') && ('a'=='\141') && ('A'=='\101')) */
310 #endif /* def _DCC */
314 char *const scm_charnames[] =
316 "nul", "soh", "stx", "etx", "pf", "ht", "lc", "del",
317 0 , 0 , "smm", "vt", "ff", "cr", "so", "si",
318 "dle", "dc1", "dc2", "dc3", "res", "nl", "bs", "il",
319 "can", "em", "cc", 0 , "ifs", "igs", "irs", "ius",
320 "ds", "sos", "fs", 0 , "byp", "lf", "eob", "pre",
321 0 , 0 , "sm", 0 , 0 , "enq", "ack", "bel",
322 0 , 0 , "syn", 0 , "pn", "rs", "uc", "eot",
323 0 , 0 , 0 , 0 , "dc4", "nak", 0 , "sub",
324 "space", scm_s_newline, "tab", "backspace", "return", "page", "null"};
326 const char scm_charnums[] =
327 "\000\001\002\003\004\005\006\007\
328 \010\011\012\013\014\015\016\017\
329 \020\021\022\023\024\025\026\027\
330 \030\031\032\033\034\035\036\037\
331 \040\041\042\043\044\045\046\047\
332 \050\051\052\053\054\055\056\057\
333 \060\061\062\063\064\065\066\067\
334 \070\071\072\073\074\075\076\077\
336 #endif /* def EBCDIC */
338 char *const scm_charnames[] =
340 "nul","soh","stx","etx","eot","enq","ack","bel",
341 "bs", "ht", "newline", "vt", "np", "cr", "so", "si",
342 "dle","dc1","dc2","dc3","dc4","nak","syn","etb",
343 "can", "em","sub","esc", "fs", "gs", "rs", "us",
344 "space", "sp", "nl", "tab", "backspace", "return", "page", "null", "del"};
345 const char scm_charnums[] =
346 "\000\001\002\003\004\005\006\007\
347 \010\011\012\013\014\015\016\017\
348 \020\021\022\023\024\025\026\027\
349 \030\031\032\033\034\035\036\037\
351 #endif /* def ASCII */
353 int scm_n_charnames = sizeof (scm_charnames) / sizeof (char *);
362 #include "libguile/chars.x"