Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8694620

Browse filesBrowse files
Internal change
PiperOrigin-RevId: 759439360
1 parent acd71c7 commit 8694620
Copy full SHA for 8694620

File tree

3 files changed

+12
-0
lines changed
Filter options

3 files changed

+12
-0
lines changed

‎src/google/protobuf/compiler/cpp/field.cc

Copy file name to clipboardExpand all lines: src/google/protobuf/compiler/cpp/field.cc
+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ std::vector<Sub> FieldVars(const FieldDescriptor* field, const Options& opts) {
5858
{"field_", FieldMemberName(field, split)},
5959
{"DeclaredType", DeclaredTypeMethodName(field->type())},
6060
{"DeclaredCppType", DeclaredCppTypeMethodName(field->cpp_type())},
61+
{"Utf8", IsStrictUtf8String(field, opts) ? "Utf8" : "Raw"},
6162
{"kTagBytes", WireFormat::TagSize(field->number(), field->type())},
6263
Sub("PrepareSplitMessageForWrite",
6364
split ? "PrepareSplitMessageForWrite();" : "")

‎src/google/protobuf/compiler/cpp/helpers.cc

Copy file name to clipboardExpand all lines: src/google/protobuf/compiler/cpp/helpers.cc
+9
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,15 @@ void NamespaceOpener::ChangeTo(absl::string_view name,
14691469
name_stack_ = std::move(new_stack);
14701470
}
14711471

1472+
bool IsStrictUtf8String(const FieldDescriptor* field, const Options& options) {
1473+
if (field->type() != FieldDescriptor::TYPE_STRING) return false;
1474+
1475+
bool is_lite =
1476+
GetOptimizeFor(field->file(), options) == FileOptions::LITE_RUNTIME;
1477+
return internal::cpp::GetUtf8CheckMode(field, is_lite) ==
1478+
internal::cpp::Utf8CheckMode::kStrict;
1479+
}
1480+
14721481
static void GenerateUtf8CheckCode(io::Printer* p, const FieldDescriptor* field,
14731482
const Options& options, bool for_parse,
14741483
absl::string_view params,

‎src/google/protobuf/compiler/cpp/helpers.h

Copy file name to clipboardExpand all lines: src/google/protobuf/compiler/cpp/helpers.h
+2
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ void GenerateUtf8CheckCodeForCord(io::Printer* p, const FieldDescriptor* field,
11441144
const Options& options, bool for_parse,
11451145
absl::string_view parameters);
11461146

1147+
bool IsStrictUtf8String(const FieldDescriptor* field, const Options& options);
1148+
11471149
inline bool ShouldGenerateExternSpecializations(const Options& options) {
11481150
// For OSS we omit the specializations to reduce codegen size.
11491151
// Some compilers can't handle that much input in a single translation unit.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.