mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-04 11:13:58 +08:00
refs #18, revert change due to VS2015 compilation issues.
This commit is contained in:
parent
6d173c50a9
commit
082e606591
@ -1208,15 +1208,12 @@ GHC_INLINE unsigned consumeUtf8Fragment(const unsigned state, const uint8_t frag
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <class StringType, typename std::enable_if<(sizeof(typename StringType::value_type) == 1)>::type* = nullptr>
|
||||
inline StringType fromUtf8(const std::string& utf8String, const typename StringType::allocator_type& alloc = typename StringType::allocator_type())
|
||||
{
|
||||
return StringType(utf8String.begin(), utf8String.end(), alloc);
|
||||
}
|
||||
|
||||
template <class StringType, typename std::enable_if<(sizeof(typename StringType::value_type) == 2)>::type* = nullptr>
|
||||
template <class StringType>
|
||||
inline StringType fromUtf8(const std::string& utf8String, const typename StringType::allocator_type& alloc = typename StringType::allocator_type())
|
||||
{
|
||||
if (sizeof(typename StringType::value_type) == 1) {
|
||||
return StringType(utf8String.begin(), utf8String.end(), alloc);
|
||||
}
|
||||
StringType result(alloc);
|
||||
result.reserve(utf8String.length());
|
||||
std::string::const_iterator iter = utf8String.begin();
|
||||
@ -1224,13 +1221,18 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT
|
||||
std::uint32_t codepoint = 0;
|
||||
while (iter < utf8String.end()) {
|
||||
if ((utf8_state = consumeUtf8Fragment(utf8_state, (uint8_t)*iter++, codepoint)) == S_STRT) {
|
||||
if (codepoint <= 0xffff) {
|
||||
result += (typename StringType::value_type)codepoint;
|
||||
if (sizeof(typename StringType::value_type) == 4) {
|
||||
result += codepoint;
|
||||
}
|
||||
else {
|
||||
codepoint -= 0x10000;
|
||||
result += (typename StringType::value_type)((codepoint >> 10) + 0xd800);
|
||||
result += (typename StringType::value_type)((codepoint & 0x3ff) + 0xdc00);
|
||||
if (codepoint <= 0xffff) {
|
||||
result += (typename StringType::value_type)codepoint;
|
||||
}
|
||||
else {
|
||||
codepoint -= 0x10000;
|
||||
result += (typename StringType::value_type)((codepoint >> 10) + 0xd800);
|
||||
result += (typename StringType::value_type)((codepoint & 0x3ff) + 0xdc00);
|
||||
}
|
||||
}
|
||||
codepoint = 0;
|
||||
}
|
||||
@ -1246,31 +1248,6 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class StringType, typename std::enable_if<(sizeof(typename StringType::value_type) == 4)>::type* = nullptr>
|
||||
inline StringType fromUtf8(const std::string& utf8String, const typename StringType::allocator_type& alloc = typename StringType::allocator_type())
|
||||
{
|
||||
StringType result(alloc);
|
||||
result.reserve(utf8String.length());
|
||||
std::string::const_iterator iter = utf8String.begin();
|
||||
unsigned utf8_state = S_STRT;
|
||||
std::uint32_t codepoint = 0;
|
||||
while (iter < utf8String.end()) {
|
||||
if ((utf8_state = consumeUtf8Fragment(utf8_state, (uint8_t)*iter++, codepoint)) == S_STRT) {
|
||||
result += codepoint;
|
||||
codepoint = 0;
|
||||
}
|
||||
else if (utf8_state == S_RJCT) {
|
||||
result += (typename StringType::value_type)0xfffd;
|
||||
utf8_state = S_STRT;
|
||||
codepoint = 0;
|
||||
}
|
||||
}
|
||||
if (utf8_state) {
|
||||
result += (typename StringType::value_type)0xfffd;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 1)>::type* = nullptr>
|
||||
inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicodeString)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user