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';
165 bool isAlnumASCII(char_type c)
167 return ('0' <= c && c <= '9')
168 || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
174 int compare_no_case(docstring const & s, docstring const & s2)
176 docstring::const_iterator p = s.begin();
177 docstring::const_iterator p2 = s2.begin();
179 while (p != s.end() && p2 != s2.end()) {
180 char_type const lc1 = lowercase(*p);
181 char_type const lc2 = lowercase(*p2);
183 return (lc1 < lc2) ? -1 : 1;
188 if (s.size() == s2.size())
190 if (s.size() < s2.size())
198 template<typename Char>
199 Char ascii_tolower(Char c) {
200 if (c >= 'A' && c <= 'Z')
201 return c - 'A' + 'a';
208 int compare_ascii_no_case(string const & s, string const & s2)
210 string::const_iterator p = s.begin();
211 string::const_iterator p2 = s2.begin();
213 while (p != s.end() && p2 != s2.end()) {
214 int const lc1 = ascii_tolower(*p);
215 int const lc2 = ascii_tolower(*p2);
217 return (lc1 < lc2) ? -1 : 1;
222 if (s.size() == s2.size())
224 if (s.size() < s2.size())
230 int compare_ascii_no_case(docstring const & s, docstring const & s2)
232 docstring::const_iterator p = s.begin();
233 docstring::const_iterator p2 = s2.begin();
235 while (p != s.end() && p2 != s2.end()) {
236 char_type const lc1 = ascii_tolower(*p);
237 char_type const lc2 = ascii_tolower(*p2);
239 return (lc1 < lc2) ? -1 : 1;
244 if (s.size() == s2.size())
246 if (s.size() < s2.size())
252 bool isStrInt(string const & str)
257 // Remove leading and trailing white space chars.
258 string const tmpstr = trim(str);
262 string::const_iterator cit = tmpstr.begin();
266 string::const_iterator end = tmpstr.end();
267 for (; cit != end; ++cit)
268 if (!isdigit((*cit)))
275 bool isStrUnsignedInt(string const & str)
280 // Remove leading and trailing white space chars.
281 string const tmpstr = trim(str);
285 string::const_iterator cit = tmpstr.begin();
286 string::const_iterator end = tmpstr.end();
287 for (; cit != end; ++cit)
288 if (!isdigit((*cit)))
295 bool isStrDbl(string const & str)
300 // Remove leading and trailing white space chars.
301 string const tmpstr = trim(str);
304 // if (tmpstr.count('.') > 1) return false;
306 string::const_iterator cit = tmpstr.begin();
307 bool found_dot = false;
310 string::const_iterator end = tmpstr.end();
311 for (; cit != end; ++cit) {
312 if (!isdigit(*cit) && *cit != '.')
324 bool hasDigit(docstring const & str)
329 docstring::const_iterator cit = str.begin();
330 docstring::const_iterator const end = str.end();
331 for (; cit != end; ++cit) {
341 static bool isHexChar(char_type c)
353 c == 'a' || c == 'A' ||
354 c == 'b' || c == 'B' ||
355 c == 'c' || c == 'C' ||
356 c == 'd' || c == 'D' ||
357 c == 'e' || c == 'E' ||
358 c == 'f' || c == 'F';
362 bool isHex(docstring const & str)
366 if (str.length() > 2 && str[0] == '0' &&
367 (str[1] == 'x' || str[1] == 'X'))
370 int const len = str.length();
372 for (; index < len; ++index) {
373 if (!isHexChar(str[index]))
380 int hexToInt(docstring const & str)
382 string s = to_ascii(str);
384 sscanf(s.c_str(), "%x", &h);
389 bool isAscii(docstring const & str)
391 int const len = str.length();
392 for (int i = 0; i < len; ++i)
399 bool isAscii(string const & str)
401 int const len = str.length();
402 for (int i = 0; i < len; ++i)
403 if (static_cast<unsigned char>(str[i]) >= 0x80)
409 char lowercase(char c)
411 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
412 return char(tolower(c));
416 char uppercase(char c)
418 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
419 return char(toupper(c));
423 char_type lowercase(char_type c)
426 // We don't know how to lowercase a non-utf16 char
428 return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
432 char_type uppercase(char_type c)
435 // We don't know how to uppercase a non-utf16 char
437 return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
441 bool isLowerCase(char_type ch) {
442 return lowercase(ch) == ch;
446 bool isUpperCase(char_type ch) {
447 return uppercase(ch) == ch;
453 // since we cannot use tolower and toupper directly in the
454 // calls to transform yet, we use these helper clases. (Lgb)
456 struct local_lowercase {
457 char_type operator()(char_type c) const {
462 struct local_uppercase {
463 char_type operator()(char_type c) const {
468 template<typename Char> struct local_ascii_lowercase {
469 Char operator()(Char c) const { return ascii_tolower(c); }
472 } // end of anon namespace
475 docstring const lowercase(docstring const & a)
478 transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
483 docstring const uppercase(docstring const & a)
486 transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase());
491 string const ascii_lowercase(string const & a)
494 transform(tmp.begin(), tmp.end(), tmp.begin(),
495 local_ascii_lowercase<char>());
500 docstring const ascii_lowercase(docstring const & a)
503 transform(tmp.begin(), tmp.end(), tmp.begin(),
504 local_ascii_lowercase<char_type>());
509 bool prefixIs(docstring const & a, char_type c)
517 bool prefixIs(string const & a, string 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 prefixIs(docstring const & a, docstring const & pre)
527 size_t const prelen = pre.length();
528 size_t const alen = a.length();
529 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
533 bool suffixIs(string const & a, char c)
537 return a[a.length() - 1] == c;
541 bool suffixIs(docstring const & a, char_type c)
545 return a[a.length() - 1] == c;
549 bool suffixIs(string const & a, string 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 suffixIs(docstring const & a, docstring const & suf)
559 size_t const suflen = suf.length();
560 size_t const alen = a.length();
561 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
565 bool containsOnly(string const & s, string const & cset)
567 return s.find_first_not_of(cset) == string::npos;
571 // ale970405+lasgoutt-970425
572 // rewritten to use new string (Lgb)
573 string const token(string const & a, char delim, int n)
581 // Find delimiter or end of string
583 if ((i = a.find(delim, i)) == string::npos)
589 // i is now the n'th delim (or string::npos)
590 if (i == string::npos)
593 k = a.find(delim, i);
594 // k is now the n'th + 1 delim (or string::npos)
596 return a.substr(i, k - i);
600 docstring const token(docstring const & a, char_type delim, int n)
608 // Find delimiter or end of string
610 if ((i = a.find(delim, i)) == docstring::npos)
616 // i is now the n'th delim (or string::npos)
617 if (i == docstring::npos)
620 k = a.find(delim, i);
621 // k is now the n'th + 1 delim (or string::npos)
623 return a.substr(i, k - i);
627 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
628 // rewritten to use new string (Lgb)
629 int tokenPos(string const & a, char delim, string const & tok)
635 while (!str.empty()) {
636 str = split(str, tmptok, delim);
645 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
646 // rewritten to use new string (Lgb)
647 int tokenPos(docstring const & a, char_type delim, docstring const & tok)
653 while (!str.empty()) {
654 str = split(str, tmptok, delim);
665 /// Substitute all \a oldchar with \a newchar
666 template<typename Ch> inline
667 basic_string<Ch> const subst_char(basic_string<Ch> const & a,
668 Ch oldchar, Ch newchar)
670 typedef basic_string<Ch> String;
672 typename String::iterator lit = tmp.begin();
673 typename String::iterator end = tmp.end();
674 for (; lit != end; ++lit)
675 if ((*lit) == oldchar)
681 /// Substitute all \a oldchar with \a newchar
682 docstring const subst_char(docstring const & a,
683 docstring::value_type oldchar, docstring::value_type newchar)
686 docstring::iterator lit = tmp.begin();
687 docstring::iterator end = tmp.end();
688 for (; lit != end; ++lit)
689 if ((*lit) == oldchar)
695 /// substitutes all instances of \a oldstr with \a newstr
696 template<typename String> inline
697 String const subst_string(String const & a,
698 String const & oldstr, String const & newstr)
700 LASSERT(!oldstr.empty(), /**/);
703 size_t const olen = oldstr.length();
704 while ((i = lstr.find(oldstr, i)) != string::npos) {
705 lstr.replace(i, olen, newstr);
706 i += newstr.length(); // We need to be sure that we dont
707 // use the same i over and over again.
713 docstring const subst_string(docstring const & a,
714 docstring const & oldstr, docstring const & newstr)
716 LASSERT(!oldstr.empty(), /**/);
719 size_t const olen = oldstr.length();
720 while ((i = lstr.find(oldstr, i)) != string::npos) {
721 lstr.replace(i, olen, newstr);
722 i += newstr.length(); // We need to be sure that we dont
723 // use the same i over and over again.
731 string const subst(string const & a, char oldchar, char newchar)
733 return subst_char(a, oldchar, newchar);
737 docstring const subst(docstring const & a,
738 char_type oldchar, char_type newchar)
740 return subst_char(a, oldchar, newchar);
744 string const subst(string const & a,
745 string const & oldstr, string const & newstr)
747 return subst_string(a, oldstr, newstr);
751 docstring const subst(docstring const & a,
752 docstring const & oldstr, docstring const & newstr)
754 return subst_string(a, oldstr, newstr);
758 /// Count all occurences of char \a chr inside \a str
759 int count_char(docstring const & str, docstring::value_type chr)
762 docstring::const_iterator lit = str.begin();
763 docstring::const_iterator end = str.end();
764 for (; lit != end; ++lit)
771 docstring const trim(docstring const & a, char const * p)
775 if (a.empty() || !*p)
778 docstring s = from_ascii(p);
779 size_t r = a.find_last_not_of(s);
780 size_t l = a.find_first_not_of(s);
782 // Is this the minimal test? (lgb)
783 if (r == docstring::npos && l == docstring::npos)
786 return a.substr(l, r - l + 1);
790 string const trim(string const & a, char const * p)
794 if (a.empty() || !*p)
797 size_t r = a.find_last_not_of(p);
798 size_t l = a.find_first_not_of(p);
800 // Is this the minimal test? (lgb)
801 if (r == string::npos && l == string::npos)
804 return a.substr(l, r - l + 1);
808 string const rtrim(string const & a, char const * p)
812 if (a.empty() || !*p)
815 size_t r = a.find_last_not_of(p);
817 // Is this test really needed? (Lgb)
818 if (r == string::npos)
821 return a.substr(0, r + 1);
825 docstring const rtrim(docstring const & a, char const * p)
829 if (a.empty() || !*p)
832 size_t r = a.find_last_not_of(from_ascii(p));
834 // Is this test really needed? (Lgb)
835 if (r == docstring::npos)
838 return a.substr(0, r + 1);
842 string const ltrim(string const & a, char const * p)
845 if (a.empty() || !*p)
847 size_t l = a.find_first_not_of(p);
848 if (l == string::npos)
850 return a.substr(l, string::npos);
854 docstring const ltrim(docstring const & a, char const * p)
857 if (a.empty() || !*p)
859 size_t l = a.find_first_not_of(from_ascii(p));
860 if (l == docstring::npos)
862 return a.substr(l, docstring::npos);
867 template<typename String, typename Char> inline
868 String const doSplit(String const & a, String & piece, Char delim)
871 size_t i = a.find(delim);
872 if (i == a.length() - 1) {
873 piece = a.substr(0, i);
874 } else if (i != String::npos) {
875 piece = a.substr(0, i);
876 tmp = a.substr(i + 1);
879 tmp = a.substr(i + 1);
886 template<typename Char> inline
887 docstring const doSplit(docstring const & a, docstring & piece, Char delim)
890 size_t i = a.find(delim);
891 if (i == a.length() - 1) {
892 piece = a.substr(0, i);
893 } else if (i != docstring::npos) {
894 piece = a.substr(0, i);
895 tmp = a.substr(i + 1);
898 tmp = a.substr(i + 1);
908 string const split(string const & a, string & piece, char delim)
910 return doSplit(a, piece, delim);
914 docstring const split(docstring const & a, docstring & piece, char_type delim)
916 return doSplit(a, piece, delim);
920 string const split(string const & a, char delim)
923 size_t i = a.find(delim);
924 if (i != string::npos) // found delim
925 tmp = a.substr(i + 1);
931 string const rsplit(string const & a, string & piece, char delim)
934 size_t i = a.rfind(delim);
935 if (i != string::npos) { // delimiter was found
936 piece = a.substr(0, i);
937 tmp = a.substr(i + 1);
938 } else { // delimiter was not found
945 docstring const rsplit(docstring const & a, char_type delim)
948 size_t i = a.rfind(delim);
949 if (i != string::npos)
950 tmp = a.substr(i + 1);
955 docstring const escape(docstring const & lab)
957 char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
958 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
960 for (size_t i = 0; i < lab.length(); ++i) {
961 char_type c = lab[i];
962 if (c >= 128 || c == '=' || c == '%') {
963 // Although char_type is a 32 bit type we know that
964 // UCS4 occupies only 21 bits, so we don't need to
965 // encode bigger values. Test for 2^24 because we
966 // can encode that with the 6 hex digits that are
967 // needed for 21 bits anyway.
968 LASSERT(c < (1 << 24), /**/);
970 enc += hexdigit[(c>>20) & 15];
971 enc += hexdigit[(c>>16) & 15];
972 enc += hexdigit[(c>>12) & 15];
973 enc += hexdigit[(c>> 8) & 15];
974 enc += hexdigit[(c>> 4) & 15];
975 enc += hexdigit[ c & 15];
986 // this doesn't check whether str is empty, so do that first.
987 vector<docstring> wrapToVec(docstring const & str, int ind,
990 docstring s = trim(str);
992 return vector<docstring>();
996 indent.insert(0, -ind, ' ');
999 s.insert(0, ind, ' ');
1001 vector<docstring> retval;
1002 while (s.size() > width) {
1003 // find the last space within the first 'width' chars
1004 size_t const i = s.find_last_of(' ', width - 1);
1005 if (i == docstring::npos || i <= size_t(ind)) {
1007 s = s.substr(0, width - 3) + "...";
1010 retval.push_back(s.substr(0, i));
1011 s = indent + s.substr(i);
1012 ind = indent.size();
1015 retval.push_back(s);
1022 docstring wrap(docstring const & str, int const ind, size_t const width)
1024 docstring s = trim(str);
1028 vector<docstring> const svec = wrapToVec(str, ind, width);
1029 return getStringFromVector(svec, from_ascii("\n"));
1033 docstring wrapParas(docstring const & str, int const indent,
1034 size_t const width, size_t const maxlines)
1039 vector<docstring> const pars = getVectorFromString(str, from_ascii("\n"), true);
1040 vector<docstring> retval;
1042 vector<docstring>::const_iterator it = pars.begin();
1043 vector<docstring>::const_iterator const en = pars.end();
1044 for (; it != en; ++it) {
1045 vector<docstring> tmp = wrapToVec(*it, indent, width);
1046 size_t const nlines = tmp.size();
1049 size_t const curlines = retval.size();
1050 if (maxlines > 0 && curlines + nlines >= maxlines) {
1051 tmp.resize(maxlines - curlines - 1);
1052 tmp.push_back(from_ascii("..."));
1054 retval.insert(retval.end(), tmp.begin(), tmp.end());
1055 if (maxlines > 0 && retval.size() >= maxlines)
1058 return getStringFromVector(retval, from_ascii("\n"));
1064 template<typename String> vector<String> const
1065 getVectorFromStringT(String const & str, String const & delim, bool keepempty)
1067 // Lars would like this code to go, but for now his replacement (below)
1068 // doesn't fullfil the same function. I have, therefore, reactivated the
1069 // old code for now. Angus 11 Nov 2002.
1074 String keys = rtrim(str);
1076 size_t const idx = keys.find(delim);
1077 if (idx == String::npos) {
1078 vec.push_back(ltrim(keys));
1081 String const key = trim(keys.substr(0, idx));
1082 if (!key.empty() || keepempty)
1084 size_t const start = idx + delim.size();
1085 keys = keys.substr(start);
1089 typedef boost::char_separator<typename String::value_type> Separator;
1090 typedef boost::tokenizer<Separator, typename String::const_iterator, String> Tokenizer;
1091 Separator sep(delim.c_str());
1092 Tokenizer tokens(str, sep);
1093 return vector<String>(tokens.begin(), tokens.end());
1098 template<typename String> const String
1099 getStringFromVector(vector<String> const & vec, String const & delim)
1102 typename vector<String>::const_iterator it = vec.begin();
1103 typename vector<String>::const_iterator en = vec.end();
1104 for (; it != en; ++it) {
1105 String item = trim(*it);
1118 vector<string> const getVectorFromString(string const & str,
1119 string const & delim,
1122 return getVectorFromStringT<string>(str, delim, keepempty);
1126 vector<docstring> const getVectorFromString(docstring const & str,
1127 docstring const & delim,
1130 return getVectorFromStringT<docstring>(str, delim, keepempty);
1134 string const getStringFromVector(vector<string> const & vec,
1135 string const & delim)
1137 return getStringFromVector<string>(vec, delim);
1141 docstring const getStringFromVector(vector<docstring> const & vec,
1142 docstring const & delim)
1144 return getStringFromVector<docstring>(vec, delim);
1148 int findToken(char const * const str[], string const & search_token)
1152 while (str[i][0] && str[i] != search_token)
1161 docstring bformat(docstring const & fmt, int arg1)
1163 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1164 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1165 return subst(str, from_ascii("%%"), from_ascii("%"));
1170 docstring bformat(docstring const & fmt, long arg1)
1172 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1173 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1174 return subst(str, from_ascii("%%"), from_ascii("%"));
1179 docstring bformat(docstring const & fmt, unsigned int arg1)
1181 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1182 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1183 return subst(str, from_ascii("%%"), from_ascii("%"));
1188 docstring bformat(docstring const & fmt, docstring arg1)
1190 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1191 docstring const str = subst(fmt, from_ascii("%1$s"), arg1);
1192 return subst(str, from_ascii("%%"), from_ascii("%"));
1197 docstring bformat(docstring const & fmt, char * arg1)
1199 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1200 docstring const str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1201 return subst(str, from_ascii("%%"), from_ascii("%"));
1206 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
1208 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1209 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1210 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1211 str = subst(str, from_ascii("%2$s"), arg2);
1212 return subst(str, from_ascii("%%"), from_ascii("%"));
1217 docstring bformat(docstring const & fmt, docstring arg1, int arg2)
1219 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1220 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1221 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1222 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1223 return subst(str, from_ascii("%%"), from_ascii("%"));
1228 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
1230 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1231 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1232 docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1233 str = subst(fmt, from_ascii("%2$s"), arg2);
1234 return subst(str, from_ascii("%%"), from_ascii("%"));
1239 docstring bformat(docstring const & fmt, int arg1, int arg2)
1241 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1242 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1243 docstring str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1244 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1245 return subst(str, from_ascii("%%"), from_ascii("%"));
1250 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
1252 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1253 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1254 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1255 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1256 str = subst(str, from_ascii("%2$s"), arg2);
1257 str = subst(str, from_ascii("%3$s"), arg3);
1258 return subst(str, from_ascii("%%"), from_ascii("%"));
1263 docstring bformat(docstring const & fmt,
1264 docstring arg1, docstring arg2, docstring arg3, docstring arg4)
1266 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1267 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1268 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1269 LASSERT(contains(fmt, from_ascii("%4$s")), /**/);
1270 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1271 str = subst(str, from_ascii("%2$s"), arg2);
1272 str = subst(str, from_ascii("%3$s"), arg3);
1273 str = subst(str, from_ascii("%4$s"), arg4);
1274 return subst(str, from_ascii("%%"), from_ascii("%"));
1277 } // namespace support