瀏覽代碼

Bugfix: Unicode string reads/writes from/to files now work properly

BearishSun 8 年之前
父節點
當前提交
171aadce1a
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7 5
      Source/BansheeUtility/FileSystem/BsDataStream.cpp

+ 7 - 5
Source/BansheeUtility/FileSystem/BsDataStream.cpp

@@ -54,7 +54,7 @@ namespace bs
 			write(bom, sizeof(bom));
 
 			U16String u16string = UTF8::toUTF16(string);
-			write(u16string.data(), u16string.length());
+			write(u16string.data(), u16string.length() * sizeof(char16_t));
 		}
 		else
 		{
@@ -76,7 +76,7 @@ namespace bs
 
 			String u8string = UTF8::fromWide(string);
 			U16String u16string = UTF8::toUTF16(u8string);
-			write(u16string.data(), u16string.length());
+			write(u16string.data(), u16string.length() * sizeof(char16_t));
 		}
 		else
 		{
@@ -104,7 +104,7 @@ namespace bs
 		size_t numHeaderBytes = read(headerBytes, 4);
 
 		size_t dataOffset = 0;
-		if(numHeaderBytes == 4)
+		if(numHeaderBytes >= 4)
 		{
 			if (isUTF32LE(headerBytes))
 				dataOffset = 4;
@@ -114,12 +114,14 @@ namespace bs
 				return u8"";
 			}			
 		}
-		else if(numHeaderBytes == 3)
+		
+		if(dataOffset == 0 && numHeaderBytes >= 3)
 		{
 			if (isUTF8(headerBytes))
 				dataOffset = 3;
 		}
-		else if(numHeaderBytes == 2)
+		
+		if(dataOffset == 0 && numHeaderBytes >= 2)
 		{
 			if (isUTF16LE(headerBytes))
 				dataOffset = 2;