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()
52 * Convert a QChar into a UCS4 character.
53 * This is a hack (it does only make sense for the common part of the UCS4
54 * and UTF16 encodings) and should not be used.
55 * This does only exist because of performance reasons (a real conversion
56 * using iconv is too slow on windows).
58 inline char_type qchar_to_ucs4(QChar const & qchar)
60 LASSERT(is_utf16(static_cast<char_type>(qchar.unicode())), /**/);
61 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 inline QChar const ucs4_to_qchar(char_type const ucs4)
73 LASSERT(is_utf16(ucs4), /**/);
74 return QChar(static_cast<unsigned short>(ucs4));
77 /// Maximum valid UCS4 code point
78 char_type const ucs4_max = 0x10ffff;
82 bool isLetterChar(char_type c)
86 // outside the UCS4 range
88 // assume that all non-utf16 characters are letters
91 return ucs4_to_qchar(c).isLetter();
95 bool isLower(char_type c)
99 return ucs4_to_qchar(c).isLower();
103 bool isAlphaASCII(char_type c)
105 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
109 bool isPrintable(char_type c)
113 // outside the UCS4 range
115 // assume that all non-utf16 characters are printable
118 return ucs4_to_qchar(c).isPrint();
122 bool isPrintableNonspace(char_type c)
126 // outside the UCS4 range
128 // assume that all non-utf16 characters are printable and
132 QChar const qc = ucs4_to_qchar(c);
133 return qc.isPrint() && !qc.isSpace();
137 bool isSpace(char_type c)
140 // assume that no non-utf16 character is a space
141 // c outside the UCS4 range is catched as well
144 QChar const qc = ucs4_to_qchar(c);
149 bool isDigit(char_type c)
152 // assume that no non-utf16 character is a digit
153 // c outside the UCS4 range is catched as well
155 return ucs4_to_qchar(c).isDigit();
159 bool isDigitASCII(char_type c)
161 return '0' <= c && c <= '9';
166 int compare_no_case(docstring const & s, docstring const & s2)
168 docstring::const_iterator p = s.begin();
169 docstring::const_iterator p2 = s2.begin();
171 while (p != s.end() && p2 != s2.end()) {
172 char_type const lc1 = lowercase(*p);
173 char_type const lc2 = lowercase(*p2);
175 return (lc1 < lc2) ? -1 : 1;
180 if (s.size() == s2.size())
182 if (s.size() < s2.size())
190 template<typename Char>
191 Char ascii_tolower(Char c) {
192 if (c >= 'A' && c <= 'Z')
193 return c - 'A' + 'a';
200 int compare_ascii_no_case(string const & s, string const & s2)
202 string::const_iterator p = s.begin();
203 string::const_iterator p2 = s2.begin();
205 while (p != s.end() && p2 != s2.end()) {
206 int const lc1 = ascii_tolower(*p);
207 int const lc2 = ascii_tolower(*p2);
209 return (lc1 < lc2) ? -1 : 1;
214 if (s.size() == s2.size())
216 if (s.size() < s2.size())
222 int compare_ascii_no_case(docstring const & s, docstring const & s2)
224 docstring::const_iterator p = s.begin();
225 docstring::const_iterator p2 = s2.begin();
227 while (p != s.end() && p2 != s2.end()) {
228 char_type const lc1 = ascii_tolower(*p);
229 char_type const lc2 = ascii_tolower(*p2);
231 return (lc1 < lc2) ? -1 : 1;
236 if (s.size() == s2.size())
238 if (s.size() < s2.size())
244 bool isStrInt(string const & str)
249 // Remove leading and trailing white space chars.
250 string const tmpstr = trim(str);
254 string::const_iterator cit = tmpstr.begin();
258 string::const_iterator end = tmpstr.end();
259 for (; cit != end; ++cit)
260 if (!isdigit((*cit)))
267 bool isStrUnsignedInt(string const & str)
272 // Remove leading and trailing white space chars.
273 string const tmpstr = trim(str);
277 string::const_iterator cit = tmpstr.begin();
278 string::const_iterator end = tmpstr.end();
279 for (; cit != end; ++cit)
280 if (!isdigit((*cit)))
287 bool isStrDbl(string const & str)
292 // Remove leading and trailing white space chars.
293 string const tmpstr = trim(str);
296 // if (tmpstr.count('.') > 1) return false;
298 string::const_iterator cit = tmpstr.begin();
299 bool found_dot = false;
302 string::const_iterator end = tmpstr.end();
303 for (; cit != end; ++cit) {
304 if (!isdigit(*cit) && *cit != '.')
316 bool hasDigit(docstring const & str)
321 docstring::const_iterator cit = str.begin();
322 docstring::const_iterator const end = str.end();
323 for (; cit != end; ++cit) {
333 static bool isHexChar(char_type c)
345 c == 'a' || c == 'A' ||
346 c == 'b' || c == 'B' ||
347 c == 'c' || c == 'C' ||
348 c == 'd' || c == 'D' ||
349 c == 'e' || c == 'E' ||
350 c == 'f' || c == 'F';
354 bool isHex(docstring const & str)
358 if (str.length() > 2 && str[0] == '0' &&
359 (str[1] == 'x' || str[1] == 'X'))
362 int const len = str.length();
364 for (; index < len; ++index) {
365 if (!isHexChar(str[index]))
372 int hexToInt(docstring const & str)
374 string s = to_ascii(str);
376 sscanf(s.c_str(), "%x", &h);
381 bool isAscii(docstring const & str)
383 int const len = str.length();
384 for (int i = 0; i < len; ++i)
391 bool isAscii(string const & str)
393 int const len = str.length();
394 for (int i = 0; i < len; ++i)
395 if (static_cast<unsigned char>(str[i]) >= 0x80)
401 char lowercase(char c)
403 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
404 return char(tolower(c));
408 char uppercase(char c)
410 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
411 return char(toupper(c));
415 char_type lowercase(char_type c)
418 // We don't know how to lowercase a non-utf16 char
420 return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
424 char_type uppercase(char_type c)
427 // We don't know how to uppercase a non-utf16 char
429 return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
433 bool isLowerCase(char_type ch) {
434 return lowercase(ch) == ch;
438 bool isUpperCase(char_type ch) {
439 return uppercase(ch) == ch;
445 // since we cannot use tolower and toupper directly in the
446 // calls to transform yet, we use these helper clases. (Lgb)
448 struct local_lowercase {
449 char_type operator()(char_type c) const {
454 struct local_uppercase {
455 char_type operator()(char_type c) const {
460 template<typename Char> struct local_ascii_lowercase {
461 Char operator()(Char c) const { return ascii_tolower(c); }
464 } // 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)
673 /// Substitute all \a oldchar with \a newchar
674 docstring const subst_char(docstring const & a,
675 docstring::value_type oldchar, docstring::value_type newchar)
678 docstring::iterator lit = tmp.begin();
679 docstring::iterator end = tmp.end();
680 for (; lit != end; ++lit)
681 if ((*lit) == oldchar)
687 /// substitutes all instances of \a oldstr with \a newstr
688 template<typename String> inline
689 String const subst_string(String const & a,
690 String const & oldstr, String const & newstr)
692 LASSERT(!oldstr.empty(), /**/);
695 size_t const olen = oldstr.length();
696 while ((i = lstr.find(oldstr, i)) != string::npos) {
697 lstr.replace(i, olen, newstr);
698 i += newstr.length(); // We need to be sure that we dont
699 // use the same i over and over again.
705 docstring const subst_string(docstring const & a,
706 docstring const & oldstr, docstring const & newstr)
708 LASSERT(!oldstr.empty(), /**/);
711 size_t const olen = oldstr.length();
712 while ((i = lstr.find(oldstr, i)) != string::npos) {
713 lstr.replace(i, olen, newstr);
714 i += newstr.length(); // We need to be sure that we dont
715 // use the same i over and over again.
723 string const subst(string const & a, char oldchar, char newchar)
725 return subst_char(a, oldchar, newchar);
729 docstring const subst(docstring const & a,
730 char_type oldchar, char_type newchar)
732 return subst_char(a, oldchar, newchar);
736 string const subst(string const & a,
737 string const & oldstr, string const & newstr)
739 return subst_string(a, oldstr, newstr);
743 docstring const subst(docstring const & a,
744 docstring const & oldstr, docstring const & newstr)
746 return subst_string(a, oldstr, newstr);
750 /// Count all occurences of char \a chr inside \a str
751 int count_char(docstring const & str, docstring::value_type chr)
754 docstring::const_iterator lit = str.begin();
755 docstring::const_iterator end = str.end();
756 for (; lit != end; ++lit)
763 docstring const trim(docstring const & a, char const * p)
767 if (a.empty() || !*p)
770 docstring s = from_ascii(p);
771 size_t r = a.find_last_not_of(s);
772 size_t l = a.find_first_not_of(s);
774 // Is this the minimal test? (lgb)
775 if (r == docstring::npos && l == docstring::npos)
778 return a.substr(l, r - l + 1);
782 string const trim(string const & a, char const * p)
786 if (a.empty() || !*p)
789 size_t r = a.find_last_not_of(p);
790 size_t l = a.find_first_not_of(p);
792 // Is this the minimal test? (lgb)
793 if (r == string::npos && l == string::npos)
796 return a.substr(l, r - l + 1);
800 string const rtrim(string const & a, char const * p)
804 if (a.empty() || !*p)
807 size_t r = a.find_last_not_of(p);
809 // Is this test really needed? (Lgb)
810 if (r == string::npos)
813 return a.substr(0, r + 1);
817 docstring const rtrim(docstring const & a, char const * p)
821 if (a.empty() || !*p)
824 size_t r = a.find_last_not_of(from_ascii(p));
826 // Is this test really needed? (Lgb)
827 if (r == docstring::npos)
830 return a.substr(0, r + 1);
834 string const ltrim(string const & a, char const * p)
837 if (a.empty() || !*p)
839 size_t l = a.find_first_not_of(p);
840 if (l == string::npos)
842 return a.substr(l, string::npos);
846 docstring const ltrim(docstring const & a, char const * p)
849 if (a.empty() || !*p)
851 size_t l = a.find_first_not_of(from_ascii(p));
852 if (l == docstring::npos)
854 return a.substr(l, docstring::npos);
859 template<typename String, typename Char> inline
860 String const doSplit(String const & a, String & piece, Char delim)
863 size_t i = a.find(delim);
864 if (i == a.length() - 1) {
865 piece = a.substr(0, i);
866 } else if (i != String::npos) {
867 piece = a.substr(0, i);
868 tmp = a.substr(i + 1);
871 tmp = a.substr(i + 1);
878 template<typename Char> inline
879 docstring const doSplit(docstring const & a, docstring & piece, Char delim)
882 size_t i = a.find(delim);
883 if (i == a.length() - 1) {
884 piece = a.substr(0, i);
885 } else if (i != docstring::npos) {
886 piece = a.substr(0, i);
887 tmp = a.substr(i + 1);
890 tmp = a.substr(i + 1);
900 string const split(string const & a, string & piece, char delim)
902 return doSplit(a, piece, delim);
906 docstring const split(docstring const & a, docstring & piece, char_type delim)
908 return doSplit(a, piece, delim);
912 string const split(string const & a, char delim)
915 size_t i = a.find(delim);
916 if (i != string::npos) // found delim
917 tmp = a.substr(i + 1);
923 string const rsplit(string const & a, string & piece, char delim)
926 size_t i = a.rfind(delim);
927 if (i != string::npos) { // delimiter was found
928 piece = a.substr(0, i);
929 tmp = a.substr(i + 1);
930 } else { // delimiter was not found
937 docstring const rsplit(docstring const & a, char_type delim)
940 size_t i = a.rfind(delim);
941 if (i != string::npos)
942 tmp = a.substr(i + 1);
947 docstring const escape(docstring const & lab)
949 char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
950 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
952 for (size_t i = 0; i < lab.length(); ++i) {
953 char_type c = lab[i];
954 if (c >= 128 || c == '=' || c == '%') {
955 // Although char_type is a 32 bit type we know that
956 // UCS4 occupies only 21 bits, so we don't need to
957 // encode bigger values. Test for 2^24 because we
958 // can encode that with the 6 hex digits that are
959 // needed for 21 bits anyway.
960 LASSERT(c < (1 << 24), /**/);
962 enc += hexdigit[(c>>20) & 15];
963 enc += hexdigit[(c>>16) & 15];
964 enc += hexdigit[(c>>12) & 15];
965 enc += hexdigit[(c>> 8) & 15];
966 enc += hexdigit[(c>> 4) & 15];
967 enc += hexdigit[ c & 15];
978 // this doesn't check whether str is empty, so do that first.
979 vector<docstring> wrapToVec(docstring const & str, int ind,
982 docstring s = trim(str);
984 return vector<docstring>();
988 indent.insert(0, -ind, ' ');
991 s.insert(0, ind, ' ');
993 vector<docstring> retval;
994 while (s.size() > width) {
995 // find the last space within the first 'width' chars
996 size_t const i = s.find_last_of(' ', width - 1);
997 if (i == docstring::npos || i <= size_t(ind)) {
999 s = s.substr(0, width - 3) + "...";
1002 retval.push_back(s.substr(0, i));
1003 s = indent + s.substr(i);
1004 ind = indent.size();
1007 retval.push_back(s);
1014 docstring wrap(docstring const & str, int const ind, size_t const width)
1016 docstring s = trim(str);
1020 vector<docstring> const svec = wrapToVec(str, ind, width);
1021 return getStringFromVector(svec, from_ascii("\n"));
1025 docstring wrapParas(docstring const & str, int const indent,
1026 size_t const width, size_t const maxlines)
1031 vector<docstring> const pars = getVectorFromString(str, from_ascii("\n"), true);
1032 vector<docstring> retval;
1034 vector<docstring>::const_iterator it = pars.begin();
1035 vector<docstring>::const_iterator const en = pars.end();
1036 for (; it != en; ++it) {
1037 vector<docstring> tmp = wrapToVec(*it, indent, width);
1038 size_t const nlines = tmp.size();
1041 size_t const curlines = retval.size();
1042 if (maxlines > 0 && curlines + nlines >= maxlines) {
1043 tmp.resize(maxlines - curlines - 1);
1044 tmp.push_back(from_ascii("..."));
1046 retval.insert(retval.end(), tmp.begin(), tmp.end());
1047 if (maxlines > 0 && retval.size() >= maxlines)
1050 return getStringFromVector(retval, from_ascii("\n"));
1056 template<typename String> vector<String> const
1057 getVectorFromStringT(String const & str, String const & delim, bool keepempty)
1059 // Lars would like this code to go, but for now his replacement (below)
1060 // doesn't fullfil the same function. I have, therefore, reactivated the
1061 // old code for now. Angus 11 Nov 2002.
1066 String keys = rtrim(str);
1068 size_t const idx = keys.find(delim);
1069 if (idx == String::npos) {
1070 vec.push_back(ltrim(keys));
1073 String const key = trim(keys.substr(0, idx));
1074 if (!key.empty() || keepempty)
1076 size_t const start = idx + delim.size();
1077 keys = keys.substr(start);
1081 typedef boost::char_separator<typename String::value_type> Separator;
1082 typedef boost::tokenizer<Separator, typename String::const_iterator, String> Tokenizer;
1083 Separator sep(delim.c_str());
1084 Tokenizer tokens(str, sep);
1085 return vector<String>(tokens.begin(), tokens.end());
1090 template<typename String> const String
1091 getStringFromVector(vector<String> const & vec, String const & delim)
1094 typename vector<String>::const_iterator it = vec.begin();
1095 typename vector<String>::const_iterator en = vec.end();
1096 for (; it != en; ++it) {
1097 String item = trim(*it);
1110 vector<string> const getVectorFromString(string const & str,
1111 string const & delim,
1114 return getVectorFromStringT<string>(str, delim, keepempty);
1118 vector<docstring> const getVectorFromString(docstring const & str,
1119 docstring const & delim,
1122 return getVectorFromStringT<docstring>(str, delim, keepempty);
1126 string const getStringFromVector(vector<string> const & vec,
1127 string const & delim)
1129 return getStringFromVector<string>(vec, delim);
1133 docstring const getStringFromVector(vector<docstring> const & vec,
1134 docstring const & delim)
1136 return getStringFromVector<docstring>(vec, delim);
1140 int findToken(char const * const str[], string const & search_token)
1144 while (str[i][0] && str[i] != search_token)
1153 docstring bformat(docstring const & fmt, 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, long arg1)
1164 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1165 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1166 return subst(str, from_ascii("%%"), from_ascii("%"));
1171 docstring bformat(docstring const & fmt, unsigned int arg1)
1173 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1174 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1175 return subst(str, from_ascii("%%"), from_ascii("%"));
1180 docstring bformat(docstring const & fmt, docstring arg1)
1182 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1183 docstring const str = subst(fmt, from_ascii("%1$s"), arg1);
1184 return subst(str, from_ascii("%%"), from_ascii("%"));
1189 docstring bformat(docstring const & fmt, char * arg1)
1191 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1192 docstring const str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1193 return subst(str, from_ascii("%%"), from_ascii("%"));
1198 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
1200 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1201 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1202 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1203 str = subst(str, from_ascii("%2$s"), arg2);
1204 return subst(str, from_ascii("%%"), from_ascii("%"));
1209 docstring bformat(docstring const & fmt, docstring arg1, int arg2)
1211 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1212 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1213 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1214 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1215 return subst(str, from_ascii("%%"), from_ascii("%"));
1220 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
1222 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1223 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1224 docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1225 str = subst(fmt, from_ascii("%2$s"), arg2);
1226 return subst(str, from_ascii("%%"), from_ascii("%"));
1231 docstring bformat(docstring const & fmt, int arg1, int arg2)
1233 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1234 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1235 docstring str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1236 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1237 return subst(str, from_ascii("%%"), from_ascii("%"));
1242 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
1244 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1245 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1246 LASSERT(contains(fmt, from_ascii("%3$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 return subst(str, from_ascii("%%"), from_ascii("%"));
1255 docstring bformat(docstring const & fmt,
1256 docstring arg1, docstring arg2, docstring arg3, docstring arg4)
1258 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1259 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1260 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1261 LASSERT(contains(fmt, from_ascii("%4$s")), /**/);
1262 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1263 str = subst(str, from_ascii("%2$s"), arg2);
1264 str = subst(str, from_ascii("%3$s"), arg3);
1265 str = subst(str, from_ascii("%4$s"), arg4);
1266 return subst(str, from_ascii("%%"), from_ascii("%"));
1269 } // namespace support