1 /* $Id: str.c,v 1.2 2002/10/14 07:09:51 tommy Exp $ */
2
3 /*
4 * Copyright (c) 2002 Tom Marshall <tommy@tig-grr.com>
5 *
6 * This program is free software. It may be distributed under the terms
7 * in the file LICENSE, found in the top level of the distribution.
8 */
9
10 #include "config.h"
11 #include "dbg.h"
12 #include "str.h"
13
strlwr(char * s)14 void strlwr( char* s )
15 {
16 while( *s != '\0' )
17 {
18 *s = tolower(*s);
19 s++;
20 }
21 }
22
strcpylwr(char * d,const char * s)23 void strcpylwr( char* d, const char* s )
24 {
25 while( *s != '\0' )
26 {
27 *d++ = tolower(*s++);
28 }
29 }
30
strncpylwr(char * d,const char * s,int n)31 void strncpylwr( char* d, const char* s, int n )
32 {
33 while( n-- )
34 {
35 *d++ = tolower(*s++);
36 }
37 }
38
str_create(str_t * pstr)39 void str_create( str_t* pstr )
40 {
41 pstr->p = NULL;
42 pstr->len = 0;
43 }
44
str_destroy(str_t * pstr)45 void str_destroy( str_t* pstr )
46 {
47 /* empty */
48 }
49
str_cmp(const str_t * pthis,const str_t * pother)50 int str_cmp( const str_t* pthis, const str_t* pother )
51 {
52 uint minlen = min( pthis->len, pother->len );
53 int cmp;
54 assert( pthis->p != NULL && pother->p != NULL && minlen != 0 );
55
56 cmp = strncmp( pthis->p, pother->p, minlen );
57
58 if( cmp == 0 && pthis->len != pother->len )
59 {
60 cmp = (pthis->len < pother->len) ? -1 : 1;
61 }
62 return cmp;
63 }
64
str_casecmp(const str_t * pthis,const str_t * pother)65 int str_casecmp( const str_t* pthis, const str_t* pother )
66 {
67 uint minlen = min( pthis->len, pother->len );
68 int cmp;
69 assert( pthis->p != NULL && pother->p != NULL && minlen != 0 );
70
71 cmp = strncasecmp( pthis->p, pother->p, minlen );
72
73 if( cmp == 0 && pthis->len != pother->len )
74 {
75 cmp = (pthis->len < pother->len) ? -1 : 1;
76 }
77 return cmp;
78 }
79