Browse Source

Replaced eolLF with normalizeEolLf.

Branimir Karadžić 7 years ago
parent
commit
53298802c1
2 changed files with 12 additions and 5 deletions
  1. 1 1
      include/bx/string.h
  2. 11 4
      src/string.cpp

+ 1 - 1
include/bx/string.h

@@ -255,7 +255,7 @@ namespace bx
 	StringView strFindBlock(const StringView& _str, char _open, char _close);
 	StringView strFindBlock(const StringView& _str, char _open, char _close);
 
 
 	// Normalize string to sane line endings.
 	// 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.
 	// Finds identifier.
 	StringView findIdentifierMatch(const StringView& _str, const StringView& _word);
 	StringView findIdentifierMatch(const StringView& _str, const StringView& _word);

+ 11 - 4
src/string.cpp

@@ -643,12 +643,17 @@ namespace bx
 		return StringView(term, term);
 		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)
 		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)
 				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)
 	StringView findIdentifierMatch(const StringView& _str, const StringView& _word)