Browse Source

Fix text files with mixed EOL (#260)

* fix some end of line bugs

* reduce change

Co-authored-by: Lee Thomason <[email protected]>
Lee Thomason 4 years ago
parent
commit
0c7e4c1167
2 changed files with 6 additions and 16 deletions
  1. 1 1
      include/bx/inline/string.inl
  2. 5 15
      src/string.cpp

+ 1 - 1
include/bx/inline/string.inl

@@ -276,7 +276,7 @@ namespace bx
 
 
 			StringView line(curr.getPtr(), m_curr.getPtr() );
 			StringView line(curr.getPtr(), m_curr.getPtr() );
 
 
-			return strRTrim(line, "\n\r");
+			return strRTrim(strRTrim(line, "\n"), "\r");
 		}
 		}
 
 
 		return m_curr;
 		return m_curr;

+ 5 - 15
src/string.cpp

@@ -564,23 +564,13 @@ namespace bx
 	{
 	{
 		StringView str(_str);
 		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() );
 		return StringView(_str.getTerm(), _str.getTerm() );
 	}
 	}