From b0f661181d10bddc08e380992590a1cdd92be92b Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 21 Aug 2015 11:18:45 -0700 Subject: Down-integrate from internal branch. Change-Id: Ieb7a2c2fbf35bc2a8fa65b915a5ecb68c83863e4 --- src/google/protobuf/stubs/common.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/google/protobuf/stubs/common.h') diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index de866e14..88e7084f 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -35,6 +35,7 @@ #ifndef GOOGLE_PROTOBUF_COMMON_H__ #define GOOGLE_PROTOBUF_COMMON_H__ +#include #include #include @@ -137,12 +138,35 @@ std::string LIBPROTOBUF_EXPORT VersionString(int version); // =================================================================== // from google3/util/utf8/public/unilib.h +class StringPiece; namespace internal { // Checks if the buffer contains structurally-valid UTF-8. Implemented in // structurally_valid.cc. LIBPROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len); +inline bool IsStructurallyValidUTF8(const std::string& str) { + return IsStructurallyValidUTF8(str.data(), str.length()); +} + +// Returns initial number of bytes of structually valid UTF-8. +LIBPROTOBUF_EXPORT int UTF8SpnStructurallyValid(const StringPiece& str); + +// Coerce UTF-8 byte string in src_str to be +// a structurally-valid equal-length string by selectively +// overwriting illegal bytes with replace_char (typically ' ' or '?'). +// replace_char must be legal printable 7-bit Ascii 0x20..0x7e. +// src_str is read-only. +// +// Returns pointer to output buffer, src_str.data() if no changes were made, +// or idst if some bytes were changed. idst is allocated by the caller +// and must be at least as big as src_str +// +// Optimized for: all structurally valid and no byte copying is done. +// +LIBPROTOBUF_EXPORT char* UTF8CoerceToStructurallyValid( + const StringPiece& str, char* dst, char replace_char); + } // namespace internal -- cgit v1.2.3