Index: third_party/protobuf/src/google/protobuf/util/field_mask_util.h |
diff --git a/third_party/protobuf/src/google/protobuf/util/field_mask_util.h b/third_party/protobuf/src/google/protobuf/util/field_mask_util.h |
index 92f69893a01322c1dc4f933a8aa2094eff1e241e..644161b940190735e6956c0cedbf1c3aff63c933 100644 |
--- a/third_party/protobuf/src/google/protobuf/util/field_mask_util.h |
+++ b/third_party/protobuf/src/google/protobuf/util/field_mask_util.h |
@@ -45,11 +45,18 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { |
typedef google::protobuf::FieldMask FieldMask; |
public: |
- // Converts FieldMask to/from string, formatted according to proto3 JSON |
- // spec for FieldMask (e.g., "foo,bar,baz.quz"). |
+ // Converts FieldMask to/from string, formatted by separating each path |
+ // with a comma (e.g., "foo_bar,baz.quz"). |
static string ToString(const FieldMask& mask); |
static void FromString(StringPiece str, FieldMask* out); |
+ // Converts FieldMask to/from string, formatted according to proto3 JSON |
+ // spec for FieldMask (e.g., "fooBar,baz.quz"). If the field name is not |
+ // style conforming (i.e., not snake_case when converted to string, or not |
+ // camelCase when converted from string), the conversion will fail. |
+ static bool ToJsonString(const FieldMask& mask, string* out); |
+ static bool FromJsonString(StringPiece str, FieldMask* out); |
+ |
// Checks whether the given path is valid for type T. |
template <typename T> |
static bool IsValidPath(StringPiece path) { |
@@ -105,6 +112,35 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { |
const MergeOptions& options, Message* destination); |
private: |
+ friend class SnakeCaseCamelCaseTest; |
+ // Converts a field name from snake_case to camelCase: |
+ // 1. Every character after "_" will be converted to uppercase. |
+ // 2. All "_"s are removed. |
+ // The conversion will fail if: |
+ // 1. The field name contains uppercase letters. |
+ // 2. Any character after a "_" is not a lowercase letter. |
+ // If the conversion succeeds, it's guaranteed that the resulted |
+ // camelCase name will yield the original snake_case name when |
+ // converted using CamelCaseToSnakeCase(). |
+ // |
+ // Note that the input can contain characters not allowed in C identifiers. |
+ // For example, "foo_bar,baz_quz" will be converted to "fooBar,bazQuz" |
+ // successfully. |
+ static bool SnakeCaseToCamelCase(StringPiece input, string* output); |
+ // Converts a field name from camelCase to snake_case: |
+ // 1. Every uppercase letter is converted to lowercase with a additional |
+ // preceding "-". |
+ // The conversion will fail if: |
+ // 1. The field name contains "_"s. |
+ // If the conversion succeeds, it's guaranteed that the resulted |
+ // snake_case name will yield the original camelCase name when |
+ // converted using SnakeCaseToCamelCase(). |
+ // |
+ // Note that the input can contain characters not allowed in C identifiers. |
+ // For example, "fooBar,bazQuz" will be converted to "foo_bar,baz_quz" |
+ // successfully. |
+ static bool CamelCaseToSnakeCase(StringPiece input, string* output); |
+ |
static bool InternalIsValidPath(const Descriptor* descriptor, |
StringPiece path); |