From 323f3f0c9f6d8de3fc2d7ba66be9482e2b1f2f36 Mon Sep 17 00:00:00 2001 From: mikemirzayanov Date: Tue, 26 Sep 2023 10:58:40 +0300 Subject: [PATCH] setAppesModeEncoding --- testlib.h | 55 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/testlib.h b/testlib.h index 57b5781..dda5833 100644 --- a/testlib.h +++ b/testlib.h @@ -386,6 +386,20 @@ static std::string removeDoubleTrailingZeroes(std::string value) { return value; } +inline std::string upperCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('a' <= s[i] && s[i] <= 'z') + s[i] = char(s[i] - 'a' + 'A'); + return s; +} + +inline std::string lowerCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('A' <= s[i] && s[i] <= 'Z') + s[i] = char(s[i] - 'A' + 'a'); + return s; +} + #ifdef __GNUC__ __attribute__ ((format (printf, 1, 2))) #endif @@ -2314,6 +2328,7 @@ InStream inf; InStream ouf; InStream ans; bool appesMode; +std::string appesModeEncoding = "windows-1251"; std::string resultName; std::string checkerName = "untitled checker"; random_t rnd; @@ -2966,7 +2981,7 @@ NORETURN void InStream::quit(TResult result, const char *msg) { quit(_fail, "Can not write to the result file"); } if (appesMode) { - std::fprintf(resultFile, ""); + std::fprintf(resultFile, "", appesModeEncoding.c_str()); if (isPartial) std::fprintf(resultFile, "", outcomes[(int) _partially].c_str(), pctype); @@ -4396,6 +4411,30 @@ void registerGen(int argc, char *argv[]) { } #endif +static void setAppesModeEncoding(std::string appesModeEncoding) { + static const char* const ENCODINGS[] = {"ascii", "utf-7", "utf-8", "utf-16", "utf-16le", "utf-16be", "utf-32", "utf-32le", "utf-32be", "iso-8859-1", +"iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-9", "iso-8859-10", "iso-8859-11", +"iso-8859-13", "iso-8859-14", "iso-8859-15", "iso-8859-16", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255", +"windows-1256", "windows-1257", "windows-1258", "gb2312", "gbk", "gb18030", "big5", "shift-jis", "euc-jp", "euc-kr", +"euc-cn", "euc-tw", "koi8-r", "koi8-u", "tis-620", "ibm437", "ibm850", "ibm852", "ibm855", "ibm857", +"ibm860", "ibm861", "ibm862", "ibm863", "ibm865", "ibm866", "ibm869", "macroman", "maccentraleurope", "maciceland", +"maccroatian", "macromania", "maccyrillic", "macukraine", "macgreek", "macturkish", "machebrew", "macarabic", "macthai", "hz-gb-2312", +"iso-2022-jp", "iso-2022-kr", "iso-2022-cn", "armscii-8", "tscii", "iscii", "viscii", "geostd8", "cp949", "cp874", +"cp1006", "cp775", "cp858", "cp737", "cp853", "cp856", "cp922", "cp1046", "cp1125", "cp1131", +"ptcp154", "koi8-t", "koi8-ru", "mulelao-1", "cp1133", "iso-ir-166", "tcvn", "iso-ir-14", "iso-ir-87", "iso-ir-159"}; + + appesModeEncoding = lowerCase(appesModeEncoding); + bool valid = false; + for (size_t i = 0; i < sizeof(ENCODINGS) / sizeof(ENCODINGS[0]); i++) + if (appesModeEncoding == ENCODINGS[i]) { + valid = true; + break; + } + if (!valid) + quit(_fail, "Unexpected encoding for setAppesModeEncoding(encoding)"); + ::appesModeEncoding = appesModeEncoding; +} + void registerInteraction(int argc, char *argv[]) { __testlib_ensuresPreconditions(); __testlib_set_testset_and_group(argc, argv); @@ -4758,20 +4797,6 @@ void startTest(int test) { __testlib_fail("Unable to write file '" + testFileName + "'"); } -inline std::string upperCase(std::string s) { - for (size_t i = 0; i < s.length(); i++) - if ('a' <= s[i] && s[i] <= 'z') - s[i] = char(s[i] - 'a' + 'A'); - return s; -} - -inline std::string lowerCase(std::string s) { - for (size_t i = 0; i < s.length(); i++) - if ('A' <= s[i] && s[i] <= 'Z') - s[i] = char(s[i] - 'A' + 'a'); - return s; -} - inline std::string compress(const std::string &s) { return __testlib_part(s); }