diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-03-26 00:14:38 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-03-26 00:14:38 +0100 |
| commit | 1982144b041a9e1054be5f24ea7c7f4eb77d1826 (patch) | |
| tree | a02f4ba3374d53f4d9e07292114ef3737941b8a8 /src/option_types.cc | |
| parent | 36dc6c23a0faa1441f616f4347992bdce9a33035 (diff) | |
Add a special option type LineAndFlag, use it for FlagLines highlighter
Diffstat (limited to 'src/option_types.cc')
| -rw-r--r-- | src/option_types.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/option_types.cc b/src/option_types.cc new file mode 100644 index 00000000..29d21e8f --- /dev/null +++ b/src/option_types.cc @@ -0,0 +1,26 @@ +#include "option_types.hh" + +#include "exception.hh" + +namespace Kakoune +{ + +String option_to_string(const LineAndFlag& opt) +{ + return int_to_str((int)opt.line) + ":" + color_to_str(opt.color) + ":" + opt.flag; +} + +void option_from_string(const String& str, LineAndFlag& opt) +{ + static Regex re{R"((\d+):(\w+):(.+))"}; + + boost::match_results<String::iterator> res; + if (not boost::regex_match(str.begin(), str.end(), res, re)) + throw runtime_error("wrong syntax, expected <line>:<color>:<flag>"); + + opt.line = str_to_int(String{res[1].first, res[1].second}); + opt.color = str_to_color(String{res[2].first, res[2].second}); + opt.flag = String{res[3].first, res[3].second}; +} + +} |
