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 static bool isHexChar(char_type c)
330 c == 'a' || c == 'A' ||
331 c == 'b' || c == 'B' ||
332 c == 'c' || c == 'C' ||
333 c == 'd' || c == 'D' ||
334 c == 'e' || c == 'E' ||
335 c == 'f' || c == 'F';
339 bool isHex(docstring const & str)
343 if (str.length() > 2 && str[0] == '0' &&
344 (str[1] == 'x' || str[1] == 'X'))
347 int const len = str.length();
349 for (; index < len; ++index) {
350 if (!isHexChar(str[index]))
357 int hexToInt(docstring const & str)
359 string s = to_ascii(str);
361 sscanf(s.c_str(), "%x", &h);
366 bool isAscii(docstring const & str)
368 int const len = str.length();
369 for (int i = 0; i < len; ++i)
376 bool isAscii(string const & str)
378 int const len = str.length();
379 for (int i = 0; i < len; ++i)
380 if (static_cast<unsigned char>(str[i]) >= 0x80)
386 char lowercase(char c)
388 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
389 return char(tolower(c));
393 char uppercase(char c)
395 LASSERT(static_cast<unsigned char>(c) < 0x80, /**/);
396 return char(toupper(c));
400 char_type lowercase(char_type c)
403 // We don't know how to lowercase a non-utf16 char
405 return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
409 char_type uppercase(char_type c)
412 // We don't know how to uppercase a non-utf16 char
414 return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
420 // since we cannot use tolower and toupper directly in the
421 // calls to transform yet, we use these helper clases. (Lgb)
423 struct local_lowercase {
424 char_type operator()(char_type c) const {
426 // We don't know how to lowercase a non-utf16 char
428 return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
432 struct local_uppercase {
433 char_type operator()(char_type c) const {
435 // We don't know how to uppercase a non-utf16 char
437 return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
441 template<typename Char> struct local_ascii_lowercase {
442 Char operator()(Char c) const { return ascii_tolower(c); }
445 } // end of anon namespace
447 docstring const lowercase(docstring const & a)
450 transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
455 docstring const uppercase(docstring const & a)
458 transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase());
463 string const ascii_lowercase(string const & a)
466 transform(tmp.begin(), tmp.end(), tmp.begin(),
467 local_ascii_lowercase<char>());
472 docstring const ascii_lowercase(docstring const & a)
475 transform(tmp.begin(), tmp.end(), tmp.begin(),
476 local_ascii_lowercase<char_type>());
481 bool prefixIs(docstring const & a, char_type c)
489 bool prefixIs(string const & a, string const & pre)
491 size_t const prelen = pre.length();
492 size_t const alen = a.length();
493 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
497 bool prefixIs(docstring const & a, docstring const & pre)
499 size_t const prelen = pre.length();
500 size_t const alen = a.length();
501 return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
505 bool suffixIs(string const & a, char c)
509 return a[a.length() - 1] == c;
513 bool suffixIs(docstring const & a, char_type c)
517 return a[a.length() - 1] == c;
521 bool suffixIs(string const & a, string const & suf)
523 size_t const suflen = suf.length();
524 size_t const alen = a.length();
525 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
529 bool suffixIs(docstring const & a, docstring const & suf)
531 size_t const suflen = suf.length();
532 size_t const alen = a.length();
533 return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
537 bool containsOnly(string const & s, string const & cset)
539 return s.find_first_not_of(cset) == string::npos;
543 // ale970405+lasgoutt-970425
544 // rewritten to use new string (Lgb)
545 string const token(string const & a, char delim, int n)
553 // Find delimiter or end of string
555 if ((i = a.find(delim, i)) == string::npos)
561 // i is now the n'th delim (or string::npos)
562 if (i == string::npos)
565 k = a.find(delim, i);
566 // k is now the n'th + 1 delim (or string::npos)
568 return a.substr(i, k - i);
572 docstring const token(docstring const & a, char_type delim, int n)
580 // Find delimiter or end of string
582 if ((i = a.find(delim, i)) == docstring::npos)
588 // i is now the n'th delim (or string::npos)
589 if (i == docstring::npos)
592 k = a.find(delim, i);
593 // k is now the n'th + 1 delim (or string::npos)
595 return a.substr(i, k - i);
599 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
600 // rewritten to use new string (Lgb)
601 int tokenPos(string const & a, char delim, string const & tok)
607 while (!str.empty()) {
608 str = split(str, tmptok, delim);
617 // this could probably be faster and/or cleaner, but it seems to work (JMarc)
618 // rewritten to use new string (Lgb)
619 int tokenPos(docstring const & a, char_type delim, docstring const & tok)
625 while (!str.empty()) {
626 str = split(str, tmptok, delim);
637 /// Substitute all \a oldchar with \a newchar
638 template<typename Ch> inline
639 basic_string<Ch> const subst_char(basic_string<Ch> const & a,
640 Ch oldchar, Ch newchar)
642 typedef basic_string<Ch> String;
644 typename String::iterator lit = tmp.begin();
645 typename String::iterator end = tmp.end();
646 for (; lit != end; ++lit)
647 if ((*lit) == oldchar)
652 /// Substitute all \a oldchar with \a newchar
653 docstring const subst_char(docstring const & a,
654 docstring::value_type oldchar, docstring::value_type newchar)
657 docstring::iterator lit = tmp.begin();
658 docstring::iterator end = tmp.end();
659 for (; lit != end; ++lit)
660 if ((*lit) == oldchar)
666 /// substitutes all instances of \a oldstr with \a newstr
667 template<typename String> inline
668 String const subst_string(String const & a,
669 String const & oldstr, String const & newstr)
671 LASSERT(!oldstr.empty(), /**/);
674 size_t const olen = oldstr.length();
675 while ((i = lstr.find(oldstr, i)) != string::npos) {
676 lstr.replace(i, olen, newstr);
677 i += newstr.length(); // We need to be sure that we dont
678 // use the same i over and over again.
683 docstring const subst_string(docstring const & a,
684 docstring const & oldstr, docstring const & newstr)
686 LASSERT(!oldstr.empty(), /**/);
689 size_t const olen = oldstr.length();
690 while ((i = lstr.find(oldstr, i)) != string::npos) {
691 lstr.replace(i, olen, newstr);
692 i += newstr.length(); // We need to be sure that we dont
693 // use the same i over and over again.
701 string const subst(string const & a, char oldchar, char newchar)
703 return subst_char(a, oldchar, newchar);
707 docstring const subst(docstring const & a,
708 char_type oldchar, char_type newchar)
710 return subst_char(a, oldchar, newchar);
714 string const subst(string const & a,
715 string const & oldstr, string const & newstr)
717 return subst_string(a, oldstr, newstr);
721 docstring const subst(docstring const & a,
722 docstring const & oldstr, docstring const & newstr)
724 return subst_string(a, oldstr, newstr);
728 docstring const trim(docstring const & a, char const * p)
732 if (a.empty() || !*p)
735 docstring s = from_ascii(p);
736 size_t r = a.find_last_not_of(s);
737 size_t l = a.find_first_not_of(s);
739 // Is this the minimal test? (lgb)
740 if (r == docstring::npos && l == docstring::npos)
743 return a.substr(l, r - l + 1);
747 string const trim(string const & a, char const * p)
751 if (a.empty() || !*p)
754 size_t r = a.find_last_not_of(p);
755 size_t l = a.find_first_not_of(p);
757 // Is this the minimal test? (lgb)
758 if (r == string::npos && l == string::npos)
761 return a.substr(l, r - l + 1);
765 string const rtrim(string const & a, char const * p)
769 if (a.empty() || !*p)
772 size_t r = a.find_last_not_of(p);
774 // Is this test really needed? (Lgb)
775 if (r == string::npos)
778 return a.substr(0, r + 1);
782 docstring const rtrim(docstring const & a, char const * p)
786 if (a.empty() || !*p)
789 size_t r = a.find_last_not_of(from_ascii(p));
791 // Is this test really needed? (Lgb)
792 if (r == docstring::npos)
795 return a.substr(0, r + 1);
799 string const ltrim(string const & a, char const * p)
802 if (a.empty() || !*p)
804 size_t l = a.find_first_not_of(p);
805 if (l == string::npos)
807 return a.substr(l, string::npos);
811 docstring const ltrim(docstring const & a, char const * p)
814 if (a.empty() || !*p)
816 size_t l = a.find_first_not_of(from_ascii(p));
817 if (l == docstring::npos)
819 return a.substr(l, docstring::npos);
824 template<typename String, typename Char> inline
825 String const doSplit(String const & a, String & piece, Char delim)
828 size_t i = a.find(delim);
829 if (i == a.length() - 1) {
830 piece = a.substr(0, i);
831 } else if (i != String::npos) {
832 piece = a.substr(0, i);
833 tmp = a.substr(i + 1);
836 tmp = a.substr(i + 1);
843 template<typename Char> inline
844 docstring const doSplit(docstring const & a, docstring & piece, Char delim)
847 size_t i = a.find(delim);
848 if (i == a.length() - 1) {
849 piece = a.substr(0, i);
850 } else if (i != docstring::npos) {
851 piece = a.substr(0, i);
852 tmp = a.substr(i + 1);
855 tmp = a.substr(i + 1);
865 string const split(string const & a, string & piece, char delim)
867 return doSplit(a, piece, delim);
871 docstring const split(docstring const & a, docstring & piece, char_type delim)
873 return doSplit(a, piece, delim);
877 string const split(string const & a, char delim)
880 size_t i = a.find(delim);
881 if (i != string::npos) // found delim
882 tmp = a.substr(i + 1);
888 string const rsplit(string const & a, string & piece, char delim)
891 size_t i = a.rfind(delim);
892 if (i != string::npos) { // delimiter was found
893 piece = a.substr(0, i);
894 tmp = a.substr(i + 1);
895 } else { // delimiter was not found
902 docstring const rsplit(docstring const & a, char_type delim)
905 size_t i = a.rfind(delim);
906 if (i != string::npos)
907 tmp = a.substr(i + 1);
912 docstring const escape(docstring const & lab)
914 char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
915 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
917 for (size_t i = 0; i < lab.length(); ++i) {
918 char_type c = lab[i];
919 if (c >= 128 || c == '=' || c == '%') {
920 // Although char_type is a 32 bit type we know that
921 // UCS4 occupies only 21 bits, so we don't need to
922 // encode bigger values. Test for 2^24 because we
923 // can encode that with the 6 hex digits that are
924 // needed for 21 bits anyway.
925 LASSERT(c < (1 << 24), /**/);
927 enc += hexdigit[(c>>20) & 15];
928 enc += hexdigit[(c>>16) & 15];
929 enc += hexdigit[(c>>12) & 15];
930 enc += hexdigit[(c>> 8) & 15];
931 enc += hexdigit[(c>> 4) & 15];
932 enc += hexdigit[ c & 15];
943 // this doesn't check whether str is empty, so do that first.
944 vector<docstring> wrapToVec(docstring const & str, int const ind,
947 docstring s = trim(str);
949 return vector<docstring>();
953 for (int j = 0; j > ind; --j)
956 for (int j = 0; j < ind; ++j)
959 vector<docstring> retval;
960 while (s.size() > width) {
962 // find the last space
968 s = s.substr(0, width - 3) + "...";
971 retval.push_back(s.substr(0, i));
972 s = indent + s.substr(i);
982 docstring wrap(docstring const & str, int const ind, size_t const width)
984 docstring s = trim(str);
988 vector<docstring> const svec = wrapToVec(str, ind, width);
989 return getStringFromVector(svec, from_ascii("\n"));
993 docstring wrapParas(docstring const & str, int const indent,
994 size_t const width, size_t const maxlines)
999 vector<docstring> pars = getVectorFromString(str, from_ascii("\n"), true);
1000 vector<docstring> retval;
1002 vector<docstring>::iterator it = pars.begin();
1003 vector<docstring>::iterator en = pars.end();
1004 for (; it != en; ++it) {
1005 vector<docstring> tmp = wrapToVec(*it, indent, width);
1006 size_t const nlines = tmp.size();
1009 size_t const curlines = retval.size();
1010 if (maxlines > 0 && curlines + nlines >= maxlines) {
1011 tmp.resize(maxlines - curlines - 1);
1012 tmp.push_back(from_ascii("..."));
1014 retval.insert(retval.end(), tmp.begin(), tmp.end());
1015 if (maxlines > 0 && retval.size() >= maxlines)
1018 return getStringFromVector(retval, from_ascii("\n"));
1024 template<typename String> vector<String> const
1025 getVectorFromStringT(String const & str, String const & delim, bool keepempty)
1027 // Lars would like this code to go, but for now his replacement (below)
1028 // doesn't fullfil the same function. I have, therefore, reactivated the
1029 // old code for now. Angus 11 Nov 2002.
1034 String keys = rtrim(str);
1036 size_t const idx = keys.find(delim);
1037 if (idx == String::npos) {
1038 vec.push_back(ltrim(keys));
1041 String const key = trim(keys.substr(0, idx));
1042 if (!key.empty() || keepempty)
1044 size_t const start = idx + delim.size();
1045 keys = keys.substr(start);
1049 typedef boost::char_separator<typename String::value_type> Separator;
1050 typedef boost::tokenizer<Separator, typename String::const_iterator, String> Tokenizer;
1051 Separator sep(delim.c_str());
1052 Tokenizer tokens(str, sep);
1053 return vector<String>(tokens.begin(), tokens.end());
1058 template<typename String> const String
1059 getStringFromVector(vector<String> const & vec, String const & delim)
1062 typename vector<String>::const_iterator it = vec.begin();
1063 typename vector<String>::const_iterator en = vec.end();
1064 for (; it != en; ++it) {
1065 String item = trim(*it);
1078 vector<string> const getVectorFromString(string const & str,
1079 string const & delim,
1082 return getVectorFromStringT<string>(str, delim, keepempty);
1086 vector<docstring> const getVectorFromString(docstring const & str,
1087 docstring const & delim,
1090 return getVectorFromStringT<docstring>(str, delim, keepempty);
1094 string const getStringFromVector(vector<string> const & vec,
1095 string const & delim)
1097 return getStringFromVector<string>(vec, delim);
1101 docstring const getStringFromVector(vector<docstring> const & vec,
1102 docstring const & delim)
1104 return getStringFromVector<docstring>(vec, delim);
1108 int findToken(char const * const str[], string const & search_token)
1112 while (str[i][0] && str[i] != search_token)
1121 docstring bformat(docstring const & fmt, int arg1)
1123 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1124 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1125 return subst(str, from_ascii("%%"), from_ascii("%"));
1130 docstring bformat(docstring const & fmt, long arg1)
1132 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1133 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1134 return subst(str, from_ascii("%%"), from_ascii("%"));
1139 docstring bformat(docstring const & fmt, unsigned int arg1)
1141 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1142 docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1143 return subst(str, from_ascii("%%"), from_ascii("%"));
1148 docstring bformat(docstring const & fmt, docstring arg1)
1150 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1151 docstring const str = subst(fmt, from_ascii("%1$s"), arg1);
1152 return subst(str, from_ascii("%%"), from_ascii("%"));
1157 docstring bformat(docstring const & fmt, char * arg1)
1159 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1160 docstring const str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1161 return subst(str, from_ascii("%%"), from_ascii("%"));
1166 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
1168 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1169 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1170 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1171 str = subst(str, from_ascii("%2$s"), arg2);
1172 return subst(str, from_ascii("%%"), from_ascii("%"));
1177 docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
1179 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1180 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1181 docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
1182 str = subst(fmt, from_ascii("%2$s"), arg2);
1183 return subst(str, from_ascii("%%"), from_ascii("%"));
1188 docstring bformat(docstring const & fmt, int arg1, int arg2)
1190 LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
1191 LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
1192 docstring str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
1193 str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
1194 return subst(str, from_ascii("%%"), from_ascii("%"));
1199 docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
1201 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1202 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1203 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1204 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1205 str = subst(str, from_ascii("%2$s"), arg2);
1206 str = subst(str, from_ascii("%3$s"), arg3);
1207 return subst(str, from_ascii("%%"), from_ascii("%"));
1212 docstring bformat(docstring const & fmt,
1213 docstring arg1, docstring arg2, docstring arg3, docstring arg4)
1215 LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
1216 LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
1217 LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
1218 LASSERT(contains(fmt, from_ascii("%4$s")), /**/);
1219 docstring str = subst(fmt, from_ascii("%1$s"), arg1);
1220 str = subst(str, from_ascii("%2$s"), arg2);
1221 str = subst(str, from_ascii("%3$s"), arg3);
1222 str = subst(str, from_ascii("%4$s"), arg4);
1223 return subst(str, from_ascii("%%"), from_ascii("%"));
1226 } // namespace support