From 239c57a714ac868d963c2bee9d8223d8f61ffaf3 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Mon, 9 Oct 2023 20:45:52 +0900 Subject: [PATCH] crystaledit: Reduce MFC dependency --- Externals/crystaledit/Sample/SampleDoc.cpp | 4 +- .../crystaledit/editlib/ccrystaltextview.cpp | 11 ++- .../crystaledit/editlib/editlib.vcxitems | 10 ++- .../crystaledit/editlib/utils/filesup.cpp | 85 +++---------------- Externals/crystaledit/editlib/utils/filesup.h | 9 +- .../crystaledit/editlib/utils/wcwidth.cpp | 2 +- 6 files changed, 32 insertions(+), 89 deletions(-) diff --git a/Externals/crystaledit/Sample/SampleDoc.cpp b/Externals/crystaledit/Sample/SampleDoc.cpp index 5eb47e87bda..fc61b8f8a7f 100755 --- a/Externals/crystaledit/Sample/SampleDoc.cpp +++ b/Externals/crystaledit/Sample/SampleDoc.cpp @@ -118,8 +118,8 @@ BOOL CSampleDoc::OnOpenDocument(LPCTSTR lpszPathName) bool result = m_xTextBuffer.LoadFromFile(lpszPathName); if (result) { - CString ext = GetExt(lpszPathName).MakeLower(); - if (ext == "csv" || ext == "tsv") + std::basic_string ext = GetExt(lpszPathName); + if (tc::tcsicmp(ext.c_str(), _T("csv")) == 0 || tc::tcsicmp(ext.c_str(), _T("tsv")) == 0) { m_xTextBuffer.SetTableEditing(true); m_xTextBuffer.SetFieldDelimiter(ext == _T("csv") ? ',' : '\t'); diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index 6e2b1db15e2..485ed109ced 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -3382,9 +3382,9 @@ void CCrystalTextView:: OnInitialUpdate () { CView::OnInitialUpdate (); - CString sDoc = GetDocument ()->GetPathName (), sExt = GetExt (sDoc); - if (!sExt.IsEmpty()) - SetTextType (sExt); + std::basic_string sDoc = GetDocument ()->GetPathName (), sExt = GetExt (sDoc); + if (!sExt.empty ()) + SetTextType (sExt.c_str ()); AttachToBuffer (nullptr); CSplitterWnd *pSplitter = GetParentSplitter (this, false); @@ -6523,6 +6523,11 @@ OnUpdateToggleSourceHeader (CCmdUI * pCmdUI) void CCrystalTextView:: OnToggleSourceHeader () { + auto FileExist = [](const tchar_t* lpszPath) -> bool + { + CFileStatus status; + return CFile::GetStatus(lpszPath, status) != 0; + }; if (m_CurSourceDef->type == CrystalLineParser::SRC_C) { CDocument *pDoc = GetDocument (); diff --git a/Externals/crystaledit/editlib/editlib.vcxitems b/Externals/crystaledit/editlib/editlib.vcxitems index 358117cb4ed..711dd5e7a14 100644 --- a/Externals/crystaledit/editlib/editlib.vcxitems +++ b/Externals/crystaledit/editlib/editlib.vcxitems @@ -48,10 +48,16 @@ - + + pch.h + $(IntDir)$(TargetName)2.pch + - + + pch.h + $(IntDir)$(TargetName)2.pch + pch.h $(IntDir)$(TargetName)2.pch diff --git a/Externals/crystaledit/editlib/utils/filesup.cpp b/Externals/crystaledit/editlib/utils/filesup.cpp index 786e23cbc08..3acde57d4bc 100644 --- a/Externals/crystaledit/editlib/utils/filesup.cpp +++ b/Externals/crystaledit/editlib/utils/filesup.cpp @@ -14,26 +14,20 @@ // - LEAVE THIS HEADER INTACT //////////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "pch.h" #include "filesup.h" //////////////////////////////////////////////////////////////////////////////// -bool FileExist(const tchar_t* lpszPath) -{ - CFileStatus status; - return CFile::GetStatus(lpszPath, status) != 0; -} - int GetExtPosition (const tchar_t* pszString) { if (pszString == nullptr || !*pszString) return 0; - const CString sString = pszString; - int len = sString.GetLength (), posit = len; + const std::basic_string sString = pszString; + int len = static_cast(sString.length ()), posit = len; tchar_t test; do - if ((test = sString.GetAt (--posit)) == _T ('.')) + if ((test = sString.at (--posit)) == _T ('.')) return posit; #ifdef _UNICODE while (posit && test != _T ('\\') && test != _T (':')); @@ -43,75 +37,18 @@ int GetExtPosition (const tchar_t* pszString) return len; } -CString GetExt (CString sString) +std::basic_string GetExt (const std::basic_string& sString) { - if (!sString.IsEmpty ()) + std::basic_string sString2 = sString; + if (!sString2.empty ()) { - sString = sString.Mid (GetExtPosition (sString)); - if (!sString.IsEmpty () && sString[0] == _T ('.')) + sString2 = sString2.substr (GetExtPosition (sString2.c_str ())); + if (!sString2.empty () && sString2[0] == _T ('.')) { - sString = sString.Mid (1); + sString2 = sString2.substr (1); } } - return sString; -} - -CString GetName (const CString & sString) -{ - int nPosition = GetNamePosition (sString), nPosition2 = GetExtPosition (sString); - - return sString.IsEmpty ()? sString : (nPosition2 == sString.GetLength ()? sString.Mid (nPosition) : sString.Mid (nPosition, nPosition2 - nPosition)); -} - -CString GetNameExt (const CString & sString) -{ - return sString.IsEmpty ()? sString : sString.Mid (GetNamePosition (sString)); -} - -int GetNamePosition (const tchar_t* pszString) -{ - if (pszString == nullptr || !*pszString) - return 0; - const CString sString = pszString; - int posit = sString.GetLength (); - do - { - tchar_t test; -#ifdef _UNICODE - if ((test = sString.GetAt (--posit)) == _T ('\\') || test == _T (':')) -#else - if (((test = sString.GetAt (--posit)) == _T ('\\') && !_ismbstrail((unsigned char *)pszString, (unsigned char *)pszString + posit)) || test == _T (':')) -#endif - return posit + 1; - } - while (posit); - return posit; -} - -CString GetPath (const CString & sString, bool bClose /*= false*/ ) -{ - if (sString.IsEmpty ()) - return sString; - int posit = GetNamePosition (sString); - if (posit == 0) - return bClose ? _T (".\\") : _T ("."); - - tchar_t test = sString.GetAt (posit - 1); - -#ifdef _UNICODE - if (test == _T (':') || test == _T ('\\') && (posit == 1 || sString.GetAt (posit - 2) == _T (':'))) -#else - if (test == _T (':') || (test == _T ('\\') && !_ismbstrail((unsigned char *)(const tchar_t*)sString, (unsigned char *)(const tchar_t*)sString + posit)) && (posit == 1 || sString.GetAt (posit - 2) == _T (':'))) -#endif - return sString.Left (posit); - return sString.Left (bClose ? posit : test == _T (':') ? posit : posit - 1); -} - -CString GetPathName (const CString & sString) -{ - int nPosition = GetExtPosition (sString); - - return sString.IsEmpty ()? sString : (nPosition == sString.GetLength ()? sString : sString.Left (nPosition)); + return sString2; } //////////////////////////////////////////////////////////////////////////////// diff --git a/Externals/crystaledit/editlib/utils/filesup.h b/Externals/crystaledit/editlib/utils/filesup.h index 93de15d7544..853e9daa53b 100644 --- a/Externals/crystaledit/editlib/utils/filesup.h +++ b/Externals/crystaledit/editlib/utils/filesup.h @@ -17,14 +17,9 @@ #pragma once #include "ctchar.h" +#include ///////////////////////////////////////////////////////////////////////////// -bool EDITPADC_CLASS FileExist(const tchar_t* lpszPath); int EDITPADC_CLASS GetExtPosition (const tchar_t* pszString); -CString EDITPADC_CLASS GetExt (CString sString); -CString EDITPADC_CLASS GetName (const CString & sString); -CString EDITPADC_CLASS GetNameExt (const CString & sString); -int EDITPADC_CLASS GetNamePosition (const tchar_t* pszString); -CString EDITPADC_CLASS GetPath (const CString & sString, bool bClose = false); -CString EDITPADC_CLASS GetPathName (const CString & sString); +std::basic_string EDITPADC_CLASS GetExt (const std::basic_string& sString); diff --git a/Externals/crystaledit/editlib/utils/wcwidth.cpp b/Externals/crystaledit/editlib/utils/wcwidth.cpp index 93834d0e848..ef642e024b0 100644 --- a/Externals/crystaledit/editlib/utils/wcwidth.cpp +++ b/Externals/crystaledit/editlib/utils/wcwidth.cpp @@ -9,7 +9,7 @@ * https://github.com/termux/wcwidth */ -#include "StdAfx.h" +#include "pch.h" #include struct width_interval {