aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/stubs
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2016-03-30 11:39:59 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2016-03-30 11:39:59 -0700
commit3b3c8abb9635eb3ea078a821a99c9ef29d66dff7 (patch)
tree7d2ec154f15c9f9153d890e76b6cf30e471ea488 /src/google/protobuf/stubs
parent78105897a8f01c7be9cf8502b6c58d47eb1ccdd7 (diff)
Integrate google internal changes.
Diffstat (limited to 'src/google/protobuf/stubs')
-rwxr-xr-xsrc/google/protobuf/stubs/hash.h12
-rw-r--r--src/google/protobuf/stubs/logging.h2
-rw-r--r--src/google/protobuf/stubs/mathutil.h2
-rw-r--r--src/google/protobuf/stubs/stringpiece.h38
-rw-r--r--src/google/protobuf/stubs/strutil.h8
5 files changed, 60 insertions, 2 deletions
diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h
index 58334322..bbd8ee65 100755
--- a/src/google/protobuf/stubs/hash.h
+++ b/src/google/protobuf/stubs/hash.h
@@ -214,6 +214,8 @@ class hash_map : public std::map<Key, Data, HashFcn, Alloc> {
hash_map(int a = 0, const HashFcn& b = HashFcn(),
const EqualKey& c = EqualKey(),
const Alloc& d = Alloc()) : BaseClass(b, d) {}
+
+ HashFcn hash_function() const { return HashFcn(); }
};
template <typename Key,
@@ -222,6 +224,8 @@ template <typename Key,
class hash_set : public std::set<Key, HashFcn> {
public:
hash_set(int = 0) {}
+
+ HashFcn hash_function() const { return HashFcn(); }
};
#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION)
@@ -257,6 +261,8 @@ class hash_map
hash_map(int a = 0, const HashFcn& b = HashFcn(),
const EqualKey& c = EqualKey(),
const Alloc& d = Alloc()) : BaseClass(a, b, c, d) {}
+
+ HashFcn hash_function() const { return HashFcn(); }
};
template <typename Key, typename HashFcn = hash<Key>,
@@ -266,6 +272,8 @@ class hash_set
Key, HashFcn, EqualKey> {
public:
hash_set(int = 0) {}
+
+ HashFcn hash_function() const { return HashFcn(); }
};
#else
@@ -315,6 +323,8 @@ class hash_map
hash_map(int a = 0, const HashFcn& b = HashFcn(),
const EqualKey& c = EqualKey(),
const Alloc& d = Alloc()) : BaseClass(a, b, c, d) {}
+
+ HashFcn hash_function() const { return HashFcn(); }
};
template <typename Key, typename HashFcn = hash<Key>,
@@ -324,6 +334,8 @@ class hash_set
Key, HashFcn, EqualKey> {
public:
hash_set(int = 0) {}
+
+ HashFcn hash_function() const { return HashFcn(); }
};
#endif // !GOOGLE_PROTOBUF_MISSING_HASH
diff --git a/src/google/protobuf/stubs/logging.h b/src/google/protobuf/stubs/logging.h
index 3108db8c..f69605d9 100644
--- a/src/google/protobuf/stubs/logging.h
+++ b/src/google/protobuf/stubs/logging.h
@@ -174,7 +174,7 @@ T* CheckNotNull(const char* /* file */, int /* line */,
#ifdef NDEBUG
-#define GOOGLE_DLOG GOOGLE_LOG_IF(INFO, false)
+#define GOOGLE_DLOG(LEVEL) GOOGLE_LOG_IF(LEVEL, false)
#define GOOGLE_DCHECK(EXPRESSION) while(false) GOOGLE_CHECK(EXPRESSION)
#define GOOGLE_DCHECK_OK(E) GOOGLE_DCHECK(::google::protobuf::internal::IsOk(E))
diff --git a/src/google/protobuf/stubs/mathutil.h b/src/google/protobuf/stubs/mathutil.h
index 3a1ef8a8..27956a8e 100644
--- a/src/google/protobuf/stubs/mathutil.h
+++ b/src/google/protobuf/stubs/mathutil.h
@@ -83,7 +83,7 @@ class MathUtil {
if (value == T(0) || ::google::protobuf::internal::IsNan<T>(value)) {
return value;
}
- return value > T(0) ? value : -value;
+ return value > T(0) ? 1 : -1;
}
template<typename T>
diff --git a/src/google/protobuf/stubs/stringpiece.h b/src/google/protobuf/stubs/stringpiece.h
index ec3ffd5b..91671659 100644
--- a/src/google/protobuf/stubs/stringpiece.h
+++ b/src/google/protobuf/stubs/stringpiece.h
@@ -435,6 +435,44 @@ inline bool operator>=(StringPiece x, StringPiece y) {
// allow StringPiece to be logged
extern std::ostream& operator<<(std::ostream& o, StringPiece piece);
+namespace internal {
+// StringPiece is not a POD and can not be used in an union (pre C++11). We
+// need a POD version of it.
+struct StringPiecePod {
+ // Create from a StringPiece.
+ static StringPiecePod CreateFromStringPiece(StringPiece str) {
+ StringPiecePod pod;
+ pod.data_ = str.data();
+ pod.size_ = str.size();
+ return pod;
+ }
+
+ // Cast to StringPiece.
+ operator StringPiece() const { return StringPiece(data_, size_); }
+
+ bool operator==(const char* value) const {
+ return StringPiece(data_, size_) == StringPiece(value);
+ }
+
+ char operator[](stringpiece_ssize_type i) const {
+ assert(0 <= i);
+ assert(i < size_);
+ return data_[i];
+ }
+
+ const char* data() const { return data_; }
+
+ stringpiece_ssize_type size() const {
+ return size_;
+ }
+
+ std::string ToString() const { return std::string(data_, size_); }
+ private:
+ const char* data_;
+ stringpiece_ssize_type size_;
+};
+
+} // namespace internal
} // namespace protobuf
} // namespace google
diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h
index 27d47575..8bdd6110 100644
--- a/src/google/protobuf/stubs/strutil.h
+++ b/src/google/protobuf/stubs/strutil.h
@@ -648,6 +648,9 @@ struct LIBPROTOBUF_EXPORT AlphaNum {
AlphaNum(StringPiece str)
: piece_data_(str.data()), piece_size_(str.size()) {}
+ AlphaNum(internal::StringPiecePod str)
+ : piece_data_(str.data()), piece_size_(str.size()) {}
+
size_t size() const { return piece_size_; }
const char *data() const { return piece_data_; }
@@ -847,6 +850,11 @@ LIBPROTOBUF_EXPORT void Base64Escape(const unsigned char* src, int szsrc,
LIBPROTOBUF_EXPORT void WebSafeBase64Escape(const unsigned char* src, int szsrc,
string* dest, bool do_padding);
+inline bool IsValidCodePoint(uint32 code_point) {
+ return code_point < 0xD800 ||
+ (code_point >= 0xE000 && code_point <= 0x10FFFF);
+}
+
static const int UTFmax = 4;
// ----------------------------------------------------------------------
// EncodeAsUTF8Char()