diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-12-06 12:51:55 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-12-06 12:51:55 +0000 |
| commit | 966ac90fe71f46c63efd370d4837b5ddf4ca7e10 (patch) | |
| tree | 7ca8593ad9c7c6eb490bbf02eb83bd51c640637a /src/buffer.cc | |
| parent | 39fffec104c7e9e65baa16c220e9fe4b4a2f56bc (diff) | |
Change eolformat and BOM options to be enums instead of strings
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 044a8f1e..cd014574 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -17,43 +17,47 @@ namespace Kakoune { -struct ParsedLines { BufferLines lines; bool bom, crlf; }; +struct ParsedLines +{ + BufferLines lines; + ByteOrderMark bom = ByteOrderMark::None; + EolFormat eolformat = EolFormat::Lf; +}; static ParsedLines parse_lines(StringView data) { - bool bom = false, crlf = false; + ParsedLines res; const char* pos = data.begin(); if (data.substr(0, 3_byte) == "\xEF\xBB\xBF") { - bom = true; + res.bom = ByteOrderMark::Utf8; pos = data.begin() + 3; } - BufferLines lines; while (pos < data.end()) { const char* line_end = pos; while (line_end < data.end() and *line_end != '\r' and *line_end != '\n') ++line_end; - lines.emplace_back(StringData::create({pos, line_end}, '\n')); + res.lines.emplace_back(StringData::create({pos, line_end}, '\n')); if (line_end+1 != data.end() and *line_end == '\r' and *(line_end+1) == '\n') { - crlf = true; + res.eolformat = EolFormat::Crlf; pos = line_end + 2; } else pos = line_end + 1; } - return { std::move(lines), bom, crlf }; + return res; } static void apply_options(OptionManager& options, const ParsedLines& parsed_lines) { - options.get_local_option("eolformat").set<String>(parsed_lines.crlf ? "crlf" : "lf"); - options.get_local_option("BOM").set<String>(parsed_lines.bom ? "utf-8" : "no"); + options.get_local_option("eolformat").set(parsed_lines.eolformat); + options.get_local_option("BOM").set(parsed_lines.bom); } Buffer::Buffer(String name, Flags flags, StringView data, |
