citrus_bcs.c revision 1.2 1 /* $NetBSD: citrus_bcs.c,v 1.2 2003/06/30 12:32:21 tshiozak Exp $ */
2
3 /*-
4 * Copyright (c)2003 Citrus Project,
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #if HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <sys/cdefs.h>
34 #if defined(LIBC_SCCS) && !defined(lint)
35 __RCSID("$NetBSD: citrus_bcs.c,v 1.2 2003/06/30 12:32:21 tshiozak Exp $");
36 #endif /* LIBC_SCCS and not lint */
37
38 #ifndef HOSTPROG
39 #include "namespace.h"
40 #endif
41 #include <assert.h>
42 #include <stdlib.h>
43
44 #include "citrus_namespace.h"
45 #include "citrus_bcs.h"
46
47 int
48 _citrus_bcs_strcasecmp(const char * __restrict str1,
49 const char * __restrict str2)
50 {
51 int c1=1, c2=1;
52
53 while (c1 && c2 && c1==c2) {
54 c1 = _bcs_toupper(*str1++);
55 c2 = _bcs_toupper(*str2++);
56 }
57
58 return ((c1==c2) ? 0 : ((c1>c2) ? 1:-1));
59 }
60
61 int
62 _citrus_bcs_strncasecmp(const char * __restrict str1,
63 const char * __restrict str2, size_t sz)
64 {
65 int c1=1, c2=1;
66
67 while (c1 && c2 && c1==c2 && sz!=0) {
68 c1 = _bcs_toupper(*str1++);
69 c2 = _bcs_toupper(*str2++);
70 sz--;
71 }
72
73 return ((c1==c2) ? 0 : ((c1>c2) ? 1:-1));
74 }
75
76 const char *
77 _citrus_bcs_skip_ws(const char *p)
78 {
79
80 while (*p && _bcs_isspace(*p))
81 p++;
82
83 return (p);
84 }
85
86 const char *
87 _citrus_bcs_skip_nonws(const char *p)
88 {
89
90 while (*p && !_bcs_isspace(*p))
91 p++;
92
93 return (p);
94 }
95
96 const char *
97 _citrus_bcs_skip_ws_len(const char * __restrict p, size_t * __restrict len)
98 {
99
100 while (*p && *len>0 && _bcs_isspace(*p)) {
101 p++;
102 (*len)--;
103 }
104
105 return (p);
106 }
107
108 const char *
109 _citrus_bcs_skip_nonws_len(const char * __restrict p, size_t * __restrict len)
110 {
111
112 while (*p && *len>0 && !_bcs_isspace(*p)) {
113 p++;
114 (*len)--;
115 }
116
117 return (p);
118 }
119
120 void
121 _citrus_bcs_trunc_rws_len(const char * __restrict p, size_t * __restrict len)
122 {
123
124 while (*len>0 && _bcs_isspace(p[*len-1]))
125 (*len)--;
126 }
127
128 void
129 _citrus_bcs_convert_to_lower(char *s)
130 {
131 while (*s) {
132 *s = _bcs_tolower(*s);
133 s++;
134 }
135 }
136
137 void _citrus_bcs_convert_to_upper(char *s)
138 {
139 while (*s) {
140 *s = _bcs_toupper(*s);
141 s++;
142 }
143 }
144