diff --git a/DesktopEditor/common/File.h b/DesktopEditor/common/File.h index 8d729de231..b6ebe04fe5 100644 --- a/DesktopEditor/common/File.h +++ b/DesktopEditor/common/File.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "Array.h" #include "errno.h" #include "Base64.h" @@ -569,7 +570,6 @@ namespace NSFile { return m_pFile; } - inline long GetFileSize() { return m_lFileSize; @@ -642,12 +642,12 @@ namespace NSFile m_lFilePosition = 0; return true; } - bool SeekFile(int lFilePosition) + bool SeekFile(int lFilePosition, int nSeekMode = 0) { if (!m_pFile) return false; - m_lFilePosition = fseek(m_pFile, lFilePosition, 0); + m_lFilePosition = fseek(m_pFile, lFilePosition, nSeekMode); return true; } bool ReadFile(BYTE* pData, DWORD nBytesToRead, DWORD& dwSizeRead) @@ -666,6 +666,25 @@ namespace NSFile size_t nCountWrite = fwrite((void*)pData, 1, nBytesCount, m_pFile); return true; } + long TellFile() + { + if (!m_pFile) + return 0; + + return ftell(m_pFile); + } + long SizeFile() + { + if (!m_pFile) + return 0; + + long lPos = TellFile(); + fseek(m_pFile, 0, SEEK_END); + m_lFileSize = ftell(m_pFile); + fseek(m_pFile, lPos, SEEK_SET); + + return m_lFileSize; + } void WriteStringUTF8(const std::wstring& strXml, bool bIsBOM = false) { BYTE* pData = NULL; diff --git a/DesktopEditor/common/String.h b/DesktopEditor/common/String.h index 91c275435b..006750d0ab 100644 --- a/DesktopEditor/common/String.h +++ b/DesktopEditor/common/String.h @@ -4,6 +4,7 @@ #include "CPEncodings/CodePage.h" #include #include +#include namespace NSString { @@ -234,6 +235,24 @@ namespace NSString return arrElements; } + static inline void ToLower(std::wstring& wsString) + { + std::transform(wsString.begin(), wsString.end(), wsString.begin(), ::towlower); + } + static inline void ToUpper(std::wstring& wsString) + { + std::transform(wsString.begin(), wsString.end(), wsString.begin(), ::towupper); + } + static inline void Replace(std::wstring& wsString, const std::wstring& wsFrom, const std::wstring& wsTo) + { + int nFromLen = wsFrom.length(); + int nToLen = wsTo.length(); + int nPos = -nToLen; + while (std::wstring::npos != (nPos = wsString.find(wsFrom, nPos + nToLen))) + { + wsString.replace(nPos, nFromLen, wsTo); + } + } }; #endif // _BUILD_STRING_CROSSPLATFORM_H_