18#ifndef AMINO_CORE_STRING_H
19#define AMINO_CORE_STRING_H
26#include "internal/ConfigMacros.h"
27#include "internal/Storage.h"
28#include "internal/TypeTraits.h"
51 using is_string_view_like = std::is_convertible<T const&, StringView>;
52 template <
typename T,
typename R =
void>
53 using enable_if_string_view_like =
54 std::enable_if_t<is_string_view_like<T>::value, R>;
138 typename StringViewLike,
139 typename = enable_if_string_view_like<StringViewLike>>
149 AMINO_INTERNAL_FORCEINLINE
operator std::string_view()
const {
150 return {internal_string_view()};
164 template <
typename StringViewLike>
165 AMINO_INTERNAL_FORCEINLINE
166 enable_if_string_view_like<StringViewLike, String&>
216 template <
typename StringViewLike>
217 AMINO_INTERNAL_FORCEINLINE
218 enable_if_string_view_like<StringViewLike, String&>
295 template <
typename StringViewLike>
296 AMINO_INTERNAL_FORCEINLINE
297 enable_if_string_view_like<StringViewLike, int>
299 return internal_compare(s);
523 template <
typename StringViewLike>
524 AMINO_INTERNAL_FORCEINLINE
525 enable_if_string_view_like<StringViewLike, String&>
527 return internal_append(s);
634 template <
typename StringViewLike>
635 AMINO_INTERNAL_FORCEINLINE
636 enable_if_string_view_like<StringViewLike, bool>
638 return internal_equals(rhs);
649 bool operator!=(
char const* rhs)
const {
return !(*
this == rhs); }
651 template <
typename StringViewLike>
652 AMINO_INTERNAL_FORCEINLINE
653 enable_if_string_view_like<StringViewLike, bool>
655 return !internal_equals(rhs);
665 template <
typename T>
666 AMINO_INTERNAL_FORCEINLINE
auto operator<(T
const& rhs)
const
667 ->
decltype(compare(rhs) < 0) {
668 return compare(rhs) < 0;
670 template <
typename T>
671 AMINO_INTERNAL_FORCEINLINE
auto operator>(T
const& rhs)
const
672 ->
decltype(compare(rhs) > 0) {
673 return compare(rhs) > 0;
675 template <
typename T>
676 AMINO_INTERNAL_FORCEINLINE
auto operator<=(T
const& rhs)
const
677 ->
decltype(compare(rhs) <= 0) {
678 return compare(rhs) <= 0;
680 template <
typename T>
681 AMINO_INTERNAL_FORCEINLINE
auto operator>=(T
const& rhs)
const
682 ->
decltype(compare(rhs) >= 0) {
683 return compare(rhs) >= 0;
694 template <
typename S>
695 AMINO_INTERNAL_FORCEINLINE
static std::
696 enable_if_t<std::is_constructible_v<String, S>,
String>
698 return String{std::forward<S>(s)};
700 template <
typename S1,
typename S2,
typename... S>
702 S1
const& s1, S2
const& s2, S&&... s) {
703 constexpr auto N = 2 +
sizeof...(s);
737 Internal::Storage_t<2> m_storage{};
761using is_amino_string = std::
762 is_same<std::remove_cv_t<std::remove_reference_t<std::decay_t<T>>>,
String>;
763template <
typename LHS,
typename RHS>
764using enable_if_rhs_compare = std::enable_if_t<
765 !is_amino_string<LHS>::value && is_amino_string<RHS>::value,
774template <
typename LHS,
typename RHS>
775AMINO_INTERNAL_FORCEINLINE Internal::enable_if_rhs_compare<LHS, RHS>
operator==(
776 LHS
const& lhs, RHS&& rhs) {
777 return rhs.operator==(lhs);
779template <
typename LHS,
typename RHS>
780AMINO_INTERNAL_FORCEINLINE Internal::enable_if_rhs_compare<LHS, RHS>
operator!=(
781 LHS
const& lhs, RHS&& rhs) {
782 return rhs.operator!=(lhs);
784template <
typename LHS,
typename RHS>
785AMINO_INTERNAL_FORCEINLINE Internal::enable_if_rhs_compare<LHS, RHS>
operator<(
786 LHS
const& lhs, RHS&& rhs) {
787 return rhs.operator>(lhs);
789template <
typename LHS,
typename RHS>
790AMINO_INTERNAL_FORCEINLINE Internal::enable_if_rhs_compare<LHS, RHS>
operator>(
791 LHS
const& lhs, RHS&& rhs) {
792 return rhs.operator<(lhs);
794template <
typename LHS,
typename RHS>
795AMINO_INTERNAL_FORCEINLINE Internal::enable_if_rhs_compare<LHS, RHS>
operator<=(
796 LHS
const& lhs, RHS&& rhs) {
797 return rhs.operator>=(lhs);
799template <
typename LHS,
typename RHS>
800AMINO_INTERNAL_FORCEINLINE Internal::enable_if_rhs_compare<LHS, RHS>
operator>=(
801 LHS
const& lhs, RHS&& rhs) {
802 return rhs.operator<=(lhs);
828struct Internal::GetTypeCategory<
String> {
829 static constexpr auto value = TypeCategory::eStr;
836namespace StringLiterals {
845inline String operator""_as(
char const* data,
size_t size) {
846 return String{data, size};
Definition of macros for symbol visibility.
String view class (similar to std::string_view)
bool operator<(Ptr< T > const &x, Ptr< U > const &y) noexcept
Compares the pointer values.
bool operator>(Ptr< T > const &x, Ptr< U > const &y) noexcept
Compares the pointer values.
AMINO_CORE_SHARED_DECL String to_string(signed char value)
Converts a integral value to a string (in base 10).
bool operator==(Ptr< T > const &x, Ptr< U > const &y) noexcept
Return true if pointers are equal.
bool operator<=(Ptr< T > const &x, Ptr< U > const &y) noexcept
Compares the pointer values.
AMINO_CORE_SHARED_DECL String operator+(const String &lhs, const String &rhs)
Concatenation operators( non member )
void swap(Any &lhs, Any &rhs) noexcept
Swap the payloads of two instances of Any.
bool operator!=(Ptr< T > const &x, Ptr< U > const &y) noexcept
Return true if pointers are not equal.
bool operator>=(Ptr< T > const &x, Ptr< U > const &y) noexcept
Compares the pointer values.
Same as Span but the constructor from a range is implicit, making it more convenient and safe to use ...
The string class used by Amino.
String & operator=(String &&s) noexcept
Assign to a string.
char & at(size_type pos)
Return a character at a position.
size_type find_first_of(const char *s, size_type pos=0) const
Multiple methods for finding the first character that matches.
size_type length() const
Return the length of the string.
String & insert(size_type pos, const char *s)
Multiple methods for string insertion.
size_type find_first_not_of(const String &str, size_type pos=0) const
Multiple methods for finding the first character that does not match.
void reserve(size_type n=0)
Change the capacity of the string.
size_type find_first_not_of(const char *s, size_type pos, size_type n) const
Multiple methods for finding the first character that does not match.
static AMINO_INTERNAL_FORCEINLINE std::enable_if_t< std::is_constructible_v< String, S >, String > concat(S &&s)
Concatenate multiple strings.
String & insert(size_type pos, const String &str, size_type subpos, size_type sublen)
Multiple methods for string insertion.
int compare(size_type pos, size_type len, const String &str, size_type subpos, size_type sublen) const
Compare a string.
const char & at(size_type pos) const
Return a character at a position.
AMINO_INTERNAL_FORCEINLINE enable_if_string_view_like< StringViewLike, String & > append(StringViewLike const &s)
Append a copy of a string.
size_type find_first_of(char c, size_type pos=0) const
Multiple methods for finding the first character that matches.
size_type max_size() const
Return the maximum size this string can reach.
const char * asChar() const
Return the string as a char*.
int compare(size_type pos, size_type len, const String &str) const
Compare a string.
int compare(const char *s) const
Compare a string.
size_type capacity() const
Return the allocated storage size of the string.
size_type find_last_of(const char *s, size_type pos=npos) const
Multiple methods for finding the first character that matches from the end.
size_type find_last_of(const String &str, size_type pos=npos) const
Multiple methods for finding the first character that matches from the end.
String()
Construct an empty string.
size_type size() const
Return the size of the string.
void resize(size_type n)
Change the size of the string.
const_iterator cend() const
String & append(const String &str, size_type subpos, size_type sublen)
Appends a part of a string.
AMINO_INTERNAL_FORCEINLINE auto operator<(T const &rhs) const -> decltype(compare(rhs)< 0)
Operator <.
size_type rfind(char c, size_type pos=npos) const
Multiple methods for finding a string starting from the end.
const_iterator cbegin() const
char & back()
Return the last character.
String(std::nullptr_t)=delete
Constructing a String from a nullptr_t is not allowed.
size_type find_first_of(const char *s, size_type pos, size_type n) const
Multiple methods for finding the first character that matches.
const_iterator begin() const
AMINO_INTERNAL_FORCEINLINE auto operator>(T const &rhs) const -> decltype(compare(rhs) > 0)
Operator <.
String & operator=(const char *s)
Assign to a string.
const char & operator[](size_type pos) const
Return a character at a position.
void resize(size_type n, char c)
Change the size of the string.
void pop_back()
Remove the last character of the string.
size_type find(char c, size_type pos=0) const
Multiple methods for finding strings.
size_type find(const char *s, size_type pos, size_type n) const
Multiple methods for finding strings.
int compare(size_type pos, size_type len, const char *s) const
Compare a string.
String(const char *s, size_type n)
Construct a string from a char*.
void shrink_to_fit()
Try to reduce the memory footprint of the string.
size_type rfind(const char *s, size_type pos, size_type n) const
Multiple methods for finding a string starting from the end.
size_type find_last_of(char c, size_type pos=npos) const
Multiple methods for finding the first character that matches from the end.
size_type copy(char *s, size_type len, size_type pos=0) const
Copy part of the string into a char*.
String & append(const char *s)
Append a copy of a string.
size_type find_first_of(const String &str, size_type pos=0) const
Multiple methods for finding the first character that matches.
char & operator[](size_type pos)
Return a character at a position.
size_type find(const char *s, size_type pos=0) const
Multiple methods for finding strings.
String & insert(size_type pos, size_type n, char c)
Multiple methods for string insertion.
String & assign(const String &s)
Assign a string.
String & append(String &&s)
Append a copy of a string.
bool operator==(char const *rhs) const
Operator ==.
void swap(String &str)
Swap this string with another.
String(StringView sv)
Construct a String from a StringView.
String & append(size_type n, char c)
Append the same character multiple times.
String & replace(size_type pos, size_type len, const String &str, size_type subpos, size_type sublen)
Multiple methods for string replacement.
String substr(size_type pos=0, size_type len=npos) const
Return a part of this string.
String & assign(const char *s)
Assign a string.
String & operator+=(const char *s)
The append operator.
const value_type * const_iterator
static AMINO_INTERNAL_FORCEINLINE String concat(S1 const &s1, S2 const &s2, S &&... s)
Concatenate multiple strings.
String(const String &str)
Copy constructor.
String & replace(size_type pos, size_type len, const char *s, size_type n)
Multiple methods for string replacement.
std::ptrdiff_t difference_type
const char & front() const
String(String &&str) noexcept
Move constructor.
String & assign(size_type n, char c)
Assign a character multiple times to the string.
int compare(size_type pos, size_type len, const char *s, size_type n) const
Compare a string.
String & replace(size_type pos, size_type len, size_type n, char c)
Multiple methods for string replacement.
void clear()
Clear the string.
const char & back() const
Return the last character.
AMINO_INTERNAL_FORCEINLINE enable_if_string_view_like< StringViewLike, String & > assign(StringViewLike const &s)
Assign a string.
size_type rfind(const String &str, size_type pos=npos) const
Multiple methods for finding a string starting from the end.
bool operator==(const String &rhs) const
Operator ==.
void push_back(char c)
Push a new character onto the back of the string.
String & append(const char *s, size_type n)
Appends a char* to the string.
AMINO_INTERNAL_FORCEINLINE auto operator>=(T const &rhs) const -> decltype(compare(rhs) >=0)
Operator <.
static AMINO_INTERNAL_FORCEINLINE String concat()
Concatenate multiple strings.
String & assign(String &&s) noexcept
Assign a string.
const char * c_str() const
Return the string as a char*.
String & operator+=(char s)
The append operator.
String & assign(const String &str, size_type subpos, size_type sublen)
String & operator=(const String &s)
Assign to a string.
String & append(const String &s)
Append a copy of a string.
String(const String &str, size_type pos, size_type len=npos)
Construct a string from another.
static String concat(SpanParam< StringView const > const &strs)
Concatenate multiple strings.
AMINO_INTERNAL_FORCEINLINE enable_if_string_view_like< StringViewLike, bool > operator==(StringViewLike const &rhs) const
Operator ==.
String(const char *s)
Construct a string from char char*.
size_type find_first_not_of(const char *s, size_type pos=0) const
Multiple methods for finding the first character that does not match.
bool operator!=(const String &rhs) const
Operator !=.
size_type find_first_not_of(char c, size_type pos=0) const
Multiple methods for finding the first character that does not match.
String & operator+=(const String &s)
The append operator.
String & insert(size_type pos, const String &str)
Multiple methods for string insertion.
AMINO_INTERNAL_FORCEINLINE enable_if_string_view_like< StringViewLike, String & > operator+=(StringViewLike const &s)
The append operator.
AMINO_INTERNAL_FORCEINLINE String & operator=(StringViewLike const &s)
Assign to a string.
size_type find_last_not_of(const char *s, size_type pos=npos) const
Multiple methods for finding the first character that does not match from the end.
String & operator=(char s)
Assign to a string.
String & erase(size_type pos=0, size_type len=npos)
Erase a part of a string.
size_type find_last_of(const char *s, size_type pos, size_type n) const
Multiple methods for finding the first character that matches from the end.
String & replace(size_type pos, size_type len, const char *s)
Multiple methods for string replacement.
AMINO_INTERNAL_FORCEINLINE enable_if_string_view_like< StringViewLike, int > compare(StringViewLike const &s) const
Compare a string.
String & replace(size_type pos, size_type len, const String &str)
Multiple methods for string replacement.
size_type find_last_not_of(const char *s, size_type pos, size_type n) const
Multiple methods for finding the first character that does not match from the end.
size_type find_last_not_of(const String &str, size_type pos=npos) const
Multiple methods for finding the first character that does not match from the end.
AMINO_INTERNAL_FORCEINLINE enable_if_string_view_like< StringViewLike, bool > operator!=(StringViewLike const &rhs) const
Operator !=.
String & assign(const char *s, size_type n)
Assign a char* to the string.
size_type find(const String &str, size_type pos=0) const
Multiple methods for finding strings.
String(size_type n, char c)
Construct a string by filling it.
const char * data() const
Return the string as a char*.
size_type rfind(const char *s, size_type pos=npos) const
Multiple methods for finding a string starting from the end.
bool empty() const
Return true if this string is empty.
size_type find_last_not_of(char c, size_type pos=npos) const
Multiple methods for finding the first character that does not match from the end.
String & insert(size_type pos, const char *s, size_type n)
Multiple methods for string insertion.
const_iterator end() const
AMINO_INTERNAL_FORCEINLINE auto operator<=(T const &rhs) const -> decltype(compare(rhs)<=0)
Operator <.
int compare(const String &s) const
Compare a string.
bool operator!=(char const *rhs) const
Operator !=.
String view class (similar to std::string_view).