Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / third_party / re2 / util / util.h
bloba4fdfcc936ac99577b5380216d3fe42f95a37f75
1 // Copyright 2009 The RE2 Authors. All Rights Reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 #ifndef RE2_UTIL_UTIL_H__
6 #define RE2_UTIL_UTIL_H__
8 // C
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdint.h>
12 #include <stddef.h> // For size_t
13 #include <assert.h>
14 #include <stdarg.h>
15 #ifndef WIN32
16 #include <sys/time.h>
17 #endif
18 #include <time.h>
19 #include <ctype.h> // For isdigit, isalpha.
21 // C++
22 #include <vector>
23 #include <string>
24 #include <algorithm>
25 #include <iosfwd>
26 #include <map>
27 #include <stack>
28 #include <ostream>
29 #include <utility>
30 #include <set>
32 #include "build/build_config.h"
33 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
35 // Use std names.
36 using std::set;
37 using std::pair;
38 using std::vector;
39 using std::string;
40 using std::min;
41 using std::max;
42 using std::ostream;
43 using std::map;
44 using std::stack;
45 using std::sort;
46 using std::swap;
47 using std::make_pair;
49 #if defined(__GNUC__) && !defined(USE_CXX0X) && !defined(_LIBCPP_ABI_VERSION) && !defined(OS_ANDROID)
51 #include <tr1/unordered_set>
52 using std::tr1::unordered_set;
54 #else
56 #include <unordered_set>
57 #if defined(WIN32) || (defined(OS_ANDROID) && !defined(_LIBCPP_ABI_VERSION))
58 using std::tr1::unordered_set;
59 #else
60 using std::unordered_set;
61 #endif
63 #endif
65 namespace re2 {
67 typedef int8_t int8;
68 typedef uint8_t uint8;
69 typedef int16_t int16;
70 typedef uint16_t uint16;
71 typedef int32_t int32;
72 typedef uint32_t uint32;
73 typedef int64_t int64;
74 typedef uint64_t uint64;
76 typedef unsigned long ulong;
77 typedef unsigned int uint;
78 typedef unsigned short ushort;
80 // COMPILE_ASSERT causes a compile error about msg if expr is not true.
81 #if __cplusplus >= 201103L
82 #define COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
83 #else
84 template<bool> struct CompileAssert {};
85 #define COMPILE_ASSERT(expr, msg) \
86 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
87 #endif
89 // DISALLOW_EVIL_CONSTRUCTORS disallows the copy and operator= functions.
90 // It goes in the private: declarations in a class.
91 #define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
92 TypeName(const TypeName&); \
93 void operator=(const TypeName&)
95 #define arraysize(array) (sizeof(array)/sizeof((array)[0]))
97 // Fake lock annotations. For real ones, see
98 // http://code.google.com/p/data-race-test/
99 #ifndef ANNOTATE_PUBLISH_MEMORY_RANGE
100 #define ANNOTATE_PUBLISH_MEMORY_RANGE(a, b)
101 #define ANNOTATE_IGNORE_WRITES_BEGIN()
102 #define ANNOTATE_IGNORE_WRITES_END()
103 #define ANNOTATE_BENIGN_RACE(a, b)
104 #define NO_THREAD_SAFETY_ANALYSIS
105 #define ANNOTATE_HAPPENS_BEFORE(x)
106 #define ANNOTATE_HAPPENS_AFTER(x)
107 #define ANNOTATE_UNPROTECTED_READ(x) (x)
108 #endif
110 class StringPiece;
112 string CEscape(const StringPiece& src);
113 int CEscapeString(const char* src, int src_len, char* dest, int dest_len);
115 extern string StringPrintf(const char* format, ...);
116 extern void SStringPrintf(string* dst, const char* format, ...);
117 extern void StringAppendF(string* dst, const char* format, ...);
118 extern string PrefixSuccessor(const StringPiece& prefix);
120 uint32 hashword(const uint32*, size_t, uint32);
121 void hashword2(const uint32*, size_t, uint32*, uint32*);
123 static inline uint32 Hash32StringWithSeed(const char* s, int len, uint32 seed) {
124 return hashword((uint32*)s, len/4, seed);
127 static inline uint64 Hash64StringWithSeed(const char* s, int len, uint32 seed) {
128 uint32 x, y;
129 x = seed;
130 y = 0;
131 hashword2((uint32*)s, len/4, &x, &y);
132 return ((uint64)x << 32) | y;
135 inline bool RunningOnValgrindOrMemorySanitizer() {
136 #if defined(MEMORY_SANITIZER)
137 return true;
138 #else
139 return RunningOnValgrind();
140 #endif
143 } // namespace re2
145 #include "util/arena.h"
146 #include "util/logging.h"
147 #include "util/mutex.h"
148 #include "util/utf.h"
150 #endif // RE2_UTIL_UTIL_H__