2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
19 #include <folly/Range.h>
24 ///////////////////////////////////////////////////////////////////////////////
26 // chrcaseeq performs a case insensitive comparison and returns true if the
27 // characters are equal, false otherwise
28 inline bool chrcaseeq(char left
, char right
) {
29 char k
= left
^ right
;
30 if (k
== 0) return true;
31 if (k
!= 32) return false;
35 // chrcasecmp performs a case insensitive comparison and returns < 0 if left
36 // is less than right, > 0 if left is greater than right, and 0 if the
37 // characters are equal
38 inline int chrcasecmp(char left
, char right
) {
39 if (chrcaseeq(left
, right
)) return 0;
40 if (left
>= 'A' && left
<= 'Z') left
+= 32;
41 if (right
>= 'A' && right
<= 'Z') right
+= 32;
42 return (int)(unsigned char)left
- (int)(unsigned char)right
;
45 // Given two binary strings of equal length, bstrcaseeq does a case insensitive
46 // comparison and returns true if the strings are equal, false otherwise
47 bool bstrcaseeq(const char* left
, const char* right
, size_t n
);
49 // Given two binary strings (possibly of different lengths), bstrcasecmp
50 // does a case insensitive comparison and returns < 0 if left is less than
51 // right, > 0 if left is greater than right, and 0 if the strings are equal
52 int bstrcasecmp(const char* left
, size_t leftSize
,
53 const char* right
, size_t rightSize
);
54 inline int bstrcasecmp(folly::StringPiece left
, folly::StringPiece right
) {
55 return bstrcasecmp(left
.begin(), left
.size(), right
.begin(), right
.size());
58 // Given a binary string haystack and a character needle, bstrcasechr performs
59 // a case insensitive search and returns a pointer to the first occurrence of
60 // needle in haystack, or NULL if needle is not part of haystack
61 char* bstrcasechr(const char* haystack
, char needle
, size_t haystackSize
);
63 // Given two binary strings haystack and needle, bstrcasestr performs a case
64 // insensitive search and returns a pointer to the first occurrence of needle
65 // in haystack, or NULL if needle is not part of haystack. If needleSize is 0,
66 // this function will return haystack.
67 char* bstrcasestr(const char* haystack
, size_t haystackSize
,
68 const char* needle
, size_t needleSize
);
70 // Given a binary strings haystack and a character needle, bstrcasestr performs
71 // a case insensitive search and returns a pointer to the last occurrence of
72 // needle in haystack, or NULL if needle is not part of haystack
73 char* bstrrcasechr(const char* haystack
, char needle
, size_t haystackSize
);
75 // Given two binary strings haystack and needle, bstrcasestr performs a case
76 // insensitive search and returns a pointer to the last occurrence of needle in
77 // haystack, or NULL if needle is not part of haystack. If needleSize is 0,
78 // this function returns haystack + haystackSize.
79 char* bstrrcasestr(const char* haystack
, size_t haystackSize
,
80 const char* needle
, size_t needleSize
);
82 // Given two binary strings haystack and needle, bstrrstr performs a case
83 // sensitive search and returns a pointer to the last occurrence of needle in
84 // haystack, or NULL if needle is not part of haystack. If needleSize is 0,
85 // this function returns haystack + haystackSize.
86 char* bstrrstr(const char* haystack
, size_t haystackSize
,
87 const char* needle
, size_t needleSize
);
89 ///////////////////////////////////////////////////////////////////////////////