From 53298802c1b295d383e4a2df2f90ec0bc5f3ebbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 28 Oct 2018 20:47:45 -0700 Subject: [PATCH] Replaced eolLF with normalizeEolLf. --- include/bx/string.h | 2 +- src/string.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/bx/string.h b/include/bx/string.h index 7ed6fbf..e080056 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -255,7 +255,7 @@ namespace bx StringView strFindBlock(const StringView& _str, char _open, char _close); // Normalize string to sane line endings. - void eolLF(char* _out, int32_t _size, const char* _str); + StringView normalizeEolLf(char* _out, int32_t _size, const StringView& _str); // Finds identifier. StringView findIdentifierMatch(const StringView& _str, const StringView& _word); diff --git a/src/string.cpp b/src/string.cpp index 86847a2..3a25456 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -643,12 +643,17 @@ namespace bx return StringView(term, term); } - void eolLF(char* _out, int32_t _size, const char* _str) + StringView normalizeEolLf(char* _out, int32_t _size, const StringView& _str) { + const char* start = _out; + const char* end = _out; + if (0 < _size) { - char* end = _out + _size - 1; - for (char ch = *_str++; ch != '\0' && _out < end; ch = *_str++) + const char* curr = _str.getPtr(); + const char* term = _str.getTerm(); + end = _out + _size; + for (char ch = *curr; curr != term && _out < end; ch = *(++curr) ) { if ('\r' != ch) { @@ -656,8 +661,10 @@ namespace bx } } - *_out = '\0'; + end = _out; } + + return StringView(start, end); } StringView findIdentifierMatch(const StringView& _str, const StringView& _word)