string: add reusable C locale

This is frequently needed locale.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2023-08-22 17:16:23 +02:00
parent 4ca3ed0718
commit fe47a47e4e
2 changed files with 19 additions and 1 deletions

View File

@ -390,7 +390,7 @@ namespace stdex {
template<class _Traits = std::char_traits<char>, class _Ax = std::allocator<char>>
static std::basic_string<char, _Traits, _Ax> to_rfc822(_In_ const time_point tp)
{
return to_str(tp, "%a, %d %b %Y %H:%M:%S GMT", locale_C);
return to_str(tp, "%a, %d %b %Y %H:%M:%S GMT", locale_C.get());
}
};
}

View File

@ -8,14 +8,32 @@
#include "sal.hpp"
#include <assert.h>
#include <ctype.h>
#include <locale.h>
#include <stdarg.h>
#include <stdint.h>
#include <memory>
#include <stdexcept>
namespace stdex
{
#ifdef _WIN32
using locale_t = _locale_t;
///
/// Deleter for unique_ptr using _free_locale
///
struct free_locale_delete
{
///
/// Delete a pointer
///
void operator()(_In_ locale_t locale) const
{
_free_locale(locale);
}
};
static std::unique_ptr<__crt_locale_pointers, free_locale_delete> locale_C(_create_locale(LC_ALL, "C"));
#else
using locale_t = ::locale_t;
#endif