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());
435 bool isLowerCase(char_type ch) {
436 return lowercase(ch) == ch;
440 bool isUpperCase(char_type ch) {
441 return uppercase(ch) == ch;
447 // since we cannot use tolower and toupper directly in the
448 // calls to transform yet, we use these helper clases. (Lgb)
450 struct local_lowercase {
451 char_type operator()(char_type c) const {
456 struct local_uppercase {
457 char_type operator()(char_type c) const {
462 template<typename Char> struct local_ascii_lowercase {
463 Char operator()(Char c) const { return ascii_tolower(c); }
466 } // end of anon namespace
469 docstring const lowercase(docstring const & a)
472 transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
477 docstring const uppercase(docstring const & a)
480 transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase());
485 string const ascii_lowercase(string const & a)
488 transform(tmp.begin(), tmp.end(), tmp.begin(),
489 local_ascii_lowercase<char>());
494 docstring const ascii_lowercase(docstring const & a)
497 transform(tmp.begin(), tmp.end(), tmp.begin(),
498 local_ascii_lowercase<char_type>());
503 bool prefixIs(docstring const & a, char_type c)
511 bool prefixIs(string const & a, string const & pre)
513 size_t const prelen = pre.length();
514 size_t const alen = a.length();
515 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
519 bool prefixIs(docstring const & a, docstring const & pre)
521 size_t const prelen = pre.length();
522 size_t const alen = a.length();
523 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
527 bool suffixIs(string const & a, char c)
531 return a[a.length() - 1] == c;
535 bool suffixIs(docstring const & a, char_type c)
539 return a[a.length() - 1] == c;
543 bool suffixIs(string const & a, string const & suf)
545 size_t const suflen = suf.length();
546 size_t const alen = a.length();
547 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
551 bool suffixIs(docstring const & a, docstring const & suf)
553 size_t const suflen = suf.length();
554 size_t const alen = a.length();
555 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
559 bool containsOnly(string const & s, string const & cset)
561 return s.find_first_not_of(cset) == string::npos;
565 // ale970405+lasgoutt-970425
566 // rewritten to use new string (Lgb)
567 string const token(string const & a, char delim, int n)
575 // Find delimiter or end of string
577 if ((i = a.find(delim, i)) == string::npos)
583 // i is now the n'th delim (or string::npos)
584 if (i == string::npos)
587 k = a.find(delim, i);
588 // k is now the n'th + 1 delim (or string::npos)
590 return a.substr(i, k - i);
594 docstring const token(docstring const & a, char_type delim, int n)
602 // Find delimiter or end of string
604 if ((i = a.find(delim, i)) == docstring::npos)
610 // i is now the n'th delim (or string::npos)
611 if (i == docstring::npos)
614 k = a.find(delim, i);
615 // k is now the n'th + 1 delim (or string::npos)
617 return a.substr(i, k - i);
621 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
622 // rewritten to use new string (Lgb)
623 int tokenPos(string const & a, char delim, string const & tok)
629 while (!str.empty()) {
630 str = split(str, tmptok, delim);
639 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
640 // rewritten to use new string (Lgb)
641 int tokenPos(docstring const & a, char_type delim, docstring const & tok)
647 while (!str.empty()) {
648 str = split(str, tmptok, delim);
659 /// Substitute all \a oldchar with \a newchar
660 template<typename Ch> inline
661 basic_string<Ch> const subst_char(basic_string<Ch> const & a,
662 Ch oldchar, Ch newchar)
664 typedef basic_string<Ch> String;
666 typename String::iterator lit = tmp.begin();
667 typename String::iterator end = tmp.end();
668 for (; lit != end; ++lit)
669 if ((*lit) == oldchar)
675 /// Substitute all \a oldchar with \a newchar
676 docstring const subst_char(docstring const & a,
677 docstring::value_type oldchar, docstring::value_type newchar)
680 docstring::iterator lit = tmp.begin();
681 docstring::iterator end = tmp.end();
682 for (; lit != end; ++lit)
683 if ((*lit) == oldchar)
689 /// substitutes all instances of \a oldstr with \a newstr
690 template<typename String> inline
691 String const subst_string(String const & a,
692 String const & oldstr, String const & newstr)
694 LASSERT(!oldstr.empty(), /**/);
697 size_t const olen = oldstr.length();
698 while ((i = lstr.find(oldstr, i)) != string::npos) {
699 lstr.replace(i, olen, newstr);
700 i += newstr.length(); // We need to be sure that we dont
701 // use the same i over and over again.
707 docstring const subst_string(docstring const & a,
708 docstring const & oldstr, docstring const & newstr)
710 LASSERT(!oldstr.empty(), /**/);
713 size_t const olen = oldstr.length();
714 while ((i = lstr.find(oldstr, i)) != string::npos) {
715 lstr.replace(i, olen, newstr);
716 i += newstr.length(); // We need to be sure that we dont
717 // use the same i over and over again.
725 string const subst(string const & a, char oldchar, char newchar)
727 return subst_char(a, oldchar, newchar);
731 docstring const subst(docstring const & a,
732 char_type oldchar, char_type newchar)
734 return subst_char(a, oldchar, newchar);
738 string const subst(string const & a,
739 string const & oldstr, string const & newstr)
741 return subst_string(a, oldstr, newstr);
745 docstring const subst(docstring const & a,
746 docstring const & oldstr, docstring const & newstr)
748 return subst_string(a, oldstr, newstr);
752 /// Count all occurences of char \a chr inside \a str
753 int count_char(docstring const & str, docstring::value_type chr)
756 docstring::const_iterator lit = str.begin();
757 docstring::const_iterator end = str.end();
758 for (; lit != end; ++lit)
765 docstring const trim(docstring const & a, char const * p)
769 if (a.empty() || !*p)
772 docstring s = from_ascii(p);
773 size_t r = a.find_last_not_of(s);
774 size_t l = a.find_first_not_of(s);
776 // Is this the minimal test? (lgb)
777 if (r == docstring::npos && l == docstring::npos)
780 return a.substr(l, r - l + 1);
784 string const trim(string const & a, char const * p)
788 if (a.empty() || !*p)
791 size_t r = a.find_last_not_of(p);
792 size_t l = a.find_first_not_of(p);
794 // Is this the minimal test? (lgb)
795 if (r == string::npos && l == string::npos)
798 return a.substr(l, r - l + 1);
802 string const rtrim(string const & a, char const * p)
806 if (a.empty() || !*p)
809 size_t r = a.find_last_not_of(p);
811 // Is this test really needed? (Lgb)
812 if (r == string::npos)
815 return a.substr(0, r + 1);
819 docstring const rtrim(docstring const & a, char const * p)
823 if (a.empty() || !*p)
826 size_t r = a.find_last_not_of(from_ascii(p));
828 // Is this test really needed? (Lgb)
829 if (r == docstring::npos)
832 return a.substr(0, r + 1);
836 string const ltrim(string const & a, char const * p)
839 if (a.empty() || !*p)
841 size_t l = a.find_first_not_of(p);
842 if (l == string::npos)
844 return a.substr(l, string::npos);
848 docstring const ltrim(docstring const & a, char const * p)
851 if (a.empty() || !*p)
853 size_t l = a.find_first_not_of(from_ascii(p));
854 if (l == docstring::npos)
856 return a.substr(l, docstring::npos);
861 template<typename String, typename Char> inline
862 String const doSplit(String const & a, String & piece, Char delim)
865 size_t i = a.find(delim);
866 if (i == a.length() - 1) {
867 piece = a.substr(0, i);
868 } else if (i != String::npos) {
869 piece = a.substr(0, i);
870 tmp = a.substr(i + 1);
873 tmp = a.substr(i + 1);
880 template<typename Char> inline
881 docstring const doSplit(docstring const & a, docstring & piece, Char delim)
884 size_t i = a.find(delim);
885 if (i == a.length() - 1) {
886 piece = a.substr(0, i);
887 } else if (i != docstring::npos) {
888 piece = a.substr(0, i);
889 tmp = a.substr(i + 1);
892 tmp = a.substr(i + 1);
902 string const split(string const & a, string & piece, char delim)
904 return doSplit(a, piece, delim);
908 docstring const split(docstring const & a, docstring & piece, char_type delim)
910 return doSplit(a, piece, delim);
914 string const split(string const & a, char delim)
917 size_t i = a.find(delim);
918 if (i != string::npos) // found delim
919 tmp = a.substr(i + 1);
925 string const rsplit(string const & a, string & piece, char delim)
928 size_t i = a.rfind(delim);
929 if (i != string::npos) { // delimiter was found
930 piece = a.substr(0, i);
931 tmp = a.substr(i + 1);
932 } else { // delimiter was not found
939 docstring const rsplit(docstring const & a, char_type delim)
942 size_t i = a.rfind(delim);
943 if (i != string::npos)
944 tmp = a.substr(i + 1);
949 docstring const escape(docstring const & lab)
951 char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
952 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
954 for (size_t i = 0; i < lab.length(); ++i) {
955 char_type c = lab[i];
956 if (c >= 128 || c == '=' || c == '%') {
957 // Although char_type is a 32 bit type we know that
958 // UCS4 occupies only 21 bits, so we don't need to
959 // encode bigger values. Test for 2^24 because we
960 // can encode that with the 6 hex digits that are
961 // needed for 21 bits anyway.
962 LASSERT(c < (1 << 24), /**/);
964 enc += hexdigit[(c>>20) & 15];
965 enc += hexdigit[(c>>16) & 15];
966 enc += hexdigit[(c>>12) & 15];
967 enc += hexdigit[(c>> 8) & 15];
968 enc += hexdigit[(c>> 4) & 15];
969 enc += hexdigit[ c & 15];
980 // this doesn't check whether str is empty, so do that first.
981 vector<docstring> wrapToVec(docstring const & str, int ind,
984 docstring s = trim(str);
986 return vector<docstring>();
990 indent.insert(0, -ind, ' ');
993 s.insert(0, ind, ' ');
995 vector<docstring> retval;
996 while (s.size() > width) {
997 // find the last space within the first 'width' chars
998 size_t const i = s.find_last_of(' ', width - 1);
999 if (i == docstring::npos || i <= size_t(ind)) {
1001 s = s.substr(0, width - 3) + "...";
1004 retval.push_back(s.substr(0, i));
1005 s = indent + s.substr(i);
1006 ind = indent.size();
1009 retval.push_back(s);
1016 docstring wrap(docstring const & str, int const ind, size_t const width)
1018 docstring s = trim(str);
1022 vector<docstring> const svec = wrapToVec(str, ind, width);
1023 return getStringFromVector(svec, from_ascii("\n"));
1027 docstring wrapParas(docstring const & str, int const indent,
1028 size_t const width, size_t const maxlines)
1033 vector<docstring> const pars = getVectorFromString(str, from_ascii("\n"), true);
1034 vector<docstring> retval;
1036 vector<docstring>::const_iterator it = pars.begin();
1037 vector<docstring>::const_iterator const en = pars.end();
1038 for (; it != en; ++it) {
1039 vector<docstring> tmp = wrapToVec(*it, indent, width);
1040 size_t const nlines = tmp.size();
1043 size_t const curlines = retval.size();
1044 if (maxlines > 0 && curlines + nlines >= maxlines) {
1045 tmp.resize(maxlines - curlines - 1);
1046 tmp.push_back(from_ascii("..."));
1048 retval.insert(retval.end(), tmp.begin(), tmp.end());
1049 if (maxlines > 0 && retval.size() >= maxlines)
1052 return getStringFromVector(retval, from_ascii("\n"));
1058 template<typename String> vector<String> const
1059 getVectorFromStringT(String const & str, String const & delim, bool keepempty)
1061 // Lars would like this code to go, but for now his replacement (below)
1062 // doesn't fullfil the same function. I have, therefore, reactivated the
1063 // old code for now. Angus 11 Nov 2002.
1068 String keys = rtrim(str);
1070 size_t const idx = keys.find(delim);
1071 if (idx == String::npos) {
1072 vec.push_back(ltrim(keys));
1075 String const key = trim(keys.substr(0, idx));
1076 if (!key.empty() || keepempty)
1078 size_t const start = idx + delim.size();
1079 keys = keys.substr(start);
1083 typedef boost::char_separator<typename String::value_type> Separator;
1084 typedef boost::tokenizer<Separator, typename String::const_iterator, String> Tokenizer;
1085 Separator sep(delim.c_str());
1086 Tokenizer tokens(str, sep);
1087 return vector<String>(tokens.begin(), tokens.end());
1092 template<typename String> const String
1093 getStringFromVector(vector<String> const & vec, String const & delim)
1096 typename vector<String>::const_iterator it = vec.begin();
1097 typename vector<String>::const_iterator en = vec.end();
1098 for (; it != en; ++it) {
1099 String item = trim(*it);
1112 vector<string> const getVectorFromString(string const & str,
1113 string const & delim,
1116 return getVectorFromStringT<string>(str, delim, keepempty);
1120 vector<docstring> const getVectorFromString(docstring const & str,
1121 docstring const & delim,
1124 return getVectorFromStringT<docstring>(str, delim, keepempty);
1128 string const getStringFromVector(vector<string> const & vec,
1129 string const & delim)
1131 return getStringFromVector<string>(vec, delim);
1135 docstring const getStringFromVector(vector<docstring> const & vec,
1136 docstring const & delim)
1138 return getStringFromVector<docstring>(vec, delim);
1142 int findToken(char const * const str[], string const & search_token)
1146 while (str[i][0] && str[i] != search_token)
1155 docstring bformat(docstring const & fmt, int arg1)
1157 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1158 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1159 return subst(str, from_ascii("%%"), from_ascii("%"));
1164 docstring bformat(docstring const & fmt, long arg1)
1166 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1167 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1168 return subst(str, from_ascii("%%"), from_ascii("%"));
1173 docstring bformat(docstring const & fmt, unsigned int arg1)
1175 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1176 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1177 return subst(str, from_ascii("%%"), from_ascii("%"));
1182 docstring bformat(docstring const & fmt, docstring arg1)
1184 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1185 docstring const str = subst(fmt, from_ascii("%1$s"), arg1);
1186 return subst(str, from_ascii("%%"), from_ascii("%"));
1191 docstring bformat(docstring const & fmt, char * arg1)
1193 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1194 docstring const str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1195 return subst(str, from_ascii("%%"), from_ascii("%"));
1200 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
1202 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1203 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1204 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1205 str = subst(str, from_ascii("%2$s"), arg2);
1206 return subst(str, from_ascii("%%"), from_ascii("%"));
1211 docstring bformat(docstring const & fmt, docstring arg1, int arg2)
1213 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1214 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1215 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1216 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1217 return subst(str, from_ascii("%%"), from_ascii("%"));
1222 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
1224 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1225 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1226 docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1227 str = subst(fmt, from_ascii("%2$s"), arg2);
1228 return subst(str, from_ascii("%%"), from_ascii("%"));
1233 docstring bformat(docstring const & fmt, int arg1, int arg2)
1235 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1236 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1237 docstring str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1238 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1239 return subst(str, from_ascii("%%"), from_ascii("%"));
1244 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
1246 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1247 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1248 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1249 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1250 str = subst(str, from_ascii("%2$s"), arg2);
1251 str = subst(str, from_ascii("%3$s"), arg3);
1252 return subst(str, from_ascii("%%"), from_ascii("%"));
1257 docstring bformat(docstring const & fmt,
1258 docstring arg1, docstring arg2, docstring arg3, docstring arg4)
1260 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1261 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1262 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1263 LASSERT(contains(fmt, from_ascii("%4$s")), /**/);
1264 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1265 str = subst(str, from_ascii("%2$s"), arg2);
1266 str = subst(str, from_ascii("%3$s"), arg3);
1267 str = subst(str, from_ascii("%4$s"), arg4);
1268 return subst(str, from_ascii("%%"), from_ascii("%"));
1271 } // namespace support