From 0c7e4c1167ecf2d715b8046ff84c6684f6898ec1 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Fri, 5 Feb 2021 17:39:18 -0800 Subject: [PATCH] Fix text files with mixed EOL (#260) * fix some end of line bugs * reduce change Co-authored-by: Lee Thomason --- include/bx/inline/string.inl | 2 +- src/string.cpp | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/include/bx/inline/string.inl b/include/bx/inline/string.inl index 70c2b8a..1aa830f 100644 --- a/include/bx/inline/string.inl +++ b/include/bx/inline/string.inl @@ -276,7 +276,7 @@ namespace bx StringView line(curr.getPtr(), m_curr.getPtr() ); - return strRTrim(line, "\n\r"); + return strRTrim(strRTrim(line, "\n"), "\r"); } return m_curr; diff --git a/src/string.cpp b/src/string.cpp index ed4e56c..0c5f06d 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -564,23 +564,13 @@ namespace bx { StringView str(_str); - for (; str.getPtr() != _str.getTerm() - ; str = StringView(min(str.getPtr() + kFindStep, _str.getTerm() ), min(str.getPtr() + kFindStep*2, _str.getTerm() ) ) - ) + // This method returns the character past the \n, so + // there is no need to look for he \r which preceedes it. + StringView eol = strFind(str, "\n"); + if (!eol.isEmpty() ) { - StringView eol = strFind(str, "\r\n"); - if (!eol.isEmpty() ) - { - return StringView(eol.getTerm(), _str.getTerm() ); - } - - eol = strFind(str, '\n'); - if (!eol.isEmpty() ) - { - return StringView(eol.getTerm(), _str.getTerm() ); - } + return StringView(eol.getTerm(), str.getTerm() ); } - return StringView(_str.getTerm(), _str.getTerm() ); }