Skip to content

Commit 1c0db7d

Browse files
committed
add a valueToQuotedString overload to take a string length to support things like a string_view more directly.
1 parent 42e892d commit 1c0db7d

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
@@ -354,6 +354,7 @@ String JSON_API valueToString(
354354
PrecisionType precisionType = PrecisionType::significantDigits);
355355
String JSON_API valueToString(bool value);
356356
String JSON_API valueToQuotedString(const char* value);
357+
String JSON_API valueToQuotedString(const char* value, size_t length);
357358

358359
/// \brief Output using the StyledStreamWriter.
359360
/// \see Json::operator>>()

src/lib_json/json_writer.cpp

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

356+
String valueToQuotedString(const char* value, size_t length) {
357+
return valueToQuotedStringN(value, length);
358+
}
359+
356360
// Class Writer
357361
// //////////////////////////////////////////////////////////////////
358362
Writer::~Writer() = default;
@@ -490,7 +494,7 @@ void StyledWriter::writeValue(const Value& value) {
490494
const String& name = *it;
491495
const Value& childValue = value[name];
492496
writeCommentBeforeValue(childValue);
493-
writeWithIndent(valueToQuotedString(name.c_str()));
497+
writeWithIndent(valueToQuotedString(name.c_str(),name.size()));
494498
document_ += " : ";
495499
writeValue(childValue);
496500
if (++it == members.end()) {
@@ -708,7 +712,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
708712
const String& name = *it;
709713
const Value& childValue = value[name];
710714
writeCommentBeforeValue(childValue);
711-
writeWithIndent(valueToQuotedString(name.c_str()));
715+
writeWithIndent(valueToQuotedString(name.c_str(),name.size()));
712716
*document_ << " : ";
713717
writeValue(childValue);
714718
if (++it == members.end()) {

0 commit comments

Comments
 (0)