Introduce constants for clipboard option names

This commit is contained in:
Allan Odgaard
2020-04-06 22:24:33 +07:00
parent 47d0345d5a
commit 5166b6bfed
3 changed files with 18 additions and 8 deletions

View File

@@ -2,6 +2,11 @@
#include <text/utf8.h>
#include <text/hexdump.h>
std::string const kClipboardOptionIndent = "indent";
std::string const kClipboardOptionComplete = "complete";
std::string const kClipboardOptionFragments = "fragments";
std::string const kClipboardOptionColumnar = "columnar";
clipboard_t::entry_t::entry_t (std::string const& content, std::map<std::string, std::string> const& options) : _content(content), _options(options)
{
if(!utf8::is_valid(_content.begin(), _content.end()))

View File

@@ -3,6 +3,11 @@
#include <oak/misc.h>
extern std::string const kClipboardOptionIndent;
extern std::string const kClipboardOptionComplete;
extern std::string const kClipboardOptionFragments;
extern std::string const kClipboardOptionColumnar;
struct PUBLIC clipboard_t
{
struct PUBLIC entry_t

View File

@@ -293,10 +293,10 @@ namespace ng
static std::map<std::string, std::string> create_find_options (std::string const& indent, bool complete, size_t fragments, bool columnar)
{
std::map<std::string, std::string> res;
if(indent != NULL_STR) res["indent"] = indent;
if(complete) res["complete"] = "1";
if(fragments > 1) res["fragments"] = std::to_string(fragments);
if(columnar) res["columnar"] = "1";
if(indent != NULL_STR) res[kClipboardOptionIndent] = indent;
if(complete) res[kClipboardOptionComplete] = "1";
if(fragments > 1) res[kClipboardOptionFragments] = std::to_string(fragments);
if(columnar) res[kClipboardOptionColumnar] = "1";
return res;
}
@@ -455,10 +455,10 @@ namespace ng
std::map<std::string, std::string> options = entry->options();
str.erase(text::convert_line_endings(str.begin(), str.end(), text::estimate_line_endings(str.begin(), str.end())), str.end());
std::string const& indent = options["indent"];
bool const complete = options["complete"] == "1";
size_t const fragments = strtol(options["fragments"].c_str(), nullptr, 10);
bool const columnar = options["columnar"] == "1";
std::string const& indent = options[kClipboardOptionIndent];
bool const complete = options[kClipboardOptionComplete] == "1";
size_t const fragments = strtol(options[kClipboardOptionFragments].c_str(), nullptr, 10);
bool const columnar = options[kClipboardOptionColumnar] == "1";
if((selections.size() != 1 || selections.last().columnar) && (fragments > 1 || oak::contains(str.begin(), str.end(), '\n')))
{