// License: Modified MIT (NON-AI) // See the LICENSE file in the root directory for license information. // Copyright 2025 Timothy Prepscius #pragma once #include "Str.hpp" #include "../algorithm/small_cmp.hpp" #include namespace tjp { namespace core { namespace str { typedef StringView compare_type; TJP_STR_INLINE auto cmp (const compare_type &l, const compare_type &r) { return small_cmp(l.data(), l.size(), r.data(), r.size()); } TJP_STR_INLINE auto cmp (const compare_type &l, const char *r) { return small_cmp(l.data(), l.size(), r); } TJP_STR_INLINE auto cmp (const char *l, const compare_type &r) { return -cmp(r, l); } TJP_STR_TEMPLATE12 TJP_STR_INLINE auto cmp(const TJP_STR &lhs, const TJP_STR2 &rhs) { return small_cmp(lhs.data(), lhs.size(), rhs.data(), rhs.size()); } TJP_STR_INLINE auto add(const compare_type &l, const compare_type &r) { return Str(l, r); } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR::Str() { } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR::Str(size_t size, char c) { for (auto i=0; i &rhs) : string(rhs.data(), rhs.data() + rhs.size()) { } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR::Str(const StringView &rhs) : string(rhs.data(), rhs.data() + rhs.size()) { } TJP_STR_TEMPLATE TJP_STR_TEMPLATE2 TJP_STR_INLINE TJP_STR::Str(const TJP_STR2 &rhs) : string(rhs.string) { } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR::Str(const char *begin, const char *end) : string(begin, end) { } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR::Str(const char *rhs) { debug_assert(rhs); if (!rhs) return; auto MAX = 16384; for (auto i=0; i(this)->c_str(); } TJP_STR_INLINE bool operator ==(const compare_type &lhs, const char *rhs) { return cmp(lhs, rhs) == 0; } TJP_STR_INLINE bool operator ==(const char *lhs, const compare_type &rhs) { return rhs == lhs; } TJP_STR_INLINE bool operator !=(const compare_type &lhs, const char *rhs) { return !(lhs == rhs); } TJP_STR_INLINE bool operator !=(const char *lhs, const compare_type &rhs) { return !(lhs == rhs); } TJP_STR_INLINE bool operator <(const compare_type &lhs, const char *rhs) { return cmp(lhs, rhs) < 0; } TJP_STR_INLINE bool operator <(const char *lhs, const compare_type &rhs) { return cmp(lhs, rhs) < 0; } TJP_STR_TEMPLATE12 TJP_STR_INLINE bool operator ==(const TJP_STR &lhs, const TJP_STR2 &rhs) { return cmp(lhs, rhs) == 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator ==(const TJP_STR &lhs, const String &r) { return cmp((const compare_type &)lhs, compare_type(r)) == 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator ==(const TJP_STR &lhs, const StringView &r) { return cmp((const compare_type &)lhs, r) == 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator ==(const TJP_STR &lhs, const char *r) { return cmp((const compare_type &)lhs, r) == 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator ==(const String &l, const TJP_STR &rhs) { return cmp(compare_type(l), (const compare_type &)rhs) == 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator ==(const StringView &l, const TJP_STR &rhs) { return cmp(l, (const compare_type &)rhs) == 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator ==(const char *l, const TJP_STR &rhs) { return cmp(l, (const compare_type &)rhs) == 0; } TJP_STR_TEMPLATE12 TJP_STR_INLINE bool operator !=(const TJP_STR &lhs, const TJP_STR2 &rhs) { return cmp(lhs, rhs) != 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator !=(const TJP_STR &lhs, const String &r) { return cmp((const compare_type &)lhs, compare_type(r)) != 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator !=(const TJP_STR &lhs, const StringView &r) { return cmp((const compare_type &)lhs, r) != 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator !=(const TJP_STR &lhs, const char *r) { return cmp((const compare_type &)lhs, r) != 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator !=(const String &l, const TJP_STR &rhs) { return cmp(compare_type(l), (const compare_type &)rhs) != 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator !=(const StringView &l, const TJP_STR &rhs) { return cmp(compare_type(l), (const compare_type &)rhs) != 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator !=(const char *l, const TJP_STR &rhs) { return cmp(l, (const compare_type &)rhs) != 0; } TJP_STR_TEMPLATE12 TJP_STR_INLINE bool operator <(const TJP_STR &lhs, const TJP_STR2 &rhs) { return cmp(lhs, rhs) < 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator <(const TJP_STR &lhs, const String &r) { return cmp((const compare_type &)lhs, compare_type(r)) < 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator <(const TJP_STR &lhs, const StringView &r) { return cmp((const compare_type &)lhs, r) < 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator <(const TJP_STR &lhs, const char *r) { return cmp((const compare_type &)lhs, r) < 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator <(const String &l, const TJP_STR &rhs) { return cmp(compare_type(l), (const compare_type &)rhs) < 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator <(const StringView &l, const TJP_STR &rhs) { return cmp(l, (const compare_type &)rhs) < 0; } TJP_STR_TEMPLATE TJP_STR_INLINE bool operator <(const char *l, const TJP_STR &rhs) { return cmp(l, (const compare_type &)rhs) < 0; } TJP_STR_TEMPLATE12 TJP_STR_INLINE TJP_STR operator+(const TJP_STR &lhs, const TJP_STR2 &rhs) { return add(lhs, rhs); } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR operator+(const String &lhs, const TJP_STR &rhs) { return add(lhs, rhs); } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR operator+(const StringView &lhs, const TJP_STR &rhs) { return add(lhs, rhs); } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR operator+(const char *lhs, const TJP_STR &rhs) { return add(lhs, rhs); } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR operator+(const TJP_STR &lhs, const String &rhs) { return add(lhs, rhs); } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR operator+(const TJP_STR &lhs, const StringView &rhs) { return add(lhs, rhs); } TJP_STR_TEMPLATE TJP_STR_INLINE TJP_STR operator+(const TJP_STR &lhs, const char *rhs) { return add(lhs, rhs); } } // namespace } // namespace } // namespace