mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 19:10:11 +08:00
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.
This commit is contained in:
@@ -200,7 +200,11 @@ struct serializer
|
|||||||
if(std::find(s.str.cbegin(), s.str.cend(), '\n') != s.str.cend() ||
|
if(std::find(s.str.cbegin(), s.str.cend(), '\n') != s.str.cend() ||
|
||||||
std::find(s.str.cbegin(), s.str.cend(), '\'') != 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("'''");
|
const std::string close("'''");
|
||||||
return open + s.str + close;
|
return open + s.str + close;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user