Home | History | Annotate | Line # | Download | only in citrus
citrus_bcs.c revision 1.1
      1 /*	$NetBSD: citrus_bcs.c,v 1.1 2003/06/25 09:51:26 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 #include <sys/cdefs.h>
     30 #if defined(LIBC_SCCS) && !defined(lint)
     31 __RCSID("$NetBSD: citrus_bcs.c,v 1.1 2003/06/25 09:51:26 tshiozak Exp $");
     32 #endif /* LIBC_SCCS and not lint */
     33 
     34 #ifndef HOSTPROG
     35 #include "namespace.h"
     36 #endif
     37 #include <assert.h>
     38 #include <stdlib.h>
     39 
     40 #include "citrus_namespace.h"
     41 #include "citrus_bcs.h"
     42 
     43 int
     44 _citrus_bcs_strcasecmp(const char * __restrict str1,
     45 		       const char * __restrict str2)
     46 {
     47 	int c1=1, c2=1;
     48 
     49 	while (c1 && c2 && c1==c2) {
     50 		c1 = _bcs_toupper(*str1++);
     51 		c2 = _bcs_toupper(*str2++);
     52 	}
     53 
     54 	return ((c1==c2) ? 0 : ((c1>c2) ? 1:-1));
     55 }
     56 
     57 int
     58 _citrus_bcs_strncasecmp(const char * __restrict str1,
     59 			const char * __restrict str2, size_t sz)
     60 {
     61 	int c1=1, c2=1;
     62 
     63 	while (c1 && c2 && c1==c2 && sz!=0) {
     64 		c1 = _bcs_toupper(*str1++);
     65 		c2 = _bcs_toupper(*str2++);
     66 		sz--;
     67 	}
     68 
     69 	return ((c1==c2) ? 0 : ((c1>c2) ? 1:-1));
     70 }
     71 
     72 const char *
     73 _citrus_bcs_skip_ws(const char *p)
     74 {
     75 
     76 	while (*p && _bcs_isspace(*p))
     77 		p++;
     78 
     79 	return (p);
     80 }
     81 
     82 const char *
     83 _citrus_bcs_skip_nonws(const char *p)
     84 {
     85 
     86 	while (*p && !_bcs_isspace(*p))
     87 		p++;
     88 
     89 	return (p);
     90 }
     91 
     92 const char *
     93 _citrus_bcs_skip_ws_len(const char * __restrict p, size_t * __restrict len)
     94 {
     95 
     96 	while (*p && *len>0 && _bcs_isspace(*p)) {
     97 		p++;
     98 		(*len)--;
     99 	}
    100 
    101 	return (p);
    102 }
    103 
    104 const char *
    105 _citrus_bcs_skip_nonws_len(const char * __restrict p, size_t * __restrict len)
    106 {
    107 
    108 	while (*p && *len>0 && !_bcs_isspace(*p)) {
    109 		p++;
    110 		(*len)--;
    111 	}
    112 
    113 	return (p);
    114 }
    115 
    116 void
    117 _citrus_bcs_trunc_rws_len(const char * __restrict p, size_t * __restrict len)
    118 {
    119 
    120 	while (*len>0 && _bcs_isspace(p[*len-1]))
    121 		(*len)--;
    122 }
    123 
    124 void
    125 _citrus_bcs_convert_to_lower(char *s)
    126 {
    127 	while (*s) {
    128 		*s = _bcs_tolower(*s);
    129 		s++;
    130 	}
    131 }
    132 
    133 void _citrus_bcs_convert_to_upper(char *s)
    134 {
    135 	while (*s) {
    136 		*s = _bcs_toupper(*s);
    137 		s++;
    138 	}
    139 }
    140