This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
forked from litchie/exult-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
istring.cc
84 lines (64 loc) · 1.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Copyright (C) 1997-2001 Id Software, Inc.
Copyright (C) 2003 The Pentagram 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"
namespace Pentagram {
int strncasecmp(const char *s1, const char *s2, uint32 length) {
uint32 c1, c2;
do {
c1 = *s1++;
c2 = *s2++;
if (!length--)
return 0; // strings are equal until end point
if (c1 != c2) {
if (c1 >= 'a' && c1 <= 'z')
c1 -= ('a' - 'A');
if (c2 >= 'a' && c2 <= 'z')
c2 -= ('a' - 'A');
if (c1 != c2)
return (c1 < c2) ? -1 : 1; // strings not equal
}
} while (c1);
return 0; // strings are equal
}
int strcasecmp(const char *s1, const char *s2) {
return strncasecmp(s1, s2, 2147483647);
}
bool ichar_traits::eq(const char_type &c1, const char_type &c2) {
uint32 c3 = c1;
uint32 c4 = c2;
if (c3 >= 'a' && c3 <= 'z')
c3 -= ('a' - 'A');
if (c4 >= 'a' && c4 <= 'z')
c4 -= ('a' - 'A');
return c3 == c4;
}
bool ichar_traits::lt(const char_type &c1, const char_type &c2) {
uint32 c3 = c1;
uint32 c4 = c2;
if (c3 >= 'a' && c3 <= 'z')
c3 -= ('a' - 'A');
if (c4 >= 'a' && c4 <= 'z')
c4 -= ('a' - 'A');
return c3 < c4;
}
int ichar_traits::compare(const char_type *s1, const char_type *s2, size_t length) {
return strncasecmp(s1, s2, length);
}
}