]> git.lyx.org Git - lyx.git/blob - src/Lexer.cpp
Fix dialog handling of Insert Plain Text
[lyx.git] / src / Lexer.cpp
1 /**
2  * \file Lexer.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "Lexer.h"
17
18 #include "debug.h"
19
20 #include "support/convert.h"
21 #include "support/filetools.h"
22 #include "support/gzstream.h"
23 #include "support/lstrings.h"
24 #include "support/lyxalgo.h"
25 #include "support/types.h"
26 #include "support/unicode.h"
27
28 #include <boost/noncopyable.hpp>
29
30 #include <functional>
31 #include <istream>
32 #include <stack>
33 #include <sstream>
34 #include <vector>
35
36
37 namespace lyx {
38
39 using support::compare_ascii_no_case;
40 using support::FileName;
41 using support::isStrDbl;
42 using support::isStrInt;
43 using support::ltrim;
44 using support::makeDisplayPath;
45 using support::prefixIs;
46 using support::split;
47 using support::subst;
48 using support::trim;
49
50 using std::endl;
51 using std::getline;
52 using std::lower_bound;
53 using std::sort;
54 using std::string;
55 using std::ios;
56 using std::istream;
57 using std::ostream;
58
59
60 //////////////////////////////////////////////////////////////////////
61 //
62 // Lexer::Pimpl
63 //
64 //////////////////////////////////////////////////////////////////////
65
66
67 ///
68 class Lexer::Pimpl : boost::noncopyable {
69 public:
70         ///
71         Pimpl(keyword_item * tab, int num);
72         ///
73         std::string const getString() const;
74         ///
75         docstring const getDocString() const;
76         ///
77         void printError(std::string const & message) const;
78         ///
79         void printTable(std::ostream & os);
80         ///
81         void pushTable(keyword_item * tab, int num);
82         ///
83         void popTable();
84         ///
85         bool setFile(support::FileName const & filename);
86         ///
87         void setStream(std::istream & i);
88         ///
89         void setCommentChar(char c);
90         ///
91         bool next(bool esc = false);
92         ///
93         int search_kw(char const * const tag) const;
94         ///
95         int lex();
96         ///
97         bool eatLine();
98         ///
99         bool nextToken();
100         /// test if there is a pushed token or the stream is ok
101         bool inputAvailable();
102         ///
103         void pushToken(std::string const &);
104         /// fb_ is only used to open files, the stream is accessed through is.
105         std::filebuf fb_;
106
107         /// gz_ is only used to open files, the stream is accessed through is.
108         gz::gzstreambuf gz_;
109
110         /// the stream that we use.
111         std::istream is;
112         ///
113         std::string name;
114         ///
115         keyword_item * table;
116         ///
117         int no_items;
118         ///
119         std::string buff;
120         ///
121         int status;
122         ///
123         int lineno;
124         ///
125         std::string pushTok;
126         ///
127         char commentChar;
128 private:
129         ///
130         void verifyTable();
131         ///
132         class pushed_table {
133         public:
134                 ///
135                 pushed_table()
136                         : table_elem(0), table_siz(0) {}
137                 ///
138                 pushed_table(keyword_item * ki, int siz)
139                         : table_elem(ki), table_siz(siz) {}
140                 ///
141                 keyword_item * table_elem;
142                 ///
143                 int table_siz;
144         };
145         ///
146         std::stack<pushed_table> pushed;
147 };
148
149
150
151 namespace {
152
153 class compare_tags
154         : public std::binary_function<keyword_item, keyword_item, bool> {
155 public:
156         // used by lower_bound, sort and sorted
157         bool operator()(keyword_item const & a, keyword_item const & b) const
158         {
159                 // we use the ascii version, because in turkish, 'i'
160                 // is not the lowercase version of 'I', and thus
161                 // turkish locale breaks parsing of tags.
162                 return compare_ascii_no_case(a.tag, b.tag) < 0;
163         }
164 };
165
166 } // end of anon namespace
167
168
169 Lexer::Pimpl::Pimpl(keyword_item * tab, int num)
170         : is(&fb_), table(tab), no_items(num),
171           status(0), lineno(0), commentChar('#')
172 {
173         verifyTable();
174 }
175
176
177 string const Lexer::Pimpl::getString() const
178 {
179         return buff;
180 }
181
182
183 docstring const Lexer::Pimpl::getDocString() const
184 {
185         return from_utf8(buff);
186 }
187
188
189 void Lexer::Pimpl::printError(string const & message) const
190 {
191         string const tmpmsg = subst(message, "$$Token", getString());
192         lyxerr << "LyX: " << tmpmsg << " [around line " << lineno
193                 << " of file " << to_utf8(makeDisplayPath(name)) << ']' << endl;
194 }
195
196
197 void Lexer::Pimpl::printTable(ostream & os)
198 {
199         os << "\nNumber of tags: " << no_items << endl;
200         for (int i= 0; i < no_items; ++i)
201                 os << "table[" << i
202                    << "]:  tag: `" << table[i].tag
203                    << "'  code:" << table[i].code << '\n';
204         os.flush();
205 }
206
207
208 void Lexer::Pimpl::verifyTable()
209 {
210         // Check if the table is sorted and if not, sort it.
211         if (table
212             && !lyx::sorted(table, table + no_items, compare_tags())) {
213                 lyxerr << "The table passed to Lexer is not sorted!\n"
214                        << "Tell the developers to fix it!" << endl;
215                 // We sort it anyway to avoid problems.
216                 lyxerr << "\nUnsorted:" << endl;
217                 printTable(lyxerr);
218
219                 sort(table, table + no_items, compare_tags());
220                 lyxerr << "\nSorted:" << endl;
221                 printTable(lyxerr);
222         }
223 }
224
225
226 void Lexer::Pimpl::pushTable(keyword_item * tab, int num)
227 {
228         pushed_table tmppu(table, no_items);
229         pushed.push(tmppu);
230
231         table = tab;
232         no_items = num;
233
234         verifyTable();
235 }
236
237
238 void Lexer::Pimpl::popTable()
239 {
240         if (pushed.empty()) {
241                 lyxerr << "Lexer error: nothing to pop!" << endl;
242                 return;
243         }
244
245         pushed_table tmp = pushed.top();
246         pushed.pop();
247         table = tmp.table_elem;
248         no_items = tmp.table_siz;
249 }
250
251
252 bool Lexer::Pimpl::setFile(FileName const & filename)
253 {
254         // Check the format of the file.
255         string const format = filename.guessFormatFromContents();
256
257         if (format == "gzip" || format == "zip" || format == "compress") {
258                 LYXERR(Debug::LYXLEX, "lyxlex: compressed");
259                 // The check only outputs a debug message, because it triggers
260                 // a bug in compaq cxx 6.2, where is_open() returns 'true' for
261                 // a fresh new filebuf.  (JMarc)
262                 if (gz_.is_open() || istream::off_type(is.tellg()) > -1)
263                         lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: "
264                                 "file or stream already set." << endl;
265                 gz_.open(filename.toFilesystemEncoding().c_str(), ios::in);
266                 is.rdbuf(&gz_);
267                 name = filename.absFilename();
268                 lineno = 0;
269                 return gz_.is_open() && is.good();
270         } else {
271                 LYXERR(Debug::LYXLEX, "lyxlex: UNcompressed");
272
273                 // The check only outputs a debug message, because it triggers
274                 // a bug in compaq cxx 6.2, where is_open() returns 'true' for
275                 // a fresh new filebuf.  (JMarc)
276                 if (fb_.is_open() || istream::off_type(is.tellg()) > 0) {
277                         LYXERR(Debug::LYXLEX, "Error in Lexer::setFile: "
278                                 "file or stream already set.");
279                 }
280                 fb_.open(filename.toFilesystemEncoding().c_str(), ios::in);
281                 is.rdbuf(&fb_);
282                 name = filename.absFilename();
283                 lineno = 0;
284                 return fb_.is_open() && is.good();
285         }
286 }
287
288
289 void Lexer::Pimpl::setStream(istream & i)
290 {
291         if (fb_.is_open() || istream::off_type(is.tellg()) > 0) {
292                 LYXERR(Debug::LYXLEX, "Error in Lexer::setStream: "
293                         "file or stream already set.");
294         }
295         is.rdbuf(i.rdbuf());
296         lineno = 0;
297 }
298
299
300 void Lexer::Pimpl::setCommentChar(char c)
301 {
302         commentChar = c;
303 }
304
305
306 bool Lexer::Pimpl::next(bool esc /* = false */)
307 {
308         if (!pushTok.empty()) {
309                 // There can have been a whole line pushed so
310                 // we extract the first word and leaves the rest
311                 // in pushTok. (Lgb)
312                 if (pushTok[0] == '\\' && pushTok.find(' ') != string::npos) {
313                         buff.clear();
314                         pushTok = split(pushTok, buff, ' ');
315                 } else {
316                         buff = pushTok;
317                         pushTok.clear();
318                 }
319                 status = LEX_TOKEN;
320                 return true;
321         }
322         if (!esc) {
323                 unsigned char c = 0; // getc() returns an int
324                 char cc = 0;
325                 status = 0;
326                 while (is && !status) {
327                         is.get(cc);
328                         c = cc;
329                         if (c == commentChar) {
330                                 // Read rest of line (fast :-)
331 #if 1
332                                 // That is not fast... (Lgb)
333                                 string dummy;
334                                 getline(is, dummy);
335
336                                 LYXERR(Debug::LYXLEX, "Comment read: `" << c << dummy << '\'');
337 #else
338                                 // unfortunately ignore is buggy (Lgb)
339                                 is.ignore(100, '\n');
340 #endif
341                                 ++lineno;
342                                 continue;
343                         }
344
345                         if (c == '\"') {
346                                 buff.clear();
347
348                                 do {
349                                         is.get(cc);
350                                         c = cc;
351                                         if (c != '\r')
352                                                 buff.push_back(c);
353                                 } while (c != '\"' && c != '\n' && is);
354
355                                 if (c != '\"') {
356                                         printError("Missing quote");
357                                         if (c == '\n')
358                                                 ++lineno;
359                                 }
360
361                                 buff.resize(buff.size()-1);
362                                 status = LEX_DATA;
363                                 break;
364                         }
365
366                         if (c == ',')
367                                 continue;              /* Skip ','s */
368
369                                 // using relational operators with chars other
370                                 // than == and != is not safe. And if it is done
371                                 // the type _have_ to be unsigned. It usually a
372                                 // lot better to use the functions from cctype
373                         if (c > ' ' && is)  {
374                                 buff.clear();
375
376                                 do {
377                                         buff.push_back(c);
378                                         is.get(cc);
379                                         c = cc;
380                                 } while (c > ' ' && c != ',' && is);
381
382                                 status = LEX_TOKEN;
383                         }
384
385                         if (c == '\r' && is) {
386                                 // The Windows support has lead to the
387                                 // possibility of "\r\n" at the end of
388                                 // a line.  This will stop LyX choking
389                                 // when it expected to find a '\n'
390                                 is.get(cc);
391                                 c = cc;
392                         }
393
394                         if (c == '\n')
395                                 ++lineno;
396
397                 }
398                 if (status)
399                         return true;
400
401                 status = is.eof() ? LEX_FEOF: LEX_UNDEF;
402                 buff.clear();
403                 return false;
404         } else {
405                 unsigned char c = 0; // getc() returns an int
406                 char cc = 0;
407
408                 status = 0;
409                 while (is && !status) {
410                         is.get(cc);
411                         c = cc;
412
413                         // skip ','s
414                         if (c == ',')
415                                 continue;
416
417                         if (c == commentChar) {
418                                 // Read rest of line (fast :-)
419 #if 1
420                                 // That is still not fast... (Lgb)
421                                 string dummy;
422                                 getline(is, dummy);
423
424                                 LYXERR(Debug::LYXLEX, "Comment read: `" << c << dummy << '\'');
425 #else
426                                 // but ignore is also still buggy (Lgb)
427                                 // This is fast (Lgb)
428                                 is.ignore(100, '\n');
429 #endif
430                                 ++lineno;
431                                 continue;
432                         }
433
434                         // string
435                         if (c == '\"') {
436                                 buff.clear();
437
438                                 bool escaped = false;
439                                 do {
440                                         escaped = false;
441                                         is.get(cc);
442                                         c = cc;
443                                         if (c == '\r') continue;
444                                         if (c == '\\') {
445                                                 // escape the next char
446                                                 is.get(cc);
447                                                 c = cc;
448                                                 if (c == '\"' || c == '\\')
449                                                         escaped = true;
450                                                 else
451                                                         buff.push_back('\\');
452                                         }
453                                         buff.push_back(c);
454
455                                         if (!escaped && c == '\"')
456                                                 break;
457                                 } while (c != '\n' && is);
458
459                                 if (c != '\"') {
460                                         printError("Missing quote");
461                                         if (c == '\n')
462                                                 ++lineno;
463                                 }
464
465                                 buff.resize(buff.size() -1);
466                                 status = LEX_DATA;
467                                 break;
468                         }
469
470                         if (c > ' ' && is) {
471                                 buff.clear();
472
473                                 do {
474                                         if (c == '\\') {
475                                                 // escape the next char
476                                                 is.get(cc);
477                                                 c = cc;
478                                                 //escaped = true;
479                                         }
480                                         buff.push_back(c);
481                                         is.get(cc);
482                                         c = cc;
483                                 } while (c > ' ' && c != ',' && is);
484
485                                 status = LEX_TOKEN;
486                         }
487                         // new line
488                         if (c == '\n')
489                                 ++lineno;
490                 }
491
492                 if (status)
493                         return true;
494
495                 status = is.eof() ? LEX_FEOF : LEX_UNDEF;
496                 buff.clear();
497                 return false;
498         }
499 }
500
501
502 int Lexer::Pimpl::search_kw(char const * const tag) const
503 {
504         keyword_item search_tag = { tag, 0 };
505         keyword_item * res =
506                 lower_bound(table, table + no_items,
507                             search_tag, compare_tags());
508         // use the compare_ascii_no_case instead of compare_no_case,
509         // because in turkish, 'i' is not the lowercase version of 'I',
510         // and thus turkish locale breaks parsing of tags.
511         if (res != table + no_items
512             && !compare_ascii_no_case(res->tag, tag))
513                 return res->code;
514         return LEX_UNDEF;
515 }
516
517
518 int Lexer::Pimpl::lex()
519 {
520         //NOTE: possible bug.
521         if (next() && status == LEX_TOKEN)
522                 return search_kw(getString().c_str());
523         return status;
524 }
525
526
527 bool Lexer::Pimpl::eatLine()
528 {
529         buff.clear();
530
531         unsigned char c = '\0';
532         char cc = 0;
533         while (is && c != '\n') {
534                 is.get(cc);
535                 c = cc;
536                 //LYXERR(Debug::LYXLEX, "Lexer::EatLine read char: `" << c << '\'');
537                 if (c != '\r')
538                         buff.push_back(c);
539         }
540
541         if (c == '\n') {
542                 ++lineno;
543                 buff.resize(buff.size() - 1);
544                 status = LEX_DATA;
545                 return true;
546         } else if (buff.length() > 0) { // last line
547                 status = LEX_DATA;
548                 return true;
549         } else {
550                 return false;
551         }
552 }
553
554
555 bool Lexer::Pimpl::nextToken()
556 {
557         if (!pushTok.empty()) {
558                 // There can have been a whole line pushed so
559                 // we extract the first word and leaves the rest
560                 // in pushTok. (Lgb)
561                 if (pushTok[0] == '\\' && pushTok.find(' ') != string::npos) {
562                         buff.clear();
563                         pushTok = split(pushTok, buff, ' ');
564                 } else {
565                         buff = pushTok;
566                         pushTok.clear();
567                 }
568                 status = LEX_TOKEN;
569                 return true;
570         }
571
572         status = 0;
573         while (is && !status) {
574                 unsigned char c = 0;
575                 char cc = 0;
576                 is.get(cc);
577                 c = cc;
578                 if (c >= ' ' && is) {
579                         buff.clear();
580
581                         if (c == '\\') { // first char == '\\'
582                                 do {
583                                         buff.push_back(c);
584                                         is.get(cc);
585                                         c = cc;
586                                 } while (c > ' ' && c != '\\' && is);
587                         } else {
588                                 do {
589                                         buff.push_back(c);
590                                         is.get(cc);
591                                         c = cc;
592                                 } while (c >= ' ' && c != '\\' && is);
593                         }
594
595                         if (c == '\\') is.putback(c); // put it back
596                         status = LEX_TOKEN;
597                 }
598
599                 if (c == '\n')
600                         ++lineno;
601
602         }
603         if (status)
604                 return true;
605
606         status = is.eof() ? LEX_FEOF: LEX_UNDEF;
607         buff.clear();
608         return false;
609 }
610
611
612 bool Lexer::Pimpl::inputAvailable()
613 {
614         return is.good();
615 }
616
617
618 void Lexer::Pimpl::pushToken(string const & pt)
619 {
620         pushTok = pt;
621 }
622
623
624
625
626 //////////////////////////////////////////////////////////////////////
627 //
628 // Lexer
629 //
630 //////////////////////////////////////////////////////////////////////
631
632 Lexer::Lexer(keyword_item * tab, int num)
633         : pimpl_(new Pimpl(tab, num))
634 {}
635
636
637 Lexer::~Lexer()
638 {
639         delete pimpl_;
640 }
641
642
643 bool Lexer::isOK() const
644 {
645         return pimpl_->inputAvailable();
646 }
647
648
649 void Lexer::setLineNo(int l)
650 {
651         pimpl_->lineno = l;
652 }
653
654
655 int Lexer::getLineNo() const
656 {
657         return pimpl_->lineno;
658 }
659
660
661 istream & Lexer::getStream()
662 {
663         return pimpl_->is;
664 }
665
666
667 void Lexer::pushTable(keyword_item * tab, int num)
668 {
669         pimpl_->pushTable(tab, num);
670 }
671
672
673 void Lexer::popTable()
674 {
675         pimpl_->popTable();
676 }
677
678
679 void Lexer::printTable(ostream & os)
680 {
681         pimpl_->printTable(os);
682 }
683
684
685 void Lexer::printError(string const & message) const
686 {
687         pimpl_->printError(message);
688 }
689
690
691 bool Lexer::setFile(support::FileName const & filename)
692 {
693         return pimpl_->setFile(filename);
694 }
695
696
697 void Lexer::setStream(istream & i)
698 {
699         pimpl_->setStream(i);
700 }
701
702
703 void Lexer::setCommentChar(char c)
704 {
705         pimpl_->setCommentChar(c);
706 }
707
708 int Lexer::lex()
709 {
710         return pimpl_->lex();
711 }
712
713
714 int Lexer::getInteger() const
715 {
716         lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
717         if (!lastReadOk_) {
718                 pimpl_->printError("integer token missing");
719                 return -1;
720         }
721
722         if (isStrInt(pimpl_->getString()))
723                 return convert<int>(pimpl_->getString());
724
725         lastReadOk_ = false;
726         pimpl_->printError("Bad integer `$$Token'");
727         return -1;
728 }
729
730
731 double Lexer::getFloat() const
732 {
733         // replace comma with dot in case the file was written with
734         // the wrong locale (should be rare, but is easy enough to
735         // avoid).
736         lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
737         if (!lastReadOk_) {
738                 pimpl_->printError("float token missing");
739                 return -1;
740         }
741
742         string const str = subst(pimpl_->getString(), ",", ".");
743         if (isStrDbl(str))
744                 return convert<double>(str);
745
746         lastReadOk_ = false;
747         pimpl_->printError("Bad float `$$Token'");
748         return -1;
749 }
750
751
752 string const Lexer::getString() const
753 {
754         lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
755
756         if (lastReadOk_)
757         return pimpl_->getString();
758
759         return string();
760 }
761
762
763 docstring const Lexer::getDocString() const
764 {
765         lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
766
767         if (lastReadOk_)
768                 return pimpl_->getDocString();
769
770         return docstring();
771 }
772
773
774 // I would prefer to give a tag number instead of an explicit token
775 // here, but it is not possible because Buffer::readDocument uses
776 // explicit tokens (JMarc)
777 string const Lexer::getLongString(string const & endtoken)
778 {
779         string str, prefix;
780         bool firstline = true;
781
782         while (pimpl_->is) { //< eatLine only reads from is, not from pushTok
783                 if (!eatLine())
784                         // blank line in the file being read
785                         continue;
786
787                 string const token = trim(getString(), " \t");
788
789                 LYXERR(Debug::PARSER, "LongString: `" << getString() << '\'');
790
791                 // We do a case independent comparison, like search_kw does.
792                 if (compare_ascii_no_case(token, endtoken) == 0)
793                         break;
794
795                 string tmpstr = getString();
796                 if (firstline) {
797                         string::size_type i(tmpstr.find_first_not_of(' '));
798                         if (i != string::npos)
799                                 prefix = tmpstr.substr(0, i);
800                         firstline = false;
801                         LYXERR(Debug::PARSER, "Prefix = `" << prefix << "\'");
802                 }
803
804                 // further lines in long strings may have the same
805                 // whitespace prefix as the first line. Remove it.
806                 if (prefix.length() && prefixIs(tmpstr, prefix)) {
807                         tmpstr.erase(0, prefix.length() - 1);
808                 }
809
810                 str += ltrim(tmpstr, "\t") + '\n';
811         }
812
813         if (!pimpl_->is) {
814                 printError("Long string not ended by `" + endtoken + '\'');
815         }
816
817         return str;
818 }
819
820
821 bool Lexer::getBool() const
822 {
823         if (pimpl_->getString() == "true") {
824                 lastReadOk_ = true;
825                 return true;
826         } else if (pimpl_->getString() != "false") {
827                 pimpl_->printError("Bad boolean `$$Token'. "
828                                    "Use \"false\" or \"true\"");
829                 lastReadOk_ = false;
830         }
831         lastReadOk_ = true;
832         return false;
833 }
834
835
836 bool Lexer::eatLine()
837 {
838         return pimpl_->eatLine();
839 }
840
841
842 bool Lexer::next(bool esc)
843 {
844         return pimpl_->next(esc);
845 }
846
847
848 bool Lexer::nextToken()
849 {
850         return pimpl_->nextToken();
851 }
852
853
854 void Lexer::pushToken(string const & pt)
855 {
856         pimpl_->pushToken(pt);
857 }
858
859
860 Lexer::operator void const *() const
861 {
862         // This behaviour is NOT the same as the std::streams which would
863         // use fail() here. However, our implementation of getString() et al.
864         // can cause the eof() and fail() bits to be set, even though we
865         // haven't tried to read 'em.
866         return lastReadOk_? this : 0;
867 }
868
869
870 bool Lexer::operator!() const
871 {
872         return !lastReadOk_;
873 }
874
875
876 Lexer & Lexer::operator>>(std::string & s)
877 {
878         if (isOK()) {
879                 next();
880                 s = getString();
881         } else {
882                 lastReadOk_ = false;
883         }
884         return *this;
885 }
886
887
888 Lexer & Lexer::operator>>(docstring & s)
889 {
890         if (isOK()) {
891                 next();
892                 s = getDocString();
893         } else {
894                 lastReadOk_ = false;
895         }
896         return *this;
897 }
898
899
900 Lexer & Lexer::operator>>(double & s)
901 {
902         if (isOK()) {
903                 next();
904                 s = getFloat();
905         } else {
906                 lastReadOk_ = false;
907         }
908         return *this;
909 }
910
911
912 Lexer & Lexer::operator>>(int & s)
913 {
914         if (isOK()) {
915                 next();
916                 s = getInteger();
917         } else {
918                 lastReadOk_ = false;
919         }
920         return *this;
921 }
922
923
924 Lexer & Lexer::operator>>(unsigned int & s)
925 {
926         if (isOK()) {
927                 next();
928                 s = getInteger();
929         } else {
930                 lastReadOk_ = false;
931         }
932         return *this;
933 }
934
935
936 Lexer & Lexer::operator>>(bool & s)
937 {
938         if (isOK()) {
939                 next();
940                 s = getBool();
941         } else {
942                 lastReadOk_ = false;
943         }
944         return *this;
945 }
946
947
948 /// quotes a string, e.g. for use in preferences files or as an argument of the "log" dialog
949 string const Lexer::quoteString(string const & arg)
950 {
951         std::ostringstream os;
952         os << '"' << subst(subst(arg, "\\", "\\\\"), "\"", "\\\"") << '"';
953         return os.str();
954 }
955
956
957 } // namespace lyx