📄 filespec.cpp
字号:
}}CHXString CHXPathParser::GetSubstring(int nStart, int nLength) const{ if(nLength == -1) nLength = m_path.GetLength() - nStart; return m_path.Mid(nStart, nLength);}CHXString CHXPathParser::GetPersistentString() const{ return m_path;}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;}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 CHXDirSpecifier(m_parser.GetSubstring(0, m_parser.m_nVolumeLength + m_parser.m_nParentLength)); else return CHXDirSpecifier();}CHXDirSpecifier CHXFileSpecifier::GetVolume() const{ if(IsSet()) return CHXDirSpecifier(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; Unset(); strURL = pBuffer; nLength = strURL.GetLength(); nChop = 0; if (strURL.Left(8) == "file:///") nChop = 8; else if (strURL.Left(7) == "file://") nChop = 7; else if (strURL.Left(5) == "file:") nChop = 5; if (nChop > 0) { strChoppedURL = strURL.Right(nLength - nChop); 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;}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 m_parser.m_path.GetLength() == m_parser.m_nVolumeLength;}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 CHXDirSpecifier(m_parser.GetSubstring(0, m_parser.m_nVolumeLength + m_parser.m_nParentLength)); else return CHXDirSpecifier();}CHXDirSpecifier CHXDirSpecifier::GetVolume() const{ if(IsSet()) return CHXDirSpecifier(m_parser.GetSubstring(0, m_parser.m_nVolumeLength)); else return CHXDirSpecifier();}CHXFileSpecifier CHXDirSpecifier::SpecifyChildFile(const char *child) const{ if(IsSet()) { char last_ch = m_parser.m_path[m_parser.m_path.GetLength() - 1]; if(last_ch == '\\' || last_ch == '/') return CHXFileSpecifier( m_parser.m_path + child ); else return CHXFileSpecifier( m_parser.m_path + '\\' + child ); } else return child;}CHXDirSpecifier CHXDirSpecifier::SpecifyChildDirectory(const char *child) const{ if(IsSet()) { char last_ch = m_parser.m_path[m_parser.m_path.GetLength() - 1]; if(last_ch == '\\' || last_ch == '/') return CHXDirSpecifier( m_parser.m_path + child ); else return CHXDirSpecifier( 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 + -