-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci_string.h
executable file
·112 lines (88 loc) · 3.04 KB
/
ci_string.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* cistring.h -- case insensitive STL string.
Written from this, http://www.gotw.ca/gotw/029.htm.
Copyright (C) 2001-2003 Mark Weaver
Written by Mark Weaver <[email protected]>
Part of the mailparse library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef cistring_h
#define cistring_h
//////////////////////////////////////////////////////////////////////
// CASE INSENSITIVE STRING
//////////////////////////////////////////////////////////////////////
#include <string>
_STD_BEGIN
struct ci_char_traits : public char_traits<char>
// just inherit all the other functions
// that we don't need to override
{
static bool eq( char c1, char c2 )
{ return toupper(c1) == toupper(c2); }
static bool ne( char c1, char c2 )
{ return toupper(c1) != toupper(c2); }
static bool lt( char c1, char c2 )
{ return toupper(c1) < toupper(c2); }
static int compare( const char* s1,
const char* s2,
size_t n ) {
return strnicmp( s1, s2, n );
// if available on your compiler,
// otherwise you can roll your own
}
static const char*
find( const char* s, size_t n, char a ) {
a = toupper(a);
for ( ; n > 0 ; --n, ++s) {
if ( toupper(*s) == a )
return s;
}
return 0;
}
};
typedef basic_string<char, ci_char_traits> ci_string;
struct ci_wchar_traits : public char_traits<wchar_t>
// just inherit all the other functions
// that we don't need to override
{
static bool eq( wchar_t c1, wchar_t c2 )
{ return towupper(c1) == towupper(c2); }
static bool ne( wchar_t c1, wchar_t c2 )
{ return towupper(c1) != towupper(c2); }
static bool lt( wchar_t c1, wchar_t c2 )
{ return towupper(c1) < towupper(c2); }
static int compare( const wchar_t* s1,
const wchar_t* s2,
size_t n ) {
return wcsnicmp( s1, s2, n );
// if available on your compiler,
// otherwise you can roll your own
}
static const wchar_t*
find( const wchar_t* s, size_t n, wchar_t a ) {
a = towupper(a);
for ( ; n > 0 ; --n, ++s ) {
if ( towupper(*s) == a )
return s;
}
return 0;
}
};
typedef basic_string<wchar_t, ci_wchar_traits> ci_wstring;
#ifdef _UNICODE
typedef ci_wstring ci_tstring;
#else
typedef ci_string ci_tstring;
#endif
_STD_END
#endif // cistring_h