xtd 1.0.0
Loading...
Searching...
No Matches
string.hpp
Go to the documentation of this file.
1
4#pragma once
5#define __XTD_CORE_INTERNAL__
7#undef __XTD_CORE_INTERNAL__
8#include "basic_string.hpp"
9#include "character.hpp"
10#include "index.hpp"
11#include "stringable.hpp"
14#include "linq/enumerable_.hpp"
15
17namespace xtd {
27 using string = xtd::basic_string<char>;
28
39 using ustring [[deprecated("Replaced by xtd::string - Will be removed in version 1.2.0.")]] = xtd::string;
40
44 [[nodiscard]] auto to_string(int val) -> xtd::string;
48 [[nodiscard]] auto to_string(unsigned val) -> xtd::string;
52 [[nodiscard]] auto to_string(long val) -> xtd::string;
56 [[nodiscard]] auto to_string(unsigned long val) -> xtd::string;
60 [[nodiscard]] auto to_string(long long val) -> xtd::string;
64 [[nodiscard]] auto to_string(unsigned long long val) -> xtd::string;
68 [[nodiscard]] auto to_string(float val) -> xtd::string;
72 [[nodiscard]] auto to_string(double val) -> xtd::string;
76 [[nodiscard]] auto to_string(long double val) -> xtd::string;
80 template<typename type_t>
81 [[nodiscard]] inline auto to_string(type_t val) -> xtd::string {
82 return string::format("{}", val);
83 }
84
89 template<typename type_t>
90 [[deprecated("Replaced by xtd::to_string - Will be removed in version 1.2.0.")]]
91 [[nodiscard]] inline auto to_ustring(type_t val) -> xtd::string {
92 return to_string(val);
93 }
94
96 namespace collections {
97 namespace generic {
98 template<typename type_t>
99 auto enumerable_generator<type_t>::to_string() const -> xtd::string {
100 auto result = xtd::string {"["};
101 for (auto item : self_)
102 result += xtd::string::format("{}{}", result != "[" ? ", " : "", item);
103 return result + "]";
104 }
105 }
106 }
107 template<typename char_t, typename other_t>
108 requires (xtd::stringable<other_t> && !xtd::textual<other_t> && !xtd::character<other_t>)
109 auto operator +=(xtd::basic_string<char_t>& first, const other_t& second) -> xtd::basic_string<char_t>& {
110 first += xtd::string::format("{}", second);
111 return first;
112 }
113
114 template<typename char_t, typename other_t>
115 requires (xtd::stringable<other_t> && !xtd::textual<other_t> && !xtd::character<other_t>)
116 auto operator +(const xtd::basic_string<char_t>& first, const other_t& second) -> xtd::basic_string<char_t> {
117 return xtd::string::format("{}{}", first, second);
118 }
119
120 template<typename char_t, typename other_t>
121 requires (xtd::stringable<other_t> && !xtd::textual<other_t> && !xtd::character<other_t>)
122 auto operator +(const char_t* first, const other_t& second) -> xtd::basic_string<char_t> {
123 return xtd::string::format("{}{}", first, second);
124 }
125
126 template<typename char_t, typename other_t>
127 requires (xtd::stringable<other_t> && !xtd::textual<other_t> && !xtd::character<other_t>)
128 auto operator +(const other_t& first, const xtd::basic_string<char_t>& second) -> xtd::basic_string<char_t> {
129 return xtd::string::format("{}{}", first, second);
130 }
131
132 template<typename char_t, typename other_t>
133 requires (xtd::stringable<other_t> && !xtd::textual<other_t> && !xtd::character<other_t>)
134 auto operator +(const other_t& first, const char_t* second) -> xtd::basic_string<char_t> {
135 return xtd::string::format("{}{}", first, second);
136 }
138}
139
141template<typename char_t, typename traits_t, typename allocator_t>
142auto xtd::basic_string<char_t, traits_t, allocator_t>::operator [](const xtd::index& index) const -> const_reference {return operator [](index.get_offset(length()));}
143
144template<typename char_t, typename traits_t, typename allocator_t>
145auto xtd::basic_string<char_t, traits_t, allocator_t>::operator ()(const xtd::index& index) const -> const_reference {return operator [](index);}
146
147template<typename type_t>
148[[nodiscard]] inline auto __to_string_istringable_to_string(const xtd::istringable<type_t>* obj) -> std::string {
149 return obj->to_string();
150}
151
152template<typename key_t, typename value_t>
153[[nodiscard]] inline auto xtd::collections::generic::key_value_pair<key_t, value_t>::to_string() const noexcept -> xtd::string {return xtd::string::format("({}, {})", first, second);}
154
156 for (auto index = xtd::usize {}; index < count; ++index)
157 co_yield element;
158}
159
161 for (auto index = xtd::usize {}; index < count; ++index)
162 co_yield element;
163}
164
166 for (auto index = xtd::usize {}; index < count; ++index)
167 co_yield element;
168}
169
171 for (auto index = xtd::usize {}; index < count; ++index)
172 co_yield element;
173}
174
176 for (auto index = xtd::usize {}; index < count; ++index)
177 co_yield element;
178}
179
180template<typename type_t>
181[[nodiscard]] inline auto __opaque_xtd_linq_enumerable_collection__<type_t>::to_string() const -> xtd::string {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
182
183template<typename type_t, typename param_t>
184[[nodiscard]] inline auto __opaque_xtd_linq_lazy_enumerable__<type_t, param_t>::to_string() const -> xtd::string {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
185
186template<typename type_t>
187[[nodiscard]] inline auto xtd::reference_wrapper_object<type_t>::to_string() const noexcept -> xtd::string {return xtd::string::format("{} [value={}]", xtd::object::to_string(), !ref_.has_value() ? "(null)" : string::format("{}", get()));}
188
189template<typename type_t>
190[[nodiscard]] inline auto xtd::shared_ptr_object<type_t>::to_string() const noexcept -> xtd::string {return xtd::string::format("{} [pointer={}]", xtd::object::to_string(), ptr_ == xtd::null ? "null" : string::format("0x{:X16}, use_count={}", get(), use_count()));}
191
192template<typename type_t, typename deleter_t>
193[[nodiscard]] inline auto xtd::unique_ptr_object<type_t, deleter_t>::to_string() const noexcept -> xtd::string {return xtd::string::format("{} [pointer={}]", xtd::object::to_string(), ptr_ == xtd::null ? "null" : string::format("0x{:X16}", get()));}
195
196#include "literals/string.hpp"
197#define __XTD_CORE_INTERNAL__
199#undef __XTD_CORE_INTERNAL__
Contains xtd::basic_string class.
Contains xtd::character concept.
static auto join(const basic_string &separator, const collection_t &values) noexcept -> basic_string
Definition basic_string.hpp:1241
auto operator[](xtd::usize index) const -> const_reference
Returns a reference to the character at specified location index.
Definition basic_string.hpp:1379
auto operator()(xtd::usize index) const -> const_reference
Returns a reference to the character at specified location index.
Definition basic_string.hpp:1397
Represents an enumerable generator that supports deferred, lazy iteration over a collection of a spec...
Definition enumerable_generator.hpp:45
Provides a way to represent the current object as a string.
Definition istringable.hpp:26
static auto repeat(const element_t &element, xtd::usize count) -> xtd::collections::generic::enumerable_generator< element_t >
Generates a sequence that contains one repeated value.
virtual auto to_string() const -> xtd::string
Returns a xtd::string that represents the current object.
Contains xtd::collections::generic::enumerable_generator <> class.
static auto format(const basic_string< char > &fmt, args_t &&... args) -> basic_string
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
xtd::string ustring
Represents text as a sequence of UTF-8 code units.
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
null_ptr null
Represents a null pointer value.
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:23
Contains xtd::index struct.
Contains xtd::collections::generic::key_value_pair <key_t, value_t> struct.
Contains xtd::linq::enumerable <type_t> class.
Contains xtd::string suffixes.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
auto first() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:245
auto to_string() const noexcept -> xtd::string override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:354
const type_t & const_reference
Represents the read_only_span const reference type.
Definition read_only_span.hpp:75
auto to_ustring(type_t val) -> xtd::string
Converts a type_t to xtd::string.
Definition string.hpp:91
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:209
Contains xtd::stringable concept.
Represents a type that can be used to index a collection either from the beginning or the end.
Definition index.hpp:38