-
Notifications
You must be signed in to change notification settings - Fork 82
/
istring.cc
63 lines (46 loc) · 1.6 KB
/
istring.cc
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
/*
Copyright (C) 1997-2001 Id Software, Inc.
Copyright (C) 2003 The Pentagram Team
Copyright (C) 2005-2022 The Exult Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// istring.cpp -- case insensitive stl strings
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "istring.h"
#include <cctype>
#include <limits>
namespace Pentagram {
int strncasecmp(const char* s1, const char* s2, std::size_t length) {
sint32 c1;
do {
c1 = static_cast<unsigned char>(*s1++);
sint32 c2 = static_cast<unsigned char>(*s2++);
if ((length--) == 0) {
return 0; // strings are equal until end point
}
if (c1 != c2) {
c1 = std::toupper(c1);
c2 = std::toupper(c2);
if (c1 != c2) {
return (c1 < c2) ? -1 : 1; // strings not equal
}
}
} while (c1 != 0);
return 0; // strings are equal
}
int strcasecmp(const char* s1, const char* s2) {
return strncasecmp(s1, s2, std::numeric_limits<std::size_t>::max());
}
} // namespace Pentagram