-
Notifications
You must be signed in to change notification settings - Fork 14
feat: streaming Value STRING only quotes in aggregates #1401
Conversation
Fixes: googleapis#1391 This PR changes the way `Value(string)` streams its values. Specifically, double quotes are no longer included when streaming scalar `Value(string)` values. For example: `std::cout << Value("foo")` would output `foo` (no quotes). This behavior matches that of `std::cout << std::string("foo")`. However, when streaming strings as part of an aggregate type (std::vector or std::tuple), strings *will be* wrapped in double quotes so that the contents of the string does not break the structure/formatting of the printed array/struct itself. Any double quotes in the string itself will be backslash escaped. This PR also adds double-quoting to field names in tuples, which are strings and should therefore also be quoted like other string fields in aggregates.
Codecov Report
@@ Coverage Diff @@
## master #1401 +/- ##
==========================================
- Coverage 94.38% 94.35% -0.03%
==========================================
Files 190 191 +1
Lines 15659 15711 +52
==========================================
+ Hits 14779 14824 +45
- Misses 880 887 +7
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, one suggestion for you to consider. If it does not work I am Okay with merging as-is.
Reviewed 3 of 3 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @devbww and @devjgm)
google/cloud/spanner/value.cc, line 98 at r1 (raw file):
std::ostream& EscapeQuotes(std::ostream& os, std::string const& s) { for (auto const& c : s) { if (c == '"') os << "\\";
Hmm... Is the goal to make the output usable as a string literal in SQL? Then maybe using triple quotes as a delimiter would be simpler?
https://cloud.google.com/spanner/docs/lexical#string_and_bytes_literals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @coryan and @devbww)
google/cloud/spanner/value.cc, line 98 at r1 (raw file):
Previously, coryan (Carlos O'Ryan) wrote…
Hmm... Is the goal to make the output usable as a string literal in SQL? Then maybe using triple quotes as a delimiter would be simpler?
https://cloud.google.com/spanner/docs/lexical#string_and_bytes_literals
Producing Spanner string literals is explicitly not a goal.
Even if we wrapped strings in triple quotes, I believe we'd still need to escape triple quotes that appeared in the string data, so I'm not sure if it'd be simpler.
…ogle-cloud-cpp-spanner#1401) * feat: streaming Value STRING only quotes in aggregates Fixes: googleapis/google-cloud-cpp-spanner#1391 This PR changes the way `Value(string)` streams its values. Specifically, double quotes are no longer included when streaming scalar `Value(string)` values. For example: `std::cout << Value("foo")` would output `foo` (no quotes). This behavior matches that of `std::cout << std::string("foo")`. However, when streaming strings as part of an aggregate type (std::vector or std::tuple), strings *will be* wrapped in double quotes so that the contents of the string does not break the structure/formatting of the printed array/struct itself. Any double quotes in the string itself will be backslash escaped. This PR also adds double-quoting to field names in tuples, which are strings and should therefore also be quoted like other string fields in aggregates. * quiet switch fallthrough warning
Fixes: #1391
This PR changes the way
Value(string)
streams its values.Specifically, double quotes are no longer included when streaming scalar
Value(string)
values. For example:std::cout << Value("foo")
wouldoutput
foo
(no quotes). This behavior matches that ofstd::cout << std::string("foo")
.However, when streaming strings as part of an aggregate type
(std::vector or std::tuple), strings will be wrapped in double quotes
so that the contents of the string does not break the
structure/formatting of the printed array/struct itself. Any double
quotes in the string itself will be backslash escaped.
This PR also adds double-quoting to field names in tuples, which are
strings and should therefore also be quoted like other string fields in
aggregates.
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)