Revision: 5507
http://winmerge.svn.sourceforge.net/winmerge/?rev=5507&view=rev
Author: kimmov
Date: 2008-06-22 10:35:42 -0700 (Sun, 22 Jun 2008)
Log Message:
-----------
TODO: [ 1879979 ] Uni*File::ReadBom() used to check for unicode
Modified Paths:
--------------
trunk/Src/Common/UniFile.cpp
trunk/Src/Common/UniFile.h
trunk/Src/Common/multiformatText.cpp
trunk/Src/MergeDoc.cpp
Modified: trunk/Src/Common/UniFile.cpp
===================================================================
--- trunk/Src/Common/UniFile.cpp 2008-06-22 12:58:52 UTC (rev 5506)
+++ trunk/Src/Common/UniFile.cpp 2008-06-22 17:35:42 UTC (rev 5507)
@@ -54,6 +54,8 @@
m_codepage = getDefaultCodepage();
m_txtstats.clear();
m_bom = false;
+ m_bUnicodingChecked = false;
+ m_bUnicode = false;
}
/**
@@ -100,6 +102,20 @@
}
}
+/**
+ * @brief Checks if the file is an unicode file.
+ * This function Checks if the file is recognized unicode file. This detection
+ * includes reading possible BOM bytes and trying to detect UTF-8 files
+ * without BOM bytes.
+ * @return true if file is an unicode file, false otherwise.
+ */
+bool UniLocalFile::IsUnicode()
+{
+ if (!m_bUnicodingChecked)
+ m_bUnicode = ReadBom();
+ return m_bUnicode;
+}
+
/** @brief Record an API call failure */
void UniLocalFile::LastError(LPCTSTR apiname, int syserrnum)
{
@@ -304,6 +320,7 @@
m_bom = bom;
m_current = m_data;
+ m_bUnicodingChecked = true;
return unicode;
}
Modified: trunk/Src/Common/UniFile.h
===================================================================
--- trunk/Src/Common/UniFile.h 2008-06-22 12:58:52 UTC (rev 5506)
+++ trunk/Src/Common/UniFile.h 2008-06-22 17:35:42 UTC (rev 5507)
@@ -39,6 +39,7 @@
virtual String GetFullyQualifiedPath() const = 0;
virtual const UniError & GetLastUniError() const = 0;
+ virtual bool IsUnicode() = 0;
virtual bool ReadBom() = 0;
virtual bool HasBom() = 0;
virtual void SetBom(bool bom) = 0;
@@ -92,6 +93,8 @@
virtual int GetLineNumber() const { return m_lineno; }
virtual const txtstats & GetTxtStats() const { return m_txtstats; }
+ bool IsUnicode();
+
protected:
virtual bool DoGetFileStatus();
virtual void LastError(LPCTSTR apiname, int syserrnum);
@@ -109,6 +112,8 @@
int m_codepage; // only valid if m_unicoding==ucr::NONE;
txtstats m_txtstats;
bool m_bom; /**< Did the file have a BOM when reading? */
+ bool m_bUnicodingChecked; /**< Has unicoding been checked for the file? */
+ bool m_bUnicode; /**< Is the file unicode file? */
};
/**
Modified: trunk/Src/Common/multiformatText.cpp
===================================================================
--- trunk/Src/Common/multiformatText.cpp 2008-06-22 12:58:52 UTC (rev 5506)
+++ trunk/Src/Common/multiformatText.cpp 2008-06-22 17:35:42 UTC (rev 5507)
@@ -83,7 +83,7 @@
UniMemFile ufile;
if (ufile.OpenReadOnly(filename))
{
- bIsUnicode = ufile.ReadBom();
+ bIsUnicode = ufile.IsUnicode();
ufile.Close();
}
if (bIsUnicode)
@@ -601,7 +601,7 @@
BOOL UnicodeFileToOlechar(LPCTSTR filepath, LPCTSTR filepathDst, int & nFileChanged)
{
UniMemFile ufile;
- if (!ufile.OpenReadOnly(filepath) || !ufile.ReadBom())
+ if (!ufile.OpenReadOnly(filepath) || !ufile.IsUnicode())
return TRUE; // not unicode file, nothing to do
int codeOldBOM = ufile.GetUnicoding();
@@ -699,7 +699,7 @@
BOOL OlecharToUTF8(LPCTSTR filepath, LPCTSTR filepathDst, int & nFileChanged, BOOL bWriteBOM)
{
UniMemFile ufile;
- if (!ufile.OpenReadOnly(filepath) || !ufile.ReadBom())
+ if (!ufile.OpenReadOnly(filepath) || !ufile.IsUnicode())
return TRUE; // not unicode file, nothing to do
int unicoding = ufile.GetUnicoding();
// Finished with examing file contents
Modified: trunk/Src/MergeDoc.cpp
===================================================================
--- trunk/Src/MergeDoc.cpp 2008-06-22 12:58:52 UTC (rev 5506)
+++ trunk/Src/MergeDoc.cpp 2008-06-22 17:35:42 UTC (rev 5507)
@@ -1681,9 +1681,10 @@
}
else
{
- // If file is unicode(including UTF-8 without BOM), try to read BOM
- // or else, use the codepage we were given to interpret the 8-bit characters
- if (encoding.m_unicoding == ucr::NONE || !pufile->ReadBom())
+ // If the file is not unicode file, use the codepage we were given to
+ // interpret the 8-bit characters. If the file is unicode file,
+ // determine its type (IsUnicode() does that).
+ if (encoding.m_unicoding == ucr::NONE || !pufile->IsUnicode())
pufile->SetCodepage(encoding.m_codepage);
UINT lineno = 0;
CString eol, preveol;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|