]> git.lyx.org Git - lyx.git/blob - src/support/lstrings.C
This commit moves system font initialization and restoration to new support/fontutils...
[lyx.git] / src / support / lstrings.C
1 /**
2  * \file lstrings.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/lstrings.h"
15 #include "support/lyxlib.h"
16 #include "support/convert.h"
17
18 #include "debug.h"
19
20 #include <boost/tokenizer.hpp>
21 #include <boost/assert.hpp>
22
23 #ifndef I_AM_NOT_AFRAID_OF_HEADER_LIBRARIES
24 #if USE_BOOST_FORMAT
25 #include <boost/format.hpp>
26 #endif
27 #endif
28
29 #include <cctype>
30 #include <cstdlib>
31
32 #include <algorithm>
33 #include <sstream>
34
35 using lyx::docstring;
36
37 using std::transform;
38 using std::string;
39 using std::vector;
40
41 #ifndef CXX_GLOBAL_CSTD
42 using std::isdigit;
43 using std::tolower;
44 using std::toupper;
45 #endif
46
47
48 namespace lyx {
49 namespace support {
50
51 int compare_no_case(string const & s, string const & s2)
52 {
53         string::const_iterator p = s.begin();
54         string::const_iterator p2 = s2.begin();
55
56         while (p != s.end() && p2 != s2.end()) {
57                 int const lc1 = tolower(*p);
58                 int const lc2 = tolower(*p2);
59                 if (lc1 != lc2)
60                         return (lc1 < lc2) ? -1 : 1;
61                 ++p;
62                 ++p2;
63         }
64
65         if (s.size() == s2.size())
66                 return 0;
67         if (s.size() < s2.size())
68                 return -1;
69         return 1;
70 }
71
72
73 int compare_no_case(docstring const & s, docstring const & s2)
74 {
75         docstring::const_iterator p = s.begin();
76         docstring::const_iterator p2 = s2.begin();
77
78         while (p != s.end() && p2 != s2.end()) {
79                 int const lc1 = tolower(*p);
80                 int const lc2 = tolower(*p2);
81                 if (lc1 != lc2)
82                         return (lc1 < lc2) ? -1 : 1;
83                 ++p;
84                 ++p2;
85         }
86
87         if (s.size() == s2.size())
88                 return 0;
89         if (s.size() < s2.size())
90                 return -1;
91         return 1;
92 }
93
94
95 namespace {
96         int ascii_tolower(int c) {
97                 if (c >= 'A' && c <= 'Z')
98                         return c - 'A' + 'a';
99                 return c;
100         }
101 }
102
103
104 int compare_ascii_no_case(string const & s, string const & s2)
105 {
106         string::const_iterator p = s.begin();
107         string::const_iterator p2 = s2.begin();
108
109         while (p != s.end() && p2 != s2.end()) {
110                 int const lc1 = ascii_tolower(*p);
111                 int const lc2 = ascii_tolower(*p2);
112                 if (lc1 != lc2)
113                         return (lc1 < lc2) ? -1 : 1;
114                 ++p;
115                 ++p2;
116         }
117
118         if (s.size() == s2.size())
119                 return 0;
120         if (s.size() < s2.size())
121                 return -1;
122         return 1;
123 }
124
125
126 int compare_no_case(string const & s, string const & s2, unsigned int len)
127 {
128         string::const_iterator p = s.begin();
129         string::const_iterator p2 = s2.begin();
130         unsigned int i = 0;
131         while (i < len && p != s.end() && p2 != s2.end()) {
132                 int const lc1 = tolower(*p);
133                 int const lc2 = tolower(*p2);
134                 if (lc1 != lc2)
135                         return (lc1 < lc2) ? -1 : 1;
136                 ++i;
137                 ++p;
138                 ++p2;
139         }
140
141         if (s.size() >= len && s2.size() >= len)
142                 return 0;
143         if (s.size() < s2.size())
144                 return -1;
145         return 1;
146 }
147
148
149 bool isStrInt(string const & str)
150 {
151         if (str.empty()) return false;
152
153         // Remove leading and trailing white space chars.
154         string const tmpstr = trim(str);
155         if (tmpstr.empty()) return false;
156
157         string::const_iterator cit = tmpstr.begin();
158         if ((*cit) == '-') ++cit;
159         string::const_iterator end = tmpstr.end();
160         for (; cit != end; ++cit) {
161                 if (!isdigit((*cit))) return false;
162         }
163         return true;
164 }
165
166
167 bool isStrUnsignedInt(string const & str)
168 {
169         if (str.empty()) return false;
170
171         // Remove leading and trailing white space chars.
172         string const tmpstr = trim(str);
173         if (tmpstr.empty()) return false;
174
175         string::const_iterator cit = tmpstr.begin();
176         string::const_iterator end = tmpstr.end();
177         for (; cit != end; ++cit) {
178                 if (!isdigit((*cit))) return false;
179         }
180         return true;
181 }
182
183
184 bool isStrDbl(string const & str)
185 {
186         if (str.empty()) return false;
187
188         // Remove leading and trailing white space chars.
189         string const tmpstr = trim(str);
190         if (tmpstr.empty()) return false;
191         //      if (1 < tmpstr.count('.')) return false;
192
193         string::const_iterator cit = tmpstr.begin();
194         bool found_dot(false);
195         if ((*cit) == '-') ++cit;
196         string::const_iterator end = tmpstr.end();
197         for (; cit != end; ++cit) {
198                 if (!isdigit((*cit))
199                     && '.' != (*cit)) {
200                         return false;
201                 }
202                 if ('.' == (*cit)) {
203                         if (found_dot) {
204                                 return false;
205                         } else {
206                                 found_dot = true;
207                         }
208                 }
209         }
210         return true;
211 }
212
213
214 char lowercase(char c)
215 {
216         return char(tolower(c));
217 }
218
219
220 char uppercase(char c)
221 {
222         return char(toupper(c));
223 }
224
225 // FIXME for lowercase() and uppercase() function below:
226 // 1) std::tolower() and std::toupper() are templates that
227 // compile fine with char_type. With the test (c >= 256) we
228 // do not trust these function to do the right thing with
229 // unicode char.
230 // 2) these functions use the current locale, which is wrong
231 // if it is not latin1 based (latin1 is a subset of UCS4).
232
233 char_type lowercase(char_type c)
234 {
235         if (c >= 256)
236                 return c;
237
238         return tolower(c);
239 }
240
241
242 char_type uppercase(char_type c)
243 {
244         if (c >= 256)
245                 return c;
246
247         return toupper(c);
248 }
249
250
251 namespace {
252
253 // since we cannot use std::tolower and std::toupper directly in the
254 // calls to std::transform yet, we use these helper clases. (Lgb)
255
256 struct local_lowercase {
257         char operator()(char c) const {
258                 return tolower(c);
259         }
260 };
261
262 struct local_uppercase {
263         char operator()(char c) const {
264                 return toupper(c);
265         }
266 };
267
268 struct local_ascii_lowercase {
269         char operator()(char c) const {
270                 return ascii_tolower(c);
271         }
272 };
273
274 } // end of anon namespace
275
276 string const lowercase(string const & a)
277 {
278         string tmp(a);
279         transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
280         return tmp;
281 }
282
283 string const uppercase(string const & a)
284 {
285         string tmp(a);
286         transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase());
287         return tmp;
288 }
289
290
291 string const ascii_lowercase(string const & a)
292 {
293         string tmp(a);
294         transform(tmp.begin(), tmp.end(), tmp.begin(),
295                   local_ascii_lowercase());
296         return tmp;
297 }
298
299
300 bool prefixIs(string const & a, string const & pre)
301 {
302         string::size_type const prelen = pre.length();
303         string::size_type const alen = a.length();
304
305         if (prelen > alen || a.empty())
306                 return false;
307         else {
308 #if defined(STD_STRING_IS_GOOD)
309                 return a.compare(0, prelen, pre) == 0;
310 #else
311                 return ::strncmp(a.c_str(), pre.c_str(), prelen) == 0;
312 #endif
313         }
314 }
315
316
317 bool suffixIs(string const & a, char c)
318 {
319         if (a.empty()) return false;
320         return a[a.length() - 1] == c;
321 }
322
323
324 bool suffixIs(string const & a, string const & suf)
325 {
326         string::size_type const suflen = suf.length();
327         string::size_type const alen = a.length();
328
329         if (suflen > alen) {
330                 return false;
331         } else {
332 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
333                 string tmp(a, alen - suflen);
334                 return ::strncmp(tmp.c_str(), suf.c_str(), suflen) == 0;
335 #else
336                 return a.compare(alen - suflen, suflen, suf) == 0;
337 #endif
338         }
339 }
340
341
342 bool containsOnly(string const & s, string const & cset)
343 {
344         return s.find_first_not_of(cset) == string::npos;
345 }
346
347
348 // ale970405+lasgoutt-970425
349 // rewritten to use new string (Lgb)
350 string const token(string const & a, char delim, int n)
351 {
352         if (a.empty()) return string();
353
354         string::size_type k = 0;
355         string::size_type i = 0;
356
357         // Find delimiter or end of string
358         for (; n--;)
359                 if ((i = a.find(delim, i)) == string::npos)
360                         break;
361                 else
362                         ++i; // step delim
363         // i is now the n'th delim (or string::npos)
364         if (i == string::npos) return string();
365         k = a.find(delim, i);
366         // k is now the n'th + 1 delim (or string::npos)
367
368         return a.substr(i, k - i);
369 }
370
371
372 docstring const token(docstring const & a, char_type delim, int n)
373 {
374         if (a.empty()) return docstring();
375
376         string::size_type k = 0;
377         string::size_type i = 0;
378
379         // Find delimiter or end of string
380         for (; n--;)
381                 if ((i = a.find(delim, i)) == docstring::npos)
382                         break;
383                 else
384                         ++i; // step delim
385         // i is now the n'th delim (or string::npos)
386         if (i == docstring::npos) return docstring();
387         k = a.find(delim, i);
388         // k is now the n'th + 1 delim (or string::npos)
389
390         return a.substr(i, k - i);
391 }
392
393
394 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
395 // rewritten to use new string (Lgb)
396 int tokenPos(string const & a, char delim, string const & tok)
397 {
398         int i = 0;
399         string str(a);
400         string tmptok;
401
402         while (!str.empty()) {
403                 str = split(str, tmptok, delim);
404                 if (tok == tmptok)
405                         return i;
406                 ++i;
407         }
408         return -1;
409 }
410
411
412 namespace {
413
414 template<typename Ch> inline
415 std::basic_string<Ch> const subst_char(std::basic_string<Ch> const & a,
416                 Ch oldchar, Ch newchar)
417 {
418         typedef std::basic_string<Ch> String;
419         String tmp(a);
420         typename String::iterator lit = tmp.begin();
421         typename String::iterator end = tmp.end();
422         for (; lit != end; ++lit)
423                 if ((*lit) == oldchar)
424                         (*lit) = newchar;
425         return tmp;
426 }
427
428
429 template<typename String> inline
430 String const subst_string(String const & a,
431                 String const & oldstr, String const & newstr)
432 {
433         BOOST_ASSERT(!oldstr.empty());
434         String lstr = a;
435         typename String::size_type i = 0;
436         typename String::size_type const olen = oldstr.length();
437         while ((i = lstr.find(oldstr, i)) != string::npos) {
438                 lstr.replace(i, olen, newstr);
439                 i += newstr.length(); // We need to be sure that we dont
440                 // use the same i over and over again.
441         }
442         return lstr;
443 }
444
445 }
446
447
448 string const subst(string const & a, char oldchar, char newchar)
449 {
450         return subst_char(a, oldchar, newchar);
451 }
452
453
454 docstring const subst(docstring const & a,
455                 char_type oldchar, char_type newchar)
456 {
457         return subst_char(a, oldchar, newchar);
458 }
459
460
461 string const subst(string const & a,
462                 string const & oldstr, string const & newstr)
463 {
464         return subst_string(a, oldstr, newstr);
465 }
466
467
468 docstring const subst(docstring const & a,
469                 docstring const & oldstr, docstring const & newstr)
470 {
471         return subst_string(a, oldstr, newstr);
472 }
473
474
475 string const trim(string const & a, char const * p)
476 {
477         BOOST_ASSERT(p);
478
479         if (a.empty() || !*p)
480                 return a;
481
482         string::size_type r = a.find_last_not_of(p);
483         string::size_type l = a.find_first_not_of(p);
484
485         // Is this the minimal test? (lgb)
486         if (r == string::npos && l == string::npos)
487                 return string();
488
489         return a.substr(l, r - l + 1);
490 }
491
492
493 string const rtrim(string const & a, char const * p)
494 {
495         BOOST_ASSERT(p);
496
497         if (a.empty() || !*p)
498                 return a;
499
500         string::size_type r = a.find_last_not_of(p);
501
502         // Is this test really needed? (Lgb)
503         if (r == string::npos)
504                 return string();
505
506         return a.substr(0, r + 1);
507 }
508
509
510 string const ltrim(string const & a, char const * p)
511 {
512         BOOST_ASSERT(p);
513
514         if (a.empty() || !*p)
515                 return a;
516
517         string::size_type l = a.find_first_not_of(p);
518
519         if (l == string::npos)
520                 return string();
521
522         return a.substr(l, string::npos);
523 }
524
525
526 string const split(string const & a, string & piece, char delim)
527 {
528         string tmp;
529         string::size_type i = a.find(delim);
530         if (i == a.length() - 1) {
531                 piece = a.substr(0, i);
532         } else if (i != string::npos) {
533                 piece = a.substr(0, i);
534                 tmp = a.substr(i + 1);
535         } else if (i == 0) {
536                 piece.erase();
537                 tmp = a.substr(i + 1);
538         } else {
539                 piece = a;
540         }
541         return tmp;
542 }
543
544
545 string const split(string const & a, char delim)
546 {
547         string tmp;
548         string::size_type i = a.find(delim);
549         if (i != string::npos) // found delim
550                 tmp = a.substr(i + 1);
551         return tmp;
552 }
553
554
555 // ale970521
556 string const rsplit(string const & a, string & piece, char delim)
557 {
558         string tmp;
559         string::size_type i = a.rfind(delim);
560         if (i != string::npos) { // delimiter was found
561                 piece = a.substr(0, i);
562                 tmp = a.substr(i + 1);
563         } else { // delimiter was not found
564                 piece.erase();
565         }
566         return tmp;
567 }
568
569
570 // This function escapes 8-bit characters and other problematic
571 // characters that cause problems in latex labels.
572 string const escape(string const & lab)
573 {
574         char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
575                               '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
576         string enc;
577         for (string::size_type i = 0; i < lab.length(); ++i) {
578                 unsigned char c= lab[i];
579                 if (c >= 128 || c == '=' || c == '%') {
580                         enc += '=';
581                         enc += hexdigit[c>>4];
582                         enc += hexdigit[c & 15];
583                 } else {
584                         enc += c;
585                 }
586         }
587         return enc;
588 }
589
590
591 /// gives a vector of stringparts which have the delimiter delim
592 vector<string> const getVectorFromString(string const & str,
593                                          string const & delim)
594 {
595 // Lars would like this code to go, but for now his replacement (below)
596 // doesn't fullfil the same function. I have, therefore, reactivated the
597 // old code for now. Angus 11 Nov 2002.
598 #if 1
599         vector<string> vec;
600         if (str.empty())
601                 return vec;
602         string keys = rtrim(str);
603         for(;;) {
604                 string::size_type const idx = keys.find(delim);
605                 if (idx == string::npos) {
606                         vec.push_back(ltrim(keys));
607                         break;
608                 }
609                 string const key = trim(keys.substr(0, idx));
610                 if (!key.empty())
611                         vec.push_back(key);
612                 string::size_type const start = idx + delim.size();
613                 keys = keys.substr(start);
614         }
615         return vec;
616 #else
617         boost::char_separator<char> sep(delim.c_str());
618         boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
619         return vector<string>(tokens.begin(), tokens.end());
620 #endif
621 }
622
623
624 // the same vice versa
625 string const getStringFromVector(vector<string> const & vec,
626                                  string const & delim)
627 {
628         string str;
629         int i = 0;
630         for (vector<string>::const_iterator it = vec.begin();
631              it != vec.end(); ++it) {
632                 string item = trim(*it);
633                 if (item.empty())
634                         continue;
635                 if (i++ > 0)
636                         str += delim;
637                 str += item;
638         }
639         return str;
640 }
641
642
643 int findToken(char const * const str[], string const & search_token)
644 {
645         int i = 0;
646
647         while (str[i][0] && str[i] != search_token)
648                 ++i;
649         if (!str[i][0])
650                 i = -1;
651         return i;
652 }
653
654
655 docstring const externalLineEnding(docstring const & str)
656 {
657 #if defined(__APPLE__)
658         // The MAC clipboard uses \r for lineendings, and we use \n
659         return subst(str, '\n', '\r');
660 #elif defined (_WIN32) || (defined (__CYGWIN__) && defined (X_DISPLAY_MISSING))
661         // Windows clipboard uses \r\n for lineendings, and we use \n
662         return subst(str, lyx::from_ascii("\n"), lyx::from_ascii("\r\n"));
663 #else
664         return str;
665 #endif
666 }
667
668
669 docstring const internalLineEnding(docstring const & str)
670 {
671         docstring const s = subst(str,
672                         lyx::from_ascii("\r\n"), lyx::from_ascii("\n"));
673         return subst(s, '\r', '\n');
674 }
675
676
677 #ifndef I_AM_NOT_AFRAID_OF_HEADER_LIBRARIES
678 #if USE_BOOST_FORMAT
679
680 template<>
681 docstring bformat(docstring const & fmt, int arg1)
682 {
683         return (boost::basic_format<char_type>(fmt) % arg1).str();
684 }
685
686
687 template<>
688 docstring bformat(docstring const & fmt, long arg1)
689 {
690         return (boost::basic_format<char_type>(fmt) % arg1).str();
691 }
692
693
694 template<>
695 docstring bformat(docstring const & fmt, unsigned int arg1)
696 {
697         return (boost::basic_format<char_type>(fmt) % arg1).str();
698 }
699
700
701 template<>
702 docstring bformat<docstring>(docstring const & fmt, docstring arg1)
703 {
704         return (boost::basic_format<char_type>(fmt) % arg1).str();
705 }
706
707
708 template<>
709 docstring bformat(docstring const & fmt, char * arg1)
710 {
711         return (boost::basic_format<char_type>(fmt) % arg1).str();
712 }
713
714
715 template<>
716 docstring bformat(docstring const & fmt, int arg1, int arg2)
717 {
718         return (boost::basic_format<char_type>(fmt) % arg1 % arg2).str();
719 }
720
721
722 template<>
723 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
724 {
725         return (boost::basic_format<char_type>(fmt) % arg1 % arg2).str();
726 }
727
728
729 template<>
730 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
731 {
732         return (boost::basic_format<char_type>(fmt) % arg1 % arg2).str();
733 }
734
735
736 template<>
737 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
738 {
739         return (boost::basic_format<char_type>(fmt) % arg1 % arg2 % arg3).str();
740 }
741
742
743 template<>
744 docstring bformat(docstring const & fmt,
745                docstring arg1, docstring arg2, docstring arg3, docstring arg4)
746 {
747         return (boost::basic_format<char_type>(fmt) % arg1 % arg2 % arg3 % arg4).str();
748 }
749
750 #else
751
752 template<>
753 docstring bformat(docstring const & fmt, int arg1)
754 {
755         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$d")));
756         docstring const str = subst(fmt, lyx::from_ascii("%1$d"), convert<docstring>(arg1));
757         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
758 }
759
760
761 template<>
762 docstring bformat(docstring const & fmt, long arg1)
763 {
764         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$d")));
765         docstring const str = subst(fmt, lyx::from_ascii("%1$d"), convert<docstring>(arg1));
766         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
767 }
768
769
770 template<>
771 docstring bformat(docstring const & fmt, unsigned int arg1)
772 {
773         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$d")));
774         docstring const str = subst(fmt, lyx::from_ascii("%1$d"), convert<docstring>(arg1));
775         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
776 }
777
778
779 template<>
780 docstring bformat(docstring const & fmt, docstring arg1)
781 {
782         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
783         docstring const str = subst(fmt, lyx::from_ascii("%1$s"), arg1);
784         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
785 }
786
787
788 template<>
789 docstring bformat(docstring const & fmt, char * arg1)
790 {
791         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
792         docstring const str = subst(fmt, lyx::from_ascii("%1$s"), lyx::from_ascii(arg1));
793         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
794 }
795
796
797 template<>
798 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
799 {
800         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
801         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$s")));
802         docstring str = subst(fmt, lyx::from_ascii("%1$s"), arg1);
803         str = subst(str, lyx::from_ascii("%2$s"), arg2);
804         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
805 }
806
807
808 template<>
809 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
810 {
811         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
812         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$s")));
813         docstring str = subst(fmt, lyx::from_ascii("%1$s"), lyx::from_ascii(arg1));
814         str = subst(fmt, lyx::from_ascii("%2$s"), arg2);
815         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
816 }
817
818
819 template<>
820 docstring bformat(docstring const & fmt, int arg1, int arg2)
821 {
822         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$d")));
823         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$d")));
824         docstring str = subst(fmt, lyx::from_ascii("%1$d"), convert<docstring>(arg1));
825         str = subst(str, lyx::from_ascii("%2$d"), convert<docstring>(arg2));
826         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
827 }
828
829
830 template<>
831 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
832 {
833         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
834         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$s")));
835         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%3$s")));
836         docstring str = subst(fmt, lyx::from_ascii("%1$s"), arg1);
837         str = subst(str, lyx::from_ascii("%2$s"), arg2);
838         str = subst(str, lyx::from_ascii("%3$s"), arg3);
839         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
840 }
841
842
843 template<>
844 docstring bformat(docstring const & fmt,
845                docstring arg1, docstring arg2, docstring arg3, docstring arg4)
846 {
847         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
848         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$s")));
849         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%3$s")));
850         BOOST_ASSERT(contains(fmt, lyx::from_ascii("%4$s")));
851         docstring str = subst(fmt, lyx::from_ascii("%1$s"), arg1);
852         str = subst(str, lyx::from_ascii("%2$s"), arg2);
853         str = subst(str, lyx::from_ascii("%3$s"), arg3);
854         str = subst(str, lyx::from_ascii("%4$s"), arg4);
855         return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
856 }
857
858 #endif
859 #endif
860
861 } // namespace support
862 } // namespace lyx