X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFuncRequest.cpp;h=c7624c38ae336775ffe6e2da052f8ffac60dbb8b;hb=2098f1d8c20d51e63e670bcdc9da8996068975bf;hp=2d36142421fc5c0e2cd67927b0bef59efae3e879;hpb=f1cba8ff64b369792fd49f5ddf90e8126ab476ac;p=lyx.git diff --git a/src/FuncRequest.cpp b/src/FuncRequest.cpp index 2d36142421..c7624c38ae 100644 --- a/src/FuncRequest.cpp +++ b/src/FuncRequest.cpp @@ -11,12 +11,17 @@ #include #include "FuncRequest.h" +#include "LyXAction.h" +#include "support/lstrings.h" + +#include #include #include #include using namespace std; +using namespace lyx::support; namespace lyx { @@ -70,17 +75,33 @@ mouse_button::state FuncRequest::button() const } -void splitArg(vector & args, string const & str) +namespace { + +// Extracts arguments from str into args. Arguments are delimted by +// whitespace or by double quotes. +// We extract at most max + 1 arguments, treating args[max] as +// continuing to eol. +void splitArg(vector & args, string const & str, + unsigned int max = UINT_MAX) { istringstream is(str); while (is) { + if (args.size() == max) { + string s; + getline(is, s); + args.push_back(trim(s)); + return; + } + char c; string s; is >> c; if (is) { if (c == '"') + // get quote delimited argument getline(is, s, '"'); else { + // get whitespace delimited argument is.putback(c); is >> s; } @@ -89,6 +110,7 @@ void splitArg(vector & args, string const & str) } } +} string FuncRequest::getArg(unsigned int i) const { @@ -98,6 +120,14 @@ string FuncRequest::getArg(unsigned int i) const } +string FuncRequest::getLongArg(unsigned int i) const +{ + vector args; + splitArg(args, to_utf8(argument_), i); + return i < args.size() ? args[i] : string(); +} + + bool operator==(FuncRequest const & lhs, FuncRequest const & rhs) { return lhs.action == rhs.action && lhs.argument() == rhs.argument(); @@ -107,7 +137,8 @@ bool operator==(FuncRequest const & lhs, FuncRequest const & rhs) ostream & operator<<(ostream & os, FuncRequest const & cmd) { return os - << " action: " << cmd.action + << " action: " << cmd.action + << " [" << lyxaction.getActionName(cmd.action) << "] " << " arg: '" << to_utf8(cmd.argument()) << "'" << " x: " << cmd.x << " y: " << cmd.y;