Split wx_filename out of common

This commit is contained in:
Marek Roszko
2020-10-25 20:01:13 -04:00
parent 36e4b318f0
commit 1167862c86
8 changed files with 145 additions and 97 deletions
-65
View File
@@ -431,71 +431,6 @@ std::ostream& operator<<( std::ostream& out, const wxPoint& pt )
* SIGNIFICANT performance benefits.
*/
/**
* WX_FILENAME
*
* A wrapper around a wxFileName which avoids expensive calls to wxFileName::SplitPath()
* and string concatenations by caching the path and filename locally and only resolving
* the wxFileName when it has to.
*/
WX_FILENAME::WX_FILENAME( const wxString& aPath, const wxString& aFilename ) :
m_fn( aPath, aFilename ),
m_path( aPath ),
m_fullName( aFilename )
{ }
void WX_FILENAME::SetFullName( const wxString& aFileNameAndExtension )
{
m_fullName = aFileNameAndExtension;
}
wxString WX_FILENAME::GetName() const
{
size_t dot = m_fullName.find_last_of( wxT( '.' ) );
return m_fullName.substr( 0, dot );
}
wxString WX_FILENAME::GetFullName() const
{
return m_fullName;
}
wxString WX_FILENAME::GetPath() const
{
return m_path;
}
wxString WX_FILENAME::GetFullPath() const
{
return m_path + wxT( '/' ) + m_fullName;
}
// Write locally-cached values to the wxFileName. MUST be called before using m_fn.
void WX_FILENAME::resolve()
{
size_t dot = m_fullName.find_last_of( wxT( '.' ) );
m_fn.SetName( m_fullName.substr( 0, dot ) );
m_fn.SetExt( m_fullName.substr( dot + 1 ) );
}
long long WX_FILENAME::GetTimestamp()
{
resolve();
if( m_fn.FileExists() )
return m_fn.GetModificationTime().GetValue().GetValue();
return 0;
}
/**
* A copy of wxMatchWild(), which wxWidgets attributes to Douglas A. Lewis
* <[email protected]> and ircII's reg.c.