File: str.c

package info (click to toggle)
bmf 0.9.4-9
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 388 kB
  • ctags: 428
  • sloc: ansic: 5,517; sh: 322; makefile: 132
file content (78 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* $Id: str.c,v 1.2 2002/10/14 07:09:51 tommy Exp $ */

/*
 * Copyright (c) 2002 Tom Marshall <tommy@tig-grr.com>
 *
 * This program is free software.  It may be distributed under the terms
 * in the file LICENSE, found in the top level of the distribution.
 */

#include "config.h"
#include "dbg.h"
#include "str.h"

void strlwr( char* s )
{
    while( *s != '\0' )
    {
        *s = tolower(*s);
        s++;
    }
}

void strcpylwr( char* d, const char* s )
{
    while( *s != '\0' )
    {
        *d++ = tolower(*s++);
    }
}

void strncpylwr( char* d, const char* s, int n )
{
    while( n-- )
    {
        *d++ = tolower(*s++);
    }
}

void str_create( str_t* pstr )
{
    pstr->p = NULL;
    pstr->len = 0;
}

void str_destroy( str_t* pstr )
{
    /* empty */
}

int str_cmp( const str_t* pthis, const str_t* pother )
{
    uint minlen = min( pthis->len, pother->len );
    int cmp;
    assert( pthis->p != NULL && pother->p != NULL && minlen != 0 );

    cmp = strncmp( pthis->p, pother->p, minlen );

    if( cmp == 0 && pthis->len != pother->len )
    {
        cmp = (pthis->len < pother->len) ? -1 : 1;
    }
    return cmp;
}

int str_casecmp( const str_t* pthis, const str_t* pother )
{
    uint minlen = min( pthis->len, pother->len );
    int cmp;
    assert( pthis->p != NULL && pother->p != NULL && minlen != 0 );

    cmp = strncasecmp( pthis->p, pother->p, minlen );

    if( cmp == 0 && pthis->len != pother->len )
    {
        cmp = (pthis->len < pother->len) ? -1 : 1;
    }
    return cmp;
}