📄 filespec.cpp
字号:
}void CHXPathParser::SetFromPersistentString(const char *pBuffer){ ParsePath(pBuffer);}////////////////////////////////////////////////////////////// CHXFileSpecifier////////////////////////////////////////////////////////////CHXFileSpecifier::CHXFileSpecifier(){}CHXFileSpecifier::CHXFileSpecifier(const char* psz){ m_parser.ParsePath(psz);}CHXFileSpecifier::CHXFileSpecifier(const CHXString &str){ m_parser.ParsePath(str);}CHXFileSpecifier::CHXFileSpecifier(const CHXFileSpecifier &other){ *this = other;}CHXFileSpecifier::~CHXFileSpecifier(){}CHXFileSpecifier &CHXFileSpecifier::operator=(const CHXFileSpecifier &other){ m_parser = other.m_parser; return *this;}CHXFileSpecifier& CHXFileSpecifier::operator=(const char* sPath){ m_parser.ParsePath(sPath); return *this;}CHXFileSpecifier& CHXFileSpecifier::operator=(const CHXString& sPath){ m_parser.ParsePath(sPath); return *this;}BOOL CHXFileSpecifier::operator==(const CHXFileSpecifier &other){ // for now, just returns if the paths are identical // in the future, should normalize paths (i.e. remove duplicate slashes, resolve ..\..\.. type issues return m_parser == other.m_parser;}BOOL CHXFileSpecifier::operator!=(const CHXFileSpecifier &other){ // for now, just returns if the paths are not identical // in the future, should normalize paths (i.e. remove duplicate slashes, resolve ..\..\.. type issues return m_parser != other.m_parser;}CHXString CHXFileSpecifier::GetPathName() const{ return m_parser.GetPathName();}CHXString CHXFileSpecifier::GetURL() const{ const BOOL kReplaceAll = TRUE; CHXString strPath, strURL; strPath = m_parser.GetPathName(); if (strPath.GetLength() > 0) { strPath.FindAndReplace("\\", "/", kReplaceAll); // replace path separators strURL = "file://"; strURL += strPath; } return strURL;}BOOL CHXFileSpecifier::IsSet() const{ return m_parser.IsSet();}CHXDirSpecifier CHXFileSpecifier::GetParentDirectory() const{ if(IsSet()) return m_parser.GetSubstring(0, m_parser.m_nVolumeLength + m_parser.m_nParentLength); else return CHXDirSpecifier();}CHXDirSpecifier CHXFileSpecifier::GetVolume() const{ if(IsSet()) return m_parser.GetSubstring(0, m_parser.m_nVolumeLength); else return CHXDirSpecifier();}CHXString CHXFileSpecifier::GetName() const{ if(IsSet()) return m_parser.GetSubstring(m_parser.m_nVolumeLength + m_parser.m_nParentLength + m_parser.m_nSeparatorLength, m_parser.m_nNameLength + m_parser.m_nExtensionSeparatorLength + m_parser.m_nExtensionLength); else return "";}CHXString CHXFileSpecifier::GetTitle() const{ if(IsSet()) return m_parser.GetSubstring(m_parser.m_nVolumeLength + m_parser.m_nParentLength + m_parser.m_nSeparatorLength, m_parser.m_nNameLength); else return "";}CHXString CHXFileSpecifier::GetExtension() const{ if(IsSet()) return m_parser.GetSubstring(m_parser.m_nVolumeLength + m_parser.m_nParentLength + m_parser.m_nSeparatorLength + m_parser.m_nNameLength + m_parser.m_nExtensionSeparatorLength,-1); else return "";}CHXString CHXFileSpecifier::GetPersistentString() const{ return m_parser.GetPersistentString();}HX_RESULT CHXFileSpecifier::SetFromPersistentString(const char *pBuffer){ m_parser.SetFromPersistentString(pBuffer); return HXR_OK;}void CHXFileSpecifier::Unset(){ m_parser.UnSet();}HX_RESULT CHXFileSpecifier::SetFromURL(const char *pBuffer){ CHXString strURL, strChoppedURL; int nChop; int nLength; const BOOL kReplaceAll = TRUE; Unset(); strURL = pBuffer; nLength = strURL.GetLength(); nChop = 0; if (strURL.Left(9) == "file:////") nChop = 7; else if (strURL.Left(8) == "file:///") nChop = 8; else if (strURL.Left(7) == "file://") nChop = 7; else if (strURL.Left(5) == "file:") nChop = 5; else if (strURL.Left(10) == "tfile:////") nChop = 8; else if (strURL.Left(9) == "tfile:///") nChop = 9; else if (strURL.Left(8) == "tfile://") nChop = 8; else if (strURL.Left(6) == "tfile:") nChop = 6; if (nChop > 0) { strChoppedURL = strURL.Right(nLength - nChop); strChoppedURL.FindAndReplace("|", ":", kReplaceAll); strChoppedURL.FindAndReplace("/", "\\", kReplaceAll); m_parser.ParsePath(strChoppedURL); } return IsSet() ? HXR_OK : HXR_FAILED;}////////////////////////////////////////////////////////////// CHXDirSpecifier////////////////////////////////////////////////////////////CHXDirSpecifier::CHXDirSpecifier(){}CHXDirSpecifier::CHXDirSpecifier(const char* psz){ m_parser.ParsePath(psz);}CHXDirSpecifier::CHXDirSpecifier(const CHXString &str){ m_parser.ParsePath(str);}CHXDirSpecifier::CHXDirSpecifier(const CHXDirSpecifier &other){ *this = other;}CHXDirSpecifier::~CHXDirSpecifier(){}CHXDirSpecifier &CHXDirSpecifier::operator=(const CHXDirSpecifier &other){ m_parser = other.m_parser; return *this;}CHXDirSpecifier& CHXDirSpecifier::operator=(const char* sPath){ m_parser.ParsePath(sPath); return *this;}CHXDirSpecifier& CHXDirSpecifier::operator=(const CHXString& sPath){ m_parser.ParsePath(sPath); return *this;}BOOL CHXDirSpecifier::operator==(const CHXDirSpecifier &other){ // for now, just returns if the paths are identical // in the future, should normalize paths (i.e. remove duplicate slashes, resolve ..\..\.. type issues return m_parser == other.m_parser;}BOOL CHXDirSpecifier::operator!=(const CHXDirSpecifier &other){ // for now, just returns if the paths are not identical // in the future, should normalize paths (i.e. remove duplicate slashes, resolve ..\..\.. type issues return m_parser != other.m_parser;}CHXString CHXDirSpecifier::GetPathName() const{ return m_parser.GetPathName();}BOOL CHXDirSpecifier::IsSet() const{ return m_parser.IsSet();}BOOL CHXDirSpecifier::IsVolume() const{ return (IsSet() ? (m_parser.m_path.GetLength() == (UINT32)m_parser.m_nVolumeLength) : FALSE);}CHXString CHXDirSpecifier::GetName() const{ if(IsSet()) return m_parser.GetSubstring(m_parser.m_nVolumeLength + m_parser.m_nParentLength + m_parser.m_nSeparatorLength, m_parser.m_nNameLength + m_parser.m_nExtensionSeparatorLength + m_parser.m_nExtensionLength); else return "";}CHXDirSpecifier CHXDirSpecifier::GetParentDirectory() const{ if(IsSet()) return m_parser.GetSubstring(0, m_parser.m_nVolumeLength + m_parser.m_nParentLength); else return CHXDirSpecifier();}CHXDirSpecifier CHXDirSpecifier::GetVolume() const{ if(IsSet()) return m_parser.GetSubstring(0, m_parser.m_nVolumeLength); else return CHXDirSpecifier();}CHXFileSpecifier CHXDirSpecifier::SpecifyChildFile(const char *child) const{ if(IsSet()) { int nlast_ch = m_parser.m_path.GetLength() - 1; if(m_parser.m_path.ReverseFind('\\') == nlast_ch || m_parser.m_path.ReverseFind('/') == nlast_ch) return m_parser.m_path + child; else return m_parser.m_path + '\\' + child; } else return child;}CHXDirSpecifier CHXDirSpecifier::SpecifyChildDirectory(const char *child) const{ if(IsSet()) { int nlast_ch = m_parser.m_path.GetLength() - 1; if(m_parser.m_path.ReverseFind('\\') == nlast_ch || m_parser.m_path.ReverseFind('/') == nlast_ch) return m_parser.m_path + child; else return m_parser.m_path + '\\' + child; } else return child;}CHXString CHXDirSpecifier::GetPersistentString() const{ return m_parser.GetPersistentString();}HX_RESULT CHXDirSpecifier::SetFromPersistentString(const char *pBuffer){ m_parser.SetFromPersistentString(pBuffer); return HXR_OK;}#if 0Utility class:might be things like IsLocal() is this on a server or a local volume Rename() GetFilesInDirectory() (gets a list into a buffer; much better than an iterator) GetFileType() GetFileModificationDate() GetFileSize()#endif // 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -