123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
-
- #pragma once
- #include <locale>
- #include "String.DString.hpp"
- #include "String.WString.hpp"
- using namespace eSTR::Literals;
- #include "DDateTime.hpp"
- #ifndef LOCALE_EXPORTS
- #define _Localet_API _declspec(dllimport)
- #else
- #define _Localet_API _declspec(dllexport)
- #endif
- #ifndef LOCALE_EXPORTS
- #ifdef _WIN64
- #ifdef _DEBUG
- #pragma comment (lib, "ECOM.Utility.Locale64D.lib")
- #else
- #pragma comment (lib, "ECOM.Utility.Locale64.lib")
- #endif
- #else // X86
- #ifdef _DEBUG
- #pragma comment (lib, "ECOM.Utility.LocaleD.lib")
- #else
- #pragma comment (lib, "ECOM.Utility.Locale.lib")
- #endif
- #endif
- #endif // LOCALE_EXPORTS
- namespace ECOM
- {
- namespace Utility
- {
- class LocaleFormat : public ECOM::Utility::String::_string_format_detail <LocaleFormat>
- {
- _locale_t m_Locale;
- public:
- inline LocaleFormat (char * buf, int NbOfChar, _locale_t loc) : _string_format_detail (buf, NbOfChar)
- {
- m_Locale = loc;
- }
- public:
- template <typename arg>
- inline int _my_sprintf (char * buf, int NbOfChar, const char * fmt, arg a)
- {
- return _sprintf_s_l (buf, NbOfChar, fmt, m_Locale, a);
- }
- };
- //-----------------------------------------------------------------------------
- // Locale
- //-----------------------------------------------------------------------------
- class _Localet_API Locale
- {
- template <typename> static constexpr bool dependent_false = false;
- public:
- static Locale FromOS ();
- public:
- Locale (CV_String & Name);
- Locale (const eSTR::DString & Name);
- ~Locale ();
- public:
- Locale (const Locale & from) = delete;
- Locale (Locale && from);
- Locale & operator = (const Locale & from) = delete;
- Locale & operator = (Locale && from);
- public:
- template <typename... Args>
- inline eSTR::DString ToString (const char * szFormat, Args... args) const
- {
- constexpr int MaxLen = 8192;
- eSTR::DString rc;
- auto pc = rc.GetBufferSetLength (MaxLen);
- auto len = ECOM::Utility::LocaleFormat (pc, MaxLen, m_Locale).Format (szFormat, args...);
- rc.ReleaseBuffer (len);
- return std::move (rc);
- }
- public:
- enum enDateTime
- {
- enShortDate = 1,
- enLongDate = 2,
- enShortTime = 3,
- enLongTime = 4
- };
- public:
- eSTR::WString ToString (const DDateTime & dt, enDateTime type) const;
- eSTR::WString ToString (const DDateTime & dt, CV_String & fmt) const;
- public:
- template <typename T>
- static T GetFormatOf (enDateTime type)
- {
- static_assert (dependent_false <T>);
- }
- template <> static eSTR::WStringView GetFormatOf (enDateTime type);
- template <> static eSTR::DStringView GetFormatOf (enDateTime type);
- public:
- eSTR::DString GetName () const;
- _locale_t GetLocale () const;
- private:
- eSTR::DString m_LocName;
- _locale_t m_Locale;
- };
- }
- }
|