From 5029751569afb9a99c0b13db7bd2a665220225e7 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sat, 3 Feb 2018 10:26:17 -0500 Subject: [PATCH] add inline, make string_view arrays const, and make sure the templated conversion routines use template on it --- sol/stack_get.hpp | 7 ++++--- sol/unicode.hpp | 28 ++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/sol/stack_get.hpp b/sol/stack_get.hpp index 6693bc01..439f4fb7 100644 --- a/sol/stack_get.hpp +++ b/sol/stack_get.hpp @@ -454,13 +454,14 @@ namespace stack { template struct getter> { - static std::basic_string get(lua_State* L, int index, record& tracking) { + typedef std::basic_string S; + static S get(lua_State* L, int index, record& tracking) { typedef std::conditional_t Ch; - typedef std::allocator_traits::rebind_alloc ChAl; + typedef typename std::allocator_traits::template rebind_alloc ChAl; typedef std::char_traits ChTraits; getter> g; (void)g; - return g.get_into>(L, index, tracking); + return g.template get_into(L, index, tracking); } }; diff --git a/sol/unicode.hpp b/sol/unicode.hpp index 1a73a4ee..1c7f673c 100644 --- a/sol/unicode.hpp +++ b/sol/unicode.hpp @@ -2,6 +2,7 @@ #include "string_view.hpp" #include +#include namespace sol { // Everything here was lifted pretty much straight out of @@ -18,7 +19,7 @@ namespace sol { }; inline const string_view& to_string(error_code ec) { - const string_view arr[4] = { + static const string_view arr[4] = { "ok", "invalid code points", "invalid code unit", @@ -172,9 +173,14 @@ namespace sol { } template - inline decoded_result utf8_to_code_point(It it, It) { + inline decoded_result utf8_to_code_point(It it, It last) { decoded_result dr; - + if (it == last) { + dr.next = it; + dr.error = error_code::sequence_too_short; + return dr; + } + unsigned char b0 = *it; std::size_t length = unicode_detail::sequence_length(b0); @@ -200,7 +206,7 @@ namespace sol { ++it; std::array b; b[0] = b0; - for (int i = 1; i < length; ++i) { + for (std::size_t i = 1; i < length; ++i) { b[i] = *it; if (!is_continuation(b[i])) { dr.error = error_code::invalid_code_unit; @@ -245,8 +251,13 @@ namespace sol { } template - inline decoded_result utf16_to_code_point(It it, It) { + inline decoded_result utf16_to_code_point(It it, It last) { decoded_result dr; + if (it == last) { + dr.next = it; + dr.error = error_code::sequence_too_short; + return dr; + } char16_t lead = static_cast(*it); @@ -278,8 +289,13 @@ namespace sol { } template - inline decoded_result utf32_to_code_point(It it, It) { + inline decoded_result utf32_to_code_point(It it, It last) { decoded_result dr; + if (it == last) { + dr.next = it; + dr.error = error_code::sequence_too_short; + return dr; + } dr.codepoint = static_cast(*it); dr.next = ++it; dr.error = error_code::ok;