2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
19
#include "strings/ascii_ctype.h"
21
// The ""'s catch people who don't pass in a literal for "str"
22
#define strliterallen(str) (sizeof("" str "")-1)
24
inline int memcasecmp(const char *s1, const char *s2, size_t len) {
25
const unsigned char *us1 = reinterpret_cast<const unsigned char *>(s1);
26
const unsigned char *us2 = reinterpret_cast<const unsigned char *>(s2);
28
for ( int i = 0; i < len; i++ ) {
30
static_cast<int>(static_cast<unsigned char>(ascii_tolower(us1[i]))) -
31
static_cast<int>(static_cast<unsigned char>(ascii_tolower(us2[i])));
32
if (diff != 0) return diff;
37
#define memcaseis(str, len, literal) \
38
( (((len) == strliterallen(literal)) \
39
&& memcasecmp(str, literal, strliterallen(literal)) == 0) )
41
#define memis(str, len, literal) \
42
( (((len) == strliterallen(literal)) \
43
&& memcmp(str, literal, strliterallen(literal)) == 0) )