]> git.lyx.org Git - lyx.git/blobdiff - src/FuncRequest.cpp
Routines for calculating numerical labels for BibTeX citations.
[lyx.git] / src / FuncRequest.cpp
index 2d36142421fc5c0e2cd67927b0bef59efae3e879..c7624c38ae336775ffe6e2da052f8ffac60dbb8b 100644 (file)
 #include <config.h>
 
 #include "FuncRequest.h"
+#include "LyXAction.h"
 
+#include "support/lstrings.h"
+
+#include <climits>
 #include <iostream>
 #include <sstream>
 #include <vector>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
@@ -70,17 +75,33 @@ mouse_button::state FuncRequest::button() const
 }
 
 
-void splitArg(vector<string> & 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<string> & 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<string> & 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<string> 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;