blob: 9978affc005d9664247cd7096e718c8a77cc6e9c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#ifndef KSTD_STRING_HPP
#define KSTD_STRING_HPP
#include <kstd/bits/basic_string.hpp> // IWYU pragma: export
#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.hpp>
#include <kstd/os/error.hpp>
#include <kstd/vector.hpp>
#include <concepts>
#include <cstddef>
namespace kstd
{
using string = basic_string<char>;
/**
* @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<std::integral IntegralType>
[[nodiscard]] constexpr auto inline to_string(IntegralType value) -> string
{
return kstd::format("{}", value);
}
template<>
struct formatter<string> : formatter<char const *>
{
auto format(string const & str, format_context & context) const -> void
{
formatter<char const *>::format(str.data(), context);
}
};
inline namespace literals
{
inline namespace string_literals
{
//! Create a string new string from a literal C-style string.
//!
//! @param string The C-style string to use as a source for the new string.
//! @param length The length of the supplied C-style string.
//! @return a new string object, containing the same value as the provided C-style string.
constexpr auto operator""_s(char const * string, std::size_t length) -> kstd::string
{
return {string, length};
}
} // namespace string_literals
} // namespace literals
} // namespace kstd
#endif
|