Skip to content

Commit

Permalink
Fix text files with mixed EOL (#260)
Browse files Browse the repository at this point in the history
* fix some end of line bugs

* reduce change

Co-authored-by: Lee Thomason <leet@unity3d.com>
  • Loading branch information
leethomason and Lee Thomason committed Feb 6, 2021
1 parent 4a0ee26 commit 0c7e4c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/bx/inline/string.inl
Expand Up @@ -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;
Expand Down
20 changes: 5 additions & 15 deletions src/string.cpp
Expand Up @@ -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() );
}

Expand Down

0 comments on commit 0c7e4c1

Please sign in to comment.