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