aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/stubs/common.h
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2015-08-21 11:18:45 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2015-08-21 11:18:45 -0700
commitb0f661181d10bddc08e380992590a1cdd92be92b (patch)
treed9291cf324a72206ae3e474fe49186e8c96b2a9e /src/google/protobuf/stubs/common.h
parentd119a275495b7dcc9c389c9c650ebd83de265511 (diff)
Down-integrate from internal branch.
Change-Id: Ieb7a2c2fbf35bc2a8fa65b915a5ecb68c83863e4
Diffstat (limited to 'src/google/protobuf/stubs/common.h')
-rw-r--r--src/google/protobuf/stubs/common.h24
1 files changed, 24 insertions, 0 deletions
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 <string>
#include <google/protobuf/stubs/port.h>
#include <google/protobuf/stubs/macros.h>
@@ -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