#include <array>
#include <iostream>
#include <string>
std::string GetDateFormatString(const std::string& langCode)
{
if (
0 == langCode.compare(0, 2, "en")
|| 0 == langCode.compare(0, 2, "EN")
)
{
return std::string("%1$i/%2$i/%3$i");
}
else if (
0 == langCode.compare(0, 2, "fr")
|| 0 == langCode.compare(0, 2, "FR")
)
{
return std::string("%2$i/%1$i/%3$i");
}
else if (
0 == langCode.compare(0, 2, "ja")
|| 0 == langCode.compare(0, 2, "JA")
|| 0 == langCode.compare(0, 2, "jp")
|| 0 == langCode.compare(0, 2, "JP")
)
{
return std::string("%3$i/%2$i/%1$i");
}
return std::string("%1$i/%2$i/%3$i");
}
#if defined(_WIN32)
# define sprintfp _sprintf_p
#else
# define sprintfp snprintf
#endif
std::string GetDateString(
const std::string &langCode,
int month, int day, int year)
{
std::string fmt = GetDateFormatString(langCode);
std::array<char, 32> buffer;
buffer.fill(0);
sprintfp(buffer.data(), 32, fmt.c_str(), month, day, year);
std::string ret = buffer.data();
return ret;
}
int main()
{
std::cout << GetDateString("en", 11, 7, 2018) << "\n";
return 0;
}
I2luY2x1ZGUgPGFycmF5PgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiAKc3RkOjpzdHJpbmcgR2V0RGF0ZUZvcm1hdFN0cmluZyhjb25zdCBzdGQ6OnN0cmluZyYgbGFuZ0NvZGUpCnsKICAgIGlmICgKICAgICAgIDAgPT0gbGFuZ0NvZGUuY29tcGFyZSgwLCAyLCAiZW4iKQogICAgICAgfHwgMCA9PSBsYW5nQ29kZS5jb21wYXJlKDAsIDIsICJFTiIpCiAgICAgICApCiAgICB7CiAgICAgICAgcmV0dXJuIHN0ZDo6c3RyaW5nKCIlMSRpLyUyJGkvJTMkaSIpOwogICAgfQogICAgZWxzZSBpZiAoCiAgICAgICAwID09IGxhbmdDb2RlLmNvbXBhcmUoMCwgMiwgImZyIikKICAgICAgIHx8IDAgPT0gbGFuZ0NvZGUuY29tcGFyZSgwLCAyLCAiRl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