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