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