Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
5c20ca1f
Commit
5c20ca1f
authored
Dec 21, 2010
by
liujisi@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Escape C++ Trigraphs.
parent
334dfc21
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
4 deletions
+28
-4
GeneratedMessageTest.java
...c/test/java/com/google/protobuf/GeneratedMessageTest.java
+1
-0
generator_test.py
python/google/protobuf/internal/generator_test.py
+1
-0
cpp_file.cc
src/google/protobuf/compiler/cpp/cpp_file.cc
+1
-1
cpp_helpers.cc
src/google/protobuf/compiler/cpp/cpp_helpers.cc
+7
-1
cpp_helpers.h
src/google/protobuf/compiler/cpp/cpp_helpers.h
+3
-0
cpp_string_field.cc
src/google/protobuf/compiler/cpp/cpp_string_field.cc
+1
-2
cpp_unittest.cc
src/google/protobuf/compiler/cpp/cpp_unittest.cc
+7
-0
unittest.proto
src/google/protobuf/unittest.proto
+7
-0
No files found.
java/src/test/java/com/google/protobuf/GeneratedMessageTest.java
View file @
5c20ca1f
...
@@ -410,6 +410,7 @@ public class GeneratedMessageTest extends TestCase {
...
@@ -410,6 +410,7 @@ public class GeneratedMessageTest extends TestCase {
assertEquals
(
Float
.
POSITIVE_INFINITY
,
message
.
getInfFloat
());
assertEquals
(
Float
.
POSITIVE_INFINITY
,
message
.
getInfFloat
());
assertEquals
(
Float
.
NEGATIVE_INFINITY
,
message
.
getNegInfFloat
());
assertEquals
(
Float
.
NEGATIVE_INFINITY
,
message
.
getNegInfFloat
());
assertTrue
(
Float
.
isNaN
(
message
.
getNanFloat
()));
assertTrue
(
Float
.
isNaN
(
message
.
getNanFloat
()));
assertEquals
(
"? ? ?? ?? ??? ??/ ??-"
,
message
.
getCppTrigraph
());
}
}
public
void
testClear
()
throws
Exception
{
public
void
testClear
()
throws
Exception
{
...
...
python/google/protobuf/internal/generator_test.py
View file @
5c20ca1f
...
@@ -100,6 +100,7 @@ class GeneratorTest(unittest.TestCase):
...
@@ -100,6 +100,7 @@ class GeneratorTest(unittest.TestCase):
self
.
assertTrue
(
isinf
(
message
.
neg_inf_float
))
self
.
assertTrue
(
isinf
(
message
.
neg_inf_float
))
self
.
assertTrue
(
message
.
neg_inf_float
<
0
)
self
.
assertTrue
(
message
.
neg_inf_float
<
0
)
self
.
assertTrue
(
isnan
(
message
.
nan_float
))
self
.
assertTrue
(
isnan
(
message
.
nan_float
))
self
.
assertEqual
(
"? ? ?? ?? ??? ??/ ??-"
,
message
.
cpp_trigraph
)
def
testHasDefaultValues
(
self
):
def
testHasDefaultValues
(
self
):
desc
=
unittest_pb2
.
TestAllTypes
.
DESCRIPTOR
desc
=
unittest_pb2
.
TestAllTypes
.
DESCRIPTOR
...
...
src/google/protobuf/compiler/cpp/cpp_file.cc
View file @
5c20ca1f
...
@@ -541,7 +541,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
...
@@ -541,7 +541,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
static
const
int
kBytesPerLine
=
40
;
static
const
int
kBytesPerLine
=
40
;
for
(
int
i
=
0
;
i
<
file_data
.
size
();
i
+=
kBytesPerLine
)
{
for
(
int
i
=
0
;
i
<
file_data
.
size
();
i
+=
kBytesPerLine
)
{
printer
->
Print
(
"
\n
\"
$data$
\"
"
,
printer
->
Print
(
"
\n
\"
$data$
\"
"
,
"data"
,
CEscape
(
file_data
.
substr
(
i
,
kBytesPerLine
)));
"data"
,
EscapeTrigraphs
(
CEscape
(
file_data
.
substr
(
i
,
kBytesPerLine
)
)));
}
}
printer
->
Print
(
printer
->
Print
(
", $size$);
\n
"
,
", $size$);
\n
"
,
...
...
src/google/protobuf/compiler/cpp/cpp_helpers.cc
View file @
5c20ca1f
...
@@ -292,7 +292,8 @@ string DefaultValue(const FieldDescriptor* field) {
...
@@ -292,7 +292,8 @@ string DefaultValue(const FieldDescriptor* field) {
ClassName
(
field
->
enum_type
(),
true
),
ClassName
(
field
->
enum_type
(),
true
),
field
->
default_value_enum
()
->
number
());
field
->
default_value_enum
()
->
number
());
case
FieldDescriptor
:
:
CPPTYPE_STRING
:
case
FieldDescriptor
:
:
CPPTYPE_STRING
:
return
"
\"
"
+
CEscape
(
field
->
default_value_string
())
+
"
\"
"
;
return
"
\"
"
+
EscapeTrigraphs
(
CEscape
(
field
->
default_value_string
()))
+
"
\"
"
;
case
FieldDescriptor
:
:
CPPTYPE_MESSAGE
:
case
FieldDescriptor
:
:
CPPTYPE_MESSAGE
:
return
FieldMessageTypeName
(
field
)
+
"::default_instance()"
;
return
FieldMessageTypeName
(
field
)
+
"::default_instance()"
;
}
}
...
@@ -335,6 +336,11 @@ string GlobalShutdownFileName(const string& filename) {
...
@@ -335,6 +336,11 @@ string GlobalShutdownFileName(const string& filename) {
return
"protobuf_ShutdownFile_"
+
FilenameIdentifier
(
filename
);
return
"protobuf_ShutdownFile_"
+
FilenameIdentifier
(
filename
);
}
}
// Escape C++ trigraphs by escaping question marks to \?
string
EscapeTrigraphs
(
const
string
&
to_escape
)
{
return
StringReplace
(
to_escape
,
"?"
,
"
\\
?"
,
true
);
}
}
// namespace cpp
}
// namespace cpp
}
// namespace compiler
}
// namespace compiler
}
// namespace protobuf
}
// namespace protobuf
...
...
src/google/protobuf/compiler/cpp/cpp_helpers.h
View file @
5c20ca1f
...
@@ -112,6 +112,9 @@ string GlobalAssignDescriptorsName(const string& filename);
...
@@ -112,6 +112,9 @@ string GlobalAssignDescriptorsName(const string& filename);
// Return the name of the ShutdownFile() function for a given file.
// Return the name of the ShutdownFile() function for a given file.
string
GlobalShutdownFileName
(
const
string
&
filename
);
string
GlobalShutdownFileName
(
const
string
&
filename
);
// Escape C++ trigraphs by escaping question marks to \?
string
EscapeTrigraphs
(
const
string
&
to_escape
);
// Do message classes in this file keep track of unknown fields?
// Do message classes in this file keep track of unknown fields?
inline
bool
HasUnknownFields
(
const
FileDescriptor
*
file
)
{
inline
bool
HasUnknownFields
(
const
FileDescriptor
*
file
)
{
return
file
->
options
().
optimize_for
()
!=
FileOptions
::
LITE_RUNTIME
;
return
file
->
options
().
optimize_for
()
!=
FileOptions
::
LITE_RUNTIME
;
...
...
src/google/protobuf/compiler/cpp/cpp_string_field.cc
View file @
5c20ca1f
...
@@ -48,8 +48,7 @@ namespace {
...
@@ -48,8 +48,7 @@ namespace {
void
SetStringVariables
(
const
FieldDescriptor
*
descriptor
,
void
SetStringVariables
(
const
FieldDescriptor
*
descriptor
,
map
<
string
,
string
>*
variables
)
{
map
<
string
,
string
>*
variables
)
{
SetCommonFieldVariables
(
descriptor
,
variables
);
SetCommonFieldVariables
(
descriptor
,
variables
);
(
*
variables
)[
"default"
]
=
(
*
variables
)[
"default"
]
=
DefaultValue
(
descriptor
);
"
\"
"
+
CEscape
(
descriptor
->
default_value_string
())
+
"
\"
"
;
(
*
variables
)[
"default_variable"
]
=
descriptor
->
default_value_string
().
empty
()
(
*
variables
)[
"default_variable"
]
=
descriptor
->
default_value_string
().
empty
()
?
"::google::protobuf::internal::kEmptyString"
?
"::google::protobuf::internal::kEmptyString"
:
"_default_"
+
FieldName
(
descriptor
)
+
"_"
;
:
"_default_"
+
FieldName
(
descriptor
)
+
"_"
;
...
...
src/google/protobuf/compiler/cpp/cpp_unittest.cc
View file @
5c20ca1f
...
@@ -167,6 +167,13 @@ TEST(GeneratedMessageTest, FloatingPointDefaults) {
...
@@ -167,6 +167,13 @@ TEST(GeneratedMessageTest, FloatingPointDefaults) {
EXPECT_TRUE
(
extreme_default
.
nan_float
()
!=
extreme_default
.
nan_float
());
EXPECT_TRUE
(
extreme_default
.
nan_float
()
!=
extreme_default
.
nan_float
());
}
}
TEST
(
GeneratedMessageTest
,
Trigraph
)
{
const
unittest
::
TestExtremeDefaultValues
&
extreme_default
=
unittest
::
TestExtremeDefaultValues
::
default_instance
();
EXPECT_EQ
(
"? ? ?? ?? ??? ?\?/ ?\?-"
,
extreme_default
.
cpp_trigraph
());
}
TEST
(
GeneratedMessageTest
,
Accessors
)
{
TEST
(
GeneratedMessageTest
,
Accessors
)
{
// Set every field to a unique value then go back and check all those
// Set every field to a unique value then go back and check all those
// values.
// values.
...
...
src/google/protobuf/unittest.proto
View file @
5c20ca1f
...
@@ -493,6 +493,13 @@ message TestExtremeDefaultValues {
...
@@ -493,6 +493,13 @@ message TestExtremeDefaultValues {
optional
float
inf_float
=
17
[
default
=
inf
];
optional
float
inf_float
=
17
[
default
=
inf
];
optional
float
neg_inf_float
=
18
[
default
=
-inf
];
optional
float
neg_inf_float
=
18
[
default
=
-inf
];
optional
float
nan_float
=
19
[
default
=
nan
];
optional
float
nan_float
=
19
[
default
=
nan
];
// Tests for C++ trigraphs.
// Trigraphs should be escaped in C++ generated files, but they should not be
// escaped for other languages.
// Note that in .proto file, "\?" is a valid way to escape ? in string
// literals.
optional
string
cpp_trigraph
=
20
[
default
=
"? \? ?? \?? \??? ??/ ?\?-"
];
}
}
message
SparseEnumMessage
{
message
SparseEnumMessage
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment