972d53c025623e8f2c727f97b3d6b5b2e19f9c05
[dragonfly.git] / lib / libc / citrus / citrus_bcs.h
1 /*      $NetBSD: src/lib/libc/citrus/citrus_bcs.h,v 1.2 2004/01/02 21:49:35 itojun Exp $        */
2 /*      $DragonFly: src/lib/libc/citrus/citrus_bcs.h,v 1.1 2005/03/11 23:33:53 joerg Exp $ */
3
4 /*-
5  * Copyright (c)2003 Citrus Project,
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #ifndef _CITRUS_BCS_H_
31 #define _CITRUS_BCS_H_
32
33 /*
34  * predicate/conversion for basic character set.
35  */
36
37 #define _CITRUS_BCS_PRED(_name_, _cond_) \
38 static __inline int _citrus_bcs_##_name_(uint8_t c) { return (_cond_); }
39
40 _CITRUS_BCS_PRED(isblank, c == ' ' || c == '\t')
41 _CITRUS_BCS_PRED(iseol, c == '\n' || c == '\r')
42 _CITRUS_BCS_PRED(isspace,
43                  _citrus_bcs_isblank(c) || _citrus_bcs_iseol(c) ||
44                  c == '\f' || c == '\v')
45 _CITRUS_BCS_PRED(isdigit, c >= '0' && c <= '9')
46 _CITRUS_BCS_PRED(isupper, c >= 'A' && c <= 'Z')
47 _CITRUS_BCS_PRED(islower, c >= 'a' && c <= 'z')
48 _CITRUS_BCS_PRED(isalpha, _citrus_bcs_isupper(c) || _citrus_bcs_islower(c))
49 _CITRUS_BCS_PRED(isalnum, _citrus_bcs_isdigit(c) || _citrus_bcs_isalpha(c))
50 _CITRUS_BCS_PRED(isxdigit,
51                  _citrus_bcs_isdigit(c) ||
52                  (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
53
54 static __inline uint8_t
55 _citrus_bcs_toupper(uint8_t c)
56 {
57         return (_citrus_bcs_islower(c) ? (c - 'a' + 'A') : c);
58 }
59
60 static __inline uint8_t
61 _citrus_bcs_tolower(uint8_t c)
62 {
63         return (_citrus_bcs_isupper(c) ? (c - 'A' + 'a') : c);
64 }
65
66 __BEGIN_DECLS
67 int _citrus_bcs_strcasecmp(const char * __restrict, const char * __restrict);
68 int _citrus_bcs_strncasecmp(const char * __restrict, const char * __restrict,
69                             size_t);
70 const char *_citrus_bcs_skip_ws(const char * __restrict);
71 const char *_citrus_bcs_skip_nonws(const char * __restrict);
72 const char *_citrus_bcs_skip_ws_len(const char * __restrict,
73                                        size_t * __restrict);
74 const char *_citrus_bcs_skip_nonws_len(const char * __restrict,
75                                        size_t * __restrict);
76 void _citrus_bcs_trunc_rws_len(const char * __restrict, size_t * __restrict);
77 void _citrus_bcs_convert_to_lower(char *);
78 void _citrus_bcs_convert_to_upper(char *);
79 __END_DECLS
80
81 #endif