diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-08-01 16:42:22 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-08-02 01:01:41 +0300 |
commit | 6254448640530240dc9199bed60cd5568cbaf601 (patch) | |
tree | 4f859f61f1980bde1027fd3e22573157e9b5bd4b /libbutl/manifest-parser.cxx | |
parent | 12d0fb176edd8220f80f706d3fdc33431e178695 (diff) |
Add manifest_parser::split_comment() and manifest_serializer::merge_comment()
Diffstat (limited to 'libbutl/manifest-parser.cxx')
-rw-r--r-- | libbutl/manifest-parser.cxx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libbutl/manifest-parser.cxx b/libbutl/manifest-parser.cxx index ae92d79..304815a 100644 --- a/libbutl/manifest-parser.cxx +++ b/libbutl/manifest-parser.cxx @@ -125,6 +125,48 @@ namespace butl return r; } + pair<string, string> manifest_parser:: + split_comment (const string& v) + { + using iterator = string::const_iterator; + + auto space = [] (char c) -> bool {return c == ' ' || c == '\t';}; + + iterator i (v.begin ()); + iterator e (v.end ()); + + string r; + size_t n (0); + for (char c; i != e && (c = *i) != ';'; ++i) + { + // Unescape ';' character. + // + if (c == '\\' && i + 1 != e && *(i + 1) == ';') + c = *++i; + + r += c; + + if (!space (c)) + n = r.size (); + } + + // Strip the value trailing spaces. + // + if (r.size () != n) + r.resize (n); + + // Find beginning of a comment (i). + // + if (i != e) + { + // Skip spaces. + // + for (++i; i != e && space (*i); ++i); + } + + return make_pair (move (r), string (i, e)); + } + void manifest_parser:: parse_name (name_value& r) { |