[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : phil
Repository : xara
Revision   : 872
Date       : Mon Apr 24 16:13:46 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/cxfile.cpp
   M /Trunk/XaraLX/Kernel/cxfrec.cpp

Fixed WriteUnicode functions - I thought I'd done them already, ho hum.


Diff:
Index: Trunk/XaraLX/Kernel/cxfile.cpp
===================================================================
--- Trunk/XaraLX/Kernel/cxfile.cpp	(revision 871)
+++ Trunk/XaraLX/Kernel/cxfile.cpp	(revision 872)
@@ -1029,7 +1029,6 @@
 
 BOOL CXaraFile::WriteUnicode(TCHAR* pStr)
 {
-PORTNOTE("byteorder", "TODO: Check byte order")
 	ERROR3IF(pStr == NULL,"NULL pStr");
 	if (pStr == NULL)
 		return FALSE;
@@ -1038,7 +1037,25 @@
 
 #ifdef UNICODE
 	// pStr points to a Unicode string, so just write it out
-	return (Write((BYTE*)pStr,(len*2)+2));
+	//
+	// We must cope with byte-order differences between native storage and XAR file storage:
+	// Native may be big-endian or little-endian, XAR is always little-endian
+	// Native WCHAR may be 16 or 32 bits, XAR is always 16 bits
+	// These differences are handled in WriteWCHAR
+	BOOL ok = TRUE;
+	WCHAR c = 0;
+	INT32 i = 0;
+
+	do
+	{
+		c = pStr[i++];
+		ok = WriteWCHAR(c);						// Read two bytes into the WCHAR buffer
+		if (!ok) c = 0;							// If the read failed then write a terminator
+	}
+	while (c!=0);// Until end of string or no longer OK to write
+
+	return ok;									// If we terminated due to Read failure tell the caller
+
 #else
 	// pStr points to an ASCII string, and we want it written as a Unicode string
 	// Write out each char, followed by a 0 byte
Index: Trunk/XaraLX/Kernel/cxfrec.cpp
===================================================================
--- Trunk/XaraLX/Kernel/cxfrec.cpp	(revision 871)
+++ Trunk/XaraLX/Kernel/cxfrec.cpp	(revision 872)
@@ -858,29 +858,24 @@
 	
 #ifdef _UNICODE
 
-// TODO: Is this conditional stuff really needed?
-#if defined(__WXGTK__) || defined(__WXMAC__)
-	// pStr points to a Unicode string, so just write it out
-	size_t				cch = wcslen( pStr );
+	// We must cope with byte-order differences between native storage and XAR file storage:
+	// Native may be big-endian or little-endian, XAR is always little-endian
+	// Native WCHAR may be 16 or 32 bits, XAR is always 16 bits
+	// These differences are handled in WriteWCHAR
+	WCHAR c = 0;
+	INT32 i = 0;
 
-	// cch + 1 chars to include 
-	for( unsigned ord = 0; ord <= cch && ok; ord++ )
+	do
 	{
-		ok = WriteWCHAR(pStr[ord]);
+		c = pStr[i++];
+		ok = WriteWCHAR(c);						// Read two bytes into the WCHAR buffer
+		if (!ok) c = 0;							// If the read failed then write a terminator
 	}
+	while (c!=0);// Until end of string or no longer OK to write
 
-#elif defined(__WXMSW__)
-	// pStr points to a Unicode string, so just write it out
-	INT32 len = camStrlen(pStr);
-	ok = WriteBuffer((BYTE*)pStr,(len*2)+2);
+	return ok;									// If we terminated due to Read failure tell the caller
 
 #else
-	#pragma error( "This build enviroment is not supported" )
-	ok = FALSE;
-
-#endif
-
-#else
 	// pStr points to an ASCII or DBCS string, and we want it written as a Unicode string
 	// Write out each char separately, converting it to the correct Unicode value
 	// using TextManager::MultiByteToUnicode()


Xara