11590Srgrimes/* $FreeBSD$ */
228068Scharnier/* $NetBSD: citrus_bcs.h,v 1.6 2009/01/11 02:46:24 christos Exp $ */
31590Srgrimes
41590Srgrimes/*-
51590Srgrimes * Copyright (c)2003 Citrus Project,
61590Srgrimes * All rights reserved.
71590Srgrimes *
81590Srgrimes * Redistribution and use in source and binary forms, with or without
91590Srgrimes * modification, are permitted provided that the following conditions
101590Srgrimes * are met:
111590Srgrimes * 1. Redistributions of source code must retain the above copyright
121590Srgrimes *    notice, this list of conditions and the following disclaimer.
131590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141590Srgrimes *    notice, this list of conditions and the following disclaimer in the
151590Srgrimes *    documentation and/or other materials provided with the distribution.
161590Srgrimes *
171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271590Srgrimes * SUCH DAMAGE.
281590Srgrimes */
291590Srgrimes
301590Srgrimes#include <sys/types.h>
311590Srgrimes
321590Srgrimes#ifndef _CITRUS_BCS_H_
331590Srgrimes#define _CITRUS_BCS_H_
3428068Scharnier
3528068Scharnier/*
361590Srgrimes * predicate/conversion for basic character set.
3778130Sdd *
381590Srgrimes * `Basic character set' is a term defined in the ISO C standard.
391590Srgrimes * Citrus bcs is, if anything, close to `portable character set'
4028068Scharnier * defined in the POSIX.
4128068Scharnier */
4228068Scharnier
4328068Scharnier#define _CITRUS_BCS_PRED(_name_, _cond_) \
4450477Speterstatic __inline int _citrus_bcs_##_name_(uint8_t c) { return (_cond_); }
4578130Sdd
461590Srgrimes/*
471590Srgrimes * predicates.
4814542Sdg * Unlike predicates defined in ctype.h, these do not accept EOF.
491590Srgrimes */
501590Srgrimes_CITRUS_BCS_PRED(isblank, c == ' ' || c == '\t')
511590Srgrimes_CITRUS_BCS_PRED(iseol, c == '\n' || c == '\r')
5228068Scharnier_CITRUS_BCS_PRED(isspace, _citrus_bcs_isblank(c) || _citrus_bcs_iseol(c) ||
5328068Scharnier    c == '\f' || c == '\v')
54200462Sdelphij_CITRUS_BCS_PRED(isdigit, c >= '0' && c <= '9')
551590Srgrimes_CITRUS_BCS_PRED(isupper, c >= 'A' && c <= 'Z')
561590Srgrimes_CITRUS_BCS_PRED(islower, c >= 'a' && c <= 'z')
571590Srgrimes_CITRUS_BCS_PRED(isalpha, _citrus_bcs_isupper(c) || _citrus_bcs_islower(c))
58194880Sdfr_CITRUS_BCS_PRED(isalnum, _citrus_bcs_isdigit(c) || _citrus_bcs_isalpha(c))
5928068Scharnier_CITRUS_BCS_PRED(isxdigit, _citrus_bcs_isdigit(c) ||
601590Srgrimes    (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
6128068Scharnier
621590Srgrimes/*
6328068Scharnier * transliterate between uppercase and lowercase.
641590Srgrimes * Unlike transliterator defined in ctype.h, these do not accept EOF.
651590Srgrimes */
661590Srgrimesstatic __inline uint8_t
671590Srgrimes_citrus_bcs_toupper(uint8_t c)
681590Srgrimes{
691590Srgrimes
701590Srgrimes	return (_citrus_bcs_islower(c) ? (c - 'a' + 'A') : c);
711590Srgrimes}
721590Srgrimes
731590Srgrimesstatic __inline uint8_t
741590Srgrimes_citrus_bcs_tolower(uint8_t c)
75194880Sdfr{
76194880Sdfr
771590Srgrimes	return (_citrus_bcs_isupper(c) ? (c - 'A' + 'a') : c);
781590Srgrimes}
791590Srgrimes
801590Srgrimes__BEGIN_DECLS
81194880Sdfrint		 _citrus_bcs_strcasecmp(const char * __restrict,
821590Srgrimes		    const char * __restrict);
831590Srgrimesint		 _citrus_bcs_strncasecmp(const char * __restrict,
841590Srgrimes		    const char * __restrict, size_t);
851590Srgrimesconst char	*_citrus_bcs_skip_ws(const char * __restrict);
861590Srgrimesconst char	*_citrus_bcs_skip_nonws(const char * __restrict);
87194880Sdfrconst char	*_citrus_bcs_skip_ws_len(const char * __restrict,
881590Srgrimes		    size_t * __restrict);
891590Srgrimesconst char	*_citrus_bcs_skip_nonws_len(const char * __restrict,
901590Srgrimes		    size_t * __restrict);
91194880Sdfrvoid		 _citrus_bcs_trunc_rws_len(const char * __restrict,
921590Srgrimes		    size_t * __restrict);
931590Srgrimesvoid		 _citrus_bcs_convert_to_lower(char *);
9492922Simpvoid		 _citrus_bcs_convert_to_upper(char *);
9592922Simp
9692922Simplong int	 _citrus_bcs_strtol(const char * __restrict,
97194880Sdfr		    char ** __restrict, int);
9892922Simpunsigned long	 _citrus_bcs_strtoul(const char * __restrict,
9992922Simp		    char ** __restrict, int);
10028068Scharnier__END_DECLS
1011590Srgrimes
1021590Srgrimes#endif
1031590Srgrimes