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__
12 #include <stddef.h> // For size_t
31 #include "build/build_config.h"
32 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
48 #if defined(__GNUC__) && !defined(USE_CXX0X) && !defined(OS_ANDROID)
50 #include <tr1/unordered_set>
51 using std::tr1::unordered_set
;
55 #include <unordered_set>
56 #if defined(WIN32) || defined(OS_ANDROID)
57 using std::tr1::unordered_set
;
59 using std::unordered_set
;
67 typedef uint8_t uint8
;
68 typedef int16_t int16
;
69 typedef uint16_t uint16
;
70 typedef int32_t int32
;
71 typedef uint32_t uint32
;
72 typedef int64_t int64
;
73 typedef uint64_t uint64
;
75 typedef unsigned long ulong
;
76 typedef unsigned int uint
;
77 typedef unsigned short ushort
;
79 // COMPILE_ASSERT causes a compile error about msg if expr is not true.
80 template<bool> struct CompileAssert
{};
81 #define COMPILE_ASSERT(expr, msg) \
82 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
84 // DISALLOW_EVIL_CONSTRUCTORS disallows the copy and operator= functions.
85 // It goes in the private: declarations in a class.
86 #define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
87 TypeName(const TypeName&); \
88 void operator=(const TypeName&)
90 #define arraysize(array) (sizeof(array)/sizeof((array)[0]))
94 string
CEscape(const StringPiece
& src
);
95 int CEscapeString(const char* src
, int src_len
, char* dest
, int dest_len
);
97 extern string
StringPrintf(const char* format
, ...);
98 extern void SStringPrintf(string
* dst
, const char* format
, ...);
99 extern void StringAppendF(string
* dst
, const char* format
, ...);
100 extern string
PrefixSuccessor(const StringPiece
& prefix
);
102 uint32
hashword(const uint32
*, size_t, uint32
);
103 void hashword2(const uint32
*, size_t, uint32
*, uint32
*);
105 static inline uint32
Hash32StringWithSeed(const char* s
, int len
, uint32 seed
) {
106 return hashword((uint32
*)s
, len
/4, seed
);
109 static inline uint64
Hash64StringWithSeed(const char* s
, int len
, uint32 seed
) {
113 hashword2((uint32
*)s
, len
/4, &x
, &y
);
114 return ((uint64
)x
<< 32) | y
;
119 #include "util/arena.h"
120 #include "util/logging.h"
121 #include "util/mutex.h"
122 #include "util/utf.h"
124 #endif // RE2_UTIL_UTIL_H__