new method getLongArg that grabs all the remainder of the argument string

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32283 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2009-12-02 09:39:39 +00:00
parent d81c4751df
commit fc3de8c150
2 changed files with 27 additions and 2 deletions

View File

@ -13,11 +13,14 @@
#include "FuncRequest.h"
#include "LyXAction.h"
#include "support/lstrings.h"
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
using namespace lyx::support;
namespace lyx {
@ -71,10 +74,19 @@ mouse_button::state FuncRequest::button() const
}
void splitArg(vector<string> & args, string const & str)
namespace {
void splitArg(vector<string> & args, string const & str, unsigned int 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;
@ -90,11 +102,20 @@ void splitArg(vector<string> & args, string const & str)
}
}
}
string FuncRequest::getArg(unsigned int i) const
{
vector<string> args;
splitArg(args, to_utf8(argument_));
splitArg(args, to_utf8(argument_), string::npos);
return i < args.size() ? args[i] : string();
}
string FuncRequest::getLongArg(unsigned int i) const
{
vector<string> args;
splitArg(args, to_utf8(argument_), i);
return i < args.size() ? args[i] : string();
}

View File

@ -64,6 +64,10 @@ public:
/// argument parsing, extract argument i as std::string
std::string getArg(unsigned int i) const;
/// argument parsing, extract argument i as std::string,
/// eating all characters up to the end of the command line
std::string getLongArg(unsigned int i) const;
/// access the whole argument
docstring const & argument() const { return argument_; }