From 1a52006c3d215196997a2cd12450795d4ae4a1ca Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 9 Aug 2024 18:16:51 +1000 Subject: Extract format implementation to its own file Split it to avoid pulling all string_utils dependencies for just format. --- src/string_utils.hh | 72 ++--------------------------------------------------- 1 file changed, 2 insertions(+), 70 deletions(-) (limited to 'src/string_utils.hh') diff --git a/src/string_utils.hh b/src/string_utils.hh index 3034dfd5..24da0111 100644 --- a/src/string_utils.hh +++ b/src/string_utils.hh @@ -4,9 +4,10 @@ #include "string.hh" #include "enum.hh" #include "vector.hh" -#include "ranges.hh" #include "optional.hh" #include "utils.hh" +#include "format.hh" +#include "ranges.hh" namespace Kakoune { @@ -107,75 +108,6 @@ inline auto wrap_at(ColumnCount max_width) int str_to_int(StringView str); // throws on error Optional str_to_int_ifp(StringView str); -template -struct InplaceString -{ - static_assert(N < 256, "InplaceString cannot handle sizes >= 256"); - - constexpr operator StringView() const { return {m_data, ByteCount{m_length}}; } - operator String() const { return {m_data, ByteCount{m_length}}; } - - unsigned char m_length{}; - char m_data[N]; -}; - -struct Hex { size_t val; }; -constexpr Hex hex(size_t val) { return {val}; } - -struct Grouped { size_t val; }; -constexpr Grouped grouped(size_t val) { return {val}; } - -InplaceString<15> to_string(int val); -InplaceString<15> to_string(unsigned val); -InplaceString<23> to_string(long int val); -InplaceString<23> to_string(unsigned long val); -InplaceString<23> to_string(long long int val); -InplaceString<23> to_string(Hex val); -InplaceString<23> to_string(Grouped val); -InplaceString<23> to_string(float val); -InplaceString<7> to_string(Codepoint c); - -template -decltype(auto) to_string(const StronglyTypedNumber& val) -{ - return to_string((ValueType)val); -} - -namespace detail -{ - -template requires std::is_convertible_v -StringView format_param(const T& val) { return val; } - -template requires (not std::is_convertible_v) -decltype(auto) format_param(const T& val) { return to_string(val); } - -} - -String format(StringView fmt, ArrayView params); - -template -String format(StringView fmt, Types&&... params) -{ - return format(fmt, ArrayView{detail::format_param(std::forward(params))...}); -} - -StringView format_to(ArrayView buffer, StringView fmt, ArrayView params); - -template -StringView format_to(ArrayView buffer, StringView fmt, Types&&... params) -{ - return format_to(buffer, fmt, ArrayView{detail::format_param(std::forward(params))...}); -} - -void format_with(FunctionRef append, StringView fmt, ArrayView params); - -template -void format_with(FunctionRef append, StringView fmt, Types&&... params) -{ - return format_with(append, fmt, ArrayView{detail::format_param(std::forward(params))...}); -} - String double_up(StringView s, StringView characters); inline String quote(StringView s) -- cgit v1.2.3 From b804693630f61be757413e6e5a700995be1b164b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 12 Aug 2024 22:42:43 +1000 Subject: Remove unused wrap_to and reduce string_utils headers --- src/string_utils.hh | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'src/string_utils.hh') diff --git a/src/string_utils.hh b/src/string_utils.hh index 24da0111..7c115269 100644 --- a/src/string_utils.hh +++ b/src/string_utils.hh @@ -7,7 +7,7 @@ #include "optional.hh" #include "utils.hh" #include "format.hh" -#include "ranges.hh" +#include "constexpr_utils.hh" namespace Kakoune { @@ -67,44 +67,6 @@ bool subsequence_match(StringView str, StringView subseq); String expand_tabs(StringView line, ColumnCount tabstop, ColumnCount col = 0); -struct WrapView -{ - struct Iterator - { - using difference_type = ptrdiff_t; - using value_type = StringView; - using pointer = StringView*; - using reference = StringView&; - using iterator_category = std::forward_iterator_tag; - - Iterator(StringView text, ColumnCount max_width); - - Iterator& operator++(); - Iterator operator++(int) { auto copy = *this; ++(*this); return copy; } - - bool operator==(Iterator other) const { return m_remaining == other.m_remaining and m_current == other.m_current; } - StringView operator*() { return m_current; } - - private: - StringView m_current; - StringView m_remaining; - ColumnCount m_max_width; - }; - - Iterator begin() const { return {text, max_width}; } - Iterator end() const { return {{}, 1}; } - - StringView text; - ColumnCount max_width; -}; - -inline auto wrap_at(ColumnCount max_width) -{ - return ViewFactory{[=](StringView text) { - return WrapView{text, max_width}; - }}; -} - int str_to_int(StringView str); // throws on error Optional str_to_int_ifp(StringView str); -- cgit v1.2.3 From 65ac5d42c9209c4b89c590c93cfa8d985e66b168 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 15 Aug 2024 11:41:35 +1000 Subject: Remove unused ConstexprVector and rename constexpr_utils.hh to array.hh --- src/string_utils.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/string_utils.hh') diff --git a/src/string_utils.hh b/src/string_utils.hh index 7c115269..559a6867 100644 --- a/src/string_utils.hh +++ b/src/string_utils.hh @@ -7,7 +7,7 @@ #include "optional.hh" #include "utils.hh" #include "format.hh" -#include "constexpr_utils.hh" +#include "array.hh" namespace Kakoune { -- cgit v1.2.3 From 64ed046e5a841520506e1954ff0bd756ea112d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Fri, 16 Aug 2024 08:49:19 +0900 Subject: include headers cleanup --- src/string_utils.hh | 1 - 1 file changed, 1 deletion(-) (limited to 'src/string_utils.hh') diff --git a/src/string_utils.hh b/src/string_utils.hh index 24da0111..105c22f8 100644 --- a/src/string_utils.hh +++ b/src/string_utils.hh @@ -5,7 +5,6 @@ #include "enum.hh" #include "vector.hh" #include "optional.hh" -#include "utils.hh" #include "format.hh" #include "ranges.hh" -- cgit v1.2.3