aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/kstd/kstd/string30
1 files changed, 7 insertions, 23 deletions
diff --git a/libs/kstd/kstd/string b/libs/kstd/kstd/string
index de254a1d..682b8404 100644
--- a/libs/kstd/kstd/string
+++ b/libs/kstd/kstd/string
@@ -5,11 +5,12 @@
#include <kstd/bits/format/context.hpp>
#include <kstd/bits/format/formatter.hpp>
#include <kstd/bits/format/formatter/cstring.hpp>
+#include <kstd/bits/format/formatter/integral.hpp>
+#include <kstd/bits/format/vformat.hpp>
#include <kstd/cstring>
#include <kstd/os/error.hpp>
#include <kstd/vector>
-#include <algorithm>
#include <concepts>
namespace kstd
@@ -17,32 +18,15 @@ namespace kstd
using string = basic_string<char>;
/**
- * @brief Converts an unsigned integer to a string by converting each digit to the corresponding character and
- * concatenating them.
- * @tparam N The type of the unsigned integer to convert.
+ * @brief Converts an integer to a string as if by kstd::format("{}", value).
+ * @tparam IntegralType The type of the unsigned integer to convert.
* @param value The unsigned integer to convert.
* @return A string representation of the given unsigned integer.
*/
- template<typename N>
- requires std::unsigned_integral<N>
- [[nodiscard]] constexpr auto inline to_string(N value) -> string
+ template<std::integral IntegralType>
+ [[nodiscard]] constexpr auto inline to_string(IntegralType value) -> string
{
- if (value == 0)
- {
- return "0";
- }
-
- string result;
-
- while (value > 0)
- {
- char const digit = '0' + (value % 10);
- result.push_back(digit);
- value /= 10;
- }
-
- std::reverse(result.begin(), result.end());
- return result;
+ return kstd::format("{}", value);
}
template<>