Skip to content

Commit

Permalink
refs #18, revert change due to VS2015 compilation issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
gulrak committed May 18, 2019
1 parent 6d173c5 commit 082e606
Showing 1 changed file with 14 additions and 37 deletions.
51 changes: 14 additions & 37 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,29 +1208,31 @@ 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();
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) {
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;
}
Expand All @@ -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)
{
Expand Down

0 comments on commit 082e606

Please sign in to comment.