Skip to content

Commit

Permalink
Do not use date::to_stream since date might only use C locale
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Dec 4, 2023
1 parent 8577613 commit 68ea2b7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
53 changes: 53 additions & 0 deletions include/zeep/unicode-support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,59 @@ std::tuple<unicode,Iter> get_first_char(Iter ptr, Iter end)

// --------------------------------------------------------------------

/**
* @brief Return a std::wstring for the UTF-8 encoded std::string @a s.
* @note This simplistic code assumes all unicode characters will fit in a wchar_t
*
* @param s The input string
* @return std::wstring The recoded output string
*/
inline std::wstring convert_s2w(std::string_view s)
{
auto b = s.begin();
auto e = s.end();

std::wstring result;

while (b != e)
{
const auto &[uc, i] = get_first_char(b, e);
if (not uc)
break;

result += static_cast<wchar_t>(uc);
b = i;
}

return result;
}

/**
* @brief Return a std::string encoded in UTF-8 for the input std::wstring @a s.
* @note This simplistic code assumes input contains only UCS-2 characters which are deprecated, I know.
* This means UTF-16 surrogates are ruined.
*
* @param s The input string
* @return std::string The recoded output string
*/
inline std::string convert_w2s(std::wstring_view s)
{
std::string result;

for (unicode ch : s)
append(result, ch);

return result;
}

// --------------------------------------------------------------------

/**
* @brief Return a hexadecimal string representation for the numerical value in @a i
*
* @param i The value to convert
* @return std::string The hexadecimal representation
*/
inline std::string to_hex(uint32_t i)
{
char s[sizeof(i) * 2 + 3];
Expand Down
14 changes: 4 additions & 10 deletions lib-http/src/el-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,20 +1520,14 @@ class date_expr_util_object : public expression_utility_object<date_expr_util_ob

auto st = value_serializer<std::chrono::system_clock::time_point>::from_string(t);

#if __has_include(<date/date.h>)
std::ostringstream os;
os << date::format(scope.get_request().get_locale(), f, st);
#else
std::wostringstream os;
os.imbue(scope.get_request().get_locale());

std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
std::wstring time = myconv.from_bytes(f);
auto tt = std::chrono::system_clock::to_time_t(st);
auto wf = convert_s2w(f);

auto t = std::chrono::system_clock::to_time_t(st);
os << std::put_time(std::gmtime(&t), time.c_str());
#endif
result = os.str();
os << std::put_time<wchar_t>(std::gmtime(&tt), wf.c_str());
result = convert_w2s(os.str());
}
}

Expand Down

0 comments on commit 68ea2b7

Please sign in to comment.