| 35 | typedef YAML::const_iterator Iterator; |
| 36 | |
| 37 | std::string SanitizeNewlines(const std::string &input) |
| 38 | { |
| 39 | if (input.empty()) |
| 40 | return input; |
| 41 | |
| 42 | // YAML is changing the trailing newlines when reading them: |
| 43 | // - Written as YAML::Literal (starts with a "|"), descriptions will be read back with a |
| 44 | // single newline. One is added if there was none, only one is kept if there were |
| 45 | // several. |
| 46 | // - Written as YAML::Value string (does not start with "|"), all trailing newlines ('\n') |
| 47 | // are preserved. |
| 48 | // Trailing newlines are inconsistently preserved, lets remove them in all cases. |
| 49 | std::string str = input; |
| 50 | auto last = str.back(); |
| 51 | while (last == '\n' && str.length()) |
| 52 | { |
| 53 | str.pop_back(); |
| 54 | last = str.back(); |
| 55 | } |
| 56 | |
| 57 | // Also, note that a \n is only interpreted as a newline if it is used in a string that is |
| 58 | // within double quotes. E.g., "A string \n with embedded \n newlines." Indeed, without the |
| 59 | // double quotes the backslash is generally not interpreted as an escape character in YAML. |
| 60 | |
| 61 | return str; |
| 62 | } |
| 63 | |
| 64 | // Basic types |
| 65 |
no test coverage detected