diff --git a/far/changelog b/far/changelog index 5d9507d2b5..993004c998 100644 --- a/far/changelog +++ b/far/changelog @@ -1,4 +1,10 @@ -drkns 03.03.2016 21:29:48 +0200 - build 4569 +drkns 04.03.2016 22:12:43 +0200 - build 4570 + +1. Немного переделана работа с описаниями - теперь в файлы должно вноситься меньше изменений при обновлении. + +2. Прочий рефакторинг. + +drkns 03.03.2016 21:29:48 +0200 - build 4569 1. Уточнение 4568. diff --git a/far/codepage.hpp b/far/codepage.hpp index fef4b2b35c..d0d05664a4 100644 --- a/far/codepage.hpp +++ b/far/codepage.hpp @@ -37,11 +37,61 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace unicode { +// TODO: replace after decommissioning VC10 +// #define NOT_PTR(T) typename T, typename std::enable_if::value>::type* = nullptr +// typename + +#define NOT_PTR(result_type) typename std::enable_if::value, result_type>::type + size_t to(uintptr_t Codepage, const wchar_t* Data, size_t Size, char* Buffer, size_t BufferSize, bool* UsedDefaultChar = nullptr); + template + NOT_PTR(size_t) to(uintptr_t Codepage, const T& Data, char* Buffer, size_t BufferSize, bool* UsedDefaultChar = nullptr) + { + return to(Codepage, Data.data(), Data.size(), Buffer, BufferSize, UsedDefaultChar); + } + template + NOT_PTR(size_t) to(uintptr_t Codepage, const wchar_t* Data, size_t Size, T& Buffer, bool* UsedDefaultChar = nullptr) + { + return to(Codepage, Data, Size, Buffer.data(), Buffer.size(), UsedDefaultChar); + } + template + NOT_PTR(size_t) to(uintptr_t Codepage, const T& Data, Y& Buffer, bool* UsedDefaultChar = nullptr) + { + return to(Codepage, Data.data(), Data.size(), Buffer.data(), Buffer.size(), UsedDefaultChar); + } + std::string to(uintptr_t Codepage, const wchar_t* Data, size_t Size, bool* UsedDefaultChar = nullptr); + template + NOT_PTR(std::string) to(uintptr_t Codepage, const T& Data, bool* UsedDefaultChar = nullptr) + { + return to(Codepage, Data.data(), Data.size(), UsedDefaultChar); + } size_t from(uintptr_t Codepage, const char* Data, size_t Size, wchar_t* Buffer, size_t BufferSize); + template + NOT_PTR(size_t) from(uintptr_t Codepage, const T& Data, wchar_t* Buffer, size_t BufferSize) + { + return from(Codepage, Data.data(), Data.size(), Buffer, BufferSize); + } + template + NOT_PTR(size_t) from(uintptr_t Codepage, const char* Data, size_t Size, T& Buffer) + { + return from(Codepage, Data, Size, Buffer.data(), Buffer.size()); + } + template + NOT_PTR(size_t) from(uintptr_t Codepage, const T& Data, Y& Buffer) + { + return from(Codepage, Data.data(), Data.size(), Buffer.data(), Buffer.size()); + } + string from(uintptr_t Codepage, const char* Data, size_t Size); + template + NOT_PTR(string) from(uintptr_t Codepage, const T& Data) + { + return from(Codepage, Data.data(), Data.size()); + } + +#undef NOT_PTR } void swap_bytes(const void* Src, void* Dst, size_t SizeInBytes); diff --git a/far/copy.cpp b/far/copy.cpp index 23e9061782..f42e541227 100644 --- a/far/copy.cpp +++ b/far/copy.cpp @@ -1937,7 +1937,7 @@ COPY_CODES ShellCopy::CopyFileTree(const string& Dest) { if (!strRenamedName.empty()) { - DestDiz.DeleteDiz(strSelName,strSelShortName); + DestDiz.Erase(strSelName,strSelShortName); SrcPanel->CopyDiz(strSelName,strSelShortName,strRenamedName,strRenamedName,&DestDiz); } else diff --git a/far/dizlist.cpp b/far/dizlist.cpp index fdab64fe82..bd7e5226cc 100644 --- a/far/dizlist.cpp +++ b/far/dizlist.cpp @@ -48,8 +48,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cache.hpp" DizList::DizList(): - Modified(false), - OrigCodePage(CP_DEFAULT) + m_CodePage(CP_DEFAULT), + m_Modified() { } @@ -59,10 +59,10 @@ DizList::~DizList() void DizList::Reset() { - DizData.clear(); + m_DizData.clear(); m_OrderForWrite.clear(); - Modified=false; - OrigCodePage=CP_DEFAULT; + m_Modified = false; + m_CodePage = CP_DEFAULT; } static void PR_ReadingMsg() @@ -86,13 +86,13 @@ void DizList::Read(const string& Path, const string* DizName) { if (DizName) { - strDizFileName = *DizName; + m_DizFileName = *DizName; } else { - strDizFileName = Path; + m_DizFileName = Path; - if (!PathCanHoldRegularFile(strDizFileName)) + if (!PathCanHoldRegularFile(m_DizFileName)) break; string strArgName; @@ -101,12 +101,12 @@ void DizList::Read(const string& Path, const string* DizName) if (!NamePtr) break; - AddEndSlash(strDizFileName); - strDizFileName += strArgName; + AddEndSlash(m_DizFileName); + m_DizFileName += strArgName; } os::fs::file DizFile; - if (DizFile.Open(strDizFileName,GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING)) + if (DizFile.Open(m_DizFileName,GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING)) { clock_t StartTime=clock(); uintptr_t CodePage=CP_DEFAULT; @@ -117,11 +117,11 @@ void DizList::Read(const string& Path, const string* DizName) GetFileString GetStr(DizFile, CodePage); - auto LastAdded = DizData.end(); + auto LastAdded = m_DizData.end(); string DizText; while (GetStr.GetString(DizText)) { - if (!(DizData.size() & 127) && clock() - StartTime > CLOCKS_PER_SEC) + if (!(m_DizData.size() & 127) && clock() - StartTime > CLOCKS_PER_SEC) { SetCursorType(false, 0); PR_ReadingMsg(); @@ -136,11 +136,32 @@ void DizList::Read(const string& Path, const string* DizName) { if(!IsSpace(DizText.front())) { - LastAdded = AddRecord(DizText); + auto NameBegin = DizText.cbegin(); + auto NameEnd = DizText.cend(); + auto DescBegin = DizText.cend(); + + if (DizText.front() == L'"') + { + ++NameBegin; + NameEnd = std::find(NameBegin, DizText.cend(), L'"'); + if (NameEnd != DizText.cend()) + { + DescBegin = NameEnd + 1; + } + } + else + { + DescBegin = NameEnd = std::find(NameBegin, DizText.cend(), L' '); + } + + // Insert unconditionally + LastAdded = Insert(string(NameBegin, NameEnd)); + // TODO: direct emplace_back after decommissioning VC10 + LastAdded->second.emplace_back(string(DescBegin, DizText.end())); } else { - if (LastAdded != DizData.end()) + if (LastAdded != m_DizData.end()) { LastAdded->second.emplace_back(DizText); } @@ -148,9 +169,8 @@ void DizList::Read(const string& Path, const string* DizName) } } - OrigCodePage=CodePage; - Modified=false; - DizFile.Close(); + m_CodePage=CodePage; + m_Modified = false; return; } @@ -158,136 +178,138 @@ void DizList::Read(const string& Path, const string* DizName) break; } - Modified=false; - strDizFileName.clear(); + m_Modified = false; + m_DizFileName.clear(); } -DizList::desc_map::iterator DizList::AddRecord(const string& Name, const string& Description) +const wchar_t* DizList::Get(const string& Name, const string& ShortName, const __int64 FileSize) const { - Modified=true; - std::list DescStrings; - DescStrings.emplace_back(Description); - // TODO: direct emplace after decommissioning VC10 - const auto Result = DizData.emplace(VALUE_TYPE(DizData)(Name, std::move(DescStrings))); - if (Result.second) - { - m_OrderForWrite.emplace_back(&*Result.first); - } - return Result.first; -} - -DizList::desc_map::iterator DizList::AddRecord(const string& DizText) -{ - string::const_iterator NameBegin, NameEnd, DescBegin; + const auto Iterator = Find(Name, ShortName); - if (DizText.front() == L'"') + if (Iterator == m_DizData.end()) { - NameBegin = DizText.cbegin() + 1; - NameEnd = std::find(NameBegin, DizText.cend(), L'"'); - DescBegin = NameEnd == DizText.cend()? NameEnd : NameEnd + 1; + return nullptr; } - else + + const auto& Description = Iterator->second.front(); + if (Description.empty()) { - NameBegin = DizText.cbegin(); - NameEnd = std::find_if(ALL_CONST_RANGE(DizText), IsSpace); - DescBegin = NameEnd; + return nullptr; } - return AddRecord(string(NameBegin, NameEnd), string(DescBegin, DizText.end())); -} - -const wchar_t* DizList::GetDizTextAddr(const string& Name, const string& ShortName, const __int64 FileSize) -{ - const wchar_t *DizText=nullptr; - const auto DizPos = Find(Name, ShortName); + auto Begin = Description.begin(); - if (DizPos != DizData.end()) + if (std::iswdigit(*Begin)) { - DizText=DizPos->second.front().data(); + const auto SizeText = std::to_wstring(FileSize); + auto DescrIterator = Begin; + auto SkipSize = true; - if (std::iswdigit(*DizText)) + for (size_t i = 0; i < SizeText.size() && DescrIterator != Description.cend() ; ++i, ++DescrIterator) { - const auto SizeText = std::to_wstring(FileSize); - const wchar_t *DizPtr=DizText; - bool SkipSize=true; - - for (size_t i = 0; i < SizeText.size(); ++i, ++DizPtr) + if (*DescrIterator != L',' && *DescrIterator != L'.' && *DescrIterator != SizeText[i]) { - if (*DizPtr!=L',' && *DizPtr!=L'.' && *DizPtr != SizeText[i]) - { - SkipSize=false; - break; - } + SkipSize=false; + break; } + } - if (SkipSize && IsSpace(*DizPtr)) - { - DizText=DizPtr; - } + if (SkipSize && IsSpace(*DescrIterator)) + { + Begin = DescrIterator; } - while (*DizText && IsSpace(*DizText)) - DizText++; } - return DizText; + Begin = std::find_if_not(Begin, Description.cend(), IsSpace); + if (Begin == Description.cend()) + { + return nullptr; + } + + return &*Begin; } -DizList::desc_map::iterator DizList::Find(const string& Name, const string& ShortName) +template +// TODO: remove this after decommissioning VC10 +#pragma push_macro("decltype") +#undef decltype +auto Find_t(T& Map, const string& Name, const string& ShortName, uintptr_t Codepage) -> decltype(Map.begin()) +#pragma pop_macro("decltype") { - auto i = DizData.find(Name); - if(i == DizData.end()) - i = DizData.find(ShortName); + auto Iterator = Map.find(Name); + if (Iterator == Map.end()) + Iterator = Map.find(ShortName); //если файл описаний был в OEM/ANSI то имена файлов могут не совпадать с юникодными - if (i == DizData.end() && !IsUnicodeOrUtfCodePage(OrigCodePage) && OrigCodePage!=CP_DEFAULT) + if (Iterator == Map.end() && !IsUnicodeOrUtfCodePage(Codepage) && Codepage != CP_DEFAULT) { - const auto tmp = unicode::to(OrigCodePage, Name.data(), Name.size()); - const auto strRecoded = wide_n(tmp.data(), tmp.size(), OrigCodePage); + const auto strRecoded = unicode::from(Codepage, unicode::to(Codepage, Name)); + if (strRecoded == Name) + { + return Iterator; + } + return Map.find(strRecoded); + } - if (strRecoded==Name) - return DizData.end(); + return Iterator; +} - return DizData.find(strRecoded); - } +DizList::desc_map::iterator DizList::Find(const string& Name, const string& ShortName) +{ + return Find_t(m_DizData, Name, ShortName, m_CodePage); +} - return i; +DizList::desc_map::const_iterator DizList::Find(const string& Name, const string& ShortName) const +{ + return Find_t(m_DizData, Name, ShortName, m_CodePage); +} + +DizList::desc_map::iterator DizList::Insert(const string& Name) +{ + // TODO: direct emplace after decommissioning VC10 + auto Iterator = m_DizData.insert(VALUE_TYPE(m_DizData)(Name, std::list())); + m_OrderForWrite.push_back(&*Iterator); + return Iterator; } -bool DizList::DeleteDiz(const string& Name,const string& ShortName) +bool DizList::Erase(const string& Name,const string& ShortName) { - const auto i = Find(Name, ShortName); - if (i != DizData.end()) + const auto Iterator = Find(Name, ShortName); + if (Iterator == m_DizData.end()) { - m_OrderForWrite.erase(std::find(ALL_RANGE(m_OrderForWrite), &*i)); - DizData.erase(i); - Modified=true; - return true; + return false; } - return false; + + m_OrderForWrite.erase(std::find(ALL_RANGE(m_OrderForWrite), &*Iterator)); + m_DizData.erase(Iterator); + m_Modified = true; + return true; } bool DizList::Flush(const string& Path,const string* DizName) { - if (!Modified) + if (!m_Modified) + { return true; + } if (DizName) { - strDizFileName = *DizName; + m_DizFileName = *DizName; } - else if (strDizFileName.empty()) + else if (m_DizFileName.empty()) { - if (DizData.empty() || Path.empty()) + if (m_DizData.empty() || Path.empty()) return false; - strDizFileName = Path; - AddEndSlash(strDizFileName); + m_DizFileName = Path; + AddEndSlash(m_DizFileName); string strArgName; GetCommaWord(Global->Opt->Diz.strListNames.data(),strArgName); - strDizFileName += strArgName; + m_DizFileName += strArgName; } - DWORD FileAttr=os::GetFileAttributes(strDizFileName); + DWORD FileAttr=os::GetFileAttributes(m_DizFileName); if (FileAttr != INVALID_FILE_ATTRIBUTES) { @@ -295,7 +317,7 @@ bool DizList::Flush(const string& Path,const string* DizName) { if(Global->Opt->Diz.ROUpdate) { - if(os::SetFileAttributes(strDizFileName,FileAttr)) + if(os::SetFileAttributes(m_DizFileName,FileAttr)) { FileAttr^=FILE_ATTRIBUTE_READONLY; } @@ -304,7 +326,7 @@ bool DizList::Flush(const string& Path,const string* DizName) if(!(FileAttr&FILE_ATTRIBUTE_READONLY)) { - os::SetFileAttributes(strDizFileName,FILE_ATTRIBUTE_ARCHIVE); + os::SetFileAttributes(m_DizFileName,FILE_ATTRIBUTE_ARCHIVE); } else { @@ -318,8 +340,8 @@ bool DizList::Flush(const string& Path,const string* DizName) bool AnyError=false; bool EmptyDiz=true; - // Don't use CreationDisposition=CREATE_ALWAYS here - it's kills alternate streams - if(!DizData.empty() && DizFile.Open(strDizFileName, GENERIC_WRITE, FILE_SHARE_READ, nullptr, FileAttr==INVALID_FILE_ATTRIBUTES?CREATE_NEW:TRUNCATE_EXISTING)) + // Don't use CreationDisposition=CREATE_ALWAYS here - it kills alternate streams + if(!m_DizData.empty() && DizFile.Open(m_DizFileName, GENERIC_WRITE, FILE_SHARE_READ, nullptr, FileAttr==INVALID_FILE_ATTRIBUTES?CREATE_NEW:TRUNCATE_EXISTING)) { uintptr_t CodePage = Global->Opt->Diz.SaveInUTF ? CP_UTF8 : (Global->Opt->Diz.AnsiByDefault ? CP_ACP : CP_OEMCP); @@ -341,18 +363,14 @@ bool DizList::Flush(const string& Path,const string* DizName) const auto& i = *i_ptr; string dump = i.first; QuoteSpaceOnly(dump); - dump += i.second.front(); - if(i.second.size() > 1) + FOR(const auto& j, i.second) { - std::for_each(std::next(i.second.cbegin()), i.second.cend(), [&](CONST_REFERENCE(i.second) j) - { - dump.append(L"\r\n ").append(j); - }); + dump.append(j).append(L"\r\n"); } - DWORD Size=static_cast((dump.size() + 1) * (CodePage == CP_UTF8? 3 : 1)); //UTF-8, up to 3 bytes per char support + const auto Size = dump.size() * (CodePage == CP_UTF8? 3 : 1); //UTF-8, up to 3 bytes per char support char_ptr DizText(Size); - if (const auto BytesCount = unicode::to(CodePage, dump.data(), dump.size(), DizText.get(), Size)) + if (const auto BytesCount = unicode::to(CodePage, dump, DizText.get(), Size)) { if(Cache.Write(DizText.get(), BytesCount)) { @@ -363,11 +381,6 @@ bool DizList::Flush(const string& Path,const string* DizName) AnyError=true; break; } - if(!Cache.Write("\r\n", 2)) - { - AnyError=true; - break; - } } } } @@ -389,14 +402,14 @@ bool DizList::Flush(const string& Path,const string* DizName) { FileAttr=FILE_ATTRIBUTE_ARCHIVE|(Global->Opt->Diz.SetHidden?FILE_ATTRIBUTE_HIDDEN:0); } - os::SetFileAttributes(strDizFileName,FileAttr); + os::SetFileAttributes(m_DizFileName,FileAttr); } else { if(AnyError) Global->CatchError(); - os::DeleteFile(strDizFileName); + os::DeleteFile(m_DizFileName); if(AnyError) { Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MError),MSG(MCannotUpdateDiz),MSG(MOk)); @@ -404,40 +417,43 @@ bool DizList::Flush(const string& Path,const string* DizName) } } - Modified=false; + m_Modified=false; return true; } -void DizList::AddDizText(const string& Name,const string& ShortName,const string& DizText) +void DizList::Set(const string& Name,const string& ShortName,const string& DizText) { - DeleteDiz(Name, ShortName); - string strQuotedName = Name; - QuoteSpaceOnly(strQuotedName); - AddRecord(FormatString()<Opt->Diz.StartPos>1?Global->Opt->Diz.StartPos-2:0)<second; + List.clear(); + + const auto KeySize = Iterator->first.size(); + const auto NumberOfSpaces = std::max(static_cast(Global->Opt->Diz.StartPos - 1), static_cast(KeySize + 1)) - KeySize; + List.emplace_back(string(NumberOfSpaces, L' ') + DizText); + m_Modified = true; } -bool DizList::CopyDiz(const string& Name, const string& ShortName, const string& DestName, const string& DestShortName, DizList* DestDiz) +bool DizList::CopyDiz(const string& Name, const string& ShortName, const string& DestName, const string& DestShortName, DizList* DestDiz) const { - const auto i = Find(Name, ShortName); - - if (i == DizData.end()) + const auto Iterator = Find(Name, ShortName); + if (Iterator == m_DizData.end()) + { return false; + } - DestDiz->DeleteDiz(DestName, DestShortName); - // TODO: direct emplace after decommissioning VC10 - const auto it = DestDiz->DizData.emplace(VALUE_TYPE(DizData)(DestName, i->second)); - if (it.second) + auto DestIterator = DestDiz->Find(DestName, DestShortName); + if (DestIterator == DestDiz->m_DizData.end()) { - DestDiz->m_OrderForWrite.emplace_back(&*it.first); + DestIterator = DestDiz->Insert(DestName); } - DestDiz->Modified = true; + DestIterator->second = Iterator->second; + DestDiz->m_Modified = true; return true; } - -bool DizList::diz_less::operator()(const string& a, const string& b) const -{ - return StrCmpI(a, b) < 0; -} - diff --git a/far/dizlist.hpp b/far/dizlist.hpp index 8fd59e66e9..10f7873696 100644 --- a/far/dizlist.hpp +++ b/far/dizlist.hpp @@ -41,32 +41,30 @@ class DizList: noncopyable DizList(); ~DizList(); - void Read(const string& Path, const string* DizName=nullptr); + void Read(const string& Path, const string* DizName = nullptr); + + void Set(const string& Name, const string& ShortName, const string& DizText); + bool Erase(const string& Name, const string& ShortName); + + const wchar_t* Get(const string& Name, const string& ShortName, const __int64 FileSize) const; + void Reset(); - const wchar_t *GetDizTextAddr(const string& Name, const string& ShortName, const __int64 FileSize); - bool DeleteDiz(const string& Name, const string& ShortName); bool Flush(const string& Path, const string *DizName=nullptr); - void AddDizText(const string& Name, const string& ShortName, const string& DizText); - bool CopyDiz(const string& Name, const string& ShortName, const string& DestName, const string& DestShortName,DizList *DestDiz); - const string& GetDizName() const { return strDizFileName; } + bool CopyDiz(const string& Name, const string& ShortName, const string& DestName, const string& DestShortName,DizList *DestDiz) const; + const string& GetDizName() const { return m_DizFileName; } private: - struct diz_less - { - bool operator()(const string& a, const string& b) const; - }; - - typedef std::map, diz_less> desc_map; + typedef std::unordered_multimap> desc_map; + desc_map::iterator Insert(const string& Name); desc_map::iterator Find(const string& Name, const string& ShortName); - desc_map::iterator AddRecord(const string& Name, const string& Description); - desc_map::iterator AddRecord(const string& DizText); + desc_map::const_iterator Find(const string& Name, const string& ShortName) const; - string strDizFileName; - desc_map DizData; - std::list m_OrderForWrite; - bool Modified; - uintptr_t OrigCodePage; + desc_map m_DizData; + std::list::type> m_OrderForWrite; + string m_DizFileName; + uintptr_t m_CodePage; + bool m_Modified; }; #endif // DIZLIST_HPP_0115E7F4_A98B_42CE_A43A_275B8A6DFFEF diff --git a/far/editor.cpp b/far/editor.cpp index 0cd8fc5815..49df560439 100644 --- a/far/editor.cpp +++ b/far/editor.cpp @@ -5016,7 +5016,7 @@ int64_t Editor::GetCurPos(bool file_pos, bool add_bom) const const auto TotalSize = std::accumulate(Lines.cbegin(), m_it_TopScreen.cbase(), bom, [&](uint64_t Value, CONST_REFERENCE(Lines) line) -> uint64_t { const auto& Str = line.GetString(); - return Value + (Multiplier != Unknown? Str.size() : unicode::to(m_codepage, Str.data(), Str.size(), nullptr, 0)) + wcslen(line.GetEOL()); + return Value + (Multiplier != Unknown? Str.size() : unicode::to(m_codepage, Str, nullptr, 0)) + wcslen(line.GetEOL()); }); return Multiplier != Unknown? TotalSize * Multiplier : TotalSize; @@ -7054,7 +7054,7 @@ void Editor::SetCacheParams(EditorPosCache &pc, bool count_bom) if (m_codepage == CP_UTF8) { - TotalSize += unicode::to(CP_UTF8, SaveStr.data(), SaveStr.size(), nullptr, 0); + TotalSize += unicode::to(CP_UTF8, SaveStr, nullptr, 0); } else { @@ -7144,7 +7144,7 @@ DWORD Editor::EditSetCodePage(const iterator& edit, uintptr_t codepage, bool che if (3 * static_cast(edit->m_Str.size()) + 1 > decoded.size()) decoded.resize(256 + 4 * edit->m_Str.size()); - const size_t length = unicode::to(m_codepage, edit->m_Str.data(), edit->m_Str.size(), decoded.data(), decoded.size(), lpUsedDefaultChar); + const size_t length = unicode::to(m_codepage, edit->m_Str, decoded, lpUsedDefaultChar); if (!length || UsedDefaultChar) { Ret |= SETCP_WC2MBERROR; diff --git a/far/fileedit.cpp b/far/fileedit.cpp index 052242b374..2970c10c50 100644 --- a/far/fileedit.cpp +++ b/far/fileedit.cpp @@ -2071,7 +2071,7 @@ int FileEditor::SaveFile(const string& Name,int Ask, bool bSaveAs, int TextForma { const auto EncodedSize = unicode::to(codepage, Data, Size, nullptr, 0); Buffer.resize(EncodedSize); - unicode::to(codepage, Data, Size, Buffer.data(), Buffer.size()); + unicode::to(codepage, Data, Size, Buffer); if (!Cache.Write(Buffer.data(), Buffer.size())) { bError = true; diff --git a/far/filelist.cpp b/far/filelist.cpp index 6db6103ae4..6834feda16 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -4752,7 +4752,7 @@ void FileList::SelectSortMode() void FileList::DeleteDiz(const string& Name, const string& ShortName) { if (m_PanelMode == panel_mode::NORMAL_PANEL) - Diz.DeleteDiz(Name,ShortName); + Diz.Erase(Name,ShortName); } @@ -4791,8 +4791,7 @@ void FileList::DescribeFiles() while (GetSelName(&strSelName,FileAttr,&strSelShortName)) { string strDizText, strMsg, strQuotedName; - const wchar_t *PrevText; - PrevText=Diz.GetDizTextAddr(strSelName,strSelShortName,GetLastSelectedSize()); + const auto PrevText = NullToEmpty(Diz.Get(strSelName,strSelShortName,GetLastSelectedSize())); strQuotedName = strSelName; QuoteSpaceOnly(strQuotedName); strMsg.append(MSG(MEnterDescription)).append(L" ").append(strQuotedName).append(L":"); @@ -4801,7 +4800,7 @@ void FileList::DescribeFiles() Для Ctrl-Z не нужно брать предыдущее значение! */ if (!GetString(MSG(MDescribeFiles),strMsg.data(),L"DizText", - PrevText ? PrevText:L"",strDizText, + PrevText, strDizText, L"FileDiz",FIB_ENABLEEMPTY|(!DizCount?FIB_NOUSELASTHISTORY:0)|FIB_BUTTONS, nullptr,nullptr,nullptr,&DescribeFileId)) break; @@ -4810,11 +4809,11 @@ void FileList::DescribeFiles() if (strDizText.empty()) { - Diz.DeleteDiz(strSelName,strSelShortName); + Diz.Erase(strSelName,strSelShortName); } else { - Diz.AddDizText(strSelName,strSelShortName,strDizText); + Diz.Set(strSelName,strSelShortName,strDizText); } ClearLastGetSelection(); @@ -5770,13 +5769,13 @@ void FileList::PutDizToPlugin(FileList *DestPanel, const std::vectorDiz.DeleteDiz(i.FileName, i.AlternateFileName); + Code = DestPanel->Diz.Erase(i.FileName, i.AlternateFileName); else { Code = SrcDiz->CopyDiz(i.FileName, i.AlternateFileName, i.FileName, i.AlternateFileName, &DestPanel->Diz); if (Code && Move) - SrcDiz->DeleteDiz(i.FileName, i.AlternateFileName); + SrcDiz->Erase(i.FileName, i.AlternateFileName); } if (Code) @@ -7360,7 +7359,7 @@ void FileList::ReadDiz(PluginPanelItem *ItemList,int ItemLength,DWORD dwFlags) if (!i.DizText) { i.DeleteDiz = false; - i.DizText = Diz.GetDizTextAddr(i.strName, i.strShortName, i.FileSize); + i.DizText = Diz.Get(i.strName, i.strShortName, i.FileSize); } }); } diff --git a/far/filestr.cpp b/far/filestr.cpp index 53ed790a4f..42c7cc0490 100644 --- a/far/filestr.cpp +++ b/far/filestr.cpp @@ -235,7 +235,7 @@ bool GetFileString::GetString(LPWSTR* DestStr, size_t& Length) } if (bGet) { - nResultLength = unicode::from(m_CodePage, CharStr.data(), CharStr.size(), m_wStr.data(), m_wStr.size()); + nResultLength = unicode::from(m_CodePage, CharStr, m_wStr); if (!nResultLength) { Result = GetLastError(); @@ -243,9 +243,9 @@ bool GetFileString::GetString(LPWSTR* DestStr, size_t& Length) } if (Result == ERROR_INSUFFICIENT_BUFFER) { - nResultLength = unicode::from(m_CodePage, CharStr.data(), CharStr.size(), nullptr, 0); + nResultLength = unicode::from(m_CodePage, CharStr, nullptr, 0); m_wStr.resize(nResultLength); - nResultLength = unicode::from(m_CodePage, CharStr.data(), CharStr.size(), m_wStr.data(), m_wStr.size()); + nResultLength = unicode::from(m_CodePage, CharStr, m_wStr); } m_wStr.resize(nResultLength); diff --git a/far/findfile.cpp b/far/findfile.cpp index f241cf78bb..caad439659 100644 --- a/far/findfile.cpp +++ b/far/findfile.cpp @@ -1184,7 +1184,7 @@ bool background_searcher::LookForString(const string& Name) else { // Конвертируем буфер чтения из кодировки поиска в UTF-16 - bufferCount = unicode::from(i.CodePage, readBufferA.data(), readBlockSize, readBuffer.data(), readBuffer.size()); + bufferCount = unicode::from(i.CodePage, readBufferA.data(), readBlockSize, readBuffer); // Выходим, если нам не удалось сконвертировать строку if (!bufferCount) diff --git a/far/fnparce.cpp b/far/fnparce.cpp index 697adec9e0..3afa7759b3 100644 --- a/far/fnparce.cpp +++ b/far/fnparce.cpp @@ -827,7 +827,7 @@ bool Panel::MakeListFile(string &strListFileName,bool ShortNames,const string& M } else { - Buffer = unicode::to(CodePage, strFileName.data(), strFileName.size()); + Buffer = unicode::to(CodePage, strFileName); Blob = blob(Buffer.data(), Buffer.size()); } diff --git a/far/plugsettings.cpp b/far/plugsettings.cpp index 9d65444a3e..c7ba3b181e 100644 --- a/far/plugsettings.cpp +++ b/far/plugsettings.cpp @@ -109,9 +109,9 @@ PluginSettings::PluginSettings(const GUID& Guid, bool Local): Diz.Read(strDbPath); string strDbName = strGuid + L".db"; string Description = string(pPlugin->GetTitle()) + L" (" + pPlugin->GetDescription() + L")"; - if(Description != NullToEmpty(Diz.GetDizTextAddr(strDbName, L"", 0))) + if(Description != NullToEmpty(Diz.Get(strDbName, L"", 0))) { - Diz.AddDizText(strDbName, L"", Description); + Diz.Set(strDbName, L"", Description); Diz.Flush(strDbPath); } } diff --git a/far/usermenu.cpp b/far/usermenu.cpp index 51b298e8af..c6e2ac7518 100644 --- a/far/usermenu.cpp +++ b/far/usermenu.cpp @@ -299,7 +299,7 @@ void UserMenu::SaveMenu(const string& MenuFileName) } else { - Buffer = unicode::to(m_MenuCP, SerializedMenu.data(), SerializedMenu.size()); + Buffer = unicode::to(m_MenuCP, SerializedMenu); MenuBlob = blob(Buffer.data(), Buffer.size()); } diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 6af8b0fc38..688d05242d 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -m4_define(BUILD,4569)m4_dnl +m4_define(BUILD,4570)m4_dnl