17#ifndef IOX_HOOFS_CXX_STRING_HPP
18#define IOX_HOOFS_CXX_STRING_HPP
20#include "iceoryx_hoofs/cxx/type_traits.hpp"
21#include "iceoryx_hoofs/internal/cxx/string_internal.hpp"
22#include "optional.hpp"
43template <
typename T1,
typename T2>
44typename std::enable_if<(internal::IsCharArray<T1>::value || internal::IsCxxString<T1>::value)
45 && (internal::IsCharArray<T2>::value || internal::IsCxxString<T2>::value),
46 string<internal::GetCapa<T1>::capa + internal::GetCapa<T2>::capa>>::type
47concatenate(
const T1& t1,
const T2& t2)
noexcept;
59template <
typename T1,
typename T2,
typename... Targs>
60typename std::enable_if<(internal::IsCharArray<T1>::value || internal::IsCxxString<T1>::value)
61 && (internal::IsCharArray<T2>::value || internal::IsCxxString<T2>::value),
62 string<internal::SumCapa<T1, T2, Targs...>::value>>::type
63concatenate(
const T1& t1,
const T2& t2,
const Targs&... targs)
noexcept;
71template <
typename T1,
typename T2>
72typename std::enable_if<(internal::IsCharArray<T1>::value && internal::IsCxxString<T2>::value)
73 || (internal::IsCxxString<T1>::value && internal::IsCharArray<T2>::value)
74 || (internal::IsCxxString<T1>::value && internal::IsCxxString<T2>::value),
75 string<internal::GetCapa<T1>::capa + internal::GetCapa<T2>::capa>>::type
76operator+(
const T1& t1,
const T2& t2)
noexcept;
88template <u
int64_t Capacity>
91 static_assert(Capacity > 0U,
"The capacity of the fixed string must be greater than 0!");
95 constexpr string() noexcept = default;
100 string(const
string& other) noexcept;
105 string(
string&& other) noexcept;
112 string& operator=(const
string& rhs) noexcept;
119 string& operator=(
string&& rhs) noexcept;
125 template <uint64_t N>
126 string(const
string<N>& other) noexcept;
132 template <uint64_t N>
133 string(
string<N>&& other) noexcept;
141 template <uint64_t N>
142 string& operator=(const
string<N>& rhs) noexcept;
150 template <uint64_t N>
151 string& operator=(
string<N>&& rhs) noexcept;
170 template <uint64_t N>
171 string(const
char (&other)[N]) noexcept;
251 template <uint64_t N>
252 string& operator=(const
char (&rhs)[N]) noexcept;
260 template <uint64_t N>
261 string&
assign(const
string<N>& str) noexcept;
285 template <uint64_t N>
286 string&
assign(const
char (&str)[N]) noexcept;
311 template <uint64_t N>
312 int64_t
compare(const
string<N>& other) const noexcept;
319 template <uint64_t N>
320 bool operator==(const
string<N>& rhs) const noexcept;
327 template <uint64_t N>
328 bool operator!=(const
string<N>& rhs) const noexcept;
335 template <uint64_t N>
336 bool operator<(const
string<N>& rhs) const noexcept;
343 template <uint64_t N>
344 bool operator<=(const
string<N>& rhs) const noexcept;
351 template <uint64_t N>
352 bool operator>(const
string<N>& rhs) const noexcept;
359 template <uint64_t N>
360 bool operator>=(const
string<N>& rhs) const noexcept;
375 bool operator==(const
char* const rhs) const noexcept;
390 bool operator!=(const
char* const rhs) const noexcept;
400 constexpr uint64_t
size() const noexcept;
410 constexpr
bool empty() const noexcept;
415 operator std::
string() const noexcept;
420 template <typename T>
421 string& operator+=(const T&) noexcept;
436 template <typename T>
437 typename std::enable_if<internal::IsCharArray<T>::value || internal::IsCxxString<T>::value,
string&>::type
446 template <typename T>
447 typename std::enable_if<internal::IsCharArray<T>::value || internal::IsCxxString<T>::value,
bool>::type
459 iox::cxx::
optional<
string<Capacity>>
substr(const uint64_t pos, const uint64_t count) const noexcept;
478 template <typename T>
479 typename std::enable_if<std::is_same<T, std::
string>::value || internal::IsCharArray<T>::value
480 || internal::IsCxxString<T>::value,
482 find(const T& t, const uint64_t pos = 0U) const noexcept;
493 template <typename T>
494 typename std::enable_if<std::is_same<T, std::
string>::value || internal::IsCharArray<T>::value
495 || internal::IsCxxString<T>::value,
507 template <typename T>
508 typename std::enable_if<std::is_same<T, std::
string>::value || internal::IsCharArray<T>::value
509 || internal::IsCxxString<T>::value,
511 find_last_of(const T& t, const uint64_t pos = Capacity) const noexcept;
513 template <uint64_t N>
516 template <typename T1, typename T2>
517 friend typename std::enable_if<(internal::IsCharArray<T1>::value || internal::IsCxxString<T1>::value)
518 && (internal::IsCharArray<T2>::value || internal::IsCxxString<T2>::value),
519 string<internal::GetCapa<T1>::capa + internal::GetCapa<T2>::capa>>::type
529 template <uint64_t N>
530 string& copy(const
string<N>& rhs) noexcept;
538 template <uint64_t N>
539 string& move(
string<N>&& rhs) noexcept;
541 char m_rawstring[Capacity + 1U]{
'\0'};
542 uint64_t m_rawstringSize{0U};
551template <u
int64_t Capacity>
552inline bool operator==(
const std::string& lhs,
const string<Capacity>& rhs)
noexcept;
560template <u
int64_t Capacity>
561inline bool operator==(
const string<Capacity>& lhs,
const std::string& rhs)
noexcept;
569template <u
int64_t Capacity>
570inline bool operator!=(
const std::string& lhs,
const string<Capacity>& rhs)
noexcept;
578template <u
int64_t Capacity>
579inline bool operator!=(
const string<Capacity>& lhs,
const std::string& rhs)
noexcept;
590template <u
int64_t Capacity>
591inline bool operator==(
const char*
const lhs,
const string<Capacity>& rhs)
noexcept;
602template <u
int64_t Capacity>
603inline bool operator!=(
const char*
const lhs,
const string<Capacity>& rhs)
noexcept;
611template <u
int64_t Capacity>
612inline std::ostream& operator<<(std::ostream& stream,
const string<Capacity>& str)
noexcept;
615#include "iceoryx_hoofs/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:69
string implementation with some adjustments in the API, because we are not allowed to throw exception...
Definition string.hpp:90
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 ...
constexpr bool empty() const noexcept
returns if the string is empty or not
constexpr string() noexcept=default
creates an empty string with size 0
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...
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...
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...
static constexpr uint64_t capacity() noexcept
returns the maximum number of characters that can be stored in the string
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...
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...
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...
constexpr uint64_t size() const noexcept
returns the number of characters stored in the string
int64_t compare(const string< N > &other) const noexcept
compares two strings
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...
const char * c_str() const noexcept
returns a pointer to the char array of self
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) noexcept
concatenates two fixed strings/string literals
building block to easily create free function for logging in a library context
Definition lockfree_queue.hpp:29
struct used to define a compile time variable which is used to distinguish between constructors with ...
Definition string.hpp:81