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