-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_utils.h
53 lines (46 loc) · 994 Bytes
/
string_utils.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
#ifndef RDESTL_STRING_UTILS_H
#define RDESTL_STRING_UTILS_H
namespace rde
{
//-----------------------------------------------------------------------------
template<typename T> int strlen(const T* str)
{
int len(0);
while (*str++)
++len;
return len;
}
//-----------------------------------------------------------------------------
template<typename T> int strcompare(const T* s1, const T* s2, size_t len)
{
for (/**/; len != 0; --len)
{
const T c1 = *s1;
const T c2 = *s2;
if (c1 != c2)
return (c1 < c2 ? -1 : 1);
++s1;
++s2;
}
return 0;
}
//-----------------------------------------------------------------------------
template<typename T> int strcompare(const T* s1, const T* s2)
{
while (*s1 && *s2)
{
const T c1 = *s1;
const T c2 = *s2;
if (c1 != c2)
return (c1 < c2 ? -1 : 1);
++s1;
++s2;
}
if (*s1)
return 1;
if (*s2)
return -1;
return 0;
}
} // rde
#endif // RDESTL_STRING_UTILS_H