OSDN Git Service

crystaledit: Reduce MFC dependency
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Mon, 9 Oct 2023 11:45:52 +0000 (20:45 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Mon, 9 Oct 2023 11:45:52 +0000 (20:45 +0900)
Externals/crystaledit/Sample/SampleDoc.cpp
Externals/crystaledit/editlib/ccrystaltextview.cpp
Externals/crystaledit/editlib/editlib.vcxitems
Externals/crystaledit/editlib/utils/filesup.cpp
Externals/crystaledit/editlib/utils/filesup.h
Externals/crystaledit/editlib/utils/wcwidth.cpp

index 5eb47e8..fc61b8f 100755 (executable)
@@ -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<tchar_t> 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');
index 6e2b1db..485ed10 100644 (file)
@@ -3382,9 +3382,9 @@ void CCrystalTextView::
 OnInitialUpdate ()
 {
   CView::OnInitialUpdate ();
-  CString sDoc = GetDocument ()->GetPathName (), sExt = GetExt (sDoc);
-  if (!sExt.IsEmpty())
-    SetTextType (sExt);
+  std::basic_string<tchar_t> 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 ();
index 358117c..711dd5e 100644 (file)
     <ClCompile Include="$(MSBuildThisFileDirectory)utils\cregexp.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)utils\cregexp_poco.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)utils\cs2cs.cpp" />
-    <ClCompile Include="$(MSBuildThisFileDirectory)utils\filesup.cpp" />
+    <ClCompile Include="$(MSBuildThisFileDirectory)utils\filesup.cpp">
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+      <PrecompiledHeaderOutputFile>$(IntDir)$(TargetName)2.pch</PrecompiledHeaderOutputFile>
+    </ClCompile>
     <ClCompile Include="$(MSBuildThisFileDirectory)utils\hqbitmap.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)utils\icu.cpp" />
-    <ClCompile Include="$(MSBuildThisFileDirectory)utils\wcwidth.cpp" />
+    <ClCompile Include="$(MSBuildThisFileDirectory)utils\wcwidth.cpp">
+      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+      <PrecompiledHeaderOutputFile>$(IntDir)$(TargetName)2.pch</PrecompiledHeaderOutputFile>
+    </ClCompile>
     <ClCompile Include="$(MSBuildThisFileDirectory)ViewableWhitespace.cpp">
       <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
       <PrecompiledHeaderOutputFile>$(IntDir)$(TargetName)2.pch</PrecompiledHeaderOutputFile>
index 786e23c..3acde57 100644 (file)
 //  - 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<tchar_t> sString = pszString;
+  int len = static_cast<int>(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<tchar_t> GetExt (const std::basic_string<tchar_t>& sString)
 {
-  if (!sString.IsEmpty ())
+  std::basic_string<tchar_t> 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;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
index 93de15d..853e9da 100644 (file)
 #pragma once
 
 #include "ctchar.h"
+#include <string>
 
 /////////////////////////////////////////////////////////////////////////////
 
-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<tchar_t> EDITPADC_CLASS GetExt (const std::basic_string<tchar_t>& sString);
index 93834d0..ef642e0 100644 (file)
@@ -9,7 +9,7 @@
  * https://github.com/termux/wcwidth
  */
 
-#include "StdAfx.h"
+#include "pch.h"
 #include <cstdlib>
 
 struct width_interval {