From 882d843083895f4905571dc273e801ee18fd5984 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 12 Jan 2022 02:30:25 +0800 Subject: ... --- include/cru/common/String.hpp | 14 +++++++------- include/cru/common/StringUtil.hpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'include/cru/common') diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp index 8acb6a87..88dd06f0 100644 --- a/include/cru/common/String.hpp +++ b/include/cru/common/String.hpp @@ -328,16 +328,16 @@ std::enable_if_t, String> ToString(T value) { auto result = std::to_chars(buffer.data(), buffer.data() + buffer.size(), value); + if (result.ec == std::errc{}) { + } else { + throw std::invalid_argument("Failed to convert value to chars."); + } + auto size = result.ptr - buffer.data(); auto b = new char16_t[size + 1]; b[size] = 0; std::copy(buffer.data(), result.ptr, b); return String::FromBuffer(b, size, size); - - if (result.ec == std::errc{}) { - } else { - throw std::invalid_argument("Failed to convert value to chars."); - } } template @@ -346,7 +346,7 @@ std::enable_if_t, String> ToString(T value) { return String(str.cbegin(), str.cend()); } -inline String ToString(String value) { return std::move(value); } +inline String ToString(String value) { return value; } namespace details { enum class FormatTokenType { PlaceHolder, Text }; @@ -366,7 +366,7 @@ template void FormatAppendFromFormatTokenList( String& current, const std::vector& format_token_list, Index index, TA&& args0, T&&... args) { - for (Index i = index; i < format_token_list.size(); i++) { + for (Index i = index; i < static_cast(format_token_list.size()); i++) { const auto& token = format_token_list[i]; if (token.type == FormatTokenType::PlaceHolder) { current += ToString(std::forward(args0)); diff --git a/include/cru/common/StringUtil.hpp b/include/cru/common/StringUtil.hpp index a0cb6b0b..27ad4b43 100644 --- a/include/cru/common/StringUtil.hpp +++ b/include/cru/common/StringUtil.hpp @@ -49,7 +49,7 @@ class CodePointIterator { struct past_end_tag_t {}; explicit CodePointIterator(const CharType* ptr, Index size, Index current = 0) - : ptr_(ptr), size_(size), position_(0) {} + : ptr_(ptr), size_(size), position_(current) {} explicit CodePointIterator(const CharType* ptr, Index size, past_end_tag_t) : ptr_(ptr), size_(size), position_(size) {} -- cgit v1.2.3