From 8d1585f065c9b7e8e329339063201ca22901aff5 Mon Sep 17 00:00:00 2001 From: Antonio Borondo Date: Wed, 3 Oct 2018 11:44:02 +0100 Subject: [PATCH] Change implementation to use templates --- .../nlohmann/detail/input/input_adapters.hpp | 20 +++++++++---------- single_include/nlohmann/json.hpp | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 40560ca16..f8155faa9 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -126,7 +126,7 @@ class wide_string_input_adapter : public input_adapter_protocol // check if buffer needs to be filled if (utf8_bytes_index == utf8_bytes_filled) { - fill_buffer(sizeof(typename WideStringType::value_type)); + fill_buffer(); assert(utf8_bytes_filled > 0); assert(utf8_bytes_index == 0); @@ -139,16 +139,16 @@ class wide_string_input_adapter : public input_adapter_protocol } private: - void fill_buffer(size_t size) + template + void fill_buffer() { - if (2 == size) - { - fill_buffer_utf16(); - } - else - { - fill_buffer_utf32(); - } + fill_buffer_utf32(); + } + + template<> + void fill_buffer<2>() + { + fill_buffer_utf16(); } void fill_buffer_utf16() diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 7af55b3a6..c19ee6c9e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2004,7 +2004,7 @@ class wide_string_input_adapter : public input_adapter_protocol // check if buffer needs to be filled if (utf8_bytes_index == utf8_bytes_filled) { - fill_buffer(sizeof(typename WideStringType::value_type)); + fill_buffer(); assert(utf8_bytes_filled > 0); assert(utf8_bytes_index == 0); @@ -2017,18 +2017,18 @@ class wide_string_input_adapter : public input_adapter_protocol } private: - void fill_buffer(size_t size) + template + void fill_buffer() { - if (2 == size) - { - fill_buffer_utf16(); - } - else - { - fill_buffer_utf32(); - } + fill_buffer_utf32(); } + template<> + void fill_buffer<2>() + { + fill_buffer_utf16(); + } + void fill_buffer_utf16() { utf8_bytes_index = 0;