]> git.lyx.org Git - features.git/blob - src/insets/InsetListingsParams.cpp
make InsetListings ready for dialects, part 1 (joint work with Bo Peng):
[features.git] / src / insets / InsetListingsParams.cpp
1 /**
2  * \file InsetListingsParams.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Bo Peng
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Lexer.h"
14 #include "InsetListingsParams.h"
15
16 #include "gettext.h"
17 #include "Length.h"
18
19 #include <sstream>
20 #include <boost/assert.hpp>
21
22 #include "support/lstrings.h"
23 #include "support/convert.h"
24
25 using std::vector;
26 using std::ostream;
27 using std::string;
28 using std::exception;
29 using lyx::support::trim;
30 using lyx::support::isStrInt;
31 using lyx::support::prefixIs;
32 using lyx::support::suffixIs;
33 using lyx::support::getVectorFromString;
34
35 namespace lyx
36 {
37
38 enum param_type {
39         ALL,  // accept all
40         TRUEFALSE, // accept 'true' or 'false'
41         INTEGER, // accept an integer
42         LENGTH,  // accept an latex length
43         ONEOF,  // accept one of a few values
44         SUBSETOF, // accept a string composed of given characters
45 };
46
47
48 /** Information about each parameter
49  */
50 struct listings_param_info {
51         /// name of the parameter
52         char const * name;
53         /// default value
54         char const * value;
55         // for option with value "true", "false", 
56         // if onoff is true,
57         //   "true":  option
58         //   "false": 
59         //   "other": option="other"
60         // onoff is false,
61         //   "true":  option=true
62         //   "false": option=false
63         bool onoff;
64         /// validator type
65         param_type type;
66         // ALL:
67         // TRUEFALSE:
68         // INTEGER:
69         // LENGTH:
70         //     info is ignored.
71         // ONEOF
72         //     info is a \n separated string with allowed values
73         // SUBSETOF
74         //     info is a string from which par is composed of
75         //     (e.g. floatplacement can be one or more of tbph)
76         char const * info;
77         //
78         char const * hint;
79 };
80
81
82
83 /// languages and language/dialect combinations
84 char const * allowed_languages = 
85         "no language\nABAP\n[R/2 4.3]ABAP\n[R/2 5.0]ABAP\n[R/3 3.1]ABAP\n"
86         "[R/3 4.6C]ABAP\n[R/3 6.10]ABAP\nACSL\nAda\n[2005]Ada\n[83]Ada\n"
87         "[95]Ada\nALGOL\n[60]ALGOL\n[68]ALGOL\nAssembler\n"
88         "[Motorola68k]Assembler\n[x86masm]Assembler\nAwk\n[gnu]Awk\n[POSIX]Awk\n"
89         "bash\nBasic\n[Visual]Basic\nC\n[ANSI]C\n[Handel]C\n[Objective]C\n"
90         "[Sharp]C\nC++\n[ANSI]C++\n[GNU]C++\n[ISO]C++\n[Visual]C++\nCaml\n"
91         "[light]Caml\n[Objective]Caml\nClean\nCobol\n[1974]Cobol\n[1985]Cobol\n"
92         "[ibm]Cobol\nComal 80\ncommand.com\n[WinXP]command.com\nComsol\ncsh\n"
93         "Delphi\nEiffel\nElan\nEuphoria\nFortran\n[77]Fortran\n[90]Fortran\n"
94         "[95]Fortran\nGCL\nGnuplot\nHaskell\nHTML\nIDL\n[CORBA]IDL\ninform\n"
95         "Java\n[AspectJ]Java\nJVMIS\nksh\nLingo\nLisp\n[Auto]Lisp\nLogo\n"
96         "make\n[gnu]make\nMathematica\n[1.0]Mathematica\n[3.0]Mathematica\n"
97         "[5.2]Mathematica\nMatlab\nMercury\nMetaPost\nMiranda\nMizar\nML\n"
98         "Modula-2\nMuPAD\nNASTRAN\nOberon-2\nOCL\n[decorative]OCL\n[OMG]OCL\n"
99         "Octave\nOz\nPascal\n[Borland6]Pascal\n[Standard]Pascal\n[XSC]Pascal\n"
100         "Perl\nPHP\nPL/I\nPlasm\nPostScript\nPOV\nProlog\nPromela\nPSTricks\n"
101         "Python\nR\nReduce\nRexx\nRSL\nRuby\nS\n[PLUS]S\nSAS\nScilab\nsh\n"
102         "SHELXL\nSimula\n[67]Simula\n[CII]Simula\n[DEC]Simula\n[IBM]Simula\n"
103         "SPARQL\nSQL\ntcl\n[tk]tcl\nTeX\n[AlLaTeX]TeX\n[common]TeX\n[LaTeX]TeX\n"
104         "[plain]TeX\n[primitive]TeX\nVBScript\nVerilog\nVHDL\n[AMS]VHDL\nVRML\n"
105         "[97]VRML\nXML\nXSLT";
106
107 char const * style_hint = "Use \\footnotesize, \\small, \\itshape, \\ttfamily or something like that";
108 char const * frame_hint = "none, leftline, topline, bottomline, lines, single, shadowbox or subset of trblTRBL";
109 char const * frameround_hint = 
110         "Enter four letters (either t = round or f = square) for top right, bottom right, bottom left and top left corner.";
111 char const * color_hint = "Enter something like \\color{white}";
112
113 /// options copied from page 26 of listings manual
114 // FIXME: add default parameters ... (which is not used now)
115 listings_param_info const listings_param_table[] = {
116         { "float", "false", true,  SUBSETOF, "tbph", "" },
117         { "floatplacement", "tbp", false, SUBSETOF, "tbph", "" },
118         { "aboveskip", "\\medskipamount", false, LENGTH, "", "" },
119         { "belowskip", "\\medskipamount", false, LENGTH, "", "" },
120         { "lineskip", "", false, LENGTH, "", "" },
121         { "boxpos", "", false, SUBSETOF, "bct", "" },
122         { "print", "", false, TRUEFALSE, "", "" },
123         { "firstline", "", false, INTEGER, "", "" },
124         { "lastline", "", false, INTEGER, "", "" },
125         { "showlines", "", false, TRUEFALSE, "", "" },
126         { "emptylines", "", false, ALL, "", "Expect a number with an optional * before it" },
127         { "gobble", "", false, INTEGER, "", "" },
128         { "style", "", false, ALL, "", "" },
129         { "language", "", false, ONEOF, allowed_languages, "" },
130         { "alsolanguage", "", false, ONEOF, allowed_languages, "" },
131         { "defaultdialect", "", false, ONEOF, allowed_languages, "" },
132         { "printpod", "", false, TRUEFALSE, "", "" },
133         { "usekeywordsintag", "", false, TRUEFALSE, "", "" },
134         { "tagstyle", "", false, ALL, "", style_hint },
135         { "markfirstintag", "", false, ALL, "", style_hint },
136         { "makemacrouse", "", false, TRUEFALSE, "", "" },
137         { "basicstyle", "", false, ALL, "", style_hint },
138         { "identifierstyle", "", false, ALL, "", style_hint },
139         { "commentstyle", "", false, ALL, "", style_hint },
140         { "stringstyle", "", false, ALL, "", style_hint },
141         { "keywordstyle", "", false, ALL, "", style_hint },
142         { "ndkeywordstyle", "", false, ALL, "", style_hint },
143         { "classoffset", "", false, INTEGER, "", "" },
144         { "texcsstyle", "", false, ALL, "", style_hint },
145         { "directivestyle", "", false, ALL, "", style_hint },
146         { "emph", "", false, ALL, "", "" },
147         { "moreemph", "", false, ALL, "", "" },
148         { "deleteemph", "", false, ALL, "", "" },
149         { "emphstyle", "", false, ALL, "", "" },
150         { "delim", "", false, ALL, "", "" },
151         { "moredelim", "", false, ALL, "", "" },
152         { "deletedelim", "", false, ALL, "", "" },
153         { "extendedchars", "", false, TRUEFALSE, "", "" },
154         { "inputencoding", "", false, ALL, "", "" },
155         { "upquote", "", false, TRUEFALSE, "", "" },
156         { "tabsize", "", false, INTEGER, "", "" },
157         { "showtabs", "", false, ALL, "", "" },
158         { "tab", "", false, ALL, "", "" },
159         { "showspaces", "", false, TRUEFALSE, "", "" },
160         { "showstringspaces", "", false, TRUEFALSE, "", "" },
161         { "formfeed", "", false, ALL, "", "" },
162         { "numbers", "", false, ONEOF, "none\nleft\nright", "" },
163         { "stepnumber", "", false, INTEGER, "", "" },
164         { "numberfirstline", "", false, TRUEFALSE, "", "" },
165         { "numberstyle", "", false, ALL, "", style_hint },
166         { "numbersep", "", false, LENGTH, "", "" },
167         { "numberblanklines", "", false, ALL, "", "" },
168         { "firstnumber", "", false, ALL, "", "auto, last or a number" },
169         { "name", "", false, ALL, "", "" },
170         { "thelstnumber", "", false, ALL, "", "" },
171         { "title", "", false, ALL, "", "" },
172         // this option is not handled in the parameter box
173         { "caption", "", false, ALL, "", "This parameter should not be entered here. "
174                 "Please use caption editbox (Include dialog) or insert->caption (listings inset)" },
175         // this option is not handled in the parameter box
176         { "label", "", false, ALL, "", "This parameter should not be entered here."
177                 "Please use label editbox (Include dialog) or insert->caption (listings inset)"},
178         { "nolol", "", false, TRUEFALSE, "", "" },
179         { "captionpos", "", false, SUBSETOF, "tb", "" },
180         { "abovecaptionskip", "", false, LENGTH, "", "" },
181         { "belowcaptionskip", "", false, LENGTH, "", "" },
182         { "linewidth", "", false, LENGTH, "", "" },
183         { "xleftmargin", "", false, LENGTH, "", "" },
184         { "xrightmargin", "", false, LENGTH, "", "" },
185         { "resetmargins", "", false, TRUEFALSE, "", "" },
186         { "breaklines", "", false, TRUEFALSE, "", "" },
187         { "prebreak", "", false, ALL, "", "" },
188         { "postbreak", "", false, ALL, "", "" },
189         { "breakindent", "", false, LENGTH, "", "" },
190         { "breakautoindent", "", false, TRUEFALSE, "", "" },
191         { "frame", "", false, ALL, "", frame_hint },
192         { "frameround", "", false, SUBSETOF, "tf", frameround_hint },
193         { "framesep", "", false, LENGTH, "", "" },
194         { "rulesep", "", false, LENGTH, "", "" },
195         { "framerule", "", false, LENGTH, "", "" },
196         { "framexleftmargin", "", false, LENGTH, "", "" },
197         { "framexrightmargin", "", false, LENGTH, "", "" },
198         { "framextopmargin", "", false, LENGTH, "", "" },
199         { "framexbottommargin", "", false, LENGTH, "", "" },
200         { "backgroundcolor", "", false, ALL, "", color_hint },
201         { "rulecolor", "", false, ALL, "", color_hint },
202         { "fillcolor", "", false, ALL, "", color_hint },
203         { "rulesepcolor", "", false, ALL, "", color_hint },
204         { "frameshape", "", false, ALL, "", "" },
205         { "index", "", false, ALL, "", "" },
206         { "moreindex", "", false, ALL, "", "" },
207         { "deleteindex", "", false, ALL, "", "" },
208         { "indexstyle", "", false, ALL, "", "" },
209         { "columns", "", false, ALL, "", "" },
210         { "flexiblecolumns", "", false, ALL, "", "" },
211         { "keepspaces", "", false, TRUEFALSE, "", "" },
212         { "basewidth", "", false, LENGTH, "", "" },
213         { "fontadjust", "", true, TRUEFALSE, "", "" },
214         { "texcl", "", false, TRUEFALSE, "", "" },
215         { "mathescape", "", false, TRUEFALSE, "", "" },
216         { "escapechar", "", false, ALL, "", "" },
217         { "escapeinside", "", false, ALL, "", "" },
218         { "escepeinside", "", false, ALL, "", "" },
219         { "escepebegin", "", false, ALL, "", "" },
220         { "escepeend", "", false, ALL, "", "" },
221         { "fancyvrb", "", false, TRUEFALSE, "", "" },
222         { "fvcmdparams", "", false, ALL, "", "" },
223         { "morefvcmdparams", "", false, ALL, "", "" },
224         { "keywordsprefix", "", false, ALL, "", "" },
225         { "keywords", "", false, ALL, "", "" },
226         { "morekeywords", "", false, ALL, "", "" },
227         { "deletekeywords", "", false, ALL, "", "" },
228         { "ndkeywords", "", false, ALL, "", "" },
229         { "morendkeywords", "", false, ALL, "", "" },
230         { "deletendkeywords", "", false, ALL, "", "" },
231         { "texcs", "", false, ALL, "", "" },
232         { "moretexcs", "", false, ALL, "", "" },
233         { "deletetexcs", "", false, ALL, "", "" },
234         { "directives", "", false, ALL, "", "" },
235         { "moredirectives", "", false, ALL, "", "" },
236         { "deletedirectives", "", false, ALL, "", "" },
237         { "sensitive", "", false, ALL, "", "" },
238         { "alsoletter", "", false, ALL, "", "" },
239         { "alsodigit", "", false, ALL, "", "" },
240         { "alsoother", "", false, ALL, "", "" },
241         { "otherkeywords", "", false, ALL, "", "" },
242         { "tag", "", false, ALL, "", "" },
243         { "string", "", false, ALL, "", "" },
244         { "morestring", "", false, ALL, "", "" },
245         { "deletestring", "", false, ALL, "", "" },
246         { "comment", "", false, ALL, "", "" },
247         { "morecomment", "", false, ALL, "", "" },
248         { "deletecomment", "", false, ALL, "", "" },
249         { "keywordcomment", "", false, ALL, "", "" },
250         { "morekeywordcomment", "", false, ALL, "", "" },
251         { "deletekeywordcomment", "", false, ALL, "", "" },
252         { "keywordcommentsemicolon", "", false, ALL, "", "" },
253         { "podcomment", "", false, ALL, "", "" },
254         { "", "", false, ALL, "", ""}
255 };
256
257
258 class parValidator
259 {
260 public:
261         parValidator(string const & name);
262
263         /// validate given parameter
264         /// invalidParam will be thrown if invalid 
265         /// parameter is found.
266         void validate(std::string const & par) const;
267
268 private:
269         /// parameter name
270         string const & name;
271         ///
272         listings_param_info const * info;
273 };
274
275
276 parValidator::parValidator(string const & n)
277         : name(n), info(0)
278 {
279         if (name.empty())
280                 throw invalidParam("Invalid (empty) listings param name.");
281         else if (name == "?") {
282                 string pars;
283                 size_t idx = 0;
284                 while (listings_param_table[idx].name != string()) {
285                         if (!pars.empty())
286                                 pars += ", ";
287                         pars += listings_param_table[idx].name;
288                         ++idx;
289                 }
290                 throw invalidParam("Available listings parameters are " + pars);
291         }
292         // locate name in parameter table
293         size_t idx = 0;
294         while (listings_param_table[idx].name != name && listings_param_table[idx].name != string())
295                 ++idx;
296         // found the name
297         if (listings_param_table[idx].name != "") {
298                 info = &listings_param_table[idx];
299                 return;
300         }
301         // otherwise, produce a meaningful error message.
302         string matching_names;
303         for (size_t i = 0; i < idx; ++i) {
304                 string n(listings_param_table[i].name);
305                 if (n.size() >= name.size() && n.substr(0, name.size()) == name) {
306                         if (matching_names.empty())
307                                 matching_names += n;
308                         else
309                                 matching_names += ", " + n;
310                 }
311         }
312         if (matching_names.empty())
313                 throw invalidParam("Unknown listings param name: " + name);
314         else
315                 throw invalidParam("Parameters starting with '" + name + 
316                         "': " + matching_names);
317 }
318
319
320 void parValidator::validate(std::string const & par) const
321 {
322         bool unclosed = false;
323         string par2 = par;
324         // braces are allowed
325         if (prefixIs(par, "{") && suffixIs(par, "}"))
326                 par2 = par.substr(1, par.size() - 2);
327         else if (prefixIs(par, "{")) {
328                 par2 = par.substr(1);
329                 unclosed = true;
330         }
331         
332                 
333         switch (info->type) {
334         case ALL:
335                 if (par2.empty() && !info->onoff) {
336                         if (info->hint != "")
337                                 throw invalidParam(info->hint);
338                         else
339                                 throw invalidParam("A value is expected");
340                 }
341                 if (unclosed)
342                                 throw invalidParam("Unbalanced braces!");
343                 return;
344         case TRUEFALSE: {
345                 if (par2.empty() && !info->onoff) {
346                         if (info->hint != "")
347                                 throw invalidParam(info->hint);
348                         else
349                                 throw invalidParam("Please specify true or false");
350                 }
351                 if (par2 != "true" && par2 != "false")
352                         throw invalidParam("Only true or false is allowed for parameter" + name);
353                 if (unclosed)
354                                 throw invalidParam("Unbalanced braces!");
355                 return;
356         }
357         case INTEGER: {
358                 if (!isStrInt(par2)) {
359                         if (info->hint != "")
360                                 throw invalidParam(info->hint);
361                         else
362                                 throw invalidParam("Please specify an integer value");
363                 }
364                 if (convert<int>(par2) == 0 && par2[0] != '0')
365                         throw invalidParam("An integer is expected for parameter " + name);
366                 if (unclosed)
367                                 throw invalidParam("Unbalanced braces!");
368                 return;
369         }
370         case LENGTH: {
371                 if (par2.empty() && !info->onoff) {
372                         if (info->hint != "")
373                                 throw invalidParam(info->hint);
374                         else
375                                 throw invalidParam("Please specify a latex length expression");
376                 }
377                 if (!isValidLength(par2))
378                         throw invalidParam("Invalid latex length expression for parameter " + name);
379                 if (unclosed)
380                                 throw invalidParam("Unbalanced braces!");
381                 return;
382         }
383         case ONEOF: {
384                 if (par2.empty() && !info->onoff) {
385                         if (info->hint != "")
386                                 throw invalidParam(info->hint);
387                         else
388                                 throw invalidParam("Please specify one of " + string(info->info));
389                 }
390                 // break value to allowed strings
391                 vector<string> lists;
392                 string v;
393                 for (size_t i = 0; info->info[i] != '\0'; ++i) {
394                         if (info->info[i] == '\n') {
395                                 lists.push_back(v);
396                                 v = string();
397                         } else
398                                 v += info->info[i];
399                 }
400                 if (!v.empty())
401                         lists.push_back(v);
402
403                 // good, find the string
404                 if (std::find(lists.begin(), lists.end(), par2) != lists.end()) {
405                         if (unclosed)
406                                 throw invalidParam("Unbalanced braces!");
407                         return;
408                 }
409                 // otherwise, produce a meaningful error message.
410                 string matching_names;
411                 for (vector<string>::iterator it = lists.begin(); 
412                         it != lists.end(); ++it) {
413                         if (it->size() >= par2.size() && it->substr(0, par2.size()) == par2) {
414                                 if (matching_names.empty())
415                                         matching_names += *it;
416                                 else
417                                         matching_names += ", " + *it;
418                         }
419                 }
420                 if (matching_names.empty())
421                         throw invalidParam("Try one of " + string(info->info));
422                 else
423                         throw invalidParam("I guess you mean " + matching_names);
424                 return;
425         }
426         case SUBSETOF: {
427                 if (par2.empty() && !info->onoff) {
428                         if (info->hint != "")
429                                 throw invalidParam(info->hint);
430                         else
431                                 throw invalidParam("Please specify one or more of " + string(info->info));
432                 }
433                 for (size_t i = 0; i < par2.size(); ++i)
434                         if (string(info->info).find(par2[i], 0) == string::npos)
435                                 throw invalidParam("Parameter " + name + 
436                                         " should be composed of one or more of " + info->info);
437                 if (unclosed)
438                                 throw invalidParam("Unbalanced braces!");
439                 return;
440         }
441         }
442 }
443
444
445 InsetListingsParams::InsetListingsParams() :
446         inline_(false), params_(), keys_(0), status_(InsetCollapsable::Open)
447 {
448 }
449
450
451 InsetListingsParams::InsetListingsParams(string const & par, bool in, InsetCollapsable::CollapseStatus s)
452         : inline_(in), params_(), keys_(0), status_(s)
453 {
454         // this will activate parameter validation.
455         fromEncodedString(par);
456 }
457
458
459 void InsetListingsParams::write(ostream & os) const
460 {
461         if (inline_)
462                 os << "true ";
463         else
464                 os << "false ";
465         os << status_ << " \""  << encodedString() << "\"";
466 }
467
468
469 void InsetListingsParams::read(Lexer & lex)
470 {
471         lex >> inline_;
472         int s;
473         lex >> s;
474         if (lex)
475                 status_ = static_cast<InsetCollapsable::CollapseStatus>(s);
476         string par;
477         lex >> par;
478         fromEncodedString(par);
479 }
480
481
482 void InsetListingsParams::addParam(string const & key, string const & value)
483 {       
484         if (key.empty())
485                 return;
486         // exception may be thown.
487         parValidator(key.c_str()).validate(value);
488         // duplicate parameters!
489         if (find(keys_.begin(), keys_.end(), key) != keys_.end())
490                 throw invalidParam("Parameter " + key + " has already been defined");   
491         else
492                 keys_.push_back(key);
493         if (!params_.empty())
494                 params_ += ',';
495         if (value.empty())
496                 params_ += key;
497         else {
498                 // check onoff flag
499                 size_t idx = 0;
500                 while (listings_param_table[idx].name != key)
501                         ++idx;
502                 BOOST_ASSERT(listings_param_table[idx].name == key);
503                 if (listings_param_table[idx].onoff && value == "false")
504                         params_ += key;
505                 else
506                         params_ += key + '=' + value;
507         }
508 }
509
510
511 void InsetListingsParams::addParams(string const & par)
512 {
513         string key;
514         string value;
515         bool isValue = false;
516         int braces = 0;
517         for (size_t i = 0; i < par.size(); ++i) {
518                 // end of par
519                 if (par[i] == '\n') {
520                         addParam(trim(key), trim(value));
521                         key = string();
522                         value = string();
523                         isValue = false;
524                         continue;
525                 } else if (par[i] == ',' && braces == 0) {
526                         addParam(trim(key), trim(value));
527                         key = string();
528                         value = string();
529                         isValue = false;
530                         continue;
531                 } else if (par[i] == '=' && braces == 0) {
532                         isValue = true;
533                         continue;
534                 } else if (par[i] == '{' && par[i - 1] == '=')
535                         braces ++;
536                 else if (par[i] == '}' && (i == par.size() - 1 || par[i + 1] == ','))
537                         braces --;
538                 
539                 if (isValue)
540                         value += par[i];
541                 else
542                         key += par[i];
543         }
544         if (!trim(key).empty())
545                 addParam(trim(key), trim(value));
546 }
547
548
549 void InsetListingsParams::setParams(string const & par)
550 {
551         params_.clear();
552         keys_.clear();
553         addParams(par);
554 }
555
556
557 string InsetListingsParams::encodedString() const
558 {
559         // Encode string!
560         // FIXME:
561         // '"' should be handled differently because it will 
562         // terminate a lyx token. Right now, it is silently ignored. 
563         string par;
564         for (size_t i = 0; i < params_.size(); ++i) {
565                 BOOST_ASSERT(params_[i] != '\n');
566                 if (params_[i] != '"')
567                         par += params_[i];
568         }
569         return par;
570 }
571
572
573 string InsetListingsParams::separatedParams(bool keepComma) const
574 {
575         // , might be used as regular parameter option so 
576         // the prcess might be more complicated than what I am doing here
577         string opt;
578         int braces = 0;
579         for (size_t i = 0; i < params_.size(); ++i)
580                 if (params_[i] == ',' && braces == 0) {
581                         if (keepComma)
582                                 opt += ",\n";
583                         else
584                                 opt += "\n";
585                 } else if (params_[i] == '{' && params_[i - 1] == '=') {
586                         braces ++;
587                         opt += params_[i];
588                 } else if (params_[i] == '}' && (i == params_.size() -1 || params_[i + 1] == ',')) {
589                         braces --;
590                         opt += params_[i];
591                 } else
592                         opt += params_[i];
593         return opt;
594 }
595
596
597 void InsetListingsParams::fromEncodedString(string const & in)
598 {
599         // Decode string! 
600         // Do nothing because " was silently ignored.
601         setParams(in);
602 }
603
604
605 bool InsetListingsParams::isFloat() const
606 {
607         return find(keys_.begin(), keys_.end(), "float") != keys_.end();
608 }
609
610
611 string InsetListingsParams::getParamValue(string const & param) const
612 {
613         // is this parameter defined?
614         if (find(keys_.begin(), keys_.end(), param) == keys_.end())
615                 return string();
616         // if so, search for it
617         vector<string> pars = getVectorFromString(separatedParams(), "\n");
618         for (vector<string>::iterator it = pars.begin(); it != pars.end(); ++it)
619                 if (prefixIs(*it, param + "=")) {
620                         string par = it->substr(param.size() + 1);
621                         if (prefixIs(par, "{") && suffixIs(par, "}"))
622                                 return par.substr(1, par.size() - 2);
623                         else
624                                 return par;
625                 }
626         // if param= is not found, should be something like float, return ""
627         return string();
628 }
629
630
631 } // namespace lyx