#include <iostream>
#include <string>
#include <boost/format.hpp>
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");
}
std::string GetDateStringBoost(
const std::string &langCode, int month, int day, int year)
{
std::string fmt = GetDateFormatString(langCode);
std::string ret = boost::str(boost::format(fmt) % month % day % year);
return ret;
}
int main()
{
std::cout << GetDateStringBoost("en", 11, 7, 2018) << "\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Ym9vc3QvZm9ybWF0LmhwcD4KIApzdGQ6OnN0cmluZyBHZXREYXRlRm9ybWF0U3RyaW5nKGNvbnN0IHN0ZDo6c3RyaW5nJiBsYW5nQ29kZSkKewogICAgaWYgKAogICAgICAgMCA9PSBsYW5nQ29kZS5jb21wYXJlKDAsIDIsICJlbiIpCiAgICAgICB8fCAwID09IGxhbmdDb2RlLmNvbXBhcmUoMCwgMiwgIkVOIikKICAgICAgICkKICAgIHsKICAgICAgICByZXR1cm4gc3RkOjpzdHJpbmcoIiUxJGkvJTIkaS8lMyRpIik7CiAgICB9CiAgICBlbHNlIGlmICgKICAgICAgIDAgPT0gbGFuZ0NvZGUuY29tcGFyZSgwLCAyLCAiZnIiKQogICAgICAgfHwgMCA9PSBsYW5nQ29kZS5jb21wYXJlKDAsIDIsICJGUiIpCiAgICAgICApCiAgICB7CiAgICAgICAgcmV0dXJuIHN0ZDo6c3RyaW5nKCIlMiRpLy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