16 #ifndef IOX_UTILS_CXX_STRING_HPP
17 #define IOX_UTILS_CXX_STRING_HPP
19 #include "iceoryx_utils/internal/cxx/string_internal.hpp"
20 #include "optional.hpp"
39 template <
typename T1,
typename T2>
40 typename std::enable_if<(internal::IsCharArray<T1>::value || internal::IsCxxString<T1>::value)
41 && (internal::IsCharArray<T2>::value || internal::IsCxxString<T2>::value),
42 string<internal::GetCapa<T1>::capa + internal::GetCapa<T2>::capa>>::type
43 concatenate(
const T1& t1,
const T2& t2);
55 template <
typename T1,
typename T2,
typename... Targs>
56 typename std::enable_if<(internal::IsCharArray<T1>::value || internal::IsCxxString<T1>::value)
57 && (internal::IsCharArray<T2>::value || internal::IsCxxString<T2>::value),
58 string<internal::SumCapa<T1, T2, Targs...>::value>>::type
59 concatenate(
const T1& t1,
const T2& t2,
const Targs&... targs);
67 template <
typename T1,
typename T2>
68 typename std::enable_if<(internal::IsCharArray<T1>::value && internal::IsCxxString<T2>::value)
69 || (internal::IsCxxString<T1>::value && internal::IsCharArray<T2>::value)
70 || (internal::IsCxxString<T1>::value && internal::IsCxxString<T2>::value),
71 string<internal::GetCapa<T1>::capa + internal::GetCapa<T2>::capa>>::type
72 operator+(
const T1& t1,
const T2& t2);
84 template <u
int64_t Capacity>
87 static_assert(Capacity > 0U,
"The capacity of the fixed string must be greater than 0!");
91 constexpr
string() noexcept = default;
96 string(const
string& other) noexcept;
101 string(
string&& other) noexcept;
108 string& operator=(const
string& rhs) noexcept;
115 string& operator=(
string&& rhs) noexcept;
121 template <uint64_t N>
122 string(const
string<N>& other) noexcept;
128 template <uint64_t N>
129 string(
string<N>&& other) noexcept;
137 template <uint64_t N>
138 string& operator=(const
string<N>& rhs) noexcept;
146 template <uint64_t N>
147 string& operator=(
string<N>&& rhs) noexcept;
166 template <uint64_t N>
167 string(const
char (&other)[N]) noexcept;
247 template <uint64_t N>
248 string& operator=(const
char (&rhs)[N]) noexcept;
256 template <uint64_t N>
257 string&
assign(const
string<N>& str) noexcept;
281 template <uint64_t N>
282 string&
assign(const
char (&str)[N]) noexcept;
307 template <uint64_t N>
308 int64_t
compare(const
string<N>& other) const noexcept;
315 template <uint64_t N>
316 bool operator==(const
string<N>& rhs) const noexcept;
323 template <uint64_t N>
324 bool operator!=(const
string<N>& rhs) const noexcept;
331 template <uint64_t N>
332 bool operator<(const
string<N>& rhs) const noexcept;
339 template <uint64_t N>
340 bool operator<=(const
string<N>& rhs) const noexcept;
347 template <uint64_t N>
348 bool operator>(const
string<N>& rhs) const noexcept;
355 template <uint64_t N>
356 bool operator>=(const
string<N>& rhs) const noexcept;
371 bool operator==(const
char* const rhs) const noexcept;
386 bool operator!=(const
char* const rhs) const noexcept;
391 const
char*
c_str() const noexcept;
396 constexpr uint64_t
size() const noexcept;
401 constexpr uint64_t
capacity() const noexcept;
406 constexpr
bool empty() const noexcept;
411 operator std::
string() const noexcept;
416 template <typename T>
417 string& operator+=(const T&) noexcept;
432 template <typename T>
433 typename std::enable_if<internal::IsCharArray<T>::value || internal::IsCxxString<T>::value,
string&>::type
442 template <typename T>
443 typename std::enable_if<internal::IsCharArray<T>::value || internal::IsCxxString<T>::value,
bool>::type
455 iox::cxx::
optional<
string<Capacity>>
substr(const uint64_t pos, const uint64_t count) const noexcept;
464 iox::cxx::
optional<
string<Capacity>>
substr(const uint64_t pos = 0U) const noexcept;
474 template <typename T>
475 typename std::enable_if<std::is_same<T, std::
string>::value || internal::IsCharArray<T>::value
476 || internal::IsCxxString<T>::value,
478 find(const T& t, const uint64_t pos = 0U) const noexcept;
489 template <typename T>
490 typename std::enable_if<std::is_same<T, std::
string>::value || internal::IsCharArray<T>::value
491 || internal::IsCxxString<T>::value,
493 find_first_of(const T& t, const uint64_t pos = 0U) const noexcept;
503 template <typename T>
504 typename std::enable_if<std::is_same<T, std::
string>::value || internal::IsCharArray<T>::value
505 || internal::IsCxxString<T>::value,
507 find_last_of(const T& t, const uint64_t pos = Capacity) const noexcept;
509 template <uint64_t N>
512 template <typename T1, typename T2>
513 friend typename std::enable_if<(internal::IsCharArray<T1>::value || internal::IsCxxString<T1>::value)
514 && (internal::IsCharArray<T2>::value || internal::IsCxxString<T2>::value),
515 string<internal::GetCapa<T1>::capa + internal::GetCapa<T2>::capa>>::type
525 template <uint64_t N>
526 string& copy(const
string<N>& rhs) noexcept;
534 template <uint64_t N>
535 string& move(
string<N>&& rhs) noexcept;
537 char m_rawstring[Capacity + 1U]{
'\0'};
538 uint64_t m_rawstringSize{0U};
547 template <u
int64_t Capacity>
548 inline bool operator==(
const std::string& lhs,
const string<Capacity>& rhs);
556 template <u
int64_t Capacity>
557 inline bool operator==(
const string<Capacity>& lhs,
const std::string& rhs);
565 template <u
int64_t Capacity>
566 inline bool operator!=(
const std::string& lhs,
const string<Capacity>& rhs);
574 template <u
int64_t Capacity>
575 inline bool operator!=(
const string<Capacity>& lhs,
const std::string& rhs);
586 template <u
int64_t Capacity>
587 inline bool operator==(
const char*
const lhs,
const string<Capacity>& rhs);
598 template <u
int64_t Capacity>
599 inline bool operator!=(
const char*
const lhs,
const string<Capacity>& rhs);
607 template <u
int64_t Capacity>
608 inline std::ostream& operator<<(std::ostream& stream,
const string<Capacity>& str);
611 #include "iceoryx_utils/internal/cxx/string.inl"
Optional implementation from the C++17 standard with C++11. The interface is analog to the C++17 stan...
Definition: optional.hpp:63
string implementation with some adjustments in the API, because we are not allowed to throw exception...
Definition: string.hpp:86
iox::cxx::optional< string< Capacity > > substr(const uint64_t pos, const uint64_t count) const noexcept
creates a substring containing the characters from pos until count; if pos+count is greater than the ...
Definition: string.inl:506
constexpr bool empty() const noexcept
returns if the string is empty or not
Definition: string.inl:290
constexpr string() noexcept=default
creates an empty string with size 0
friend std::enable_if<(internal::IsCharArray< T1 >::value||internal::IsCxxString< T1 >::value) &&(internal::IsCharArray< T2 >::value||internal::IsCxxString< T2 >::value), string< internal::GetCapa< T1 >::capa+internal::GetCapa< T2 >::capa > >::type concatenate(const T1 &t1, const T2 &t2)
concatenates two fixed strings/string literals
Definition: string.inl:429
std::enable_if< internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, string & >::type append(TruncateToCapacity_t, const T &t) noexcept
appends a fixed string or string literal to the end of this. If this' capacity is too small for appen...
Definition: string.inl:487
std::enable_if< internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, bool >::type unsafe_append(const T &t) noexcept
appends a fixed string or string literal to the end of this. The appending fails if the sum of both s...
Definition: string.inl:465
std::enable_if< std::is_same< T, std::string >::value||internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, iox::cxx::optional< uint64_t > >::type find_first_of(const T &t, const uint64_t pos=0U) const noexcept
finds the first occurence of a character equal to one of the characters of the given character sequen...
Definition: string.inl:556
bool unsafe_assign(const char *const str) noexcept
assigns a cstring to string. The assignment fails if the cstring size is greater than the string capa...
Definition: string.inl:178
std::enable_if< std::is_same< T, std::string >::value||internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, iox::cxx::optional< uint64_t > >::type find(const T &t, const uint64_t pos=0U) const noexcept
finds the first occurence of the given character sequence; returns the position of the first characte...
Definition: string.inl:537
string & assign(const string< N > &str) noexcept
fixed string assignment with compile time check if capacity of str is less than or equal to this' cap...
constexpr uint64_t size() const noexcept
returns the number of characters stored in the string
Definition: string.inl:278
int64_t compare(const string< N > &other) const noexcept
compares two strings
Definition: string.inl:215
std::enable_if< std::is_same< T, std::string >::value||internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, iox::cxx::optional< uint64_t > >::type find_last_of(const T &t, const uint64_t pos=Capacity) const noexcept
finds the last occurence of a character equal to one of the characters of the given character sequenc...
Definition: string.inl:580
const char * c_str() const noexcept
returns a pointer to the char array of self
Definition: string.inl:272
constexpr uint64_t capacity() const noexcept
returns the maximum number of characters that can be stored in the string
Definition: string.inl:284
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28
struct used to define a compile time variable which is used to distinguish between constructors with ...
Definition: string.hpp:77