Sfoglia il codice sorgente

Added normalize EOL to LF function.

bkaradzic 13 anni fa
parent
commit
78fc5fad7c
1 ha cambiato i file con 20 aggiunte e 2 eliminazioni
  1. 20 2
      include/bx/string.h

+ 20 - 2
include/bx/string.h

@@ -59,7 +59,7 @@ namespace bx
 	{
 	{
 		for (; '\0' != *_str; _str += strnlen(_str, 1024) )
 		for (; '\0' != *_str; _str += strnlen(_str, 1024) )
 		{
 		{
-			const char* eol = strnstr(_str, "\n\r", 1024);
+			const char* eol = strnstr(_str, "\r\n", 1024);
 			if (NULL != eol)
 			if (NULL != eol)
 			{
 			{
 				return eol + 2;
 				return eol + 2;
@@ -80,7 +80,7 @@ namespace bx
 	{
 	{
 		for (; '\0' != *_str; _str += strnlen(_str, 1024) )
 		for (; '\0' != *_str; _str += strnlen(_str, 1024) )
 		{
 		{
-			const char* eol = strnstr(_str, "\n\r", 1024);
+			const char* eol = strnstr(_str, "\r\n", 1024);
 			if (NULL != eol)
 			if (NULL != eol)
 			{
 			{
 				return eol;
 				return eol;
@@ -140,6 +140,24 @@ namespace bx
 		return NULL;
 		return NULL;
 	}
 	}
 
 
+	// Normalize string to sane line endings.
+	inline void eolLF(char* _out, size_t _size, const char* _str)
+	{
+		if (0 < _size)
+		{
+			char* end = _out + _size - 1;
+			for (char ch = *_str++; ch != '\0' && _out < end; ch = *_str++)
+			{
+				if ('\r' != ch)
+				{
+					*_out++ = ch;
+				}
+			}
+
+			*end = '\0';
+		}
+	}
+
 	/// Cross platform implementation of vsnprintf that returns number of
 	/// Cross platform implementation of vsnprintf that returns number of
 	/// characters which would have been written to the final string if
 	/// characters which would have been written to the final string if
 	/// enough space had been available.
 	/// enough space had been available.