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 "index.hpp"
12
14namespace xtd {
24 using string = xtd::basic_string<char>;
25
36 using ustring [[deprecated("Replaced by xtd::string - Will be removed in version 1.2.0.")]] = xtd::string;
37
41 [[nodiscard]] auto to_string(int val) -> xtd::string;
45 [[nodiscard]] auto to_string(unsigned val) -> xtd::string;
49 [[nodiscard]] auto to_string(long val) -> xtd::string;
53 [[nodiscard]] auto to_string(unsigned long val) -> xtd::string;
57 [[nodiscard]] auto to_string(long long val) -> xtd::string;
61 [[nodiscard]] auto to_string(unsigned long long val) -> xtd::string;
65 [[nodiscard]] auto to_string(float val) -> xtd::string;
69 [[nodiscard]] auto to_string(double val) -> xtd::string;
73 [[nodiscard]] auto to_string(long double val) -> xtd::string;
77 template<typename type_t>
78 [[nodiscard]] inline auto to_string(type_t val) -> xtd::string {
79 return string::format("{}", val);
80 }
81
86 template<typename type_t>
87 [[deprecated("Replaced by xtd::to_string - Will be removed in version 1.2.0.")]]
88 [[nodiscard]] inline auto to_ustring(type_t val) -> xtd::string {
89 return to_string(val);
90 }
91
93 namespace collections {
94 namespace generic {
95 template<typename type_t>
96 auto enumerable_generator<type_t>::to_string() const -> xtd::string {
97 auto result = xtd::string {"["};
98 for (auto item : self_)
99 result += xtd::string::format("{}{}", result != "[" ? ", " : "", item);
100 return result + "]";
101 }
102 }
103 }
105}
106
108template<typename char_t, typename traits_t, typename allocator_t>
109auto xtd::basic_string<char_t, traits_t, allocator_t>::operator [](const xtd::index& index) const -> const_reference {return operator [](index.get_offset(length()));}
110
111template<typename char_t, typename traits_t, typename allocator_t>
112auto xtd::basic_string<char_t, traits_t, allocator_t>::operator ()(const xtd::index& index) const -> const_reference {return operator [](index);}
113
114template<typename type_t>
115[[nodiscard]] inline auto __to_string_istringable_to_string(const xtd::istringable<type_t>* obj) -> std::string {
116 return obj->to_string();
117}
118
119template<typename key_t, typename value_t>
120[[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);}
121
122template<typename type_t>
123[[nodiscard]] inline auto __opaque_xtd_linq_enumerable_collection__<type_t>::to_string() const -> xtd::string {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
124
125template<typename type_t, typename param_t>
126[[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));}
127
128template<typename type_t>
129[[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()));}
130
131template<typename type_t>
132[[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()));}
133
134template<typename type_t, typename deleter_t>
135[[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()));}
137
138#include "literals/string.hpp"
139#define __XTD_CORE_INTERNAL__
141#undef __XTD_CORE_INTERNAL__
Contains xtd::basic_string class.
static auto join(const basic_string &separator, const collection_t &values) noexcept -> basic_string
Definition basic_string.hpp:1240
auto operator[](xtd::usize index) const -> const_reference
Returns a reference to the character at specified location index.
Definition basic_string.hpp:1378
auto operator()(xtd::usize index) const -> const_reference
Returns a reference to the character at specified location index.
Definition basic_string.hpp:1396
Provides a way to represent the current object as a string.
Definition istringable.hpp:26
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.
null_ptr null
Represents a null pointer value.
Contains xtd::index struct.
Contains xtd::collections::generic::key_value_pair <key_t, value_t> struct.
Contains xtd::string suffixes.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
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:88
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:209
Represents a type that can be used to index a collection either from the beginning or the end.
Definition index.hpp:38