aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/include
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-04-13 14:56:39 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-04-13 14:56:39 +0200
commit45091789eb9e49856ea6c2f3606639d43f4584e7 (patch)
treef7e920f27be2616eca77d8337dbabddd52e852e9 /libs/kstd/include
parent98fc294deb6f7c27eda3f9ed3b616572a1ab2009 (diff)
downloadteachos-45091789eb9e49856ea6c2f3606639d43f4584e7.tar.xz
teachos-45091789eb9e49856ea6c2f3606639d43f4584e7.zip
kstd: move formatting implementation to kstd
Diffstat (limited to 'libs/kstd/include')
-rw-r--r--libs/kstd/include/kstd/bits/format/context.hpp5
-rw-r--r--libs/kstd/include/kstd/bits/format/formatter/bool.hpp4
-rw-r--r--libs/kstd/include/kstd/bits/format/formatter/integral.hpp4
-rw-r--r--libs/kstd/include/kstd/bits/format/specifiers.hpp6
-rw-r--r--libs/kstd/include/kstd/bits/format/vformat.hpp2
-rw-r--r--libs/kstd/include/kstd/vector2
6 files changed, 15 insertions, 8 deletions
diff --git a/libs/kstd/include/kstd/bits/format/context.hpp b/libs/kstd/include/kstd/bits/format/context.hpp
index e8d0302..7f392a0 100644
--- a/libs/kstd/include/kstd/bits/format/context.hpp
+++ b/libs/kstd/include/kstd/bits/format/context.hpp
@@ -33,6 +33,11 @@ namespace kstd
using format_args = std::span<format_arg const>;
format_args args{};
+ format_context(bits::format::output_buffer & buffer, format_args args)
+ : args{args}
+ , m_buffer{&buffer}
+ {}
+
[[nodiscard]] auto arg(std::size_t const id) const -> format_arg const &
{
if (id >= args.size())
diff --git a/libs/kstd/include/kstd/bits/format/formatter/bool.hpp b/libs/kstd/include/kstd/bits/format/formatter/bool.hpp
index 336e1b0..e371cec 100644
--- a/libs/kstd/include/kstd/bits/format/formatter/bool.hpp
+++ b/libs/kstd/include/kstd/bits/format/formatter/bool.hpp
@@ -51,11 +51,11 @@ namespace kstd
auto const text = value ? std::string_view{"true"} : std::string_view{"false"};
auto final_width = 0uz;
- if (specifiers.width_mode == bits::format::width_mode::static_value)
+ if (specifiers.mode == bits::format::width_mode::static_value)
{
final_width = specifiers.width_value;
}
- else if (specifiers.width_mode == bits::format::width_mode::dynamic_argument_id)
+ else if (specifiers.mode == bits::format::width_mode::dynamic_argument_id)
{
auto const & arg = context.arg(specifiers.width_value);
final_width = bits::format::extrat_dynamic_width(arg);
diff --git a/libs/kstd/include/kstd/bits/format/formatter/integral.hpp b/libs/kstd/include/kstd/bits/format/formatter/integral.hpp
index 4912a44..e5a234a 100644
--- a/libs/kstd/include/kstd/bits/format/formatter/integral.hpp
+++ b/libs/kstd/include/kstd/bits/format/formatter/integral.hpp
@@ -64,11 +64,11 @@ namespace kstd
auto format(T value, format_context & context) const -> void
{
auto final_width = 0uz;
- if (specifiers.width_mode == bits::format::width_mode::static_value)
+ if (specifiers.mode == bits::format::width_mode::static_value)
{
final_width = specifiers.width_value;
}
- else if (specifiers.width_mode == bits::format::width_mode::dynamic_argument_id)
+ else if (specifiers.mode == bits::format::width_mode::dynamic_argument_id)
{
auto const & arg = context.arg(specifiers.width_value);
final_width = bits::format::extrat_dynamic_width(arg);
diff --git a/libs/kstd/include/kstd/bits/format/specifiers.hpp b/libs/kstd/include/kstd/bits/format/specifiers.hpp
index 9bc66c7..18c6f66 100644
--- a/libs/kstd/include/kstd/bits/format/specifiers.hpp
+++ b/libs/kstd/include/kstd/bits/format/specifiers.hpp
@@ -43,7 +43,7 @@ namespace kstd::bits::format
bool alternative_form{};
bool zero_pad{};
- width_mode width_mode{};
+ width_mode mode{};
std::size_t width_value{};
char type{};
};
@@ -133,7 +133,7 @@ namespace kstd::bits::format
if (it != end && *it == '{')
{
- specs.width_mode = width_mode::dynamic_argument_id;
+ specs.mode = width_mode::dynamic_argument_id;
std::advance(it, 1);
auto argument_id = 0uz;
@@ -160,7 +160,7 @@ namespace kstd::bits::format
}
else if (it != end && *it >= '0' && *it <= '9')
{
- specs.width_mode = width_mode::static_value;
+ specs.mode = width_mode::static_value;
while (it != end && *it >= '0' && *it <= '9')
{
specs.width_value = specs.width_value * 10 + static_cast<std::size_t>(*it - '0');
diff --git a/libs/kstd/include/kstd/bits/format/vformat.hpp b/libs/kstd/include/kstd/bits/format/vformat.hpp
index 90b74a9..d032c3a 100644
--- a/libs/kstd/include/kstd/bits/format/vformat.hpp
+++ b/libs/kstd/include/kstd/bits/format/vformat.hpp
@@ -38,6 +38,8 @@ namespace kstd
struct string_iterator_writer : output_buffer
{
+ explicit string_iterator_writer(string::iterator iterator);
+
auto push(std::string_view text) -> void override;
auto push(char character) -> void override;
diff --git a/libs/kstd/include/kstd/vector b/libs/kstd/include/kstd/vector
index e51cbac..79593c6 100644
--- a/libs/kstd/include/kstd/vector
+++ b/libs/kstd/include/kstd/vector
@@ -111,7 +111,7 @@ namespace kstd
allocator_type const & allocator =
allocator_type{}) noexcept(std::is_nothrow_copy_constructible_v<allocator_type>)
: m_allocator{allocator}
- , m_size{std::ranges::distance(first, last)}
+ , m_size{static_cast<std::size_t>(std::ranges::distance(first, last))}
, m_capacity{m_size}
, m_data{allocate_n(m_capacity)}
{