From fd71b74bfc3181ed8b81ba6e93afc0a288054b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 24 Oct 2024 21:36:05 -0700 Subject: [PATCH] Cleanup. --- include/bx/string.h | 3 +++ src/debug.cpp | 16 ---------------- src/string.cpp | 16 ++++++++++++++++ tests/run_test.cpp | 5 ----- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/bx/string.h b/include/bx/string.h index 7b32e4a..cd5e1e8 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -319,6 +319,9 @@ namespace bx /// Returns string view with suffix trimmed. StringView strTrimSuffix(const StringView& _str, const StringView& _suffix); + /// Returns string view `_num` from the right. + StringView strTail(const StringView _str, uint32_t _num); + /// Find new line. Returns pointer after new line terminator. StringView strFindNl(const StringView& _str); diff --git a/src/debug.cpp b/src/debug.cpp index 3ea972e..f507465 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -274,22 +274,6 @@ namespace bx return 1; } - // If offset in UTF-8 string doesn't land on rune, walk back until first byte of rune is reached. - static const char* fixPtrToRune(const char* _strBegin, const char* _curr) - { - for (; _curr > _strBegin && (*_curr & 0xc0) == 0x80; --_curr); - - return _curr; - } - - StringView strTail(const StringView _str, uint32_t _num) - { - return StringView( - fixPtrToRune(_str.getPtr(), _str.getTerm() - min(_num, _str.getLength() ) ) - , _str.getTerm() - ); - } - int32_t writeCallstack(WriterI* _writer, uintptr_t* _stack, uint32_t _num, Error* _err) { BX_ERROR_SCOPE(_err); diff --git a/src/string.cpp b/src/string.cpp index 0ba4be6..f4f93ba 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -556,6 +556,22 @@ namespace bx return strLTrimSpace(strRTrimSpace(_str) ); } + // If offset in UTF-8 string doesn't land on rune, walk back until first byte of rune is reached. + static const char* fixPtrToRune(const char* _strBegin, const char* _curr) + { + for (; _curr > _strBegin && (*_curr & 0xc0) == 0x80; --_curr); + + return _curr; + } + + StringView strTail(const StringView _str, uint32_t _num) + { + return StringView( + fixPtrToRune(_str.getPtr(), _str.getTerm() - min(_num, _str.getLength() ) ) + , _str.getTerm() + ); + } + constexpr uint32_t kFindStep = 1024; StringView strFindNl(const StringView& _str) diff --git a/tests/run_test.cpp b/tests/run_test.cpp index 48361ca..43718d2 100644 --- a/tests/run_test.cpp +++ b/tests/run_test.cpp @@ -8,11 +8,6 @@ #include #include -namespace bx -{ - void debugOutputCallstack(uint32_t _skip); -} - bool testAssertHandler(const bx::Location& _location, const char* _format, va_list _argList) { bx::printf("%s(%d): ", _location.filePath, _location.line);