OSDN Git Service

Delete bForceUTF8 argument that no longer makes sense
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 10 Mar 2019 04:05:41 +0000 (13:05 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 10 Mar 2019 04:05:41 +0000 (13:05 +0900)
(At present, the content of the text buffer is always output to the file with UCS2-LE)

Src/DiffWrapper.cpp
Src/DiffWrapper.h
Src/MergeDoc.cpp

index 7cb505d..6a30733 100644 (file)
@@ -82,7 +82,6 @@ CDiffWrapper::CDiffWrapper()
 , m_bAddCmdLine(true)
 , m_bAppendFiles(false)
 , m_nDiffs(0)
-, m_codepage(GetACP())
 , m_infoPrediffer(nullptr)
 , m_pDiffList(nullptr)
 , m_bPathsAreTemp(false)
@@ -1149,7 +1148,7 @@ bool CDiffWrapper::RegExpFilter(int StartPos, int EndPos, int FileNo) const
                size_t len = files[FileNo].linbuf[line + 1] - files[FileNo].linbuf[line];
                const char *string = files[FileNo].linbuf[line];
                size_t stringlen = linelen(string, len);
-               if (!m_pFilterList->Match(std::string(string, stringlen), m_codepage))
+               if (!m_pFilterList->Match(std::string(string, stringlen)))
 
                {
                        linesMatch = false;
index c44c5e5..2dc2d49 100644 (file)
@@ -180,7 +180,6 @@ public:
        void SetAppendFiles(bool bAppendFiles);
        void SetPaths(const PathContext &files, bool tempPaths);
        void SetAlternativePaths(const PathContext &altPaths);
-       void SetCodepage(int codepage) { m_codepage = codepage; }
        bool RunFileDiff();
        void GetDiffStatus(DIFFSTATUS *status) const;
        void AddDiffRange(DiffList *pDiffList, unsigned begin0, unsigned end0, unsigned begin1, unsigned end1, OP_TYPE op);
@@ -236,7 +235,6 @@ private:
        bool m_bAddCmdLine; /**< Do we add commandline to patch file? */
        bool m_bAppendFiles; /**< Do we append to existing patch file? */
        int m_nDiffs; /**< Difference count */
-       int m_codepage; /**< Codepage used in line filter */
        DiffList *m_pDiffList; /**< Pointer to external DiffList */
        std::unique_ptr<MovedLines> m_pMovedLines[3];
        const FilterCommentsManager* m_pFilterCommentsManager; /**< Comments filtering manager */
index 377da57..70ae88c 100644 (file)
@@ -85,7 +85,7 @@ static LPCTSTR crlfs[] =
        _T ("\x0d")      //  Macintosh style
 };
 
-static void SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, bool bForceUTF8, int nStartLine = 0, int nLines = -1);
+static void SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, int nStartLine = 0, int nLines = -1);
 
 /////////////////////////////////////////////////////////////////////////////
 // CMergeDoc
@@ -265,22 +265,8 @@ void CMergeDoc::Serialize(CArchive& ar)
  * (the plugins are optional, not the conversion)
  * @todo Show SaveToFile() errors?
  */
-static void SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, bool bForceUTF8, int nStartLine, int nLines)
+static void SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, int nStartLine, int nLines)
 {
-       ASSERT(buf.m_nSourceEncoding == buf.m_nDefaultEncoding);  
-       int orig_codepage = buf.getCodepage();
-       ucr::UNICODESET orig_unicoding = buf.getUnicoding();
-       bool orig_bHasBOM = buf.getHasBom();
-
-       // If file was in Unicode
-       if (orig_unicoding != ucr::NONE || bForceUTF8)
-       {
-       // we subvert the buffer's memory of the original file encoding
-               buf.setUnicoding(ucr::UTF8);  // write as UTF-8 (for preprocessing)
-               buf.setCodepage(ucr::CP_UTF_8); // should not matter
-               buf.setHasBom(false);
-       }
-
        // and we don't repack the file
        PackingInfo * tempPacker = nullptr;
 
@@ -288,11 +274,6 @@ static void SaveBuffForDiff(CDiffTextBuffer & buf, const String& filepath, bool
        String sError;
        int retVal = buf.SaveToFile(filepath, true, sError, tempPacker,
                CRLF_STYLE_AUTOMATIC, false, nStartLine, nLines);
-
-       // restore memory of encoding of original file
-       buf.setUnicoding(orig_unicoding);
-       buf.setCodepage(orig_codepage);
-       buf.setHasBom(orig_bHasBOM);
 }
 
 /**
@@ -383,11 +364,6 @@ int CMergeDoc::Rescan(bool &bBinary, IDENTLEVEL &identical,
        // Set up DiffWrapper
        m_diffWrapper.GetOptions(&diffOptions);
 
-       bool bForceUTF8 = diffOptions.bIgnoreCase;
-       if (std::any_of(m_ptBuf, m_ptBuf + m_nBuffers,
-               [&](auto& ptBuf) { return m_ptBuf[0]->getCodepage() != ptBuf->getCodepage() || ptBuf->getUnicoding() != ucr::NONE; }))
-               bForceUTF8 = true;
-
        // Clear diff list
        m_diffList.Clear();
        m_nCurDiff = -1;
@@ -405,7 +381,6 @@ int CMergeDoc::Rescan(bool &bBinary, IDENTLEVEL &identical,
        else
                m_diffWrapper.SetPaths(PathContext(m_tempFiles[0].GetPath(), m_tempFiles[1].GetPath(), m_tempFiles[2].GetPath()), true);
        m_diffWrapper.SetCompareFiles(m_filePaths);
-       m_diffWrapper.SetCodepage(bForceUTF8 ? ucr::CP_UTF_8 : (m_ptBuf[0]->m_encoding.m_unicoding ? CP_UTF8 : m_ptBuf[0]->m_encoding.m_codepage));
 
        DIFFSTATUS status;
 
@@ -415,7 +390,7 @@ int CMergeDoc::Rescan(bool &bBinary, IDENTLEVEL &identical,
                for (nBuffer = 0; nBuffer < m_nBuffers; nBuffer++)
                {
                        m_ptBuf[nBuffer]->SetTempPath(tempPath);
-                       SaveBuffForDiff(*m_ptBuf[nBuffer], m_tempFiles[nBuffer].GetPath(), bForceUTF8);
+                       SaveBuffForDiff(*m_ptBuf[nBuffer], m_tempFiles[nBuffer].GetPath());
                }
 
                m_diffWrapper.SetCreateDiffList(&m_diffList);
@@ -438,7 +413,7 @@ int CMergeDoc::Rescan(bool &bBinary, IDENTLEVEL &identical,
                        {
                                nLines[nBuffer] = (i >= syncpoints.size()) ? -1 : syncpoints[i][nBuffer] - nStartLine[nBuffer];
                                m_ptBuf[nBuffer]->SetTempPath(tempPath);
-                               SaveBuffForDiff(*m_ptBuf[nBuffer], m_tempFiles[nBuffer].GetPath(), bForceUTF8,
+                               SaveBuffForDiff(*m_ptBuf[nBuffer], m_tempFiles[nBuffer].GetPath(), 
                                        nStartLine[nBuffer], nLines[nBuffer]);
                        }
                        DiffList templist;