-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom boost::locale::numpunct
- Loading branch information
1 parent
5789ae2
commit 348b7a8
Showing
5 changed files
with
162 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// Copyright (c) 2021-2021 Salvo Miosi | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See | ||
// accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
|
||
#ifndef BOOST_LOCALE_NUMPUNCT_HPP_INCLUDED | ||
#define BOOST_LOCALE_NUMPUNCT_HPP_INCLUDED | ||
#include <boost/locale/config.hpp> | ||
#ifdef BOOST_MSVC | ||
# pragma warning(push) | ||
# pragma warning(disable : 4275 4251 4231 4660) | ||
#endif | ||
#include <locale> | ||
#include <string> | ||
|
||
namespace boost { | ||
namespace locale { | ||
|
||
template<typename CharType> | ||
class BOOST_LOCALE_DECL numpunct_base : public std::numpunct<CharType> | ||
{ | ||
typedef std::basic_string<CharType> string_type; | ||
public: | ||
numpunct_base(size_t refs = 0) : std::numpunct<CharType>(refs) {} | ||
|
||
string_type decimal_point_full() const { | ||
return do_decimal_point_full(); | ||
} | ||
|
||
string_type thousands_sep_full() const { | ||
return do_thousands_sep_full(); | ||
} | ||
|
||
protected: | ||
virtual CharType do_decimal_point() const { | ||
string_type dec = do_decimal_point_full(); | ||
if (dec.size() > 1) { | ||
return '.'; | ||
} else { | ||
return dec[0]; | ||
} | ||
} | ||
|
||
virtual string_type do_decimal_point_full() const { | ||
static const char t[] = "."; | ||
return string_type(t, t + sizeof(t) - 1); | ||
} | ||
|
||
virtual CharType do_thousands_sep() const { | ||
string_type thous = do_thousands_sep_full(); | ||
if (thous.size() > 1) { | ||
return ','; | ||
} else { | ||
return thous[0]; | ||
} | ||
} | ||
|
||
virtual string_type do_thousands_sep_full() const { | ||
static const char t[] = ","; | ||
return string_type(t, t + sizeof(t) - 1); | ||
} | ||
|
||
virtual string_type do_truename() const { | ||
static const char t[] = "true"; | ||
return string_type(t, t + sizeof(t) - 1); | ||
} | ||
|
||
virtual string_type do_falsename() const { | ||
static const char t[] = "false"; | ||
return string_type(t, t + sizeof(t) - 1); | ||
} | ||
}; | ||
|
||
template<typename CharType> struct numpunct {}; | ||
|
||
template<> struct numpunct<char> : numpunct_base<char> { | ||
numpunct (size_t refs = 0) : numpunct_base<char>(refs) {} | ||
}; | ||
|
||
template<> struct numpunct<wchar_t> : numpunct_base<wchar_t> { | ||
numpunct (size_t refs = 0) : numpunct_base<wchar_t>(refs) {} | ||
}; | ||
|
||
#ifdef BOOST_LOCALE_ENABLE_CHAR16_T | ||
template<> struct numpunct<char16_t> : numpunct_base<char16_t> { | ||
numpunct (size_t refs = 0) : numpunct_base<char16_t>(refs) {} | ||
}; | ||
#endif | ||
#ifdef BOOST_LOCALE_ENABLE_CHAR32_T | ||
template<> struct numpunct<char32_t> : numpunct_base<char32_t> { | ||
numpunct (size_t refs = 0) : numpunct_base<char32_t>(refs) {} | ||
}; | ||
#endif | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters