aboutsummaryrefslogtreecommitdiff
path: root/libbutl
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-11-23 21:26:20 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-11-24 11:54:40 +0300
commitb90126986fbeec6f42d469e99574096c3f6abc22 (patch)
tree25de68baabd3c51438881478f1ce0c31cb585d2e /libbutl
parenta1ddd27f217f3ae2664128c72522d76cb0af8c80 (diff)
Don't separate multi-line manifest value introducer from colon with space in manifest serializer
Diffstat (limited to 'libbutl')
-rw-r--r--libbutl/manifest-rewriter.cxx8
-rw-r--r--libbutl/manifest-serializer.cxx22
-rw-r--r--libbutl/manifest-serializer.hxx10
3 files changed, 22 insertions, 18 deletions
diff --git a/libbutl/manifest-rewriter.cxx b/libbutl/manifest-rewriter.cxx
index 3bddd37..1232e9c 100644
--- a/libbutl/manifest-rewriter.cxx
+++ b/libbutl/manifest-rewriter.cxx
@@ -73,8 +73,6 @@ namespace butl
if (!nv.value.empty ())
{
- os << ' ';
-
manifest_serializer s (os, path_.string (), long_lines_);
// Note that the name can be surrounded with the ASCII whitespace
@@ -86,7 +84,7 @@ namespace butl
//
s.write_value (nv.value,
static_cast<size_t> (nv.colon_pos - nv.start_pos) -
- (nv.name.size () - utf8_length (nv.name)) + 2);
+ (nv.name.size () - utf8_length (nv.name)) + 1);
}
os << suffix;
@@ -118,15 +116,13 @@ namespace butl
if (!nv.value.empty ())
{
- os << ' ';
-
// Note that the name can be surrounded with the ASCII whitespace
// characters and the start_pos refers to the first character in the
// line.
//
s.write_value (nv.value,
static_cast<size_t> (nv.colon_pos - nv.start_pos) -
- (nv.name.size () - n) + 2);
+ (nv.name.size () - n) + 1);
}
os << suffix;
diff --git a/libbutl/manifest-serializer.cxx b/libbutl/manifest-serializer.cxx
index 8f248cf..5875052 100644
--- a/libbutl/manifest-serializer.cxx
+++ b/libbutl/manifest-serializer.cxx
@@ -4,6 +4,7 @@
#include <libbutl/manifest-serializer.hxx>
#include <ostream>
+#include <cassert>
#include <libbutl/utf8.hxx>
#include <libbutl/utility.hxx>
@@ -66,10 +67,7 @@ namespace butl
os_ << ':';
if (!v.empty ())
- {
- os_ << ' ';
- write_value (v, l + 2);
- }
+ write_value (v, l + 1);
os_ << endl;
break;
@@ -272,6 +270,8 @@ namespace butl
void manifest_serializer::
write_value (const string& v, size_t cl)
{
+ assert (!v.empty ());
+
// Consider both \r and \n characters as line separators, and the
// \r\n characters sequence as a single line separator.
//
@@ -290,9 +290,12 @@ namespace butl
// readability, still allowing the user to easily copy the value which
// seems to be the main reason for using the flag.
//
- if (cl > 39 || nl () != string::npos ||
- v.front () == ' ' || v.front () == '\t' ||
- v.back () == ' ' || v.back () == '\t')
+ if (cl + 1 > 39 || // '+ 1' for the space after the colon.
+ nl () != string::npos ||
+ v.front () == ' ' ||
+ v.front () == '\t' ||
+ v.back () == ' ' ||
+ v.back () == '\t')
{
os_ << "\\" << endl; // Multi-line mode introducer.
@@ -317,7 +320,10 @@ namespace butl
os_ << endl << "\\"; // Multi-line mode terminator.
}
else
- write_value (v.c_str (), v.size (), cl);
+ {
+ os_ << ' ';
+ write_value (v.c_str (), v.size (), cl + 1);
+ }
}
// manifest_serialization
diff --git a/libbutl/manifest-serializer.hxx b/libbutl/manifest-serializer.hxx
index dfe37da..43924e7 100644
--- a/libbutl/manifest-serializer.hxx
+++ b/libbutl/manifest-serializer.hxx
@@ -96,10 +96,12 @@ namespace butl
size_t
write_name (const std::string&);
- // Write a value assuming the current line already has the specified
- // codepoint offset. If the resulting line length would be too large then
- // the multi-line representation will be used. It is assumed that the
- // name, followed by the colon, is already written.
+ // Write a non-empty value assuming the current line already has the
+ // specified codepoint offset. If the resulting line length would be too
+ // large then the multi-line representation will be used. For the
+ // single-line representation the space character is written before the
+ // value. It is assumed that the name, followed by the colon, is already
+ // written.
//
void
write_value (const std::string&, std::size_t offset);