Skip to content

Commit 034976a

Browse files
phlptpBillyDonahuebaylesj
authored
add a valueToQuotedString overload (open-source-parsers#1397)
* add a valueToQuotedString overload to take a string length to support things like a string_view more directly. * Apply suggestions from code review Co-authored-by: Billy Donahue <[email protected]> --------- Co-authored-by: Billy Donahue <[email protected]> Co-authored-by: Jordan Bayles <[email protected]>
1 parent e1a3c64 commit 034976a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

include/json/writer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ String JSON_API valueToString(
351351
PrecisionType precisionType = PrecisionType::significantDigits);
352352
String JSON_API valueToString(bool value);
353353
String JSON_API valueToQuotedString(const char* value);
354+
String JSON_API valueToQuotedString(const char* value, size_t length);
354355

355356
/// \brief Output using the StyledStreamWriter.
356357
/// \see Json::operator>>()

src/lib_json/json_writer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ String valueToQuotedString(const char* value) {
354354
return valueToQuotedStringN(value, strlen(value));
355355
}
356356

357+
String valueToQuotedString(const char* value, size_t length) {
358+
return valueToQuotedStringN(value, length);
359+
}
360+
357361
// Class Writer
358362
// //////////////////////////////////////////////////////////////////
359363
Writer::~Writer() = default;
@@ -491,7 +495,7 @@ void StyledWriter::writeValue(const Value& value) {
491495
const String& name = *it;
492496
const Value& childValue = value[name];
493497
writeCommentBeforeValue(childValue);
494-
writeWithIndent(valueToQuotedString(name.c_str()));
498+
writeWithIndent(valueToQuotedString(name.c_str(), name.size()));
495499
document_ += " : ";
496500
writeValue(childValue);
497501
if (++it == members.end()) {
@@ -709,7 +713,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
709713
const String& name = *it;
710714
const Value& childValue = value[name];
711715
writeCommentBeforeValue(childValue);
712-
writeWithIndent(valueToQuotedString(name.c_str()));
716+
writeWithIndent(valueToQuotedString(name.c_str(), name.size()));
713717
*document_ << " : ";
714718
writeValue(childValue);
715719
if (++it == members.end()) {

0 commit comments

Comments
 (0)