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