add inline, make string_view arrays const, and make sure the templated conversion routines use template on it

This commit is contained in:
ThePhD 2018-02-03 10:26:17 -05:00
parent f48ba8b101
commit 5029751569
2 changed files with 26 additions and 9 deletions

View File

@ -454,13 +454,14 @@ namespace stack {
template <typename Traits, typename Al> template <typename Traits, typename Al>
struct getter<std::basic_string<wchar_t, Traits, Al>> { struct getter<std::basic_string<wchar_t, Traits, Al>> {
static std::basic_string<wchar_t, Traits, Al> get(lua_State* L, int index, record& tracking) { typedef std::basic_string<wchar_t, Traits, Al> S;
static S get(lua_State* L, int index, record& tracking) {
typedef std::conditional_t<sizeof(wchar_t) == 2, char16_t, char32_t> Ch; typedef std::conditional_t<sizeof(wchar_t) == 2, char16_t, char32_t> Ch;
typedef std::allocator_traits<Al>::rebind_alloc<Ch> ChAl; typedef typename std::allocator_traits<Al>::template rebind_alloc<Ch> ChAl;
typedef std::char_traits<Ch> ChTraits; typedef std::char_traits<Ch> ChTraits;
getter<std::basic_string<Ch, ChTraits, ChAl>> g; getter<std::basic_string<Ch, ChTraits, ChAl>> g;
(void)g; (void)g;
return g.get_into<std::basic_string<wchar_t, Traits, Al>>(L, index, tracking); return g.template get_into<S>(L, index, tracking);
} }
}; };

View File

@ -2,6 +2,7 @@
#include "string_view.hpp" #include "string_view.hpp"
#include <array> #include <array>
#include <cstring>
namespace sol { namespace sol {
// Everything here was lifted pretty much straight out of // Everything here was lifted pretty much straight out of
@ -18,7 +19,7 @@ namespace sol {
}; };
inline const string_view& to_string(error_code ec) { inline const string_view& to_string(error_code ec) {
const string_view arr[4] = { static const string_view arr[4] = {
"ok", "ok",
"invalid code points", "invalid code points",
"invalid code unit", "invalid code unit",
@ -172,8 +173,13 @@ namespace sol {
} }
template <typename It> template <typename It>
inline decoded_result<It> utf8_to_code_point(It it, It) { inline decoded_result<It> utf8_to_code_point(It it, It last) {
decoded_result<It> dr; decoded_result<It> dr;
if (it == last) {
dr.next = it;
dr.error = error_code::sequence_too_short;
return dr;
}
unsigned char b0 = *it; unsigned char b0 = *it;
std::size_t length = unicode_detail::sequence_length(b0); std::size_t length = unicode_detail::sequence_length(b0);
@ -200,7 +206,7 @@ namespace sol {
++it; ++it;
std::array<unsigned char, 4> b; std::array<unsigned char, 4> b;
b[0] = b0; b[0] = b0;
for (int i = 1; i < length; ++i) { for (std::size_t i = 1; i < length; ++i) {
b[i] = *it; b[i] = *it;
if (!is_continuation(b[i])) { if (!is_continuation(b[i])) {
dr.error = error_code::invalid_code_unit; dr.error = error_code::invalid_code_unit;
@ -245,8 +251,13 @@ namespace sol {
} }
template <typename It> template <typename It>
inline decoded_result<It> utf16_to_code_point(It it, It) { inline decoded_result<It> utf16_to_code_point(It it, It last) {
decoded_result<It> dr; decoded_result<It> dr;
if (it == last) {
dr.next = it;
dr.error = error_code::sequence_too_short;
return dr;
}
char16_t lead = static_cast<char16_t>(*it); char16_t lead = static_cast<char16_t>(*it);
@ -278,8 +289,13 @@ namespace sol {
} }
template <typename It> template <typename It>
inline decoded_result<It> utf32_to_code_point(It it, It) { inline decoded_result<It> utf32_to_code_point(It it, It last) {
decoded_result<It> dr; decoded_result<It> dr;
if (it == last) {
dr.next = it;
dr.error = error_code::sequence_too_short;
return dr;
}
dr.codepoint = static_cast<char32_t>(*it); dr.codepoint = static_cast<char32_t>(*it);
dr.next = ++it; dr.next = ++it;
dr.error = error_code::ok; dr.error = error_code::ok;