diff --git a/Common/3dParty/html/css/src/StyleProperties.cpp b/Common/3dParty/html/css/src/StyleProperties.cpp
index e4b8be90b5..c2ffb22901 100644
--- a/Common/3dParty/html/css/src/StyleProperties.cpp
+++ b/Common/3dParty/html/css/src/StyleProperties.cpp
@@ -63,7 +63,7 @@ namespace NSCSS
if (m_bImportant && !bImportant)
return false;
- if (arValiableValues.end() != std::find(arValiableValues.begin(), arValiableValues.end(), wsNewValue))\
+ if (arValiableValues.end() != std::find(arValiableValues.begin(), arValiableValues.end(), wsNewValue))
{
m_oValue = wsNewValue;
m_unLevel = unLevel;
@@ -1131,7 +1131,7 @@ namespace NSCSS
bool CDisplay::SetDisplay(const std::wstring &wsValue, unsigned int unLevel, bool bHardMode)
{
- return m_oHAlign.SetValue(wsValue, NSConstValues::DISPLAY_VALUES, unLevel, bHardMode);
+ return m_oDisplay.SetValue(wsValue, NSConstValues::DISPLAY_VALUES, unLevel, bHardMode);
}
const CDigit& CDisplay::GetX() const
diff --git a/Common/3dParty/html/htmltoxhtml.h b/Common/3dParty/html/htmltoxhtml.h
index c1c1b38442..b417716bcf 100644
--- a/Common/3dParty/html/htmltoxhtml.h
+++ b/Common/3dParty/html/htmltoxhtml.h
@@ -40,10 +40,10 @@ static std::wstring htmlToXhtml(std::string& sFileContent, bool bNeedConvert)
{
if (bNeedConvert)
{ // Определение кодировки
- std::string sEncoding = NSStringFinder::FindPropety(sFileContent, "charset", {"="}, {";", "\\n", "\\r", " ", "\""});
+ std::string sEncoding = NSStringFinder::FindPropety(sFileContent, "charset", {"="}, {";", "\\n", "\\r", " ", "\""}).m_sValue;
if (sEncoding.empty())
- sEncoding = NSStringFinder::FindPropety(sFileContent, "encoding", {"="}, {";", "\\n", "\\r", " "});
+ sEncoding = NSStringFinder::FindPropety(sFileContent, "encoding", {"="}, {";", "\\n", "\\r", " "}).m_sValue;
if (!sEncoding.empty() && !NSStringFinder::Equals("utf-8", sEncoding))
{
@@ -204,49 +204,60 @@ static std::string QuotedPrintableDecode(const std::string& sContent, std::strin
static void ReadMht(const std::string& sMhtContent, std::map& sRes, NSStringUtils::CStringBuilderA& oRes)
{
- size_t unContentPosition = 0, unLastPosition = 0;
+ size_t unContentPosition = 0, unCharsetBegin = 0, unCharsetEnd = std::string::npos;
+ NSStringFinder::TFoundedData oData;
+
// Content-Type
- std::string sContentType = NSStringFinder::FindPropety(sMhtContent, "content-type", {":"}, {";", "\\n", "\\r"}, 0, unLastPosition);
+ oData = NSStringFinder::FindPropety(sMhtContent, "content-type", {":"}, {";", "\\n", "\\r"});
+ const std::string sContentType{oData.m_sValue};
if (sContentType.empty())
return;
-
+
if (NSStringFinder::Equals(sContentType, "multipart/alternative"))
{
- oRes.WriteString(mhtTohtml(sMhtContent.substr(unLastPosition, sMhtContent.length() - unLastPosition)));
+ oRes.WriteString(mhtTohtml(sMhtContent.substr(oData.m_unEndPosition, sMhtContent.length() - oData.m_unEndPosition)));
return;
}
- unContentPosition = std::max(unContentPosition, unLastPosition);
+ unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
+ unCharsetBegin = oData.m_unEndPosition;
// name
// std::string sName = NSStringFinder::FindPropety(sMhtContent, "name", {"="}, {";", "\\n", "\\r"}, 0, unLastPosition);
// unContentPosition = std::max(unContentPosition, unLastPosition);
- // charset
- std::string sCharset = NSStringFinder::FindPropety(sMhtContent, "charset", {"="}, {";", "\\n", "\\r"}, 0, unLastPosition);
- unContentPosition = std::max(unContentPosition, unLastPosition);
- NSStringFinder::CutInside(sCharset, "\"");
-
// Content-Location
- std::string sContentLocation = NSStringFinder::FindPropety(sMhtContent, "content-location", {":"}, {";", "\\n", "\\r"}, 0, unLastPosition);
- unContentPosition = std::max(unContentPosition, unLastPosition);
+ oData = NSStringFinder::FindPropety(sMhtContent, "content-location", {":"}, {";", "\\n", "\\r"});
+ std::string sContentLocation{oData.m_sValue};
+ unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
+ unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
- if (sContentLocation.empty())
- {
- // Content-ID
- std::string sContentID = NSStringFinder::FindPropety(sMhtContent, "content-id", {":"}, {";", "\\n", "\\r"}, 0, unLastPosition);
- unContentPosition = std::max(unContentPosition, unLastPosition);
- NSStringFinder::CutInside(sCharset, "<", ">");
+ // Content-ID
+ oData = NSStringFinder::FindPropety(sMhtContent, "content-id", {":"}, {";", "\\n", "\\r"});
+ std::string sContentID{oData.m_sValue};
+ unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
+ unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
+ NSStringFinder::CutInside(sContentID, "<", ">");
- if (!sContentID.empty())
- sContentLocation = "cid:" + sContentID;
- }
+ if (sContentLocation.empty() && !sContentID.empty())
+ sContentLocation = "cid:" + sContentID;
// Content-Transfer-Encoding
- std::string sContentEncoding = NSStringFinder::FindPropety(sMhtContent, "content-transfer-encoding", {":"}, {";", "\\n", "\\r"}, 0, unLastPosition);
- unContentPosition = std::max(unContentPosition, unLastPosition);
+ oData = NSStringFinder::FindPropety(sMhtContent, "content-transfer-encoding", {":"}, {";", "\\n", "\\r"});
+ const std::string sContentEncoding{oData.m_sValue};
+ unContentPosition = std::max(unContentPosition, oData.m_unEndPosition);
+ unCharsetEnd = std::min(unCharsetEnd, oData.m_unBeginPosition);
+
+ // charset
+ std::string sCharset = "utf-8";
+
+ if (unCharsetBegin < unCharsetEnd)
+ {
+ sCharset = NSStringFinder::FindPropety(sMhtContent.substr(unCharsetBegin, unCharsetEnd - unCharsetBegin), "charset", {"="}, {";", "\\n", "\\r"}).m_sValue;
+ NSStringFinder::CutInside(sCharset, "\"");
+ }
// Content
std::string sContent = sMhtContent.substr(unContentPosition, sMhtContent.length() - unContentPosition);
@@ -312,9 +323,11 @@ static std::string mhtTohtml(const std::string& sFileContent)
std::map sRes;
NSStringUtils::CStringBuilderA oRes;
- size_t nFound = 0;
// Поиск boundary
- std::string sBoundary = NSStringFinder::FindPropety(sFileContent, "boundary", {"="}, {"\\r", "\\n", "\""}, 0, nFound);
+ NSStringFinder::TFoundedData oData{NSStringFinder::FindPropety(sFileContent, "boundary", {"="}, {"\\r", "\\n", "\""})};
+
+ size_t nFound{oData.m_unEndPosition};
+ std::string sBoundary{oData.m_sValue};
if (sBoundary.empty())
{
diff --git a/HtmlFile2/htmlfile2.cpp b/HtmlFile2/htmlfile2.cpp
index e2bdf5d29f..077447b99f 100644
--- a/HtmlFile2/htmlfile2.cpp
+++ b/HtmlFile2/htmlfile2.cpp
@@ -1580,21 +1580,6 @@ private:
m_bInT = false;
}
- void CheckA(NSStringUtils::CStringBuilder* pXml, const std::vector& arSelectors)
- {
- for (std::vector::const_reverse_iterator itNode = arSelectors.crbegin(); itNode < arSelectors.crend(); ++itNode)
- {
- if (NodeBelongToTable(itNode->m_wsName))
- break;
-
- if (L"a" == itNode->m_wsName)
- {
- pXml->WriteString(L"");
- break;
- }
- }
- }
-
void CloseP(NSStringUtils::CStringBuilder* pXml, const std::vector& arSelectors)
{
m_bWasSpace = true;
@@ -1602,8 +1587,6 @@ private:
if (!m_bInP)
return;
- CheckA(pXml, arSelectors);
-
CloseT(pXml);
CloseR(pXml);
@@ -2934,8 +2917,10 @@ private:
std::wstring sImageName = sImageId + L'.' + sExtention;
CBgraFrame oBgraFrame;
if (!oBgraFrame.OpenFile(m_sDst + L"/word/media/i" + sImageName))
+ {
+ NSFile::CFileBinary::Remove(m_sDst + L"/word/media/i" + sImageName);
return;
-
+ }
// Прописать рельсы
if (bNew)
{
@@ -2995,15 +2980,9 @@ private:
{
if(sNote.empty())
return;
- if (!m_bInP)
- {
- oXml->WriteString(L"");
- for (const NSCSS::CNode& item : sSelectors)
- if (item.m_wsName == L"a")
- oXml->WriteString(L"");
- m_bInP = true;
- m_bWasPStyle = false;
- }
+
+ OpenP(oXml);
+
oXml->WriteString(L"WriteString(std::to_wstring(m_nFootnoteId));
oXml->WriteString(L"\"/>");
diff --git a/HtmlFile2/src/StringFinder.h b/HtmlFile2/src/StringFinder.h
index e66b1b0045..01479d3725 100644
--- a/HtmlFile2/src/StringFinder.h
+++ b/HtmlFile2/src/StringFinder.h
@@ -13,6 +13,18 @@
namespace NSStringFinder
{
+ template, std::allocator>>
+ struct TFoundedData
+ {
+ size_t m_unBeginPosition;
+ size_t m_unEndPosition;
+ StringType m_sValue;
+
+ TFoundedData()
+ : m_unBeginPosition(0), m_unEndPosition(0)
+ {}
+ };
+
template, std::allocator>>
StringType FindPropetyTemplate(const StringType& sString, const StringType& sProperty, const StringType& sDelimiter, const StringType& sEnding, const size_t& unStarting, size_t& unEndPosition)
{
@@ -66,70 +78,61 @@ namespace NSStringFinder
}
template, std::allocator>>
- StringType FindPropetyTemplate(const StringType& sString, const StringType& sProperty, const std::vector& arDelimiters, const std::vector& arEndings, const size_t& unStarting, size_t& unEndPosition)
+ TFoundedData FindPropetyTemplate(const StringType& sString, const StringType& sProperty, const std::vector& arDelimiters, const std::vector& arEndings, const size_t& unStarting)
{
if (sString.length() < unStarting)
- return StringType();
+ return TFoundedData();
- std::string sRegexValue = "(?i)" + std::string(sProperty.begin(), sProperty.end());
+ std::wstring wsRegexValue = L"(?i)" + std::wstring(sProperty.begin(), sProperty.end());
if (!arDelimiters.empty())
{
- sRegexValue += "\\s*[";
- for (const StringType& sDelimiter : arDelimiters)
- sRegexValue += std::string(sDelimiter.begin(), sDelimiter.end()) + "|";
- sRegexValue.pop_back();
- sRegexValue += "]{1}";
+ wsRegexValue += L"\\s*[";
+ for (const StringType& wsDelimiter : arDelimiters)
+ wsRegexValue += std::wstring(wsDelimiter.begin(), wsDelimiter.end()) + L"|";
+ wsRegexValue.pop_back();
+ wsRegexValue += L"]{1}";
}
if (!arEndings.empty())
{
- std::string sEndingValue;
+ std::wstring wsEndingValue;
for (const StringType& sEnding : arEndings)
- sEndingValue += std::string(sEnding.begin(), sEnding.end()) + "|";
+ wsEndingValue += std::wstring(sEnding.begin(), sEnding.end()) + L"|";
- sEndingValue.pop_back();
+ wsEndingValue.pop_back();
- sRegexValue += "\\s*(.[^" + sEndingValue + "]*)\\s*[" + sEndingValue + "]?";
+ wsRegexValue += L"\\s*(.[^" + wsEndingValue + L"]*)\\s*[" + wsEndingValue + L"]?";
}
else
- sRegexValue += "\\s*(.*)[\\n|\\r]?";
+ wsRegexValue += L"\\s*(.*)[\\n|\\r]?";
- boost::regex oRegex(sRegexValue);
+ boost::wregex oRegex(wsRegexValue);
boost::match_results oResult;
if (!boost::regex_search(sString.begin() + unStarting, sString.end(), oResult, oRegex))
- return StringType();
+ return TFoundedData();
- unEndPosition = unStarting + oResult.position() + oResult.length();
+ TFoundedData oData;
- StringType sValue(oResult[1]);
- boost::algorithm::trim(sValue);
+ oData.m_unBeginPosition = unStarting + oResult.position();
+ oData.m_unEndPosition = unStarting + oResult.position() + oResult.length();
- return sValue;
+ oData.m_sValue = oResult[1];
+ boost::algorithm::trim(oData.m_sValue);
+
+ return oData;
}
- std::string FindPropety(const std::string& sString, const std::string& sProperty, const std::vector& arDelimiters, const std::vector& arEndings, const size_t& unStarting, size_t& unEndPosition)
+ TFoundedData FindPropety(const std::string& sString, const std::string& sProperty, const std::vector& arDelimiters, const std::vector& arEndings, const size_t& unStarting = 0)
{
- return FindPropetyTemplate(sString, sProperty, arDelimiters, arEndings, unStarting, unEndPosition);
+ return FindPropetyTemplate(sString, sProperty, arDelimiters, arEndings, unStarting);
}
- std::wstring FindPropety(const std::wstring& wsString, const std::wstring& wsProperty, const std::vector& arDelimiters, const std::vector& arEndings, const size_t& unStarting, size_t& unEndPosition)
+ TFoundedData FindPropety(const std::wstring& wsString, const std::wstring& wsProperty, const std::vector& arDelimiters, const std::vector& arEndings, const size_t& unStarting = 0)
{
- return FindPropetyTemplate(wsString, wsProperty, arDelimiters, arEndings, unStarting, unEndPosition);
- }
-
- std::string FindPropety(const std::string& sString, const std::string& sProperty, const std::vector& arDelimiters, const std::vector& arEndings, const size_t& unStarting = 0)
- {
- size_t unEndPosition = 0;
- return FindPropetyTemplate(sString, sProperty, arDelimiters, arEndings, unStarting, unEndPosition);
- }
-
- std::wstring FindPropety(const std::wstring& wsString, const std::wstring& wsProperty, const std::vector& arDelimiters, const std::vector& arEndings, const size_t& unStarting = 0)
- {
- size_t unEndPosition = 0;
- return FindPropetyTemplate(wsString, wsProperty, arDelimiters, arEndings, unStarting, unEndPosition);
+ return FindPropetyTemplate(wsString, wsProperty, arDelimiters, arEndings, unStarting);
}
template