TortoiseSVN-->Blame displayed badly formatted text when the file
contains foreign UTF-8 characters. The reason for it was that
TortoiseProc casted the svn blame output into a UTF16 CString and then
back to 8 Bit. This conversion failed on some unicode characters, which
made CStdioFile::WriteString fail.
I removed this conversion by
* adding a CStdioFileA class wich implements both WriteString(char*) and
WriteString(WCHAR *)
* Making the blame text line a CStringA
I placed the CStdioFileA class directly into the blame.cpp/h files,
breaking a "one class per module" rule. Refactor if you like....
Norbert
PS: More to come (but not today...), I have seen that TortoiseBlame is
still a MBCS app and that the blame output of UTF-8 files still does not
look very good ;-)
Index: src/TortoiseProc/Blame.cpp
===================================================================
--- src/TortoiseProc/Blame.cpp (revision 3059)
+++ src/TortoiseProc/Blame.cpp (working copy)
@@ -25,6 +25,38 @@
#include "Utils.h"
#include "UnicodeUtils.h"
+
+void CStdioFileA::WriteString(LPCSTR lpsz)
+{
+ ASSERT(lpsz != NULL);
+ ASSERT(m_pStream != NULL);
+
+ if (lpsz == NULL)
+ {
+ AfxThrowInvalidArgException();
+ }
+
+ if (fputs(lpsz, m_pStream) == EOF)
+ AfxThrowFileException(CFileException::diskFull, _doserrno, m_strFileName);
+}
+
+
+void CStdioFileA::WriteString(LPCWSTR lpsz)
+{
+ ASSERT(lpsz != NULL);
+ ASSERT(m_pStream != NULL);
+
+ if (lpsz == NULL)
+ {
+ AfxThrowInvalidArgException();
+ }
+
+ if (fputws(lpsz, m_pStream) == EOF)
+ AfxThrowFileException(CFileException::diskFull, _doserrno, m_strFileName);
+}
+
+
+
CBlame::CBlame()
{
m_bCancelled = FALSE;
@@ -41,7 +73,7 @@
BOOL CBlame::BlameCallback(LONG linenumber, LONG revision, const CString& author, const CString& date, const CStringA& line)
{
CString infolineA;
- CString fulllineA;
+ CStringA fulllineA;
if ((m_lowestrev < 0)||(m_lowestrev > revision))
m_lowestrev = revision;
@@ -51,8 +83,8 @@
CString dateA(CUnicodeUtils::GetUTF8(date));
infolineA.Format(_T("%6ld %6ld %30s %-30s "), linenumber, revision, (LPCTSTR)dateA, (LPCTSTR)author);
fulllineA = line;
- fulllineA.TrimRight(_T("\r\n"));
- fulllineA += _T("\n");
+ fulllineA.TrimRight("\r\n");
+ fulllineA += "\n";
if (m_saveFile.m_hFile != INVALID_HANDLE_VALUE)
{
m_saveFile.WriteString(infolineA);
Index: src/TortoiseProc/Blame.h
===================================================================
--- src/TortoiseProc/Blame.h (revision 3059)
+++ src/TortoiseProc/Blame.h (working copy)
@@ -23,6 +23,14 @@
class CTSVNPath;
+
+class CStdioFileA : public CStdioFile
+{
+public:
+ void WriteString(LPCSTR lpsz);
+ void WriteString(LPCWSTR lpsz);
+};
+
class CBlame : public SVN
{
public:
@@ -55,7 +63,7 @@
LONG m_nHeadRev; ///< The HEAD revision of the file
CString m_sSavePath; ///< Where to save the blame data
- CStdioFile m_saveFile; ///< The file object to write to
+ CStdioFileA m_saveFile; ///< The file object to write to
CFile m_saveLog;
CProgressDlg m_progressDlg; ///< The progress dialog shown during operation
LONG m_lowestrev;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Sun Apr 17 11:05:07 2005