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 docstring::const_iterator cit = str.begin();
324 docstring::const_iterator const end = str.end();
325 for (; cit != end; ++cit) {
335 static bool isHexChar(char_type c)
347 c == 'a' || c == 'A' ||
348 c == 'b' || c == 'B' ||
349 c == 'c' || c == 'C' ||
350 c == 'd' || c == 'D' ||
351 c == 'e' || c == 'E' ||
352 c == 'f' || c == 'F';
356 bool isHex(docstring const & str)
360 if (str.length() > 2 && str[0] == '0' &&
361 (str[1] == 'x' || str[1] == 'X'))
364 int const len = str.length();
366 for (; index < len; ++index) {
367 if (!isHexChar(str[index]))
374 int hexToInt(docstring const & str)
376 string s = to_ascii(str);
378 sscanf(s.c_str(), "%x", &h);
383 bool isAscii(docstring const & str)
385 int const len = str.length();
386 for (int i = 0; i < len; ++i)
393 bool isAscii(string const & str)
395 int const len = str.length();
396 for (int i = 0; i < len; ++i)
397 if (static_cast<unsigned char>(str[i]) >= 0x80)
403 char lowercase(char c)
405 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
406 return char(tolower(c));
410 char uppercase(char c)
412 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
413 return char(toupper(c));
417 char_type lowercase(char_type c)
420 // We don't know how to lowercase a non-utf16 char
422 return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
426 char_type uppercase(char_type c)
429 // We don't know how to uppercase a non-utf16 char
431 return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
437 // since we cannot use tolower and toupper directly in the
438 // calls to transform yet, we use these helper clases. (Lgb)
440 struct local_lowercase {
441 char_type operator()(char_type c) const {
443 // We don't know how to lowercase a non-utf16 char
445 return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
449 struct local_uppercase {
450 char_type operator()(char_type c) const {
452 // We don't know how to uppercase a non-utf16 char
454 return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
458 template<typename Char> struct local_ascii_lowercase {
459 Char operator()(Char c) const { return ascii_tolower(c); }
462 } // end of anon namespace
464 docstring const lowercase(docstring const & a)
467 transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
472 docstring const uppercase(docstring const & a)
475 transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase());
480 string const ascii_lowercase(string const & a)
483 transform(tmp.begin(), tmp.end(), tmp.begin(),
484 local_ascii_lowercase<char>());
489 docstring const ascii_lowercase(docstring const & a)
492 transform(tmp.begin(), tmp.end(), tmp.begin(),
493 local_ascii_lowercase<char_type>());
498 bool prefixIs(docstring const & a, char_type c)
506 bool prefixIs(string const & a, string const & pre)
508 size_t const prelen = pre.length();
509 size_t const alen = a.length();
510 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
514 bool prefixIs(docstring const & a, docstring const & pre)
516 size_t const prelen = pre.length();
517 size_t const alen = a.length();
518 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
522 bool suffixIs(string const & a, char c)
526 return a[a.length() - 1] == c;
530 bool suffixIs(docstring const & a, char_type c)
534 return a[a.length() - 1] == c;
538 bool suffixIs(string const & a, string const & suf)
540 size_t const suflen = suf.length();
541 size_t const alen = a.length();
542 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
546 bool suffixIs(docstring const & a, docstring const & suf)
548 size_t const suflen = suf.length();
549 size_t const alen = a.length();
550 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
554 bool containsOnly(string const & s, string const & cset)
556 return s.find_first_not_of(cset) == string::npos;
560 // ale970405+lasgoutt-970425
561 // rewritten to use new string (Lgb)
562 string const token(string const & a, char delim, int n)
570 // Find delimiter or end of string
572 if ((i = a.find(delim, i)) == string::npos)
578 // i is now the n'th delim (or string::npos)
579 if (i == string::npos)
582 k = a.find(delim, i);
583 // k is now the n'th + 1 delim (or string::npos)
585 return a.substr(i, k - i);
589 docstring const token(docstring const & a, char_type delim, int n)
597 // Find delimiter or end of string
599 if ((i = a.find(delim, i)) == docstring::npos)
605 // i is now the n'th delim (or string::npos)
606 if (i == docstring::npos)
609 k = a.find(delim, i);
610 // k is now the n'th + 1 delim (or string::npos)
612 return a.substr(i, k - i);
616 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
617 // rewritten to use new string (Lgb)
618 int tokenPos(string const & a, char delim, string const & tok)
624 while (!str.empty()) {
625 str = split(str, tmptok, delim);
634 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
635 // rewritten to use new string (Lgb)
636 int tokenPos(docstring const & a, char_type delim, docstring const & tok)
642 while (!str.empty()) {
643 str = split(str, tmptok, delim);
654 /// Substitute all \a oldchar with \a newchar
655 template<typename Ch> inline
656 basic_string<Ch> const subst_char(basic_string<Ch> const & a,
657 Ch oldchar, Ch newchar)
659 typedef basic_string<Ch> String;
661 typename String::iterator lit = tmp.begin();
662 typename String::iterator end = tmp.end();
663 for (; lit != end; ++lit)
664 if ((*lit) == oldchar)
669 /// Substitute all \a oldchar with \a newchar
670 docstring const subst_char(docstring const & a,
671 docstring::value_type oldchar, docstring::value_type newchar)
674 docstring::iterator lit = tmp.begin();
675 docstring::iterator end = tmp.end();
676 for (; lit != end; ++lit)
677 if ((*lit) == oldchar)
683 /// substitutes all instances of \a oldstr with \a newstr
684 template<typename String> inline
685 String const subst_string(String const & a,
686 String const & oldstr, String const & newstr)
688 LASSERT(!oldstr.empty(), /**/);
691 size_t const olen = oldstr.length();
692 while ((i = lstr.find(oldstr, i)) != string::npos) {
693 lstr.replace(i, olen, newstr);
694 i += newstr.length(); // We need to be sure that we dont
695 // use the same i over and over again.
700 docstring const subst_string(docstring const & a,
701 docstring const & oldstr, docstring const & newstr)
703 LASSERT(!oldstr.empty(), /**/);
706 size_t const olen = oldstr.length();
707 while ((i = lstr.find(oldstr, i)) != string::npos) {
708 lstr.replace(i, olen, newstr);
709 i += newstr.length(); // We need to be sure that we dont
710 // use the same i over and over again.
718 string const subst(string const & a, char oldchar, char newchar)
720 return subst_char(a, oldchar, newchar);
724 docstring const subst(docstring const & a,
725 char_type oldchar, char_type newchar)
727 return subst_char(a, oldchar, newchar);
731 string const subst(string const & a,
732 string const & oldstr, string const & newstr)
734 return subst_string(a, oldstr, newstr);
738 docstring const subst(docstring const & a,
739 docstring const & oldstr, docstring const & newstr)
741 return subst_string(a, oldstr, newstr);
745 docstring const trim(docstring const & a, char const * p)
749 if (a.empty() || !*p)
752 docstring s = from_ascii(p);
753 size_t r = a.find_last_not_of(s);
754 size_t l = a.find_first_not_of(s);
756 // Is this the minimal test? (lgb)
757 if (r == docstring::npos && l == docstring::npos)
760 return a.substr(l, r - l + 1);
764 string const trim(string const & a, char const * p)
768 if (a.empty() || !*p)
771 size_t r = a.find_last_not_of(p);
772 size_t l = a.find_first_not_of(p);
774 // Is this the minimal test? (lgb)
775 if (r == string::npos && l == string::npos)
778 return a.substr(l, r - l + 1);
782 string const rtrim(string const & a, char const * p)
786 if (a.empty() || !*p)
789 size_t r = a.find_last_not_of(p);
791 // Is this test really needed? (Lgb)
792 if (r == string::npos)
795 return a.substr(0, r + 1);
799 docstring const rtrim(docstring const & a, char const * p)
803 if (a.empty() || !*p)
806 size_t r = a.find_last_not_of(from_ascii(p));
808 // Is this test really needed? (Lgb)
809 if (r == docstring::npos)
812 return a.substr(0, r + 1);
816 string const ltrim(string const & a, char const * p)
819 if (a.empty() || !*p)
821 size_t l = a.find_first_not_of(p);
822 if (l == string::npos)
824 return a.substr(l, string::npos);
828 docstring const ltrim(docstring const & a, char const * p)
831 if (a.empty() || !*p)
833 size_t l = a.find_first_not_of(from_ascii(p));
834 if (l == docstring::npos)
836 return a.substr(l, docstring::npos);
841 template<typename String, typename Char> inline
842 String const doSplit(String const & a, String & piece, Char delim)
845 size_t i = a.find(delim);
846 if (i == a.length() - 1) {
847 piece = a.substr(0, i);
848 } else if (i != String::npos) {
849 piece = a.substr(0, i);
850 tmp = a.substr(i + 1);
853 tmp = a.substr(i + 1);
860 template<typename Char> inline
861 docstring const doSplit(docstring const & a, docstring & piece, Char delim)
864 size_t i = a.find(delim);
865 if (i == a.length() - 1) {
866 piece = a.substr(0, i);
867 } else if (i != docstring::npos) {
868 piece = a.substr(0, i);
869 tmp = a.substr(i + 1);
872 tmp = a.substr(i + 1);
882 string const split(string const & a, string & piece, char delim)
884 return doSplit(a, piece, delim);
888 docstring const split(docstring const & a, docstring & piece, char_type delim)
890 return doSplit(a, piece, delim);
894 string const split(string const & a, char delim)
897 size_t i = a.find(delim);
898 if (i != string::npos) // found delim
899 tmp = a.substr(i + 1);
905 string const rsplit(string const & a, string & piece, char delim)
908 size_t i = a.rfind(delim);
909 if (i != string::npos) { // delimiter was found
910 piece = a.substr(0, i);
911 tmp = a.substr(i + 1);
912 } else { // delimiter was not found
919 docstring const rsplit(docstring const & a, char_type delim)
922 size_t i = a.rfind(delim);
923 if (i != string::npos)
924 tmp = a.substr(i + 1);
929 docstring const escape(docstring const & lab)
931 char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
932 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
934 for (size_t i = 0; i < lab.length(); ++i) {
935 char_type c = lab[i];
936 if (c >= 128 || c == '=' || c == '%') {
937 // Although char_type is a 32 bit type we know that
938 // UCS4 occupies only 21 bits, so we don't need to
939 // encode bigger values. Test for 2^24 because we
940 // can encode that with the 6 hex digits that are
941 // needed for 21 bits anyway.
942 LASSERT(c < (1 << 24), /**/);
944 enc += hexdigit[(c>>20) & 15];
945 enc += hexdigit[(c>>16) & 15];
946 enc += hexdigit[(c>>12) & 15];
947 enc += hexdigit[(c>> 8) & 15];
948 enc += hexdigit[(c>> 4) & 15];
949 enc += hexdigit[ c & 15];
960 // this doesn't check whether str is empty, so do that first.
961 vector<docstring> wrapToVec(docstring const & str, int ind,
964 docstring s = trim(str);
966 return vector<docstring>();
970 indent.insert(0, -ind, ' ');
973 s.insert(0, ind, ' ');
975 vector<docstring> retval;
976 while (s.size() > width) {
977 // find the last space within the first 'width' chars
978 size_t const i = s.find_last_of(' ', width - 1);
979 if (i == docstring::npos || i <= size_t(ind)) {
981 s = s.substr(0, width - 3) + "...";
984 retval.push_back(s.substr(0, i));
985 s = indent + s.substr(i);
996 docstring wrap(docstring const & str, int const ind, size_t const width)
998 docstring s = trim(str);
1002 vector<docstring> const svec = wrapToVec(str, ind, width);
1003 return getStringFromVector(svec, from_ascii("\n"));
1007 docstring wrapParas(docstring const & str, int const indent,
1008 size_t const width, size_t const maxlines)
1013 vector<docstring> const pars = getVectorFromString(str, from_ascii("\n"), true);
1014 vector<docstring> retval;
1016 vector<docstring>::const_iterator it = pars.begin();
1017 vector<docstring>::const_iterator const en = pars.end();
1018 for (; it != en; ++it) {
1019 vector<docstring> tmp = wrapToVec(*it, indent, width);
1020 size_t const nlines = tmp.size();
1023 size_t const curlines = retval.size();
1024 if (maxlines > 0 && curlines + nlines >= maxlines) {
1025 tmp.resize(maxlines - curlines - 1);
1026 tmp.push_back(from_ascii("..."));
1028 retval.insert(retval.end(), tmp.begin(), tmp.end());
1029 if (maxlines > 0 && retval.size() >= maxlines)
1032 return getStringFromVector(retval, from_ascii("\n"));
1038 template<typename String> vector<String> const
1039 getVectorFromStringT(String const & str, String const & delim, bool keepempty)
1041 // Lars would like this code to go, but for now his replacement (below)
1042 // doesn't fullfil the same function. I have, therefore, reactivated the
1043 // old code for now. Angus 11 Nov 2002.
1048 String keys = rtrim(str);
1050 size_t const idx = keys.find(delim);
1051 if (idx == String::npos) {
1052 vec.push_back(ltrim(keys));
1055 String const key = trim(keys.substr(0, idx));
1056 if (!key.empty() || keepempty)
1058 size_t const start = idx + delim.size();
1059 keys = keys.substr(start);
1063 typedef boost::char_separator<typename String::value_type> Separator;
1064 typedef boost::tokenizer<Separator, typename String::const_iterator, String> Tokenizer;
1065 Separator sep(delim.c_str());
1066 Tokenizer tokens(str, sep);
1067 return vector<String>(tokens.begin(), tokens.end());
1072 template<typename String> const String
1073 getStringFromVector(vector<String> const & vec, String const & delim)
1076 typename vector<String>::const_iterator it = vec.begin();
1077 typename vector<String>::const_iterator en = vec.end();
1078 for (; it != en; ++it) {
1079 String item = trim(*it);
1092 vector<string> const getVectorFromString(string const & str,
1093 string const & delim,
1096 return getVectorFromStringT<string>(str, delim, keepempty);
1100 vector<docstring> const getVectorFromString(docstring const & str,
1101 docstring const & delim,
1104 return getVectorFromStringT<docstring>(str, delim, keepempty);
1108 string const getStringFromVector(vector<string> const & vec,
1109 string const & delim)
1111 return getStringFromVector<string>(vec, delim);
1115 docstring const getStringFromVector(vector<docstring> const & vec,
1116 docstring const & delim)
1118 return getStringFromVector<docstring>(vec, delim);
1122 int findToken(char const * const str[], string const & search_token)
1126 while (str[i][0] && str[i] != search_token)
1135 docstring bformat(docstring const & fmt, int arg1)
1137 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1138 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1139 return subst(str, from_ascii("%%"), from_ascii("%"));
1144 docstring bformat(docstring const & fmt, long arg1)
1146 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1147 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1148 return subst(str, from_ascii("%%"), from_ascii("%"));
1153 docstring bformat(docstring const & fmt, unsigned int arg1)
1155 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1156 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1157 return subst(str, from_ascii("%%"), from_ascii("%"));
1162 docstring bformat(docstring const & fmt, docstring arg1)
1164 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1165 docstring const str = subst(fmt, from_ascii("%1$s"), arg1);
1166 return subst(str, from_ascii("%%"), from_ascii("%"));
1171 docstring bformat(docstring const & fmt, char * arg1)
1173 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1174 docstring const str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1175 return subst(str, from_ascii("%%"), from_ascii("%"));
1180 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
1182 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1183 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1184 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1185 str = subst(str, from_ascii("%2$s"), arg2);
1186 return subst(str, from_ascii("%%"), from_ascii("%"));
1191 docstring bformat(docstring const & fmt, docstring arg1, int arg2)
1193 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1194 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1195 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1196 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1197 return subst(str, from_ascii("%%"), from_ascii("%"));
1202 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
1204 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1205 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1206 docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1207 str = subst(fmt, from_ascii("%2$s"), arg2);
1208 return subst(str, from_ascii("%%"), from_ascii("%"));
1213 docstring bformat(docstring const & fmt, int arg1, int arg2)
1215 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1216 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1217 docstring str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1218 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1219 return subst(str, from_ascii("%%"), from_ascii("%"));
1224 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
1226 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1227 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1228 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1229 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1230 str = subst(str, from_ascii("%2$s"), arg2);
1231 str = subst(str, from_ascii("%3$s"), arg3);
1232 return subst(str, from_ascii("%%"), from_ascii("%"));
1237 docstring bformat(docstring const & fmt,
1238 docstring arg1, docstring arg2, docstring arg3, docstring arg4)
1240 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1241 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1242 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1243 LASSERT(contains(fmt, from_ascii("%4$s")), /**/);
1244 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1245 str = subst(str, from_ascii("%2$s"), arg2);
1246 str = subst(str, from_ascii("%3$s"), arg3);
1247 str = subst(str, from_ascii("%4$s"), arg4);
1248 return subst(str, from_ascii("%%"), from_ascii("%"));
1251 } // namespace support