From 16fc172b21141c345d1425d7173bd4ccba77b656 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 5 Feb 2020 22:39:08 +0900 Subject: [PATCH] feat: check string length before adding newline In literal strings, only the first newline will be trimmed. ```toml str = ''' The first newline will be trimmed.''' ``` The previous code always adds this first-newline, but after this commit it checks the length of the string and adds newline if the string is sufficiently long. --- toml/serializer.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index ed3cf6c..647720e 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -200,7 +200,11 @@ struct serializer if(std::find(s.str.cbegin(), s.str.cend(), '\n') != s.str.cend() || std::find(s.str.cbegin(), s.str.cend(), '\'') != s.str.cend() ) { - const std::string open("'''\n"); + std::string open("'''"); + if(this->width_ + 6 < s.str.size()) + { + open += '\n'; // the first newline is ignored by TOML spec + } const std::string close("'''"); return open + s.str + close; }