diff options
author | Jon Skeet <skeet@pobox.com> | 2015-07-14 09:53:35 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2015-07-14 09:53:35 +0100 |
commit | 24f8626cc918b5aa58d6d3377d295a95f7049776 (patch) | |
tree | 7552ec0c94adc5ee1cf4dff0d52c9110f98d2cb4 | |
parent | 9440a2abe3e3520fd6a1288f794f8bad0b26cb31 (diff) | |
parent | 8482b6c462d54beb45ecbb7748721bfcc5e3f3d4 (diff) | |
download | protobuf-24f8626cc918b5aa58d6d3377d295a95f7049776.tar.gz protobuf-24f8626cc918b5aa58d6d3377d295a95f7049776.tar.bz2 protobuf-24f8626cc918b5aa58d6d3377d295a95f7049776.zip |
Merge pull request #583 from jskeet/issue312
Pascal-case namespace automatically in C# codegen
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_helpers.cc | 8 | ||||
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_helpers.h | 6 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index da6a7633..8ecd1dc2 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -113,7 +113,7 @@ std::string GetFileNamespace(const FileDescriptor* descriptor) { if (descriptor->options().has_csharp_namespace()) { return descriptor->options().csharp_namespace(); } - return descriptor->package(); + return UnderscoresToCamelCase(descriptor->package(), true, true); } std::string GetUmbrellaClassNameInternal(const std::string& proto_file) { @@ -154,7 +154,8 @@ std::string GetFileUmbrellaNamespace(const FileDescriptor* descriptor) { // TODO(jtattermusch): can we reuse a utility function? std::string UnderscoresToCamelCase(const std::string& input, - bool cap_next_letter) { + bool cap_next_letter, + bool preserve_period) { string result; // Note: I distrust ctype.h due to locales. for (int i = 0; i < input.size(); i++) { @@ -180,6 +181,9 @@ std::string UnderscoresToCamelCase(const std::string& input, cap_next_letter = true; } else { cap_next_letter = true; + if (input[i] == '.' && preserve_period) { + result += '.'; + } } } // Add a trailing "_" if the name should be altered. diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index d9576fbd..bd3d6e7d 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -88,7 +88,11 @@ std::string GetPropertyName(const FieldDescriptor* descriptor); int GetFixedSize(FieldDescriptor::Type type); -std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter); +std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter, bool preserve_period); + +inline std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter) { + return UnderscoresToCamelCase(input, cap_next_letter, false); +} std::string UnderscoresToPascalCase(const std::string& input); |