Remove C++14 auto return type on utf8_to_utf32

- Also remove static instance of std::wstring_convert. Access to
  std::wstring_convert<>::{from,to}_bytes() is not guaranteed to be thread
  safe.
This commit is contained in:
Jan Martin Mikkelsen 2017-06-10 18:46:46 +10:00
parent e0301636f0
commit 2d011c8e3a
1 changed files with 9 additions and 7 deletions

View File

@ -11,9 +11,11 @@ namespace antlrcpp {
// For all conversions utf8 <-> utf32.
// VS 2015 and VS 2017 have different bugs in std::codecvt_utf8<char32_t> (VS 2013 works fine).
#if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
static std::wstring_convert<std::codecvt_utf8<__int32>, __int32> utfConverter;
using UtfConverterType = std::wstring_convert<std::codecvt_utf8<__int32>, __int32>;
using UtfConverterWide = std::u32string;
#else
static std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utfConverter;
using UtfConverterType = std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t>;
using UtfConverterWide = std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t>::wide_string;
#endif
//the conversion functions fails in VS2017, so we explicitly use a workaround
@ -22,20 +24,20 @@ namespace antlrcpp {
{
#if defined(_MSC_VER) && _MSC_VER > 1900 && _MSC_VER < 2000
auto p = reinterpret_cast<const int32_t *>(_data.data());
return antlrcpp::utfConverter.to_bytes(p, p + _data.size());
return UtfConverterType().to_bytes(p, p + _data.size());
#else
return antlrcpp::utfConverter.to_bytes(_data);
return UtfConverterType().to_bytes(_data);
#endif
}
inline auto utf8_to_utf32(const char* first, const char* last)
inline UtfConverterWide utf8_to_utf32(const char* first, const char* last)
{
#if defined(_MSC_VER) && _MSC_VER > 1900 && _MSC_VER < 2000
auto r = antlrcpp::utfConverter.from_bytes(first, last);
auto r = UtfConverterType().from_bytes(first, last);
std::u32string s = reinterpret_cast<const char32_t *>(r.data());
return s;
#else
return antlrcpp::utfConverter.from_bytes(first, last);
return UtfConverterType().from_bytes(first, last);
#endif
}