~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/third_party/css_parser/src/strings/memutil.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Copyright 2010 Google Inc.
3
 
 *
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
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
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.
15
 
 */
16
 
#ifndef MEMUTIL_H_
17
 
#define MEMUTIL_H_
18
 
 
19
 
#include "strings/ascii_ctype.h"
20
 
 
21
 
// The ""'s catch people who don't pass in a literal for "str"
22
 
#define strliterallen(str) (sizeof("" str "")-1)
23
 
 
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);
27
 
 
28
 
  for ( int i = 0; i < len; i++ ) {
29
 
    const int diff =
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;
33
 
  }
34
 
  return 0;
35
 
}
36
 
 
37
 
#define memcaseis(str, len, literal)                            \
38
 
   ( (((len) == strliterallen(literal))                         \
39
 
      && memcasecmp(str, literal, strliterallen(literal)) == 0) )
40
 
 
41
 
#define memis(str, len, literal)                                \
42
 
   ( (((len) == strliterallen(literal))                         \
43
 
      && memcmp(str, literal, strliterallen(literal)) == 0) )
44
 
 
45
 
 
46
 
#endif  // MEMUTIL_H_