1219019Sgabor/* $FreeBSD$ */ 2219019Sgabor/* $NetBSD: citrus_bcs.h,v 1.6 2009/01/11 02:46:24 christos Exp $ */ 3219019Sgabor 4219019Sgabor/*- 5219019Sgabor * Copyright (c)2003 Citrus Project, 6219019Sgabor * All rights reserved. 7219019Sgabor * 8219019Sgabor * Redistribution and use in source and binary forms, with or without 9219019Sgabor * modification, are permitted provided that the following conditions 10219019Sgabor * are met: 11219019Sgabor * 1. Redistributions of source code must retain the above copyright 12219019Sgabor * notice, this list of conditions and the following disclaimer. 13219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright 14219019Sgabor * notice, this list of conditions and the following disclaimer in the 15219019Sgabor * documentation and/or other materials provided with the distribution. 16219019Sgabor * 17219019Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20219019Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27219019Sgabor * SUCH DAMAGE. 28219019Sgabor */ 29219019Sgabor 30219019Sgabor#include <sys/types.h> 31219019Sgabor 32219019Sgabor#ifndef _CITRUS_BCS_H_ 33219019Sgabor#define _CITRUS_BCS_H_ 34219019Sgabor 35219019Sgabor/* 36219019Sgabor * predicate/conversion for basic character set. 37219019Sgabor * 38219019Sgabor * `Basic character set' is a term defined in the ISO C standard. 39219019Sgabor * Citrus bcs is, if anything, close to `portable character set' 40219019Sgabor * defined in the POSIX. 41219019Sgabor */ 42219019Sgabor 43219019Sgabor#define _CITRUS_BCS_PRED(_name_, _cond_) \ 44219019Sgaborstatic __inline int _citrus_bcs_##_name_(uint8_t c) { return (_cond_); } 45219019Sgabor 46219019Sgabor/* 47219019Sgabor * predicates. 48219019Sgabor * Unlike predicates defined in ctype.h, these do not accept EOF. 49219019Sgabor */ 50219019Sgabor_CITRUS_BCS_PRED(isblank, c == ' ' || c == '\t') 51219019Sgabor_CITRUS_BCS_PRED(iseol, c == '\n' || c == '\r') 52219019Sgabor_CITRUS_BCS_PRED(isspace, _citrus_bcs_isblank(c) || _citrus_bcs_iseol(c) || 53219019Sgabor c == '\f' || c == '\v') 54219019Sgabor_CITRUS_BCS_PRED(isdigit, c >= '0' && c <= '9') 55219019Sgabor_CITRUS_BCS_PRED(isupper, c >= 'A' && c <= 'Z') 56219019Sgabor_CITRUS_BCS_PRED(islower, c >= 'a' && c <= 'z') 57219019Sgabor_CITRUS_BCS_PRED(isalpha, _citrus_bcs_isupper(c) || _citrus_bcs_islower(c)) 58219019Sgabor_CITRUS_BCS_PRED(isalnum, _citrus_bcs_isdigit(c) || _citrus_bcs_isalpha(c)) 59219019Sgabor_CITRUS_BCS_PRED(isxdigit, _citrus_bcs_isdigit(c) || 60219019Sgabor (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) 61219019Sgabor 62219019Sgabor/* 63219019Sgabor * transliterate between uppercase and lowercase. 64219019Sgabor * Unlike transliterator defined in ctype.h, these do not accept EOF. 65219019Sgabor */ 66219019Sgaborstatic __inline uint8_t 67219019Sgabor_citrus_bcs_toupper(uint8_t c) 68219019Sgabor{ 69219019Sgabor 70219019Sgabor return (_citrus_bcs_islower(c) ? (c - 'a' + 'A') : c); 71219019Sgabor} 72219019Sgabor 73219019Sgaborstatic __inline uint8_t 74219019Sgabor_citrus_bcs_tolower(uint8_t c) 75219019Sgabor{ 76219019Sgabor 77219019Sgabor return (_citrus_bcs_isupper(c) ? (c - 'A' + 'a') : c); 78219019Sgabor} 79219019Sgabor 80219019Sgabor__BEGIN_DECLS 81219019Sgaborint _citrus_bcs_strcasecmp(const char * __restrict, 82219019Sgabor const char * __restrict); 83219019Sgaborint _citrus_bcs_strncasecmp(const char * __restrict, 84219019Sgabor const char * __restrict, size_t); 85219019Sgaborconst char *_citrus_bcs_skip_ws(const char * __restrict); 86219019Sgaborconst char *_citrus_bcs_skip_nonws(const char * __restrict); 87219019Sgaborconst char *_citrus_bcs_skip_ws_len(const char * __restrict, 88219019Sgabor size_t * __restrict); 89219019Sgaborconst char *_citrus_bcs_skip_nonws_len(const char * __restrict, 90219019Sgabor size_t * __restrict); 91219019Sgaborvoid _citrus_bcs_trunc_rws_len(const char * __restrict, 92219019Sgabor size_t * __restrict); 93219019Sgaborvoid _citrus_bcs_convert_to_lower(char *); 94219019Sgaborvoid _citrus_bcs_convert_to_upper(char *); 95219019Sgabor 96219019Sgaborlong int _citrus_bcs_strtol(const char * __restrict, 97219019Sgabor char ** __restrict, int); 98219019Sgaborunsigned long _citrus_bcs_strtoul(const char * __restrict, 99219019Sgabor char ** __restrict, int); 100219019Sgabor__END_DECLS 101219019Sgabor 102219019Sgabor#endif 103