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
|
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef UTIL_STRING_UTIL_H_
#define UTIL_STRING_UTIL_H_
#include <string.h>
namespace base {
#if defined(_WIN32)
// Compare the two strings s1 and s2 without regard to case using
// the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
// s2 > s1 according to a lexicographic comparison.
inline int strcasecmp(const char* s1, const char* s2) {
return _stricmp(s1, s2);
}
inline int strncasecmp(const char* s1, const char* s2, size_t n) {
return _strnicmp(s1, s2, n);
}
#else
inline int strcasecmp(const char* s1, const char* s2) {
return ::strcasecmp(s1, s2);
}
inline int strncasecmp(const char* s1, const char* s2, size_t n) {
return ::strncasecmp(s1, s2, n);
}
#endif
}
#ifndef HAVE_MEMRCHR
#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 2)))
#define HAVE_MEMRCHR
#endif
#endif
#ifndef HAVE_MEMRCHR
inline void* memrchr(const void* s, int c, size_t n) {
const unsigned char* p = (const unsigned char*) s;
for (p += n; n > 0; n--) {
if (*--p == c)
return (void*) p;
}
return NULL;
}
#endif
#endif // UTIL_STRING_UTIL_H_
|