Skip to content

Commit

Permalink
crystaledit: Reduce MFC dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Oct 9, 2023
1 parent e91f432 commit 239c57a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 89 deletions.
4 changes: 2 additions & 2 deletions Externals/crystaledit/Sample/SampleDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 8 additions & 3 deletions Externals/crystaledit/editlib/ccrystaltextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ();
Expand Down
10 changes: 8 additions & 2 deletions Externals/crystaledit/editlib/editlib.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@
<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>
Expand Down
85 changes: 11 additions & 74 deletions Externals/crystaledit/editlib/utils/filesup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 (':'));
Expand All @@ -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;
}

////////////////////////////////////////////////////////////////////////////////
9 changes: 2 additions & 7 deletions Externals/crystaledit/editlib/utils/filesup.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@
#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);
2 changes: 1 addition & 1 deletion Externals/crystaledit/editlib/utils/wcwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* https://github.com/termux/wcwidth
*/

#include "StdAfx.h"
#include "pch.h"
#include <cstdlib>

struct width_interval {
Expand Down

0 comments on commit 239c57a

Please sign in to comment.