• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revision28757 (tree)
Zeit2020-02-23 23:55:09
Autorcsware

Log Message

Deduplicate code

Ändern Zusammenfassung

Diff

--- trunk/src/ResText/ResModule.cpp (revision 28756)
+++ trunk/src/ResText/ResModule.cpp (revision 28757)
@@ -1885,29 +1885,12 @@
18851885 const std::sregex_iterator end;
18861886 for (std::sregex_iterator it(ss.cbegin(), ss.cend(), regRevMatch); it != end; ++it)
18871887 {
1888- size_t len;
1889-
1890- std::string str1 = (*it)[1];
1891- len = str1.size();
1892- auto bufw1 = std::make_unique<wchar_t[]>(len * 4 + 1);
1893- SecureZeroMemory(bufw1.get(), (len * 4 + 1) * sizeof(wchar_t));
1894- MultiByteToWideChar(CP_UTF8, 0, str1.c_str(), -1, bufw1.get(), (int)len * 4);
1895- std::wstring strIdNameVal = bufw1.get();
1888+ std::wstring strIdNameVal = CUnicodeUtils::StdGetUnicode((*it)[1].str());
18961889 strIdNameVal += L" - Ribbon name";
18971890
1898- std::string str2 = (*it)[2];
1899- len = str2.size();
1900- auto bufw2 = std::make_unique<wchar_t[]>(len * 4 + 1);
1901- SecureZeroMemory(bufw2.get(), (len * 4 + 1)*sizeof(wchar_t));
1902- MultiByteToWideChar(CP_UTF8, 0, str2.c_str(), -1, bufw2.get(), (int)len * 4);
1903- std::wstring strIdVal = bufw2.get();
1891+ std::wstring strIdVal = CUnicodeUtils::StdGetUnicode((*it)[2].str());
19041892
1905- std::string str3 = (*it)[3];
1906- len = str3.size();
1907- auto bufw3 = std::make_unique<wchar_t[]>(len * 4 + 1);
1908- SecureZeroMemory(bufw3.get(), (len * 4 + 1)*sizeof(wchar_t));
1909- MultiByteToWideChar(CP_UTF8, 0, str3.c_str(), -1, bufw3.get(), (int)len * 4);
1910- std::wstring str = bufw3.get();
1893+ std::wstring str = CUnicodeUtils::StdGetUnicode((*it)[3].str());
19111894
19121895 RESOURCEENTRY entry = m_StringEntries[str];
19131896 InsertResourceIDs(RT_RIBBON, 0, entry, std::stoi(strIdVal), strIdNameVal.c_str());
@@ -1922,12 +1905,7 @@
19221905 const std::regex regRevMatchName("</ELEMENT_NAME><NAME>([^<]+)</NAME>");
19231906 for (std::sregex_iterator it(ss.cbegin(), ss.cend(), regRevMatchName); it != end; ++it)
19241907 {
1925- std::string str = (*it)[1];
1926- size_t len = str.size();
1927- auto bufw = std::make_unique<wchar_t[]>(len * 4 + 1);
1928- SecureZeroMemory(bufw.get(), (len*4 + 1)*sizeof(wchar_t));
1929- MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, bufw.get(), (int)len*4);
1930- std::wstring ret = bufw.get();
1908+ std::wstring ret = CUnicodeUtils::StdGetUnicode((*it)[1].str());
19311909 RESOURCEENTRY entry = m_StringEntries[ret];
19321910 InsertResourceIDs(RT_RIBBON, 0, entry, (INT_PTR)lpszType, L" - Ribbon element");
19331911 if (wcschr(ret.c_str(), '%'))
@@ -1963,23 +1941,13 @@
19631941 MYERROR;
19641942
19651943 std::string ss = std::string((const char*)p, sizeres);
1966- size_t len = ss.size();
1967- auto bufw = std::make_unique<wchar_t[]>(len * 4 + 1);
1968- SecureZeroMemory(bufw.get(), (len*4 + 1)*sizeof(wchar_t));
1969- MultiByteToWideChar(CP_UTF8, 0, ss.c_str(), -1, bufw.get(), (int)len*4);
1970- std::wstring ssw = bufw.get();
1944+ std::wstring ssw = CUnicodeUtils::StdGetUnicode(ss);
19711945
1972-
19731946 const std::regex regRevMatch("<TEXT>([^<]+)</TEXT>");
19741947 const std::sregex_iterator end;
19751948 for (std::sregex_iterator it(ss.cbegin(), ss.cend(), regRevMatch); it != end; ++it)
19761949 {
1977- std::string str = (*it)[1];
1978- size_t slen = str.size();
1979- auto bufw2 = std::make_unique<wchar_t[]>(slen * 4 + 1);
1980- SecureZeroMemory(bufw2.get(), (slen*4 + 1)*sizeof(wchar_t));
1981- MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, bufw2.get(), (int)slen*4);
1982- std::wstring ret = bufw2.get();
1950+ std::wstring ret = CUnicodeUtils::StdGetUnicode((*it)[1].str());
19831951
19841952 RESOURCEENTRY entry = m_StringEntries[ret];
19851953 ret = L"<TEXT>" + ret + L"</TEXT>";
@@ -2004,12 +1972,7 @@
20041972 const std::regex regRevMatchName("</ELEMENT_NAME><NAME>([^<]+)</NAME>");
20051973 for (std::sregex_iterator it(ss.cbegin(), ss.cend(), regRevMatchName); it != end; ++it)
20061974 {
2007- std::string str = (*it)[1];
2008- size_t slen = str.size();
2009- auto bufw2 = std::make_unique<wchar_t[]>(slen * 4 + 1);
2010- SecureZeroMemory(bufw2.get(), (slen*4 + 1)*sizeof(wchar_t));
2011- MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, bufw2.get(), (int)slen*4);
2012- std::wstring ret = bufw2.get();
1975+ std::wstring ret = CUnicodeUtils::StdGetUnicode((*it)[1].str());
20131976
20141977 RESOURCEENTRY entry = m_StringEntries[ret];
20151978 ret = L"</ELEMENT_NAME><NAME>" + ret + L"</NAME>";
@@ -2032,7 +1995,7 @@
20321995 }
20331996
20341997 auto buf = std::make_unique<char[]>(ssw.size() * 4 + 1);
2035- int lengthIncTerminator = WideCharToMultiByte(CP_UTF8, 0, ssw.c_str(), -1, buf.get(), (int)len * 4, nullptr, nullptr);
1998+ int lengthIncTerminator = WideCharToMultiByte(CP_UTF8, 0, ssw.c_str(), -1, buf.get(), static_cast<int>(ssw.size()) * 4, nullptr, nullptr); //
20361999
20372000
20382001 if (!UpdateResource(m_hUpdateRes, RT_RIBBON, lpszType, (m_wTargetLang ? m_wTargetLang : wLanguage), buf.get(), lengthIncTerminator-1))
Show on old repository browser