diff options
Diffstat (limited to 'src/util/string.cpp')
-rw-r--r-- | src/util/string.cpp | 419 |
1 files changed, 206 insertions, 213 deletions
diff --git a/src/util/string.cpp b/src/util/string.cpp index 347bb12b1..6e1db798c 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -32,16 +32,15 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <map> #ifndef _WIN32 -#include <iconv.h> + #include <iconv.h> #else -#define _WIN32_WINNT 0x0501 -#include <windows.h> + #define _WIN32_WINNT 0x0501 + #include <windows.h> #endif -#if defined(_ICONV_H_) && \ - (defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ - defined(__DragonFly__)) -#define BSD_ICONV_USED +#if defined(_ICONV_H_) && (defined(__FreeBSD__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__DragonFly__)) + #define BSD_ICONV_USED #endif static bool parseHexColorString(const std::string &value, video::SColor &color, @@ -50,8 +49,8 @@ static bool parseNamedColorString(const std::string &value, video::SColor &color #ifndef _WIN32 -bool convert(const char *to, const char *from, char *outbuf, size_t outbuf_size, - char *inbuf, size_t inbuf_size) +bool convert(const char *to, const char *from, char *outbuf, + size_t outbuf_size, char *inbuf, size_t inbuf_size) { iconv_t cd = iconv_open(to, from); @@ -99,14 +98,13 @@ std::wstring utf8_to_wide(const std::string &input) memset(outbuf, 0, outbuf_size); #ifdef __ANDROID__ - // Android need manual caring to support the full character set possible with - // wchar_t + // Android need manual caring to support the full character set possible with wchar_t SANITY_CHECK(sizeof(wchar_t) == 4); #endif if (!convert(DEFAULT_ENCODING, "UTF-8", outbuf, outbuf_size, inbuf, inbuf_size)) { infostream << "Couldn't convert UTF-8 string 0x" << hex_encode(input) - << " into wstring" << std::endl; + << " into wstring" << std::endl; delete[] inbuf; delete[] outbuf; return L"<invalid UTF-8 string>"; @@ -131,9 +129,8 @@ std::string wide_to_utf8(const std::wstring &input) memset(outbuf, 0, outbuf_size); if (!convert("UTF-8", DEFAULT_ENCODING, outbuf, outbuf_size, inbuf, inbuf_size)) { - infostream << "Couldn't convert wstring 0x" - << hex_encode(inbuf, inbuf_size) << " into UTF-8 string" - << std::endl; + infostream << "Couldn't convert wstring 0x" << hex_encode(inbuf, inbuf_size) + << " into UTF-8 string" << std::endl; delete[] inbuf; delete[] outbuf; return "<invalid wstring>"; @@ -153,7 +150,8 @@ std::wstring utf8_to_wide(const std::string &input) size_t outbuf_size = input.size() + 1; wchar_t *outbuf = new wchar_t[outbuf_size]; memset(outbuf, 0, outbuf_size * sizeof(wchar_t)); - MultiByteToWideChar(CP_UTF8, 0, input.c_str(), input.size(), outbuf, outbuf_size); + MultiByteToWideChar(CP_UTF8, 0, input.c_str(), input.size(), + outbuf, outbuf_size); std::wstring out(outbuf); delete[] outbuf; return out; @@ -164,8 +162,8 @@ std::string wide_to_utf8(const std::wstring &input) size_t outbuf_size = (input.size() + 1) * 6; char *outbuf = new char[outbuf_size]; memset(outbuf, 0, outbuf_size); - WideCharToMultiByte(CP_UTF8, 0, input.c_str(), input.size(), outbuf, outbuf_size, - NULL, NULL); + WideCharToMultiByte(CP_UTF8, 0, input.c_str(), input.size(), + outbuf, outbuf_size, NULL, NULL); std::string out(outbuf); delete[] outbuf; return out; @@ -191,12 +189,12 @@ wchar_t *narrow_to_wide_c(const char *str) { wchar_t *nstr = nullptr; #if defined(_WIN32) - int nResult = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, 0, 0); + int nResult = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) str, -1, 0, 0); if (nResult == 0) { - errorstream << "gettext: MultiByteToWideChar returned null" << std::endl; + errorstream<<"gettext: MultiByteToWideChar returned null"<<std::endl; } else { nstr = new wchar_t[nResult]; - MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, (WCHAR *)nstr, nResult); + MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) str, -1, (WCHAR *) nstr, nResult); } #else size_t len = strlen(str); @@ -210,8 +208,7 @@ wchar_t *narrow_to_wide_c(const char *str) return nstr; } -std::wstring narrow_to_wide(const std::string &mbs) -{ +std::wstring narrow_to_wide(const std::string &mbs) { #ifdef __ANDROID__ return utf8_to_wide(mbs); #else @@ -225,13 +222,14 @@ std::wstring narrow_to_wide(const std::string &mbs) #endif } + std::string wide_to_narrow(const std::wstring &wcs) { #ifdef __ANDROID__ return wide_to_utf8(wcs); #else size_t mbl = wcs.size() * 4; - SharedBuffer<char> mbs(mbl + 1); + SharedBuffer<char> mbs(mbl+1); size_t len = wcstombs(*mbs, wcs.c_str(), mbl); if (len == (size_t)(-1)) return "Character conversion failed!"; @@ -241,6 +239,7 @@ std::string wide_to_narrow(const std::wstring &wcs) #endif } + std::string urlencode(const std::string &str) { // Encodes non-unreserved URI characters by a percent sign @@ -251,8 +250,9 @@ std::string urlencode(const std::string &str) if (isalnum(c) || c == '-' || c == '.' || c == '_' || c == '~') { oss << c; } else { - oss << "%" << url_hex_chars[(c & 0xf0) >> 4] - << url_hex_chars[c & 0x0f]; + oss << "%" + << url_hex_chars[(c & 0xf0) >> 4] + << url_hex_chars[c & 0x0f]; } } return oss.str(); @@ -264,9 +264,10 @@ std::string urldecode(const std::string &str) std::ostringstream oss(std::ios::binary); for (u32 i = 0; i < str.size(); i++) { unsigned char highvalue, lowvalue; - if (str[i] == '%' && hex_digit_decode(str[i + 1], highvalue) && - hex_digit_decode(str[i + 2], lowvalue)) { - oss << (char)((highvalue << 4) | lowvalue); + if (str[i] == '%' && + hex_digit_decode(str[i+1], highvalue) && + hex_digit_decode(str[i+2], lowvalue)) { + oss << (char) ((highvalue << 4) | lowvalue); i += 2; } else { oss << str[i]; @@ -334,7 +335,7 @@ std::string writeFlagString(u32 flags, const FlagDesc *flagdesc, u32 flagmask) size_t mystrlcpy(char *dst, const char *src, size_t size) { - size_t srclen = strlen(src) + 1; + size_t srclen = strlen(src) + 1; size_t copylen = MYMIN(srclen, size); if (copylen > 0) { @@ -406,7 +407,7 @@ bool parseColorString(const std::string &value, video::SColor &color, bool quiet static bool parseHexColorString(const std::string &value, video::SColor &color, unsigned char default_alpha) { - unsigned char components[] = {0x00, 0x00, 0x00, default_alpha}; // R,G,B,A + unsigned char components[] = { 0x00, 0x00, 0x00, default_alpha }; // R,G,B,A if (value[0] != '#') return false; @@ -435,12 +436,12 @@ static bool parseHexColorString(const std::string &value, video::SColor &color, } else { unsigned char d1, d2; if (!hex_digit_decode(value[pos], d1) || - !hex_digit_decode(value[pos + 1], d2)) { + !hex_digit_decode(value[pos+1], d2)) { success = false; break; } components[cc] = (d1 & 0xf) << 4 | (d2 & 0xf); - pos++; // skip the second digit -- it's already used + pos++; // skip the second digit -- it's already used } } @@ -454,161 +455,161 @@ static bool parseHexColorString(const std::string &value, video::SColor &color, return success; } -struct ColorContainer -{ +struct ColorContainer { ColorContainer(); std::map<const std::string, u32> colors; }; ColorContainer::ColorContainer() { - colors["aliceblue"] = 0xf0f8ff; - colors["antiquewhite"] = 0xfaebd7; - colors["aqua"] = 0x00ffff; - colors["aquamarine"] = 0x7fffd4; - colors["azure"] = 0xf0ffff; - colors["beige"] = 0xf5f5dc; - colors["bisque"] = 0xffe4c4; - colors["black"] = 00000000; - colors["blanchedalmond"] = 0xffebcd; - colors["blue"] = 0x0000ff; - colors["blueviolet"] = 0x8a2be2; - colors["brown"] = 0xa52a2a; - colors["burlywood"] = 0xdeb887; - colors["cadetblue"] = 0x5f9ea0; - colors["chartreuse"] = 0x7fff00; - colors["chocolate"] = 0xd2691e; - colors["coral"] = 0xff7f50; - colors["cornflowerblue"] = 0x6495ed; - colors["cornsilk"] = 0xfff8dc; - colors["crimson"] = 0xdc143c; - colors["cyan"] = 0x00ffff; - colors["darkblue"] = 0x00008b; - colors["darkcyan"] = 0x008b8b; - colors["darkgoldenrod"] = 0xb8860b; - colors["darkgray"] = 0xa9a9a9; - colors["darkgreen"] = 0x006400; - colors["darkgrey"] = 0xa9a9a9; - colors["darkkhaki"] = 0xbdb76b; - colors["darkmagenta"] = 0x8b008b; - colors["darkolivegreen"] = 0x556b2f; - colors["darkorange"] = 0xff8c00; - colors["darkorchid"] = 0x9932cc; - colors["darkred"] = 0x8b0000; - colors["darksalmon"] = 0xe9967a; - colors["darkseagreen"] = 0x8fbc8f; - colors["darkslateblue"] = 0x483d8b; - colors["darkslategray"] = 0x2f4f4f; - colors["darkslategrey"] = 0x2f4f4f; - colors["darkturquoise"] = 0x00ced1; - colors["darkviolet"] = 0x9400d3; - colors["deeppink"] = 0xff1493; - colors["deepskyblue"] = 0x00bfff; - colors["dimgray"] = 0x696969; - colors["dimgrey"] = 0x696969; - colors["dodgerblue"] = 0x1e90ff; - colors["firebrick"] = 0xb22222; - colors["floralwhite"] = 0xfffaf0; - colors["forestgreen"] = 0x228b22; - colors["fuchsia"] = 0xff00ff; - colors["gainsboro"] = 0xdcdcdc; - colors["ghostwhite"] = 0xf8f8ff; - colors["gold"] = 0xffd700; - colors["goldenrod"] = 0xdaa520; - colors["gray"] = 0x808080; - colors["green"] = 0x008000; - colors["greenyellow"] = 0xadff2f; - colors["grey"] = 0x808080; - colors["honeydew"] = 0xf0fff0; - colors["hotpink"] = 0xff69b4; - colors["indianred"] = 0xcd5c5c; - colors["indigo"] = 0x4b0082; - colors["ivory"] = 0xfffff0; - colors["khaki"] = 0xf0e68c; - colors["lavender"] = 0xe6e6fa; - colors["lavenderblush"] = 0xfff0f5; - colors["lawngreen"] = 0x7cfc00; - colors["lemonchiffon"] = 0xfffacd; - colors["lightblue"] = 0xadd8e6; - colors["lightcoral"] = 0xf08080; - colors["lightcyan"] = 0xe0ffff; - colors["lightgoldenrodyellow"] = 0xfafad2; - colors["lightgray"] = 0xd3d3d3; - colors["lightgreen"] = 0x90ee90; - colors["lightgrey"] = 0xd3d3d3; - colors["lightpink"] = 0xffb6c1; - colors["lightsalmon"] = 0xffa07a; - colors["lightseagreen"] = 0x20b2aa; - colors["lightskyblue"] = 0x87cefa; - colors["lightslategray"] = 0x778899; - colors["lightslategrey"] = 0x778899; - colors["lightsteelblue"] = 0xb0c4de; - colors["lightyellow"] = 0xffffe0; - colors["lime"] = 0x00ff00; - colors["limegreen"] = 0x32cd32; - colors["linen"] = 0xfaf0e6; - colors["magenta"] = 0xff00ff; - colors["maroon"] = 0x800000; - colors["mediumaquamarine"] = 0x66cdaa; - colors["mediumblue"] = 0x0000cd; - colors["mediumorchid"] = 0xba55d3; - colors["mediumpurple"] = 0x9370db; - colors["mediumseagreen"] = 0x3cb371; - colors["mediumslateblue"] = 0x7b68ee; - colors["mediumspringgreen"] = 0x00fa9a; - colors["mediumturquoise"] = 0x48d1cc; - colors["mediumvioletred"] = 0xc71585; - colors["midnightblue"] = 0x191970; - colors["mintcream"] = 0xf5fffa; - colors["mistyrose"] = 0xffe4e1; - colors["moccasin"] = 0xffe4b5; - colors["navajowhite"] = 0xffdead; - colors["navy"] = 0x000080; - colors["oldlace"] = 0xfdf5e6; - colors["olive"] = 0x808000; - colors["olivedrab"] = 0x6b8e23; - colors["orange"] = 0xffa500; - colors["orangered"] = 0xff4500; - colors["orchid"] = 0xda70d6; - colors["palegoldenrod"] = 0xeee8aa; - colors["palegreen"] = 0x98fb98; - colors["paleturquoise"] = 0xafeeee; - colors["palevioletred"] = 0xdb7093; - colors["papayawhip"] = 0xffefd5; - colors["peachpuff"] = 0xffdab9; - colors["peru"] = 0xcd853f; - colors["pink"] = 0xffc0cb; - colors["plum"] = 0xdda0dd; - colors["powderblue"] = 0xb0e0e6; - colors["purple"] = 0x800080; - colors["red"] = 0xff0000; - colors["rosybrown"] = 0xbc8f8f; - colors["royalblue"] = 0x4169e1; - colors["saddlebrown"] = 0x8b4513; - colors["salmon"] = 0xfa8072; - colors["sandybrown"] = 0xf4a460; - colors["seagreen"] = 0x2e8b57; - colors["seashell"] = 0xfff5ee; - colors["sienna"] = 0xa0522d; - colors["silver"] = 0xc0c0c0; - colors["skyblue"] = 0x87ceeb; - colors["slateblue"] = 0x6a5acd; - colors["slategray"] = 0x708090; - colors["slategrey"] = 0x708090; - colors["snow"] = 0xfffafa; - colors["springgreen"] = 0x00ff7f; - colors["steelblue"] = 0x4682b4; - colors["tan"] = 0xd2b48c; - colors["teal"] = 0x008080; - colors["thistle"] = 0xd8bfd8; - colors["tomato"] = 0xff6347; - colors["turquoise"] = 0x40e0d0; - colors["violet"] = 0xee82ee; - colors["wheat"] = 0xf5deb3; - colors["white"] = 0xffffff; - colors["whitesmoke"] = 0xf5f5f5; - colors["yellow"] = 0xffff00; - colors["yellowgreen"] = 0x9acd32; + colors["aliceblue"] = 0xf0f8ff; + colors["antiquewhite"] = 0xfaebd7; + colors["aqua"] = 0x00ffff; + colors["aquamarine"] = 0x7fffd4; + colors["azure"] = 0xf0ffff; + colors["beige"] = 0xf5f5dc; + colors["bisque"] = 0xffe4c4; + colors["black"] = 00000000; + colors["blanchedalmond"] = 0xffebcd; + colors["blue"] = 0x0000ff; + colors["blueviolet"] = 0x8a2be2; + colors["brown"] = 0xa52a2a; + colors["burlywood"] = 0xdeb887; + colors["cadetblue"] = 0x5f9ea0; + colors["chartreuse"] = 0x7fff00; + colors["chocolate"] = 0xd2691e; + colors["coral"] = 0xff7f50; + colors["cornflowerblue"] = 0x6495ed; + colors["cornsilk"] = 0xfff8dc; + colors["crimson"] = 0xdc143c; + colors["cyan"] = 0x00ffff; + colors["darkblue"] = 0x00008b; + colors["darkcyan"] = 0x008b8b; + colors["darkgoldenrod"] = 0xb8860b; + colors["darkgray"] = 0xa9a9a9; + colors["darkgreen"] = 0x006400; + colors["darkgrey"] = 0xa9a9a9; + colors["darkkhaki"] = 0xbdb76b; + colors["darkmagenta"] = 0x8b008b; + colors["darkolivegreen"] = 0x556b2f; + colors["darkorange"] = 0xff8c00; + colors["darkorchid"] = 0x9932cc; + colors["darkred"] = 0x8b0000; + colors["darksalmon"] = 0xe9967a; + colors["darkseagreen"] = 0x8fbc8f; + colors["darkslateblue"] = 0x483d8b; + colors["darkslategray"] = 0x2f4f4f; + colors["darkslategrey"] = 0x2f4f4f; + colors["darkturquoise"] = 0x00ced1; + colors["darkviolet"] = 0x9400d3; + colors["deeppink"] = 0xff1493; + colors["deepskyblue"] = 0x00bfff; + colors["dimgray"] = 0x696969; + colors["dimgrey"] = 0x696969; + colors["dodgerblue"] = 0x1e90ff; + colors["firebrick"] = 0xb22222; + colors["floralwhite"] = 0xfffaf0; + colors["forestgreen"] = 0x228b22; + colors["fuchsia"] = 0xff00ff; + colors["gainsboro"] = 0xdcdcdc; + colors["ghostwhite"] = 0xf8f8ff; + colors["gold"] = 0xffd700; + colors["goldenrod"] = 0xdaa520; + colors["gray"] = 0x808080; + colors["green"] = 0x008000; + colors["greenyellow"] = 0xadff2f; + colors["grey"] = 0x808080; + colors["honeydew"] = 0xf0fff0; + colors["hotpink"] = 0xff69b4; + colors["indianred"] = 0xcd5c5c; + colors["indigo"] = 0x4b0082; + colors["ivory"] = 0xfffff0; + colors["khaki"] = 0xf0e68c; + colors["lavender"] = 0xe6e6fa; + colors["lavenderblush"] = 0xfff0f5; + colors["lawngreen"] = 0x7cfc00; + colors["lemonchiffon"] = 0xfffacd; + colors["lightblue"] = 0xadd8e6; + colors["lightcoral"] = 0xf08080; + colors["lightcyan"] = 0xe0ffff; + colors["lightgoldenrodyellow"] = 0xfafad2; + colors["lightgray"] = 0xd3d3d3; + colors["lightgreen"] = 0x90ee90; + colors["lightgrey"] = 0xd3d3d3; + colors["lightpink"] = 0xffb6c1; + colors["lightsalmon"] = 0xffa07a; + colors["lightseagreen"] = 0x20b2aa; + colors["lightskyblue"] = 0x87cefa; + colors["lightslategray"] = 0x778899; + colors["lightslategrey"] = 0x778899; + colors["lightsteelblue"] = 0xb0c4de; + colors["lightyellow"] = 0xffffe0; + colors["lime"] = 0x00ff00; + colors["limegreen"] = 0x32cd32; + colors["linen"] = 0xfaf0e6; + colors["magenta"] = 0xff00ff; + colors["maroon"] = 0x800000; + colors["mediumaquamarine"] = 0x66cdaa; + colors["mediumblue"] = 0x0000cd; + colors["mediumorchid"] = 0xba55d3; + colors["mediumpurple"] = 0x9370db; + colors["mediumseagreen"] = 0x3cb371; + colors["mediumslateblue"] = 0x7b68ee; + colors["mediumspringgreen"] = 0x00fa9a; + colors["mediumturquoise"] = 0x48d1cc; + colors["mediumvioletred"] = 0xc71585; + colors["midnightblue"] = 0x191970; + colors["mintcream"] = 0xf5fffa; + colors["mistyrose"] = 0xffe4e1; + colors["moccasin"] = 0xffe4b5; + colors["navajowhite"] = 0xffdead; + colors["navy"] = 0x000080; + colors["oldlace"] = 0xfdf5e6; + colors["olive"] = 0x808000; + colors["olivedrab"] = 0x6b8e23; + colors["orange"] = 0xffa500; + colors["orangered"] = 0xff4500; + colors["orchid"] = 0xda70d6; + colors["palegoldenrod"] = 0xeee8aa; + colors["palegreen"] = 0x98fb98; + colors["paleturquoise"] = 0xafeeee; + colors["palevioletred"] = 0xdb7093; + colors["papayawhip"] = 0xffefd5; + colors["peachpuff"] = 0xffdab9; + colors["peru"] = 0xcd853f; + colors["pink"] = 0xffc0cb; + colors["plum"] = 0xdda0dd; + colors["powderblue"] = 0xb0e0e6; + colors["purple"] = 0x800080; + colors["red"] = 0xff0000; + colors["rosybrown"] = 0xbc8f8f; + colors["royalblue"] = 0x4169e1; + colors["saddlebrown"] = 0x8b4513; + colors["salmon"] = 0xfa8072; + colors["sandybrown"] = 0xf4a460; + colors["seagreen"] = 0x2e8b57; + colors["seashell"] = 0xfff5ee; + colors["sienna"] = 0xa0522d; + colors["silver"] = 0xc0c0c0; + colors["skyblue"] = 0x87ceeb; + colors["slateblue"] = 0x6a5acd; + colors["slategray"] = 0x708090; + colors["slategrey"] = 0x708090; + colors["snow"] = 0xfffafa; + colors["springgreen"] = 0x00ff7f; + colors["steelblue"] = 0x4682b4; + colors["tan"] = 0xd2b48c; + colors["teal"] = 0x008080; + colors["thistle"] = 0xd8bfd8; + colors["tomato"] = 0xff6347; + colors["turquoise"] = 0x40e0d0; + colors["violet"] = 0xee82ee; + colors["wheat"] = 0xf5deb3; + colors["white"] = 0xffffff; + colors["whitesmoke"] = 0xf5f5f5; + colors["yellow"] = 0xffff00; + colors["yellowgreen"] = 0x9acd32; + } static const ColorContainer named_colors; @@ -652,12 +653,12 @@ static bool parseNamedColorString(const std::string &value, video::SColor &color return false; unsigned char d1, d2; - if (!hex_digit_decode(alpha_string.at(0), d1) || - !hex_digit_decode(alpha_string.at(1), d2)) + if (!hex_digit_decode(alpha_string.at(0), d1) + || !hex_digit_decode(alpha_string.at(1), d2)) return false; color_temp |= ((d1 & 0xf) << 4 | (d2 & 0xf)) << 24; } else { - color_temp |= 0xff << 24; // Fully opaque + color_temp |= 0xff << 24; // Fully opaque } color = video::SColor(color_temp); @@ -685,14 +686,15 @@ void str_replace(std::string &str, char from, char to) * For instance, suppose we have a string such as "@1 Wool" with the argument "White" * The string will be sent as "\x1bT\x1bF\x1bTWhite\x1bE\x1bE Wool\x1bE" * To translate this string, we extract what is inside \x1bT/\x1bE tags. - * When we notice the \x1bF tag, we recursively extract what is there up to the \x1bE end - * tag, translating it as well. We get the argument "White", translated, and create a - * template string with "@1" instead of it. We finally get the template "@1 Wool" that was - * used in the beginning, which we translate before filling it again. + * When we notice the \x1bF tag, we recursively extract what is there up to the \x1bE end tag, + * translating it as well. + * We get the argument "White", translated, and create a template string with "@1" instead of it. + * We finally get the template "@1 Wool" that was used in the beginning, which we translate + * before filling it again. */ -void translate_all(const std::wstring &s, size_t &i, Translations *translations, - std::wstring &res); +void translate_all(const std::wstring &s, size_t &i, + Translations *translations, std::wstring &res); void translate_string(const std::wstring &s, Translations *translations, const std::wstring &textdomain, size_t &i, std::wstring &res) @@ -741,18 +743,14 @@ void translate_string(const std::wstring &s, Translations *translations, // The escape sequence is now reconstructed. std::vector<std::wstring> parts = split(escape_sequence, L'@'); if (parts[0] == L"E") { - // "End of translation" escape sequence. We are done locating the - // string to translate. + // "End of translation" escape sequence. We are done locating the string to translate. break; } else if (parts[0] == L"F") { // "Start of argument" escape sequence. - // Recursively translate the argument, and add it to the argument - // list. Add an "@n" instead of the argument to the template to - // translate. + // Recursively translate the argument, and add it to the argument list. + // Add an "@n" instead of the argument to the template to translate. if (arg_number >= 10) { - errorstream << "Ignoring too many arguments to " - "translation" - << std::endl; + errorstream << "Ignoring too many arguments to translation" << std::endl; std::wstring arg; translate_all(s, i, translations, arg); args.push_back(arg); @@ -765,19 +763,17 @@ void translate_string(const std::wstring &s, Translations *translations, translate_all(s, i, translations, arg); args.push_back(arg); } else { - // This is an escape sequence *inside* the template string to - // translate itself. This should not happen, show an error - // message. - errorstream << "Ignoring escape sequence '" - << wide_to_narrow(escape_sequence) - << "' in translation" << std::endl; + // This is an escape sequence *inside* the template string to translate itself. + // This should not happen, show an error message. + errorstream << "Ignoring escape sequence '" << wide_to_narrow(escape_sequence) << "' in translation" << std::endl; } } std::wstring toutput; // Translate the template. if (translations != nullptr) - toutput = translations->getTranslation(textdomain, output.str()); + toutput = translations->getTranslation( + textdomain, output.str()); else toutput = output.str(); @@ -800,24 +796,21 @@ void translate_string(const std::wstring &s, Translations *translations, continue; } - // Here we have an argument; get its index and add the translated argument - // to the output. + // Here we have an argument; get its index and add the translated argument to the output. int arg_index = toutput[j] - L'1'; ++j; if (0 <= arg_index && (size_t)arg_index < args.size()) { result << args[arg_index]; } else { // This is not allowed: show an error message - errorstream << "Ignoring out-of-bounds argument escape sequence " - "in translation" - << std::endl; + errorstream << "Ignoring out-of-bounds argument escape sequence in translation" << std::endl; } } res = result.str(); } -void translate_all(const std::wstring &s, size_t &i, Translations *translations, - std::wstring &res) +void translate_all(const std::wstring &s, size_t &i, + Translations *translations, std::wstring &res) { std::wostringstream output; while (i < s.length()) { |