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