summaryrefslogtreecommitdiffstats
path: root/private/ole32/stg/wclib/wcsicmp.c
blob: 157263acab35474baa4433e6b05f4196894f8a89 (plain) (blame)
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
/***
*wcsicmp.c - compares two wide character strings with case insensitivity
*
*       Copyright (c) 1985-1988, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*       defines wcsicmp() - compares two wide character strings for lexical
*       order with case insensitivity.
*
*Revision History:
*       11-Mar-92   CarlH       Created.
*
*******************************************************************************/


#include <stdlib.h>


/***
*wchar_t wcUp(wc) - upper case wide character
*
*Notes:
*       This was copied from AlexT's version of wcsnicmp.c from the Win4
*       common project.
*/

static wchar_t wcUp(wchar_t wc)
{
    if ('a' <= wc && wc <= 'z')
        wc += (wchar_t)('A' - 'a');

    return(wc);
}


/***
*wcsicmp - compare two wide character strings with case insensitivity,
*       returning less than, equal to, or greater than
*
*Purpose:
*       WCSICMP compares two wide character strings with case insensitivity
*       and returns an integer to indicate whether the first is less than
*       the second, the two are equal, or whether the first is greater than
*       the second.
*
*       Comparison is done byte by byte on an UNSIGNED basis with lower to
*       upper case mapping by wcUp.  Null (0) is less than any other
*       character (1-0xffff).
*
*Entry:
*       const wchar_t * src - string for left-hand side of comparison
*       const wchar_t * dst - string for right-hand side of comparison
*
*Exit:
*       returns -1 if src <  dst
*       returns  0 if src == dst
*       returns +1 if src >  dst
*
*Exceptions:
*
*******************************************************************************/

int _CRTAPI1 wcsicmp(const wchar_t * src, const wchar_t * dst)
{
        int ret = 0 ;

        while( ! (ret = wcUp(*src) - wcUp(*dst)) && *dst)
                ++src, ++dst;

        if ( ret < 0 )
                ret = -1 ;
        else if ( ret > 0 )
                ret = 1 ;

        return ret;
}