3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
15 #include "support/lstrings.h"
17 #include "support/convert.h"
18 #include "support/qstring_helpers.h"
19 #include "support/textutils.h"
21 #include <boost/tokenizer.hpp>
22 #include "support/lassert.h"
34 // Using this allows us to have docstring default arguments in headers
35 // without #include "support/docstring" there.
36 docstring const & empty_docstring()
42 // Using this allows us to have string default arguments in headers
43 // without #include <string>
44 string const & empty_string()
51 * Convert a QChar into a UCS4 character.
52 * This is a hack (it does only make sense for the common part of the UCS4
53 * and UTF16 encodings) and should not be used.
54 * This does only exist because of performance reasons (a real conversion
55 * using iconv is too slow on windows).
57 static inline char_type qchar_to_ucs4(QChar const & qchar)
59 LASSERT(is_utf16(static_cast<char_type>(qchar.unicode())), /**/);
60 return static_cast<char_type>(qchar.unicode());
65 * Convert a UCS4 character into a QChar.
66 * This is a hack (it does only make sense for the common part of the UCS4
67 * and UTF16 encodings) and should not be used.
68 * This does only exist because of performance reasons (a real conversion
69 * using iconv is too slow on windows).
71 static inline QChar const ucs4_to_qchar(char_type const ucs4)
73 LASSERT(is_utf16(ucs4), /**/);
74 return QChar(static_cast<unsigned short>(ucs4));
79 /// Maximum valid UCS4 code point
80 char_type const ucs4_max = 0x10ffff;
84 bool isLetterChar(char_type c)
88 // outside the UCS4 range
90 // assume that all non-utf16 characters are letters
93 return ucs4_to_qchar(c).isLetter();
97 bool isLower(char_type c)
101 return ucs4_to_qchar(c).isLower();
105 bool isAlphaASCII(char_type c)
107 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
111 bool isPrintable(char_type c)
115 // outside the UCS4 range
117 // assume that all non-utf16 characters are printable
120 return ucs4_to_qchar(c).isPrint();
124 bool isPrintableNonspace(char_type c)
128 // outside the UCS4 range
130 // assume that all non-utf16 characters are printable and
134 QChar const qc = ucs4_to_qchar(c);
135 return qc.isPrint() && !qc.isSpace();
139 bool isSpace(char_type c)
142 // assume that no non-utf16 character is a space
143 // c outside the UCS4 range is catched as well
146 QChar const qc = ucs4_to_qchar(c);
151 bool isDigit(char_type c)
154 // assume that no non-utf16 character is a digit
155 // c outside the UCS4 range is catched as well
157 return ucs4_to_qchar(c).isDigit();
161 bool isDigitASCII(char_type c)
163 return '0' <= c && c <= '9';
168 int compare_no_case(docstring const & s, docstring const & s2)
170 docstring::const_iterator p = s.begin();
171 docstring::const_iterator p2 = s2.begin();
173 while (p != s.end() && p2 != s2.end()) {
174 char_type const lc1 = lowercase(*p);
175 char_type const lc2 = lowercase(*p2);
177 return (lc1 < lc2) ? -1 : 1;
182 if (s.size() == s2.size())
184 if (s.size() < s2.size())
192 template<typename Char>
193 Char ascii_tolower(Char c) {
194 if (c >= 'A' && c <= 'Z')
195 return c - 'A' + 'a';
202 int compare_ascii_no_case(string const & s, string const & s2)
204 string::const_iterator p = s.begin();
205 string::const_iterator p2 = s2.begin();
207 while (p != s.end() && p2 != s2.end()) {
208 int const lc1 = ascii_tolower(*p);
209 int const lc2 = ascii_tolower(*p2);
211 return (lc1 < lc2) ? -1 : 1;
216 if (s.size() == s2.size())
218 if (s.size() < s2.size())
224 int compare_ascii_no_case(docstring const & s, docstring const & s2)
226 docstring::const_iterator p = s.begin();
227 docstring::const_iterator p2 = s2.begin();
229 while (p != s.end() && p2 != s2.end()) {
230 char_type const lc1 = ascii_tolower(*p);
231 char_type const lc2 = ascii_tolower(*p2);
233 return (lc1 < lc2) ? -1 : 1;
238 if (s.size() == s2.size())
240 if (s.size() < s2.size())
246 bool isStrInt(string const & str)
251 // Remove leading and trailing white space chars.
252 string const tmpstr = trim(str);
256 string::const_iterator cit = tmpstr.begin();
260 string::const_iterator end = tmpstr.end();
261 for (; cit != end; ++cit)
262 if (!isdigit((*cit)))
269 bool isStrUnsignedInt(string const & str)
274 // Remove leading and trailing white space chars.
275 string const tmpstr = trim(str);
279 string::const_iterator cit = tmpstr.begin();
280 string::const_iterator end = tmpstr.end();
281 for (; cit != end; ++cit)
282 if (!isdigit((*cit)))
289 bool isStrDbl(string const & str)
294 // Remove leading and trailing white space chars.
295 string const tmpstr = trim(str);
298 // if (tmpstr.count('.') > 1) return false;
300 string::const_iterator cit = tmpstr.begin();
301 bool found_dot = false;
304 string::const_iterator end = tmpstr.end();
305 for (; cit != end; ++cit) {
306 if (!isdigit(*cit) && *cit != '.')
318 bool hasDigit(docstring const & str)
323 // Remove leading and trailing white space chars.
324 docstring const tmpstr = trim(str);
328 docstring::const_iterator cit = tmpstr.begin();
329 docstring::const_iterator end = tmpstr.end();
330 for (; cit != end; ++cit)
338 static bool isHexChar(char_type c)
350 c == 'a' || c == 'A' ||
351 c == 'b' || c == 'B' ||
352 c == 'c' || c == 'C' ||
353 c == 'd' || c == 'D' ||
354 c == 'e' || c == 'E' ||
355 c == 'f' || c == 'F';
359 bool isHex(docstring const & str)
363 if (str.length() > 2 && str[0] == '0' &&
364 (str[1] == 'x' || str[1] == 'X'))
367 int const len = str.length();
369 for (; index < len; ++index) {
370 if (!isHexChar(str[index]))
377 int hexToInt(docstring const & str)
379 string s = to_ascii(str);
381 sscanf(s.c_str(), "%x", &h);
386 bool isAscii(docstring const & str)
388 int const len = str.length();
389 for (int i = 0; i < len; ++i)
396 bool isAscii(string const & str)
398 int const len = str.length();
399 for (int i = 0; i < len; ++i)
400 if (static_cast<unsigned char>(str[i]) >= 0x80)
406 char lowercase(char c)
408 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
409 return char(tolower(c));
413 char uppercase(char c)
415 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
416 return char(toupper(c));
420 char_type lowercase(char_type c)
423 // We don't know how to lowercase a non-utf16 char
425 return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
429 char_type uppercase(char_type c)
432 // We don't know how to uppercase a non-utf16 char
434 return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
440 // since we cannot use tolower and toupper directly in the
441 // calls to transform yet, we use these helper clases. (Lgb)
443 struct local_lowercase {
444 char_type operator()(char_type c) const {
446 // We don't know how to lowercase a non-utf16 char
448 return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
452 struct local_uppercase {
453 char_type operator()(char_type c) const {
455 // We don't know how to uppercase a non-utf16 char
457 return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
461 template<typename Char> struct local_ascii_lowercase {
462 Char operator()(Char c) const { return ascii_tolower(c); }
465 } // end of anon namespace
467 docstring const lowercase(docstring const & a)
470 transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
475 docstring const uppercase(docstring const & a)
478 transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase());
483 string const ascii_lowercase(string const & a)
486 transform(tmp.begin(), tmp.end(), tmp.begin(),
487 local_ascii_lowercase<char>());
492 docstring const ascii_lowercase(docstring const & a)
495 transform(tmp.begin(), tmp.end(), tmp.begin(),
496 local_ascii_lowercase<char_type>());
501 bool prefixIs(docstring const & a, char_type c)
509 bool prefixIs(string const & a, string const & pre)
511 size_t const prelen = pre.length();
512 size_t const alen = a.length();
513 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
517 bool prefixIs(docstring const & a, docstring const & pre)
519 size_t const prelen = pre.length();
520 size_t const alen = a.length();
521 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
525 bool suffixIs(string const & a, char c)
529 return a[a.length() - 1] == c;
533 bool suffixIs(docstring const & a, char_type c)
537 return a[a.length() - 1] == c;
541 bool suffixIs(string const & a, string const & suf)
543 size_t const suflen = suf.length();
544 size_t const alen = a.length();
545 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
549 bool suffixIs(docstring const & a, docstring const & suf)
551 size_t const suflen = suf.length();
552 size_t const alen = a.length();
553 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
557 bool containsOnly(string const & s, string const & cset)
559 return s.find_first_not_of(cset) == string::npos;
563 // ale970405+lasgoutt-970425
564 // rewritten to use new string (Lgb)
565 string const token(string const & a, char delim, int n)
573 // Find delimiter or end of string
575 if ((i = a.find(delim, i)) == string::npos)
581 // i is now the n'th delim (or string::npos)
582 if (i == string::npos)
585 k = a.find(delim, i);
586 // k is now the n'th + 1 delim (or string::npos)
588 return a.substr(i, k - i);
592 docstring const token(docstring const & a, char_type delim, int n)
600 // Find delimiter or end of string
602 if ((i = a.find(delim, i)) == docstring::npos)
608 // i is now the n'th delim (or string::npos)
609 if (i == docstring::npos)
612 k = a.find(delim, i);
613 // k is now the n'th + 1 delim (or string::npos)
615 return a.substr(i, k - i);
619 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
620 // rewritten to use new string (Lgb)
621 int tokenPos(string const & a, char delim, string const & tok)
627 while (!str.empty()) {
628 str = split(str, tmptok, delim);
637 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
638 // rewritten to use new string (Lgb)
639 int tokenPos(docstring const & a, char_type delim, docstring const & tok)
645 while (!str.empty()) {
646 str = split(str, tmptok, delim);
657 /// Substitute all \a oldchar with \a newchar
658 template<typename Ch> inline
659 basic_string<Ch> const subst_char(basic_string<Ch> const & a,
660 Ch oldchar, Ch newchar)
662 typedef basic_string<Ch> String;
664 typename String::iterator lit = tmp.begin();
665 typename String::iterator end = tmp.end();
666 for (; lit != end; ++lit)
667 if ((*lit) == oldchar)
672 /// Substitute all \a oldchar with \a newchar
673 docstring const subst_char(docstring const & a,
674 docstring::value_type oldchar, docstring::value_type newchar)
677 docstring::iterator lit = tmp.begin();
678 docstring::iterator end = tmp.end();
679 for (; lit != end; ++lit)
680 if ((*lit) == oldchar)
686 /// substitutes all instances of \a oldstr with \a newstr
687 template<typename String> inline
688 String const subst_string(String const & a,
689 String const & oldstr, String const & newstr)
691 LASSERT(!oldstr.empty(), /**/);
694 size_t const olen = oldstr.length();
695 while ((i = lstr.find(oldstr, i)) != string::npos) {
696 lstr.replace(i, olen, newstr);
697 i += newstr.length(); // We need to be sure that we dont
698 // use the same i over and over again.
703 docstring const subst_string(docstring const & a,
704 docstring const & oldstr, docstring const & newstr)
706 LASSERT(!oldstr.empty(), /**/);
709 size_t const olen = oldstr.length();
710 while ((i = lstr.find(oldstr, i)) != string::npos) {
711 lstr.replace(i, olen, newstr);
712 i += newstr.length(); // We need to be sure that we dont
713 // use the same i over and over again.
721 string const subst(string const & a, char oldchar, char newchar)
723 return subst_char(a, oldchar, newchar);
727 docstring const subst(docstring const & a,
728 char_type oldchar, char_type newchar)
730 return subst_char(a, oldchar, newchar);
734 string const subst(string const & a,
735 string const & oldstr, string const & newstr)
737 return subst_string(a, oldstr, newstr);
741 docstring const subst(docstring const & a,
742 docstring const & oldstr, docstring const & newstr)
744 return subst_string(a, oldstr, newstr);
748 docstring const trim(docstring const & a, char const * p)
752 if (a.empty() || !*p)
755 docstring s = from_ascii(p);
756 size_t r = a.find_last_not_of(s);
757 size_t l = a.find_first_not_of(s);
759 // Is this the minimal test? (lgb)
760 if (r == docstring::npos && l == docstring::npos)
763 return a.substr(l, r - l + 1);
767 string const trim(string const & a, char const * p)
771 if (a.empty() || !*p)
774 size_t r = a.find_last_not_of(p);
775 size_t l = a.find_first_not_of(p);
777 // Is this the minimal test? (lgb)
778 if (r == string::npos && l == string::npos)
781 return a.substr(l, r - l + 1);
785 string const rtrim(string const & a, char const * p)
789 if (a.empty() || !*p)
792 size_t r = a.find_last_not_of(p);
794 // Is this test really needed? (Lgb)
795 if (r == string::npos)
798 return a.substr(0, r + 1);
802 docstring const rtrim(docstring const & a, char const * p)
806 if (a.empty() || !*p)
809 size_t r = a.find_last_not_of(from_ascii(p));
811 // Is this test really needed? (Lgb)
812 if (r == docstring::npos)
815 return a.substr(0, r + 1);
819 string const ltrim(string const & a, char const * p)
822 if (a.empty() || !*p)
824 size_t l = a.find_first_not_of(p);
825 if (l == string::npos)
827 return a.substr(l, string::npos);
831 docstring const ltrim(docstring const & a, char const * p)
834 if (a.empty() || !*p)
836 size_t l = a.find_first_not_of(from_ascii(p));
837 if (l == docstring::npos)
839 return a.substr(l, docstring::npos);
844 template<typename String, typename Char> inline
845 String const doSplit(String const & a, String & piece, Char delim)
848 size_t i = a.find(delim);
849 if (i == a.length() - 1) {
850 piece = a.substr(0, i);
851 } else if (i != String::npos) {
852 piece = a.substr(0, i);
853 tmp = a.substr(i + 1);
856 tmp = a.substr(i + 1);
863 template<typename Char> inline
864 docstring const doSplit(docstring const & a, docstring & piece, Char delim)
867 size_t i = a.find(delim);
868 if (i == a.length() - 1) {
869 piece = a.substr(0, i);
870 } else if (i != docstring::npos) {
871 piece = a.substr(0, i);
872 tmp = a.substr(i + 1);
875 tmp = a.substr(i + 1);
885 string const split(string const & a, string & piece, char delim)
887 return doSplit(a, piece, delim);
891 docstring const split(docstring const & a, docstring & piece, char_type delim)
893 return doSplit(a, piece, delim);
897 string const split(string const & a, char delim)
900 size_t i = a.find(delim);
901 if (i != string::npos) // found delim
902 tmp = a.substr(i + 1);
908 string const rsplit(string const & a, string & piece, char delim)
911 size_t i = a.rfind(delim);
912 if (i != string::npos) { // delimiter was found
913 piece = a.substr(0, i);
914 tmp = a.substr(i + 1);
915 } else { // delimiter was not found
922 docstring const rsplit(docstring const & a, char_type delim)
925 size_t i = a.rfind(delim);
926 if (i != string::npos)
927 tmp = a.substr(i + 1);
932 docstring const escape(docstring const & lab)
934 char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
935 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
937 for (size_t i = 0; i < lab.length(); ++i) {
938 char_type c = lab[i];
939 if (c >= 128 || c == '=' || c == '%') {
940 // Although char_type is a 32 bit type we know that
941 // UCS4 occupies only 21 bits, so we don't need to
942 // encode bigger values. Test for 2^24 because we
943 // can encode that with the 6 hex digits that are
944 // needed for 21 bits anyway.
945 LASSERT(c < (1 << 24), /**/);
947 enc += hexdigit[(c>>20) & 15];
948 enc += hexdigit[(c>>16) & 15];
949 enc += hexdigit[(c>>12) & 15];
950 enc += hexdigit[(c>> 8) & 15];
951 enc += hexdigit[(c>> 4) & 15];
952 enc += hexdigit[ c & 15];
963 // this doesn't check whether str is empty, so do that first.
964 vector<docstring> wrapToVec(docstring const & str, int ind,
967 docstring s = trim(str);
969 return vector<docstring>();
973 indent.insert(0, -ind, ' ');
976 s.insert(0, ind, ' ');
978 vector<docstring> retval;
979 while (s.size() > width) {
980 // find the last space within the first 'width' chars
981 size_t const i = s.find_last_of(' ', width - 1);
982 if (i == docstring::npos || i <= size_t(ind)) {
984 s = s.substr(0, width - 3) + "...";
987 retval.push_back(s.substr(0, i));
988 s = indent + s.substr(i);
999 docstring wrap(docstring const & str, int const ind, size_t const width)
1001 docstring s = trim(str);
1005 vector<docstring> const svec = wrapToVec(str, ind, width);
1006 return getStringFromVector(svec, from_ascii("\n"));
1010 docstring wrapParas(docstring const & str, int const indent,
1011 size_t const width, size_t const maxlines)
1016 vector<docstring> const pars = getVectorFromString(str, from_ascii("\n"), true);
1017 vector<docstring> retval;
1019 vector<docstring>::const_iterator it = pars.begin();
1020 vector<docstring>::const_iterator const en = pars.end();
1021 for (; it != en; ++it) {
1022 vector<docstring> tmp = wrapToVec(*it, indent, width);
1023 size_t const nlines = tmp.size();
1026 size_t const curlines = retval.size();
1027 if (maxlines > 0 && curlines + nlines >= maxlines) {
1028 tmp.resize(maxlines - curlines - 1);
1029 tmp.push_back(from_ascii("..."));
1031 retval.insert(retval.end(), tmp.begin(), tmp.end());
1032 if (maxlines > 0 && retval.size() >= maxlines)
1035 return getStringFromVector(retval, from_ascii("\n"));
1041 template<typename String> vector<String> const
1042 getVectorFromStringT(String const & str, String const & delim, bool keepempty)
1044 // Lars would like this code to go, but for now his replacement (below)
1045 // doesn't fullfil the same function. I have, therefore, reactivated the
1046 // old code for now. Angus 11 Nov 2002.
1051 String keys = rtrim(str);
1053 size_t const idx = keys.find(delim);
1054 if (idx == String::npos) {
1055 vec.push_back(ltrim(keys));
1058 String const key = trim(keys.substr(0, idx));
1059 if (!key.empty() || keepempty)
1061 size_t const start = idx + delim.size();
1062 keys = keys.substr(start);
1066 typedef boost::char_separator<typename String::value_type> Separator;
1067 typedef boost::tokenizer<Separator, typename String::const_iterator, String> Tokenizer;
1068 Separator sep(delim.c_str());
1069 Tokenizer tokens(str, sep);
1070 return vector<String>(tokens.begin(), tokens.end());
1075 template<typename String> const String
1076 getStringFromVector(vector<String> const & vec, String const & delim)
1079 typename vector<String>::const_iterator it = vec.begin();
1080 typename vector<String>::const_iterator en = vec.end();
1081 for (; it != en; ++it) {
1082 String item = trim(*it);
1095 vector<string> const getVectorFromString(string const & str,
1096 string const & delim,
1099 return getVectorFromStringT<string>(str, delim, keepempty);
1103 vector<docstring> const getVectorFromString(docstring const & str,
1104 docstring const & delim,
1107 return getVectorFromStringT<docstring>(str, delim, keepempty);
1111 string const getStringFromVector(vector<string> const & vec,
1112 string const & delim)
1114 return getStringFromVector<string>(vec, delim);
1118 docstring const getStringFromVector(vector<docstring> const & vec,
1119 docstring const & delim)
1121 return getStringFromVector<docstring>(vec, delim);
1125 int findToken(char const * const str[], string const & search_token)
1129 while (str[i][0] && str[i] != search_token)
1138 docstring bformat(docstring const & fmt, int arg1)
1140 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1141 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1142 return subst(str, from_ascii("%%"), from_ascii("%"));
1147 docstring bformat(docstring const & fmt, long arg1)
1149 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1150 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1151 return subst(str, from_ascii("%%"), from_ascii("%"));
1156 docstring bformat(docstring const & fmt, unsigned int arg1)
1158 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1159 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1160 return subst(str, from_ascii("%%"), from_ascii("%"));
1165 docstring bformat(docstring const & fmt, docstring arg1)
1167 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1168 docstring const str = subst(fmt, from_ascii("%1$s"), arg1);
1169 return subst(str, from_ascii("%%"), from_ascii("%"));
1174 docstring bformat(docstring const & fmt, char * arg1)
1176 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1177 docstring const str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1178 return subst(str, from_ascii("%%"), from_ascii("%"));
1183 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
1185 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1186 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1187 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1188 str = subst(str, from_ascii("%2$s"), arg2);
1189 return subst(str, from_ascii("%%"), from_ascii("%"));
1194 docstring bformat(docstring const & fmt, docstring arg1, int arg2)
1196 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1197 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1198 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1199 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1200 return subst(str, from_ascii("%%"), from_ascii("%"));
1205 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
1207 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1208 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1209 docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1210 str = subst(fmt, from_ascii("%2$s"), arg2);
1211 return subst(str, from_ascii("%%"), from_ascii("%"));
1216 docstring bformat(docstring const & fmt, int arg1, int arg2)
1218 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1219 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1220 docstring str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1221 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1222 return subst(str, from_ascii("%%"), from_ascii("%"));
1227 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
1229 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1230 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1231 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1232 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1233 str = subst(str, from_ascii("%2$s"), arg2);
1234 str = subst(str, from_ascii("%3$s"), arg3);
1235 return subst(str, from_ascii("%%"), from_ascii("%"));
1240 docstring bformat(docstring const & fmt,
1241 docstring arg1, docstring arg2, docstring arg3, docstring arg4)
1243 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1244 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1245 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1246 LASSERT(contains(fmt, from_ascii("%4$s")), /**/);
1247 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1248 str = subst(str, from_ascii("%2$s"), arg2);
1249 str = subst(str, from_ascii("%3$s"), arg3);
1250 str = subst(str, from_ascii("%4$s"), arg4);
1251 return subst(str, from_ascii("%%"), from_ascii("%"));
1254 } // namespace support