|
@@ -44,8 +44,8 @@ namespace bx
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<int32_t SizeT>
|
|
template<int32_t SizeT>
|
|
|
- inline constexpr StringLiteral::StringLiteral(const char (&str)[SizeT])
|
|
|
|
|
- : m_ptr(str)
|
|
|
|
|
|
|
+ inline constexpr StringLiteral::StringLiteral(const char (&_str)[SizeT])
|
|
|
|
|
+ : m_ptr(_str)
|
|
|
, m_len(SizeT - 1)
|
|
, m_len(SizeT - 1)
|
|
|
{
|
|
{
|
|
|
BX_ASSERT('\0' == m_ptr[SizeT - 1], "Must be 0 terminated.");
|
|
BX_ASSERT('\0' == m_ptr[SizeT - 1], "Must be 0 terminated.");
|
|
@@ -61,20 +61,21 @@ namespace bx
|
|
|
return m_ptr;
|
|
return m_ptr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline void StringLiteral::clear()
|
|
|
|
|
|
|
+ inline constexpr void StringLiteral::clear()
|
|
|
{
|
|
{
|
|
|
m_ptr = "";
|
|
m_ptr = "";
|
|
|
m_len = 0;
|
|
m_len = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline bool StringLiteral::isEmpty() const
|
|
|
|
|
|
|
+ inline constexpr bool StringLiteral::isEmpty() const
|
|
|
{
|
|
{
|
|
|
return 0 == m_len;
|
|
return 0 == m_len;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline StringView::StringView()
|
|
|
|
|
|
|
+ inline constexpr StringView::StringView()
|
|
|
{
|
|
{
|
|
|
- clear();
|
|
|
|
|
|
|
+ m_ptr = "";
|
|
|
|
|
+ m_len = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline constexpr StringView::StringView(const StringLiteral& _str)
|
|
inline constexpr StringView::StringView(const StringLiteral& _str)
|
|
@@ -84,49 +85,49 @@ namespace bx
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline StringView::StringView(const StringView& _rhs)
|
|
|
|
|
|
|
+ inline constexpr StringView::StringView(const StringView& _rhs)
|
|
|
{
|
|
{
|
|
|
set(_rhs);
|
|
set(_rhs);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline StringView::StringView(const StringView& _rhs, int32_t _start, int32_t _len)
|
|
|
|
|
|
|
+ inline constexpr StringView::StringView(const StringView& _rhs, int32_t _start, int32_t _len)
|
|
|
{
|
|
{
|
|
|
set(_rhs, _start, _len);
|
|
set(_rhs, _start, _len);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline StringView& StringView::operator=(const char* _rhs)
|
|
|
|
|
|
|
+ inline constexpr StringView& StringView::operator=(const char* _rhs)
|
|
|
{
|
|
{
|
|
|
set(_rhs);
|
|
set(_rhs);
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline StringView& StringView::operator=(const StringView& _rhs)
|
|
|
|
|
|
|
+ inline constexpr StringView& StringView::operator=(const StringView& _rhs)
|
|
|
{
|
|
{
|
|
|
set(_rhs);
|
|
set(_rhs);
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline StringView::StringView(const char* _ptr)
|
|
|
|
|
|
|
+ inline constexpr StringView::StringView(const char* _ptr)
|
|
|
{
|
|
{
|
|
|
set(_ptr, INT32_MAX);
|
|
set(_ptr, INT32_MAX);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline StringView::StringView(const char* _ptr, int32_t _len)
|
|
|
|
|
|
|
+ inline constexpr StringView::StringView(const char* _ptr, int32_t _len)
|
|
|
{
|
|
{
|
|
|
set(_ptr, _len);
|
|
set(_ptr, _len);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline StringView::StringView(const char* _ptr, const char* _term)
|
|
|
|
|
|
|
+ inline constexpr StringView::StringView(const char* _ptr, const char* _term)
|
|
|
{
|
|
{
|
|
|
set(_ptr, _term);
|
|
set(_ptr, _term);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline void StringView::set(const char* _ptr)
|
|
|
|
|
|
|
+ inline constexpr void StringView::set(const char* _ptr)
|
|
|
{
|
|
{
|
|
|
set(_ptr, INT32_MAX);
|
|
set(_ptr, INT32_MAX);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline void StringView::set(const char* _ptr, int32_t _len)
|
|
|
|
|
|
|
+ inline constexpr void StringView::set(const char* _ptr, int32_t _len)
|
|
|
{
|
|
{
|
|
|
clear();
|
|
clear();
|
|
|
|
|
|
|
@@ -138,68 +139,99 @@ namespace bx
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline void StringView::set(const char* _ptr, const char* _term)
|
|
|
|
|
|
|
+ inline constexpr void StringView::set(const char* _ptr, const char* _term)
|
|
|
{
|
|
{
|
|
|
set(_ptr, int32_t(_term-_ptr) );
|
|
set(_ptr, int32_t(_term-_ptr) );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline void StringView::set(const StringView& _str)
|
|
|
|
|
|
|
+ inline constexpr void StringView::set(const StringView& _str)
|
|
|
{
|
|
{
|
|
|
set(_str, 0, INT32_MAX);
|
|
set(_str, 0, INT32_MAX);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline void StringView::set(const StringView& _str, int32_t _start, int32_t _len)
|
|
|
|
|
|
|
+ inline constexpr void StringView::set(const StringView& _str, int32_t _start, int32_t _len)
|
|
|
{
|
|
{
|
|
|
const int32_t start = min(_start, _str.m_len);
|
|
const int32_t start = min(_start, _str.m_len);
|
|
|
const int32_t len = clamp(_str.m_len - start, 0, min(_len, _str.m_len) );
|
|
const int32_t len = clamp(_str.m_len - start, 0, min(_len, _str.m_len) );
|
|
|
set(_str.m_ptr + start, len);
|
|
set(_str.m_ptr + start, len);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline void StringView::clear()
|
|
|
|
|
|
|
+ inline constexpr void StringView::clear()
|
|
|
{
|
|
{
|
|
|
m_ptr = "";
|
|
m_ptr = "";
|
|
|
m_len = 0;
|
|
m_len = 0;
|
|
|
m_0terminated = true;
|
|
m_0terminated = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline const char* StringView::getPtr() const
|
|
|
|
|
|
|
+ inline constexpr const char* StringView::getPtr() const
|
|
|
{
|
|
{
|
|
|
return m_ptr;
|
|
return m_ptr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline const char* StringView::getTerm() const
|
|
|
|
|
|
|
+ inline constexpr const char* StringView::getTerm() const
|
|
|
{
|
|
{
|
|
|
return m_ptr + m_len;
|
|
return m_ptr + m_len;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline bool StringView::isEmpty() const
|
|
|
|
|
|
|
+ inline constexpr bool StringView::isEmpty() const
|
|
|
{
|
|
{
|
|
|
return 0 == m_len;
|
|
return 0 == m_len;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline int32_t StringView::getLength() const
|
|
|
|
|
|
|
+ inline constexpr int32_t StringView::getLength() const
|
|
|
{
|
|
{
|
|
|
return m_len;
|
|
return m_len;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline bool StringView::is0Terminated() const
|
|
|
|
|
|
|
+ inline constexpr bool StringView::is0Terminated() const
|
|
|
{
|
|
{
|
|
|
return m_0terminated;
|
|
return m_0terminated;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline bool operator==(const StringView& _lhs, const StringView& _rhs)
|
|
|
|
|
|
|
+ inline constexpr bool operator==(const StringView& _lhs, const StringView& _rhs)
|
|
|
{
|
|
{
|
|
|
- return 0 == strCmp(_lhs, _rhs);
|
|
|
|
|
|
|
+ const int32_t len = _lhs.getLength();
|
|
|
|
|
+
|
|
|
|
|
+ if (len != _rhs.getLength() )
|
|
|
|
|
+ {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (0 == len)
|
|
|
|
|
+ {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const char* lhs = _lhs.getPtr();
|
|
|
|
|
+ const char* rhs = _rhs.getPtr();
|
|
|
|
|
+
|
|
|
|
|
+ if constexpr (!isConstantEvaluated() )
|
|
|
|
|
+ {
|
|
|
|
|
+ // note: comparison of addresses of literals has unspecified value
|
|
|
|
|
+ if (lhs == rhs)
|
|
|
|
|
+ {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (int32_t ii = 0, num = len-1
|
|
|
|
|
+ ; ii < num && *lhs == *rhs
|
|
|
|
|
+ ; ++ii, ++lhs, ++rhs
|
|
|
|
|
+ )
|
|
|
|
|
+ {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return *lhs == *rhs;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline bool overlap(const StringView& _a, const StringView& _b)
|
|
|
|
|
|
|
+ inline constexpr bool overlap(const StringView& _a, const StringView& _b)
|
|
|
{
|
|
{
|
|
|
return _a.getTerm() > _b.getPtr()
|
|
return _a.getTerm() > _b.getPtr()
|
|
|
&& _b.getTerm() > _a.getPtr()
|
|
&& _b.getTerm() > _a.getPtr()
|
|
|
;
|
|
;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline bool contain(const StringView& _a, const StringView& _b)
|
|
|
|
|
|
|
+ inline constexpr bool contain(const StringView& _a, const StringView& _b)
|
|
|
{
|
|
{
|
|
|
return _a.getPtr() <= _b.getPtr()
|
|
return _a.getPtr() <= _b.getPtr()
|
|
|
&& _a.getTerm() >= _b.getTerm()
|
|
&& _a.getTerm() >= _b.getTerm()
|
|
@@ -207,76 +239,76 @@ namespace bx
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline FixedStringT<MaxCapacityT>::FixedStringT()
|
|
|
|
|
|
|
+ inline constexpr FixedStringT<MaxCapacityT>::FixedStringT()
|
|
|
: m_len(0)
|
|
: m_len(0)
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline FixedStringT<MaxCapacityT>::FixedStringT(const char* _str)
|
|
|
|
|
|
|
+ inline constexpr FixedStringT<MaxCapacityT>::FixedStringT(const char* _str)
|
|
|
: FixedStringT<MaxCapacityT>()
|
|
: FixedStringT<MaxCapacityT>()
|
|
|
{
|
|
{
|
|
|
set(_str);
|
|
set(_str);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline FixedStringT<MaxCapacityT>::FixedStringT(const StringView& _str)
|
|
|
|
|
|
|
+ inline constexpr FixedStringT<MaxCapacityT>::FixedStringT(const StringView& _str)
|
|
|
: FixedStringT<MaxCapacityT>()
|
|
: FixedStringT<MaxCapacityT>()
|
|
|
{
|
|
{
|
|
|
set(_str);
|
|
set(_str);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline FixedStringT<MaxCapacityT>::~FixedStringT()
|
|
|
|
|
|
|
+ inline constexpr FixedStringT<MaxCapacityT>::~FixedStringT()
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline void FixedStringT<MaxCapacityT>::set(const char* _str)
|
|
|
|
|
|
|
+ inline constexpr void FixedStringT<MaxCapacityT>::set(const char* _str)
|
|
|
{
|
|
{
|
|
|
set(StringView(_str) );
|
|
set(StringView(_str) );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline void FixedStringT<MaxCapacityT>::set(const StringView& _str)
|
|
|
|
|
|
|
+ inline constexpr void FixedStringT<MaxCapacityT>::set(const StringView& _str)
|
|
|
{
|
|
{
|
|
|
int32_t copied = strCopy(m_storage, MaxCapacityT, _str);
|
|
int32_t copied = strCopy(m_storage, MaxCapacityT, _str);
|
|
|
m_len = copied;
|
|
m_len = copied;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline void FixedStringT<MaxCapacityT>::append(const StringView& _str)
|
|
|
|
|
|
|
+ inline constexpr void FixedStringT<MaxCapacityT>::append(const StringView& _str)
|
|
|
{
|
|
{
|
|
|
m_len += strCopy(&m_storage[m_len], MaxCapacityT-m_len, _str);
|
|
m_len += strCopy(&m_storage[m_len], MaxCapacityT-m_len, _str);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline void FixedStringT<MaxCapacityT>::clear()
|
|
|
|
|
|
|
+ inline constexpr void FixedStringT<MaxCapacityT>::clear()
|
|
|
{
|
|
{
|
|
|
m_len = 0;
|
|
m_len = 0;
|
|
|
m_storage[0] = '\0';
|
|
m_storage[0] = '\0';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline bool FixedStringT<MaxCapacityT>::isEmpty() const
|
|
|
|
|
|
|
+ inline constexpr bool FixedStringT<MaxCapacityT>::isEmpty() const
|
|
|
{
|
|
{
|
|
|
return 0 == m_len;
|
|
return 0 == m_len;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline int32_t FixedStringT<MaxCapacityT>::getLength() const
|
|
|
|
|
|
|
+ inline constexpr int32_t FixedStringT<MaxCapacityT>::getLength() const
|
|
|
{
|
|
{
|
|
|
return m_len;
|
|
return m_len;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline const char* FixedStringT<MaxCapacityT>::getCPtr() const
|
|
|
|
|
|
|
+ inline constexpr const char* FixedStringT<MaxCapacityT>::getCPtr() const
|
|
|
{
|
|
{
|
|
|
return m_storage;
|
|
return m_storage;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template<uint16_t MaxCapacityT>
|
|
template<uint16_t MaxCapacityT>
|
|
|
- inline FixedStringT<MaxCapacityT>::operator StringView() const
|
|
|
|
|
|
|
+ inline constexpr FixedStringT<MaxCapacityT>::operator StringView() const
|
|
|
{
|
|
{
|
|
|
return StringView(m_storage, m_len);
|
|
return StringView(m_storage, m_len);
|
|
|
}
|
|
}
|
|
@@ -438,11 +470,23 @@ namespace bx
|
|
|
return m_line;
|
|
return m_line;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline int32_t strLen(const StringView& _str, int32_t _max)
|
|
|
|
|
|
|
+ inline constexpr int32_t strLen(const StringView& _str, int32_t _max)
|
|
|
{
|
|
{
|
|
|
return min(_str.getLength(), _max);
|
|
return min(_str.getLength(), _max);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ inline constexpr int32_t strLen(const char* _str, int32_t _max)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (NULL == _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const char* ptr = _str;
|
|
|
|
|
+ for (; 0 < _max && *ptr != '\0'; ++ptr, --_max) {};
|
|
|
|
|
+ return int32_t(ptr - _str);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
inline bool hasPrefix(const StringView& _str, const StringView& _prefix)
|
|
inline bool hasPrefix(const StringView& _str, const StringView& _prefix)
|
|
|
{
|
|
{
|
|
|
const int32_t len = _prefix.getLength();
|
|
const int32_t len = _prefix.getLength();
|
|
@@ -479,4 +523,76 @@ namespace bx
|
|
|
return _str;
|
|
return _str;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ inline bool fromString(int8_t* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inline bool fromString(uint8_t* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inline bool fromString(int16_t* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inline bool fromString(uint16_t* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inline bool fromString(int32_t* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inline bool fromString(uint32_t* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inline bool fromString(long* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inline bool fromString(unsigned long* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inline bool fromString(unsigned long long* _out, const StringView& _str)
|
|
|
|
|
+ {
|
|
|
|
|
+ long long tmp;
|
|
|
|
|
+ fromString(&tmp, _str);
|
|
|
|
|
+
|
|
|
|
|
+ return narrowCastTest(_out, tmp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
} // namespace bx
|
|
} // namespace bx
|