xref: /aosp_15_r20/external/cronet/third_party/ced/src/util/string_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 #ifndef UTIL_STRING_UTIL_H_
18 #define UTIL_STRING_UTIL_H_
19 
20 #include <string.h>
21 
22 namespace base {
23 
24 #if defined(_WIN32)
25 // Compare the two strings s1 and s2 without regard to case using
26 // the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
27 // s2 > s1 according to a lexicographic comparison.
strcasecmp(const char * s1,const char * s2)28 inline int strcasecmp(const char* s1, const char* s2) {
29   return _stricmp(s1, s2);
30 }
strncasecmp(const char * s1,const char * s2,size_t n)31 inline int strncasecmp(const char* s1, const char* s2, size_t n) {
32   return _strnicmp(s1, s2, n);
33 }
34 #else
35 inline int strcasecmp(const char* s1, const char* s2) {
36   return ::strcasecmp(s1, s2);
37 }
38 inline int strncasecmp(const char* s1, const char* s2, size_t n) {
39   return ::strncasecmp(s1, s2, n);
40 }
41 #endif
42 }
43 
44 #if !defined(__linux__)
memrchr(const void * s,int c,size_t n)45 inline void* memrchr(const void* s, int c, size_t n) {
46   const unsigned char* p = (const unsigned char*) s;
47   for (p += n; n > 0; n--) {
48     if (*--p == c)
49       return (void*) p;
50   }
51   return NULL;
52 }
53 #endif
54 
55 #endif  // UTIL_STRING_UTIL_H_
56