citrus_bcs.h revision 1.3 1 1.3 tshiozak /* $NetBSD: citrus_bcs.h,v 1.3 2005/05/14 17:55:42 tshiozak Exp $ */
2 1.1 tshiozak
3 1.1 tshiozak /*-
4 1.1 tshiozak * Copyright (c)2003 Citrus Project,
5 1.1 tshiozak * All rights reserved.
6 1.1 tshiozak *
7 1.1 tshiozak * Redistribution and use in source and binary forms, with or without
8 1.1 tshiozak * modification, are permitted provided that the following conditions
9 1.1 tshiozak * are met:
10 1.1 tshiozak * 1. Redistributions of source code must retain the above copyright
11 1.1 tshiozak * notice, this list of conditions and the following disclaimer.
12 1.1 tshiozak * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tshiozak * notice, this list of conditions and the following disclaimer in the
14 1.1 tshiozak * documentation and/or other materials provided with the distribution.
15 1.1 tshiozak *
16 1.1 tshiozak * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 tshiozak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 tshiozak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 tshiozak * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 tshiozak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 tshiozak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 tshiozak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 tshiozak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 tshiozak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 tshiozak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 tshiozak * SUCH DAMAGE.
27 1.1 tshiozak */
28 1.1 tshiozak
29 1.1 tshiozak #ifndef _CITRUS_BCS_H_
30 1.1 tshiozak #define _CITRUS_BCS_H_
31 1.1 tshiozak
32 1.1 tshiozak /*
33 1.1 tshiozak * predicate/conversion for basic character set.
34 1.3 tshiozak *
35 1.3 tshiozak * `Basic character set' is a term defined in the ISO C standard.
36 1.3 tshiozak * Citrus bcs is, if anything, close to `portable character set'
37 1.3 tshiozak * defined in the POSIX.
38 1.1 tshiozak */
39 1.1 tshiozak
40 1.1 tshiozak #define _CITRUS_BCS_PRED(_name_, _cond_) \
41 1.1 tshiozak static __inline int _citrus_bcs_##_name_(u_int8_t c) { return (_cond_); }
42 1.1 tshiozak
43 1.3 tshiozak /*
44 1.3 tshiozak * predicates.
45 1.3 tshiozak * Unlike predicates defined in ctype.h, these do not accept EOF.
46 1.3 tshiozak */
47 1.2 itojun _CITRUS_BCS_PRED(isblank, c == ' ' || c == '\t')
48 1.2 itojun _CITRUS_BCS_PRED(iseol, c == '\n' || c == '\r')
49 1.1 tshiozak _CITRUS_BCS_PRED(isspace,
50 1.1 tshiozak _citrus_bcs_isblank(c) || _citrus_bcs_iseol(c) ||
51 1.2 itojun c == '\f' || c == '\v')
52 1.2 itojun _CITRUS_BCS_PRED(isdigit, c >= '0' && c <= '9')
53 1.2 itojun _CITRUS_BCS_PRED(isupper, c >= 'A' && c <= 'Z')
54 1.2 itojun _CITRUS_BCS_PRED(islower, c >= 'a' && c <= 'z')
55 1.1 tshiozak _CITRUS_BCS_PRED(isalpha, _citrus_bcs_isupper(c) || _citrus_bcs_islower(c))
56 1.1 tshiozak _CITRUS_BCS_PRED(isalnum, _citrus_bcs_isdigit(c) || _citrus_bcs_isalpha(c))
57 1.1 tshiozak _CITRUS_BCS_PRED(isxdigit,
58 1.1 tshiozak _citrus_bcs_isdigit(c) ||
59 1.2 itojun (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
60 1.1 tshiozak
61 1.3 tshiozak /*
62 1.3 tshiozak * transliterate between uppercase and lowercase.
63 1.3 tshiozak * Unlike transliterator defined in ctype.h, these do not accept EOF.
64 1.3 tshiozak */
65 1.1 tshiozak static __inline u_int8_t
66 1.1 tshiozak _citrus_bcs_toupper(u_int8_t c)
67 1.1 tshiozak {
68 1.2 itojun return (_citrus_bcs_islower(c) ? (c - 'a' + 'A') : c);
69 1.1 tshiozak }
70 1.1 tshiozak
71 1.1 tshiozak static __inline u_int8_t
72 1.1 tshiozak _citrus_bcs_tolower(u_int8_t c)
73 1.1 tshiozak {
74 1.2 itojun return (_citrus_bcs_isupper(c) ? (c - 'A' + 'a') : c);
75 1.1 tshiozak }
76 1.1 tshiozak
77 1.1 tshiozak __BEGIN_DECLS
78 1.1 tshiozak int _citrus_bcs_strcasecmp(const char * __restrict, const char * __restrict);
79 1.1 tshiozak int _citrus_bcs_strncasecmp(const char * __restrict, const char * __restrict,
80 1.1 tshiozak size_t);
81 1.1 tshiozak const char *_citrus_bcs_skip_ws(const char * __restrict);
82 1.1 tshiozak const char *_citrus_bcs_skip_nonws(const char * __restrict);
83 1.1 tshiozak const char *_citrus_bcs_skip_ws_len(const char * __restrict,
84 1.1 tshiozak size_t * __restrict);
85 1.1 tshiozak const char *_citrus_bcs_skip_nonws_len(const char * __restrict,
86 1.1 tshiozak size_t * __restrict);
87 1.1 tshiozak void _citrus_bcs_trunc_rws_len(const char * __restrict, size_t * __restrict);
88 1.1 tshiozak void _citrus_bcs_convert_to_lower(char *);
89 1.1 tshiozak void _citrus_bcs_convert_to_upper(char *);
90 1.1 tshiozak __END_DECLS
91 1.1 tshiozak
92 1.1 tshiozak #endif
93