This commit is contained in:
Kirill Polyakov
2020-09-02 16:44:52 +03:00
parent 14f6ccca71
commit a2cdc35a56
20 changed files with 782 additions and 594 deletions

View File

@ -33,36 +33,22 @@ namespace NSCSS
if (oElement.m_mStyle.size() == 0)
return *this;
for(auto& item : oElement.m_mStyle)
for(const auto& oItem : oElement.m_mStyle)
{
std::wstring& sValue = m_mStyle[item.first];
std::wstring& sValue = m_mStyle[oItem.first];
if (sValue != L"inherit" && !item.second.empty())
sValue = item.second;
if (sValue != L"inherit" && !oItem.second.empty())
sValue = oItem.second;
auto posImportant = item.second.find(L"!important");
auto posImportant = oItem.second.find(L"!important");
if (posImportant != std::wstring::npos)
sValue = item.second.substr(0, posImportant);
sValue = oItem.second.substr(0, posImportant);
}
return *this;
}
CCompiledStyle& CCompiledStyle::operator-= (const CCompiledStyle &oElement)
{
std::map<std::wstring, std::wstring> oStyle;
for (auto item : m_mStyle)
{
if (oElement.m_mStyle.find(item.first) != oElement.m_mStyle.cend())
oStyle.emplace(item.first, item.second);
}
m_mStyle = oStyle;
return *this;
}
CCompiledStyle& CCompiledStyle::operator= (const CCompiledStyle &oElement)
{
m_mStyle = oElement.m_mStyle;
@ -166,8 +152,10 @@ namespace NSCSS
std::wstring CCompiledStyle::GetStyleW() const
{
std::wstring sStyle;
for (auto iter = m_mStyle.begin(); iter != m_mStyle.cend(); iter++)
sStyle += iter->first + L":" + iter->second + L";";
for (const auto& oIter : m_mStyle)
sStyle += oIter.first + L":" + oIter.second + L";";
return sStyle;
}
@ -175,6 +163,7 @@ namespace NSCSS
{
std::wstring sStyle = GetStyleW();
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
return converter.to_bytes(sStyle);
}
@ -185,13 +174,10 @@ namespace NSCSS
bool CCompiledStyle::Empty() const
{
if (m_mStyle.size() == 0)
return true;
if (m_mStyle.size() != 0 || m_arParentsStyles.size() != 0)
return false;
if (m_mStyle.size() == 0 && m_arParentsStyles.size() == 0)
return true;
return false;
return true;
}
void CCompiledStyle::Clear()
@ -300,13 +286,13 @@ namespace NSCSS
const double CCompiledStyle::GetWeidth()
{
double dWidth;
for (auto sValue : m_mStyle)
for (const auto& sValue : m_mStyle)
{
dWidth += sValue.first.length();
dWidth += sValue.second.length();
}
for (std::wstring sValue : m_arParentsStyles)
for (const std::wstring& sValue : m_arParentsStyles)
{
dWidth += sValue.length() / 2;
}
@ -327,6 +313,11 @@ namespace NSCSS
GetFontSize() + L"/" +
GetLineHeight() + L" " +
GetFontFamily();
if (sValue.length() == 5)
return L"";
return sValue;
}
std::wstring CCompiledStyle::GetFontFamily()
@ -335,13 +326,16 @@ namespace NSCSS
{
std::wstring sFontFamily = m_mStyle[L"font-family"];
if (sFontFamily.find(L',') != std::wstring::npos)
sFontFamily = sFontFamily.substr(0, sFontFamily.find(L','));
const auto& posComma = sFontFamily.find(L',');
if (posComma != std::wstring::npos)
sFontFamily = sFontFamily.substr(0, posComma);
if (sFontFamily.find(L'"') != std::wstring::npos || sFontFamily.find(L'\'') != std::wstring::npos)
return sFontFamily;
return L'"' + sFontFamily + L'"';
if (!sFontFamily.empty())
return L'"' + sFontFamily + L'"';
}
std::wstring sFont;
@ -349,11 +343,11 @@ namespace NSCSS
sFont = m_mStyle[L"font"];
if (sFont.empty())
return L"";
return sFont;
int nPos1;
for (int i = (int)sFont.length() - 1; i >= 0; i--)
for (int i = (int)sFont.length() - 1; i >= 0; --i)
{
if(iswdigit(sFont[i]))
{
@ -364,7 +358,7 @@ namespace NSCSS
std::wstring sValue = sFont.substr(nPos1 + 1);
auto posComma = sValue.find(L',');
const auto& posComma = sValue.find(L',');
if (posComma != std::wstring::npos)
sValue = sValue.substr(0, posComma - 1);
@ -377,7 +371,8 @@ namespace NSCSS
}
return L'"' + sValue + L'"';
}
return L"";
return sValue;
}
std::wstring CCompiledStyle::GetFontSize()
@ -391,7 +386,7 @@ namespace NSCSS
sFont = m_mStyle[L"font"];
if (sFont.empty())
return L"";
return sFont;
const std::vector<std::wstring> arValues = { L"xx-small",L"x-small", L"small",
L"medium", L"large", L"x-large",
@ -415,7 +410,7 @@ namespace NSCSS
if (posUnitMeasure != std::wstring::npos)
{
sTempUnitMeasure = sUnitMesure;
wchar_t wc = sFont[posUnitMeasure - 1];
const wchar_t& wc = sFont[posUnitMeasure - 1];
if (iswdigit(wc) || wc == L'.')
break;
@ -432,7 +427,7 @@ namespace NSCSS
std::wstring sValue;
for (int i = sFont.length() - 1; i >= 0; --i)
{
wchar_t wc = sFont[i];
const wchar_t& wc = sFont[i];
if (iswdigit(wc))
{
@ -452,7 +447,7 @@ namespace NSCSS
int num = 0;
std::wstring sValue;
while ((posUnitMeasure - num) > 0 &&
(isdigit(sFont[posUnitMeasure - num]) ||
(iswdigit(sFont[posUnitMeasure - num]) ||
sFont[posUnitMeasure - num] == '.'))
{
sValue = sFont[posUnitMeasure - num] + sValue;
@ -469,6 +464,7 @@ namespace NSCSS
{
if (m_mStyle.find(L"font-size-adjust") != m_mStyle.cend())
return m_mStyle[L"font-size-adjust"];
return L"";
}
@ -476,6 +472,7 @@ namespace NSCSS
{
if (m_mStyle.find(L"font-stretch") != m_mStyle.cend())
return m_mStyle[L"font-stretch"];
return L"";
}
@ -490,27 +487,24 @@ namespace NSCSS
sFont = m_mStyle[L"font"];
if (sFont.empty())
return L"";
return sFont;
std::vector<std::wstring> arValues = {L"italic", L"oblique"};
for (std::wstring sValue : arValues)
if (sFont.find(sValue))
for (const std::wstring& sValue : arValues)
if (sFont.find(sValue) != std::wstring::npos)
return sValue;
if (iswdigit(sFont[0]))
return L"";
std::wstring sValue;
auto posSpace = sFont.find(L' ');
const auto& posSpace = sFont.find(L' ');
if (posSpace != std::wstring::npos)
sValue = sFont.substr(0, posSpace);
if(!sValue.empty())
return L"";
return L"";
return sValue;
}
std::wstring CCompiledStyle::GetFontVariant()
@ -524,12 +518,12 @@ namespace NSCSS
sFont = m_mStyle[L"font"];
if (sFont.empty())
return L"";
return sFont;
if (sFont.find(L"small-caps"))
return L"small-caps";
if (isdigit(sFont[0]))
if (iswdigit(sFont[0]))
return L"";
std::wstring sValue;
@ -547,10 +541,7 @@ namespace NSCSS
else
return L"";
if(!sValue.empty())
return L"";
return L"";
return sValue;
}
std::wstring CCompiledStyle::GetFontWeight()
@ -598,10 +589,7 @@ namespace NSCSS
else
return L"";
if(!sValue.empty())
return L"";
return L"";
return sValue;
}
std::wstring CCompiledStyle::GetLineHeight()
@ -615,12 +603,12 @@ namespace NSCSS
sFont = m_mStyle[L"font"];
if (sFont.empty())
return L"";
return sFont;
if (sFont.find(L"/") == std::wstring::npos)
return L"";
const auto& posSlash = sFont.find(L'/');
auto posSlash = sFont.find(L"/");
if (posSlash == std::wstring::npos)
return L"";
std::wstring sValue = sFont.substr(posSlash + 1);
auto posSpace = sValue.find(L' ');
@ -653,14 +641,14 @@ namespace NSCSS
if (sFontNames.empty())
return {};
auto posLastComma = sFontNames.find_last_of(L',');
const auto& posLastComma = sFontNames.find_last_of(L',');
if (posLastComma != std::wstring::npos)
sFontNames = sFontNames.substr(0, posLastComma);
std::wstring sTemp;
for (wchar_t wc : sFontNames)
for (const wchar_t& wc : sFontNames)
{
if (wc != L',' && wc != L' ')
sTemp += wc;
@ -686,10 +674,10 @@ namespace NSCSS
std::wstring sValue;
std::wstring sTop = GetMarginTop();
std::wstring sLeft = GetMarginLeft();
std::wstring sRight = GetMarginRight();
std::wstring sBottom = GetMarginBottom();
const std::wstring& sTop = GetMarginTop();
const std::wstring& sLeft = GetMarginLeft();
const std::wstring& sRight = GetMarginRight();
const std::wstring& sBottom = GetMarginBottom();
if ((sTop == sLeft) && (sLeft == sRight) && (sRight == sBottom))
return sTop;
@ -710,21 +698,23 @@ namespace NSCSS
if (m_mStyle.find(L"margin-top") != m_mStyle.cend())
return m_mStyle[L"margin-top"];
if (!GetMarginBlockStart().empty())
return GetMarginBlockStart();
const std::wstring& sMarginBlockStart = GetMarginBlockStart();
if (!sMarginBlockStart.empty())
return sMarginBlockStart;
std::wstring sValue;
if (m_mStyle.find(L"margin") != m_mStyle.cend())
sValue = m_mStyle[L"margin"];
if (sValue.empty())
return L"";
return sValue;
std::vector<std::wstring> arValues;
std::wstring sTemp;
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
sTemp += wc;
@ -757,17 +747,18 @@ namespace NSCSS
return m_mStyle[L"margin-left"];
std::wstring sValue;
if (m_mStyle.find(L"margin") != m_mStyle.cend())
sValue = m_mStyle[L"margin"];
if (sValue.empty())
return L"";
return sValue;
std::vector<std::wstring> arValues;
std::wstring sTemp;
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
sTemp += wc;
@ -796,17 +787,18 @@ namespace NSCSS
return m_mStyle[L"margin-right"];
std::wstring sValue;
if (m_mStyle.find(L"margin") != m_mStyle.cend())
sValue = m_mStyle[L"margin"];
if (sValue.empty())
return L"";
return sValue;
std::vector<std::wstring> arValues;
std::wstring sTemp;
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
sTemp += wc;
@ -833,21 +825,24 @@ namespace NSCSS
if (m_mStyle.find(L"margin-bottom") != m_mStyle.cend())
return m_mStyle[L"margin-bottom"];
if (!GetMarginBlockEnd().empty())
return GetMarginBlockEnd();
std::wstring sMarginBlockEnd = GetMarginBlockEnd();
if (!sMarginBlockEnd.empty())
return sMarginBlockEnd;
std::wstring sValue;
if (m_mStyle.find(L"margin") != m_mStyle.cend())
sValue = m_mStyle[L"margin"];
if (sValue.empty())
return L"";
return sValue;
std::vector<std::wstring> arValues;
std::wstring sTemp;
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
sTemp += wc;
@ -884,10 +879,10 @@ namespace NSCSS
std::wstring sValue;
std::wstring sTop = GetPaddingTop();
std::wstring sLeft = GetPaddingLeft();
std::wstring sRight = GetPaddingRight();
std::wstring sBottom = GetPaddingBottom();
const std::wstring& sTop = GetPaddingTop();
const std::wstring& sLeft = GetPaddingLeft();
const std::wstring& sRight = GetPaddingRight();
const std::wstring& sBottom = GetPaddingBottom();
if ((sTop == sLeft) && (sLeft == sRight) && (sRight == sBottom))
return sTop;
@ -907,17 +902,18 @@ namespace NSCSS
return m_mStyle[L"padding-top"];
std::wstring sValue;
if (m_mStyle.find(L"padding") != m_mStyle.cend())
sValue = m_mStyle[L"padding"];
if (sValue.empty())
return L"";
return sValue;
std::vector<std::wstring> arValues;
std::wstring sTemp;
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
sTemp += wc;
@ -942,17 +938,18 @@ namespace NSCSS
return m_mStyle[L"padding-left"];
std::wstring sValue;
if (m_mStyle.find(L"padding") != m_mStyle.cend())
sValue = m_mStyle[L"padding"];
if (sValue.empty())
return L"";
return sValue;
std::vector<std::wstring> arValues;
std::wstring sTemp;
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
sTemp += wc;
@ -986,13 +983,13 @@ namespace NSCSS
sValue = m_mStyle[L"padding"];
if (sValue.empty())
return L"";
return sValue;
std::vector<std::wstring> arValues;
std::wstring sTemp;
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
sTemp += wc;
@ -1020,17 +1017,18 @@ namespace NSCSS
return m_mStyle[L"padding-bottom"];
std::wstring sValue;
if (m_mStyle.find(L"padding") != m_mStyle.cend())
sValue = m_mStyle[L"padding"];
if (sValue.empty())
return L"";
return sValue;
std::vector<std::wstring> arValues;
std::wstring sTemp;
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
sTemp += wc;
@ -1057,6 +1055,7 @@ namespace NSCSS
{
if (m_mStyle.find(L"letter-spacing") != m_mStyle.cend())
return m_mStyle[L"letter-spacing"];
return L"";
}
@ -1064,6 +1063,7 @@ namespace NSCSS
{
if (m_mStyle.find(L"word-spacing") != m_mStyle.cend())
return m_mStyle[L"word-spacing"];
return L"";
}
@ -1071,6 +1071,7 @@ namespace NSCSS
{
if (m_mStyle.find(L"border-spacing") != m_mStyle.cend())
return m_mStyle[L"border-spacing"];
return L"";
}
@ -1079,6 +1080,7 @@ namespace NSCSS
{
if (m_mStyle.find(L"text-decoration-color") != m_mStyle.cend())
return m_mStyle[L"text-decoration-color"];
return L"";
}
@ -1087,8 +1089,8 @@ namespace NSCSS
if (m_mStyle.find(L"background-color") != m_mStyle.cend())
return m_mStyle[L"background-color"];
std::wstring sBackground = GetBackground();
auto posLattice = sBackground.find(L'#');
const std::wstring& sBackground = GetBackground();
const auto& posLattice = sBackground.find(L'#');
if (!sBackground.empty() && posLattice != std::wstring::npos)
{

View File

@ -15,6 +15,7 @@ namespace NSCSS
std::wstring m_sId;
std::vector<std::wstring> m_arParentsStyles;
public:
CCompiledStyle();
CCompiledStyle(const std::map<std::wstring, std::wstring>& mStyle);
@ -121,48 +122,50 @@ namespace NSCSS
CCompiledStyle& operator+= (const CCompiledStyle& oElement);
CCompiledStyle& operator-= (const CCompiledStyle& oElement);
CCompiledStyle& operator= (const CCompiledStyle& oElement);
// CCompiledStyle& operator= (const CCompiledStyle* oElement);
// bool operator== (const CCompiledStyle& oElement);
friend bool operator== (const CCompiledStyle& oFirst, const CCompiledStyle& oSecond)
inline friend bool operator== (const CCompiledStyle& oFirst, const CCompiledStyle& oSecond)
{
std::wstring sThisName = oFirst.m_sId;
// std::wstring sThisName = oFirst.m_sId;
auto posDash = sThisName.find(L'-');
// auto posDash = sThisName.find(L'-');
if (posDash != std::wstring::npos)
sThisName = sThisName.substr(0, posDash);
// if (posDash != std::wstring::npos)
// sThisName = sThisName.substr(0, posDash);
auto posLattice = sThisName.find(L'#');
// auto posLattice = sThisName.find(L'#');
if (posLattice != std::wstring::npos)
sThisName = sThisName.substr(0, posLattice);
// if (posLattice != std::wstring::npos)
// sThisName = sThisName.substr(0, posLattice);
auto posPoint = sThisName.find(L'.');
// auto posPoint = sThisName.find(L'.');
if (posPoint != std::wstring::npos)
sThisName = sThisName.substr(0, posPoint);
// if (posPoint != std::wstring::npos)
// sThisName = sThisName.substr(0, posPoint);
std::wstring sElementName = oSecond.m_sId;
// std::wstring sElementName = oSecond.m_sId;
posDash = sElementName.find(L'-');
// posDash = sElementName.find(L'-');
if (posDash != std::wstring::npos)
sElementName = sElementName.substr(0, posDash);
// if (posDash != std::wstring::npos)
// sElementName = sElementName.substr(0, posDash);
posLattice = sElementName.find(L'#');
// posLattice = sElementName.find(L'#');
if (posLattice != std::wstring::npos)
sElementName = sElementName.substr(0, posLattice);
// if (posLattice != std::wstring::npos)
// sElementName = sElementName.substr(0, posLattice);
posPoint = sElementName.find(L'.');
// posPoint = sElementName.find(L'.');
if (posPoint != std::wstring::npos)
sElementName = sElementName.substr(0, posPoint);
// if (posPoint != std::wstring::npos)
// sElementName = sElementName.substr(0, posPoint);
if (sThisName != sElementName)
// if (sThisName != sElementName)
// return false;
if (oFirst.GetId()[0] != oSecond.GetId()[0])
return false;
if (oFirst.m_arParentsStyles.size() != oSecond.m_arParentsStyles.size())

View File

@ -25,6 +25,28 @@ namespace NSCSS
std::wstring m_sId; // Id тэга
std::wstring m_sClass; // Класс тэга
std::wstring m_sStyle; // Стиль тэга
friend bool operator> (const CNode& oLeftNode, const CNode& oRightNode)
{
return (oLeftNode.m_sId.length() + oLeftNode.m_sName.length() + oLeftNode.m_sClass.length() + oLeftNode.m_sStyle.length())
>
(oRightNode.m_sId.length() + oRightNode.m_sName.length() + oRightNode.m_sClass.length() + oRightNode.m_sStyle.length());
}
friend bool operator< (const CNode& oLeftNode, const CNode& oRightNode)
{
return (oLeftNode.m_sId.length() + oLeftNode.m_sName.length() + oLeftNode.m_sClass.length() + oLeftNode.m_sStyle.length())
<
(oRightNode.m_sId.length() + oRightNode.m_sName.length() + oRightNode.m_sClass.length() + oRightNode.m_sStyle.length());
}
friend bool operator== (const CNode& oLeftNode, const CNode& oRightNode)
{
return (oLeftNode.m_sId == oRightNode.m_sId) &&
(oLeftNode.m_sName == oRightNode.m_sName) &&
(oLeftNode.m_sClass == oRightNode.m_sClass) &&
(oLeftNode.m_sStyle == oRightNode.m_sStyle);
}
};
class CCssCalculator_Private;

View File

@ -13,20 +13,22 @@
#include "../../katana-parser/src/selector.h"
#include "../../../../../UnicodeConverter/UnicodeConverter.h"
#include "../../../../../DesktopEditor/common/File.h"
#include "../../../../../DesktopEditor/common/StringBuilder.h"
inline static std::wstring StringifyValueList(KatanaArray* oValues);
inline static std::wstring StringifyValue(KatanaValue* oValue);
inline static std::wstring stringToWstring(const std::string& sString);
inline static std::string wstringToString(const std::wstring& sWstring);
inline static std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding);
inline static std::wstring GetContentAsUTF8W(const std::wstring& sFileName);
inline static std::string GetContentAsUTF8(const std::wstring& sFileName);
inline static bool GetFirstNumber(std::wstring sString);
inline static std::wstring ConvertAbsoluteValue(const std::wstring& sAbsoluteValue);
inline std::wstring DeleteSpace(const std::wstring& sValue);
inline static void RemoveExcessFromStyles(std::wstring& sStyle);
inline static void TranslateToEn(std::wstring& sStyle);
inline static std::wstring StringifyValueList(KatanaArray* oValues);
inline static std::wstring StringifyValue(KatanaValue* oValue);
inline static std::wstring stringToWstring(const std::string& sString);
inline static std::string wstringToString(const std::wstring& sWstring);
inline static std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding);
inline static std::wstring GetContentAsUTF8W(const std::wstring& sFileName);
inline static std::string GetContentAsUTF8(const std::wstring& sFileName);
inline static bool GetFirstNumber(std::wstring sString);
inline static std::wstring ConvertAbsoluteValue(const std::wstring& sAbsoluteValue);
inline std::vector<std::string> GetWords(const std::wstring& sLine);
inline std::vector<std::string> GetSelectorsList(const std::wstring& sSelectors);
inline std::wstring DeleteSpace(const std::wstring& sValue);
inline static void RemoveExcessFromStyles(std::wstring& sStyle);
inline static void TranslateToEn(std::wstring& sStyle);
namespace NSCSS
{
@ -40,8 +42,8 @@ namespace NSCSS
CCssCalculator_Private::~CCssCalculator_Private()
{
for (size_t i = 0; i < m_arData.size(); i++)
delete m_arData[i];
for (CElement* oElement : m_arData)
delete oElement;
// m_arStyleUsed.clear();
// m_arData.clear();
@ -60,7 +62,8 @@ namespace NSCSS
if (oElement != NULL)
{
std::vector<std::pair<std::wstring, std::wstring>> arDeclarations = oElement->GetDeclarations();
for (auto pDeclaration : arDeclarations)
for (std::pair<std::wstring, std::wstring> pDeclaration : arDeclarations)
pDeclaration.second = ConvertUnitMeasure(pDeclaration.second);
oElement->SetDeclaratins(arDeclarations);
@ -104,14 +107,18 @@ namespace NSCSS
if (oElement->GetCountSelectors() > 0 ||
oElement->GetCountDeclarations() > 0)
m_arData.push_back(oElement);
else
delete oElement;
}
inline void CCssCalculator_Private::GetStylesheet(KatanaStylesheet *oStylesheet, CElement *elementRule)
{
for (size_t i = 0; i < oStylesheet->imports.length; ++i) {
for (size_t i = 0; i < oStylesheet->imports.length; ++i)
{
GetRule((KatanaRule*)oStylesheet->imports.data[i], elementRule);
}
for (size_t i = 0; i < oStylesheet->rules.length; ++i) {
for (size_t i = 0; i < oStylesheet->rules.length; ++i)
{
GetRule((KatanaRule*)oStylesheet->rules.data[i], elementRule);
}
}
@ -149,17 +156,14 @@ namespace NSCSS
inline CElement* CCssCalculator_Private::GetStyleRule(KatanaStyleRule *oRule, CElement *oElementRule)
{
std::vector<std::wstring> arSelectors;
std::vector<std::pair<std::wstring, std::wstring>> arDeclarations;
arSelectors = GetSelectorList(oRule->selectors);
if (oRule->declarations->length)
arDeclarations = GetDeclarationList(oRule->declarations);
CElement *oElement = new CElement;
oElement->AddSelectors(arSelectors);
oElement->AddSelectors(GetSelectorList(oRule->selectors));
oElement->AddDeclarations(arDeclarations);
if (oElementRule == NULL)
@ -174,8 +178,10 @@ namespace NSCSS
inline std::vector<std::wstring> CCssCalculator_Private::GetSelectorList(KatanaArray* oSelectors) const
{
std::vector<std::wstring> arSelectors;
for (size_t i = 0; i < oSelectors->length; ++i)
arSelectors.push_back(GetSelector((KatanaSelector*)oSelectors->data[i]));
return arSelectors;
}
@ -196,9 +202,9 @@ namespace NSCSS
if (sText.find(L' ') != std::wstring::npos)
{
std::wstring sTempText;
for (int i = 0; i < (int)sText.length(); i++)
if (!iswspace(sText[i]))
sTempText += sText[i];
for (const wchar_t& wc : sText)
if (!iswspace(wc))
sTempText += wc;
return sTempText;
}
@ -224,6 +230,7 @@ namespace NSCSS
if (oDecl->important)
sValueList += L" !important";
pDeclaration = std::make_pair(stringToWstring(oDecl->property), sValueList);
return pDeclaration;
@ -231,41 +238,31 @@ namespace NSCSS
inline void CCssCalculator_Private::GetImportRule(KatanaImportRule *oRule)
{
std::vector<std::wstring> arSelectors;
std::vector<std::pair<std::wstring, std::wstring>> arDeclarations;
std::wstring sSelector = L"@" + stringToWstring(oRule->base.name) + L" ";
sSelector += L"url(" + stringToWstring(oRule->href) + L")";
arSelectors.push_back(sSelector);
CElement *oElement = new CElement;
oElement->AddSelectors(arSelectors);
oElement->AddDeclarations(arDeclarations);
oElement->AddSelectors({sSelector});
oElement->AddDeclarations({});
m_arData.push_back(oElement);
}
inline void CCssCalculator_Private::GetFontFaceRule(KatanaFontFaceRule *oRule)
{
std::vector<std::wstring> arSelectors;
std::vector<std::pair<std::wstring, std::wstring>> arDeclarations = GetDeclarationList(oRule->declarations);
std::wstring sSelector = L"@" + stringToWstring(oRule->base.name);
arSelectors.push_back(sSelector);
CElement *oElement = new CElement;
oElement->AddSelectors(arSelectors);
oElement->AddDeclarations(arDeclarations);
oElement->AddSelectors({sSelector});
oElement->AddDeclarations(GetDeclarationList(oRule->declarations));
m_arData.push_back(oElement);
}
inline void CCssCalculator_Private::GetKeyframesRule(KatanaKeyframesRule *oRule)
{
std::vector<std::pair<std::wstring, std::wstring>> arDeclarations;
CElement *oElement = new CElement;
std::wstring sSelector = L"@" + stringToWstring(oRule->base.name);
@ -298,9 +295,7 @@ namespace NSCSS
}
}
std::vector<std::pair<std::wstring, std::wstring>> arDeclarations = GetDeclarationList(oKeyframe->declarations);
oElement->AddDeclarations(arDeclarations);
oElement->AddDeclarations(GetDeclarationList(oKeyframe->declarations));
return oElement;
}
@ -331,7 +326,9 @@ namespace NSCSS
{
std::wstring sText;
bool first = true;
for (size_t i = 0; i < oMedias->length; ++i) {
for (size_t i = 0; i < oMedias->length; ++i)
{
if (!first)
sText += L", ";
else
@ -363,7 +360,8 @@ namespace NSCSS
}
if ((NULL != oQuery->type && strcmp(oQuery->type, "all")) ||
oQuery->restrictor != KatanaMediaQueryRestrictorNone) {
oQuery->restrictor != KatanaMediaQueryRestrictorNone)
{
if (NULL != oQuery->type)
sText += stringToWstring(oQuery->type);
@ -372,7 +370,8 @@ namespace NSCSS
sText += GetMediaQueryExp((KatanaMediaQueryExp*)oQuery->expressions->data[0]);
for (size_t i = 1; i < oQuery->expressions->length; ++i) {
for (size_t i = 1; i < oQuery->expressions->length; ++i)
{
sText += L" and ";
sText += GetMediaQueryExp((KatanaMediaQueryExp*)oQuery->expressions->data[i]);
}
@ -384,10 +383,12 @@ namespace NSCSS
std::wstring sText;
sText += L"(";
if (NULL != oExp->feature) {
if (NULL != oExp->feature)
{
sText += stringToWstring(oExp->feature);
}
if (oExp->values && oExp->values->length) {
if (oExp->values && oExp->values->length)
{
sText += L": " + StringifyValueList(oExp->values);
}
sText += L")";
@ -399,7 +400,7 @@ namespace NSCSS
{
std::vector<std::pair<std::wstring, std::vector<std::pair<std::wstring, std::wstring>>>> arDeclarations;
for (CElement* oElement : m_arData)
for (CElement* oElement : m_arData )
{
if (oElement->FindSelector(sSelector))
{
@ -458,9 +459,9 @@ namespace NSCSS
bool fl1 = false;
for (int i = sSelector.size() - 1; i >= 0; i--)
for (int i = sSelector.size() - 1; i > 0; i--)
{
char sc = sSelector[i];
const char& sc = sSelector[i];
if (sc == '*')
{
@ -473,13 +474,14 @@ namespace NSCSS
else if (sc == '[')
{
fl1 = false;
arSel.push_back('[' + sTempStr + ']');
const std::string& sSel = '[' + sTempStr + ']';
arSel.push_back(sSel);
sTempStr.clear();
}
else if ((sc == '.' || sc == '#' ||
sc == ' ' || sc == ':') && !fl1)
{
char wcBefore = sSelector[i -1];
const char& wcBefore = sSelector[i -1];
if (i > 0 && wcBefore == ':')
{
@ -500,14 +502,14 @@ namespace NSCSS
if (sTempStr.length() != 0)
arSel.push_back(sTempStr);
for (std::string sSel : arSel)
for (const std::string& sSel : arSel)
{
if (sSel.find('#') != std::string::npos)
++arWeight[0];
else if (sSel.find(':') != std::string::npos)
{
std::string sTemp;
for (char sc : sSel)
for (const char& sc : sSel)
if (iswalpha(sc))
sTemp += sc;
@ -533,8 +535,7 @@ namespace NSCSS
inline std::vector<int> CCssCalculator_Private::GetWeightSelector(const std::wstring& sSelector) const
{
std::string sSel = wstringToString(sSelector);
return GetWeightSelector(sSel);
return GetWeightSelector(wstringToString(sSelector));
}
void CCssCalculator_Private::Print() const
@ -569,7 +570,7 @@ namespace NSCSS
arStyle = arTempDecls;
arTempDecls.clear();
for (std::string sSel : arSelectors)
for (const std::string& sSel : arSelectors)
{
std::wstring sSelector = stringToWstring(sSel);
@ -578,7 +579,7 @@ namespace NSCSS
arStyle.insert(arStyle.end(), arTempDecls.begin(), arTempDecls.end());
}
for (std::pair<std::wstring, std::vector<std::pair<std::wstring, std::wstring>>> pValue : arStyle)
for (const std::pair<std::wstring, std::vector<std::pair<std::wstring, std::wstring>>>& pValue : arStyle)
{
std::vector<std::pair<std::wstring, std::wstring>> arDeclarations = pValue.second;
for (std::pair<std::wstring, std::wstring> pDeclaration : arDeclarations)
@ -592,11 +593,11 @@ namespace NSCSS
if (sValue[sValue.length() - 1] == L';' || sValue[sValue.length() - 1] == L':')
sValue.erase(sValue.length() - 1, 1);
auto posLattice = sValue.find(L"#");
const auto& posLattice = sValue.find(L"#");
if (posLattice != std::wstring::npos)
{
auto posSpace = sValue.find(L' ', posLattice);
const auto& posSpace = sValue.find(L' ', posLattice);
if (posSpace != std::wstring::npos)
sValue = sValue.substr(posLattice, (posSpace - 1));
@ -606,8 +607,8 @@ namespace NSCSS
}
else
{
std::vector<int> arWeightFirst = GetWeightSelector(arPropSel[pDeclaration.first]);
std::vector<int> arWeightSecond = GetWeightSelector(pValue.first);
const std::vector<int>& arWeightFirst = GetWeightSelector(arPropSel[pDeclaration.first]);
const std::vector<int>& arWeightSecond = GetWeightSelector(pValue.first);
if ((arWeightFirst <= arWeightSecond &&
mStyle[pDeclaration.first].find(L"!important") == std::wstring::npos) ||
@ -618,7 +619,7 @@ namespace NSCSS
if (sValue[sValue.length() - 1] == L';' || sValue[sValue.length() - 1] == L':')
sValue.erase(sValue.length() - 1, 1);
auto posLattice = sValue.find(L"#");
const auto& posLattice = sValue.find(L"#");
if (posLattice != std::wstring::npos)
{
@ -634,14 +635,14 @@ namespace NSCSS
}
}
for (auto iter = mStyle.begin(); iter != mStyle.end(); iter++)
for (const auto& oIter : mStyle)
{
auto posExclamatory = iter->second.find(L"!");
auto posExclamatory = oIter.second.find(L"!");
if (posExclamatory != std::wstring::npos)
mStyle[iter->first] = ConvertUnitMeasure(iter->second.substr(0, posExclamatory));
mStyle[oIter.first] = ConvertUnitMeasure(oIter.second.substr(0, posExclamatory));
else
mStyle[iter->first] = ConvertUnitMeasure(iter->second);
mStyle[oIter.first] = ConvertUnitMeasure(oIter.second);
}
return CCompiledStyle(mStyle);
@ -671,7 +672,8 @@ namespace NSCSS
CElement *oElement = new CElement;
for (std::string sSelectorUTF8 : sSelectorsUTF8)
for (const std::string& sSelectorUTF8 : sSelectorsUTF8)
oElement->AddSelector(stringToWstring(sSelectorUTF8));
std::vector<std::string> arProperty;
@ -679,7 +681,7 @@ namespace NSCSS
std::string sTemp;
for (char sc : sPropertiesUTF8)
for (const char& sc : sPropertiesUTF8)
{
if (sc != ' ')
{
@ -718,7 +720,7 @@ namespace NSCSS
}
for (size_t i = 0; i < size; i++)
{
std::wstring sValue = ConvertUnitMeasure(stringToWstring(arValue[i]));
const std::wstring& sValue = ConvertUnitMeasure(stringToWstring(arValue[i]));
arDecl.push_back(std::make_pair(stringToWstring(arProperty[i]), sValue));
}
@ -726,140 +728,35 @@ namespace NSCSS
m_arData.push_back(oElement);
}
std::vector<std::string> GetWords(const std::wstring& sLine)
{
std::vector<std::string> arWords;
std::wstring sTempWord;
for (wchar_t wc : sLine)
{
if (iswspace(wc))
{
if (!sLine.empty())
{
std::string sTempStr = wstringToString(sTempWord);
if (std::find(arWords.begin(), arWords.end(), sTempStr) == arWords.cend())
{
arWords.push_back(sTempStr);
}
sTempWord.clear();
}
}
else if (wc != L'.' && wc != L'#')
sTempWord += wc;
}
if (!sTempWord.empty())
{
std::string sTempStr = wstringToString(sTempWord);
if (std::find(arWords.begin(), arWords.end(), sTempStr) == arWords.cend())
{
arWords.push_back(sTempStr);
}
}
return arWords;
}
std::vector<std::string> GetSelectorsList(const std::wstring& sSelectors)
{
std::vector<std::string> arSelectors;
std::wstring sNames = sSelectors;
auto posLattice = sNames.find(L"#");
auto posPoint = sNames.find(L'.');
if (posPoint != std::wstring::npos)
sNames = sNames.substr(0, posPoint);
else if (posLattice != std::wstring::npos)
sNames = sNames.substr(0, posLattice);
std::wstring sClasses;
posPoint = sSelectors.find(L'.');
if (posPoint != std::wstring::npos)
{
sClasses = sSelectors.substr(posPoint);
posLattice = sClasses.find(L'#');
if (posLattice != std::wstring::npos)
sClasses = sClasses.substr(0, posLattice);
}
std::wstring sIds;
posLattice = sSelectors.find(L'#');
if (posLattice != std::wstring::npos)
sIds = sSelectors.substr(posLattice);
std::vector<std::string> arNames = GetWords(sNames);
std::vector<std::string> arClasses = GetWords(sClasses);
std::vector<std::string> arIds = GetWords(sIds);
arSelectors.insert(arSelectors.end(), arNames.begin(), arNames.end());
for (size_t i = 0; i < arClasses.size(); i++)
{
if (arClasses[i].find('.') == std::string::npos)
arClasses[i] = '.' + arClasses[i];
arSelectors.push_back(arClasses[i]);
}
for (size_t i = 0; i < arIds.size(); i++)
{
if (arIds[i].find('#') == std::string::npos)
arIds[i] = '#' + arIds[i];
arSelectors.push_back(arIds[i]);
}
if (arClasses.size() > 0 || arIds.size() > 0)
{
for (std::string sName : arNames)
{
for (std::string sClass : arClasses)
{
arSelectors.push_back(sName + sClass);
}
for (std::string sId : arIds)
{
arSelectors.push_back(sName + sId);
}
}
}
if (arIds.size() > 0)
{
for (std::string sClass : arClasses)
{
for (std::string sId : arIds)
arSelectors.push_back(sClass + sId);
}
}
return arSelectors;
}
CCompiledStyle CCssCalculator_Private::GetCompiledStyle(const CNode &oNode, const std::vector<CNode> &oParents, const UnitMeasure& unitMeasure)
{
size_t parentSize = oParents.size();
if (parentSize > 0)
{
const std::pair<CNode, std::vector<CNode>>& oItem = std::make_pair(oNode, oParents);
if (m_mUsedStyles.find(oItem) != m_mUsedStyles.cend())
{
return m_mUsedStyles[oItem];
}
}
CCompiledStyle oStyle;
oStyle.Clear();
std::wstring sClassName = oNode.m_sClass;
TranslateToEn(sClassName);
// TranslateToEn(sClassName);
if (sClassName[0] != L'.' && !sClassName.empty())
if (!sClassName.empty() && sClassName[0] != L'.')
sClassName = L'.' + sClassName;
std::wstring sIdName = oNode.m_sId;
TranslateToEn(sIdName);
// TranslateToEn(sIdName);
if (sIdName[0] != L'#' && !sIdName.empty())
if (!sIdName.empty() && sIdName[0] != L'#')
sIdName = L'#' + sIdName;
for (CNode oParent : oParents)
for (const CNode& oParent : oParents)
{
if (oParent.m_sName != L"body")
{
@ -877,15 +774,15 @@ namespace NSCSS
oStyle += oTempStyle;
}
// if (sClassName.empty() && sIdName.empty() && oNode.m_sStyle.empty())
// oStyle.SetID(oNode.m_sName);
// else
// {
oStyle.SetID(oNode.m_sName + sClassName + sIdName + L'-' + std::to_wstring(m_nCountNodes));
m_nCountNodes++;
// }
// m_arUsedNode.push_back(std::make_pair(oNode, std::make_pair(oParents, oStyle.GetId())));
oStyle.SetID(oNode.m_sName + sClassName + sIdName + L'-' + std::to_wstring(m_nCountNodes));
m_nCountNodes++;
if (parentSize > 0)
{
m_mUsedStyles.emplace(std::make_pair(oNode, oParents), oStyle);
}
return oStyle;
}
@ -930,7 +827,7 @@ namespace NSCSS
void CCssCalculator_Private::AddStylesFromFile(const std::wstring& sFileName)
{
if (std::find(m_arFiles.begin(), m_arFiles.end(), sFileName) != m_arFiles.end())
if (std::find(m_arFiles.begin(), m_arFiles.end(), sFileName) != m_arFiles.cend())
return;
m_arFiles.push_back(sFileName);
@ -954,7 +851,7 @@ namespace NSCSS
if (sValue.find(L':') != std::wstring::npos)
{
for (wchar_t wc : sValue)
for (const wchar_t& wc : sValue)
{
if (wc == L':' || wc == L';')
{
@ -963,7 +860,7 @@ namespace NSCSS
sTempString += wc;
sTempString = ConvertAbsoluteValue(sTempString);
auto posPoint = sTempString.find(L'.');
const auto& posPoint = sTempString.find(L'.');
if (posPoint != std::wstring::npos)
{
@ -994,7 +891,7 @@ namespace NSCSS
if (!sTempString.empty())
{
auto posPoint = sTempString.find(L'.');
const auto& posPoint = sTempString.find(L'.');
if (posPoint != std::wstring::npos)
{
@ -1011,15 +908,16 @@ namespace NSCSS
std::wstring sValueString;
for (std::wstring sValue : arValues)
for (const std::wstring& sValue : arValues)
{
auto nPosGrid = sValue.find(L'#');
const auto& nPosGrid = sValue.find(L'#');
if (!GetFirstNumber(sValue) || nPosGrid != std::wstring::npos)
{
if (nPosGrid != std::wstring::npos)
{
auto nPosSpace = sValue.find(L' ', nPosGrid);
const auto& nPosSpace = sValue.find(L' ', nPosGrid);
if (nPosSpace != std::wstring::npos)
sValueString += sValue.substr((nPosGrid, nPosSpace - 1));
else
@ -1027,8 +925,8 @@ namespace NSCSS
}
else sValueString += DeleteSpace(sValue);
auto nPosSemicolon = sValue.find(L';');
auto nPosColon = sValue.find(L':');
const auto& nPosSemicolon = sValue.find(L';');
const auto& nPosColon = sValue.find(L':');
if (sValue.length() > 1 && nPosSemicolon == std::wstring::npos &&
nPosColon == std::wstring::npos && arValues.size() > 2)
@ -1045,11 +943,12 @@ namespace NSCSS
if (sBeforeValue.empty())
break;
auto nPosPercent = sBeforeValue.find(L'%');
if (nPosPercent != std::wstring::npos)
const auto& posPercent = sBeforeValue.find(L'%');
if (posPercent != std::wstring::npos)
{
double dValue = wcstod(sBeforeValue.substr(0, nPosPercent).c_str(), NULL);
sBeforeValue = sBeforeValue.substr(nPosPercent + 1);
double dValue = wcstod(sBeforeValue.substr(0, posPercent).c_str(), NULL);
sBeforeValue = sBeforeValue.substr(posPercent + 1);
dValue /= 100;
dValue = 22 * dValue;
sTempValue += std::to_wstring((int)floor(dValue + 0.5)) + L" ";
@ -1812,7 +1711,7 @@ inline static std::wstring StringifyValue(KatanaValue* oValue)
}
case KATANA_VALUE_PARSER_FUNCTION:
{
std::wstring args_str = StringifyValueList(oValue->function->args);
const std::wstring& args_str = StringifyValueList(oValue->function->args);
if (args_str.empty())
break;
@ -1851,7 +1750,7 @@ inline static std::wstring stringToWstring(const std::string& sString)
inline static std::string wstringToString(const std::wstring& sWstring)
{
return std::string(sWstring.begin(), sWstring.end());
return U_TO_UTF8(sWstring);
}
inline static std::string GetContentAsUTF8(const std::string &sString, const std::wstring &sEncoding)
@ -1866,13 +1765,16 @@ inline static std::string GetContentAsUTF8(const std::string &sString, const std
inline static std::wstring GetContentAsUTF8W(const std::wstring& sFileName)
{
std::wstring sSource;
if (!NSFile::CFileBinary::ReadAllTextUtf8(sFileName, sSource))
return sSource;
std::wstring sTemp;
if (sSource.find(L'{') != std::string::npos)
sTemp = sSource.substr(0, sSource.find(L'{'));
const auto& posLeftBrace = sSource.find(L'{');
if (posLeftBrace != std::string::npos)
sTemp = sSource.substr(0, posLeftBrace);
if (sTemp.empty())
return sSource;
@ -1882,9 +1784,10 @@ inline static std::wstring GetContentAsUTF8W(const std::wstring& sFileName)
if (sTemp.find(L"@charset") != std::string::npos)
{
sEncoding = sTemp.substr(sTemp.find(L"@charset ") + 9);
auto posSemicolon = sEncoding.find(L';');
auto posDoubleQuotes = sEncoding.find(L'"');
auto posQuotes = sEncoding.find(L'\'');
const auto& posSemicolon = sEncoding.find(L';');
const auto& posDoubleQuotes = sEncoding.find(L'"');
const auto& posQuotes = sEncoding.find(L'\'');
if (posSemicolon != std::string::npos)
sEncoding = sEncoding.substr(0, posSemicolon);
@ -1913,7 +1816,7 @@ inline static std::wstring GetContentAsUTF8W(const std::wstring& sFileName)
inline static std::string GetContentAsUTF8(const std::wstring& sFileName)
{
std::wstring sUnicodeContent =GetContentAsUTF8W(sFileName);
std::wstring sUnicodeContent = GetContentAsUTF8W(sFileName);
return U_TO_UTF8(sUnicodeContent);
}
@ -1929,13 +1832,13 @@ inline static void RemoveExcessFromStyles(std::wstring& sStyle)
{
while (true)
{
auto posLeftAngleBracket = sStyle.find(L'<');
auto posRightAngleBracket = sStyle.find(L'>');
const auto& posLeftAngleBracket = sStyle.find(L'<');
const auto& posRightAngleBracket = sStyle.find(L'>');
auto posLeftComment = sStyle.find(L"<!--");
auto posRightComment = sStyle.find(L"-->");
const auto& posLeftComment = sStyle.find(L"<!--");
const auto& posRightComment = sStyle.find(L"-->");
auto posDog = sStyle.find(L'@');
const auto& posDog = sStyle.find(L'@');
if (posLeftAngleBracket != std::wstring::npos || posDog != std::wstring::npos ||
posLeftComment != std::wstring::npos || posRightComment != std::wstring::npos)
@ -1971,6 +1874,7 @@ inline static void RemoveExcessFromStyles(std::wstring& sStyle)
inline static void TranslateToEn(std::wstring& sStyle)
{
bool bCorrect = false;
for (std::wstring::size_type i = 0, len = sStyle.length(); i < len; ++i)
{
wchar_t wc = sStyle[i];
@ -2020,7 +1924,7 @@ inline static std::wstring ConvertAbsoluteValue(const std::wstring& sAbsoluteVal
std::wstring sNewValue = sAbsoluteValue;
for (auto sAbsValue : arAbsoluteValues)
for (const auto& sAbsValue : arAbsoluteValues)
{
while (sNewValue.find(sAbsValue.first) != std::wstring::npos)
{
@ -2034,7 +1938,7 @@ inline static std::wstring ConvertAbsoluteValue(const std::wstring& sAbsoluteVal
return sNewValue;
}
inline std::wstring DeleteSpace(const std::wstring& sValue)
inline static std::wstring DeleteSpace(const std::wstring& sValue)
{
std::wstring sNewValue = sValue;
@ -2046,3 +1950,129 @@ inline std::wstring DeleteSpace(const std::wstring& sValue)
return sNewValue;
}
inline static std::vector<std::string> GetSelectorsList(const std::wstring& sSelectors)
{
std::vector<std::string> arSelectors;
std::wstring sNames = sSelectors;
auto posLattice = sNames.find(L"#");
auto posPoint = sNames.find(L'.');
if (posPoint != std::wstring::npos)
sNames = sNames.substr(0, posPoint);
else if (posLattice != std::wstring::npos)
sNames = sNames.substr(0, posLattice);
std::wstring sClasses;
posPoint = sSelectors.find(L'.');
if (posPoint != std::wstring::npos)
{
sClasses = sSelectors.substr(posPoint);
posLattice = sClasses.find(L'#');
if (posLattice != std::wstring::npos)
sClasses = sClasses.substr(0, posLattice);
}
std::wstring sIds;
posLattice = sSelectors.find(L'#');
if (posLattice != std::wstring::npos)
sIds = sSelectors.substr(posLattice);
const std::vector<std::string>& arNames = GetWords(sNames);
std::vector<std::string> arClasses = GetWords(sClasses);
std::vector<std::string> arIds = GetWords(sIds);
arSelectors.insert(arSelectors.end(), arNames.begin(), arNames.end());
for (std::string& sClass : arClasses)
{
if (sClass.find('.') == std::string::npos)
sClass = '.' + sClass;
arSelectors.push_back(sClass);
}
for (std::string& sId : arIds)
{
if (sId.find('#') == std::string::npos)
sId = '#' + sId;
arSelectors.push_back(sId);
}
if (arClasses.size() > 0 || arIds.size() > 0)
{
for (const std::string& sName : arNames)
{
for (const std::string& sClass : arClasses)
{
arSelectors.push_back(sName + sClass);
}
for (const std::string& sId : arIds)
{
arSelectors.push_back(sName + sId);
}
}
}
if (arIds.size() > 0)
{
for (const std::string& sClass : arClasses)
{
for (const std::string& sId : arIds)
arSelectors.push_back(sClass + sId);
}
}
return arSelectors;
}
inline static std::vector<std::string> GetWords(const std::wstring& sLine)
{
std::vector<std::string> arWords;
std::wstring sTempWord;
for (const wchar_t& wc : sLine)
{
if (iswspace(wc))
{
if (!sLine.empty())
{
const std::string& sTempStr = wstringToString(sTempWord);
if (std::find(arWords.begin(), arWords.end(), sTempStr) == arWords.cend())
{
arWords.push_back(sTempStr);
}
sTempWord.clear();
}
}
else if (wc != L'.' && wc != L'#')
sTempWord += wc;
}
if (!sTempWord.empty())
{
const std::string& sTempStr = wstringToString(sTempWord);
if (std::find(arWords.begin(), arWords.end(), sTempStr) == arWords.cend())
{
arWords.push_back(sTempStr);
}
}
return arWords;
}
inline static int GetLengthNode(NSCSS::CNode oNode)
{
return oNode.m_sId.length() + oNode.m_sName.length() + oNode.m_sClass.length();
}

View File

@ -15,7 +15,7 @@ namespace NSCSS
std::vector<CElement*> m_arData;
std::vector<std::wstring> m_arFiles;
std::vector<std::pair<CNode, std::pair<std::vector<CNode>, std::wstring>>> m_arUsedNode;
std::map<std::pair<CNode, std::vector<CNode>>, CCompiledStyle> m_mUsedStyles;
int m_nDpi;
std::wstring m_sEncoding;

View File

@ -31,10 +31,10 @@ std::wstring CElement::GetText() const
sText += L"{\n";
if (m_arChildrens.size() != 0)
for (CElement* oChildren : m_arChildrens)
for (const CElement* oChildren : m_arChildrens)
sText += oChildren->GetText();
for (std::pair<std::wstring, std::wstring> pDeclaration : m_arDeclarations)
for (const std::pair<std::wstring, std::wstring>& pDeclaration : m_arDeclarations)
{
sText += L" " + pDeclaration.first + L": " + pDeclaration.second + L";\n";
}
@ -55,10 +55,11 @@ void CElement::AddSelector(const std::wstring sSelector)
if (sSelector.find(L' ') != std::wstring::npos)
{
std::wstring sTempSelector;
for (wchar_t wc : sSelector)
if (!isspace(wc))
for (const wchar_t& wc : sSelector)
if (!iswspace(wc))
sTempSelector += wc;
m_arSelectors.push_back(sSelector);
m_arSelectors.push_back(sTempSelector);
}
else
m_arSelectors.push_back(sSelector);
@ -99,7 +100,7 @@ const int& CElement::GetCountChildrens() const
return m_arChildrens.size();
}
const bool CElement::FindSelector(std::wstring sSelector)
bool CElement::FindSelector(std::wstring sSelector)
{
if (std::find(m_arSelectors.begin(), m_arSelectors.end(), sSelector) != m_arSelectors.cend())
return true;
@ -122,13 +123,13 @@ std::vector<std::pair<std::wstring, std::vector<std::pair<std::wstring, std::wst
{
std::vector<std::pair<std::wstring, std::vector<std::pair<std::wstring, std::wstring>>>> arElement;
for (std::wstring sValueSelector : m_arSelectors)
for (const std::wstring& sValueSelector : m_arSelectors)
{
if (sValueSelector == sSelector)
{
std::wstring sTempSelectors;
for (std::wstring sParent : arParents)
for (const std::wstring& sParent : arParents)
sTempSelectors += sParent;
if (!sTempSelectors.empty())
@ -142,9 +143,9 @@ std::vector<std::pair<std::wstring, std::vector<std::pair<std::wstring, std::wst
std::vector<std::pair<std::wstring, std::vector<std::pair<std::wstring, std::wstring>>>> TempArElement;
for (CElement* oElement : m_arChildrens)
for (const CElement* oElement : m_arChildrens)
{
std::vector<std::wstring> sSelectors = oElement->GetSelectors();
const std::vector<std::wstring>& sSelectors = oElement->GetSelectors();
if (std::find(sSelectors.begin(), sSelectors.end(), sSelector) != sSelectors.cend())
{
@ -171,7 +172,7 @@ CElement& CElement::operator= (const CElement &oElement)
m_arSelectors = oElement.m_arSelectors;
m_arDeclarations = oElement.m_arDeclarations;
for (CElement *oChildren : oElement.m_arChildrens)
for (const CElement *oChildren : oElement.m_arChildrens)
{
CElement *oTempChildren = new CElement();
*oTempChildren = *oChildren;

View File

@ -24,7 +24,7 @@ public:
const int& GetCountDeclarations() const;
const int& GetCountChildrens() const;
const bool FindSelector(std::wstring sSelector);
bool FindSelector(std::wstring sSelector);
const std::vector<std::wstring>& GetSelectors() const;
const std::vector<std::pair<std::wstring, std::wstring>>& GetDeclarations() const;

View File

@ -11,14 +11,14 @@ struct ParentStyle
std::wstring oNameParent;
};
bool Comp(const std::pair<NSCSS::CCompiledStyle, bool> &oFirstElement, const std::pair<NSCSS::CCompiledStyle, bool> &oSecondElement)
inline bool Comp(const std::pair<NSCSS::CCompiledStyle, bool> &oFirstElement, const std::pair<NSCSS::CCompiledStyle, bool> &oSecondElement)
{
return oFirstElement.first.GetSize() < oSecondElement.first.GetSize();
}
namespace NSCSS
{
CDocumentStyle::CDocumentStyle()
CDocumentStyle::CDocumentStyle()
{
m_arStandardStyles = {L"a", L"li",
L"h1", L"h2",
@ -38,8 +38,9 @@ CDocumentStyle::CDocumentStyle()
std::wstring CDocumentStyle::GetStyle()
{
if (m_sId.empty())
return L"";
std::wstring sStyle = m_sStyle;
return m_sId;
const std::wstring sStyle = m_sStyle;
Clear();
return sStyle;
}
@ -59,6 +60,7 @@ CDocumentStyle::CDocumentStyle()
{
if (sStyle.empty())
return;
m_sStyle = sStyle;
}
@ -133,7 +135,7 @@ CDocumentStyle::CDocumentStyle()
oXmlElement.CreateDefaultElement(sNameStyle);
if (sNameStyle[0] == L'h' && iswdigit(sNameStyle[1]) && sNameStyle.length() == 2)
if (sNameStyle[0] == L'h' && sNameStyle.length() == 2 && iswdigit(sNameStyle[1]) )
{
std::wstring sCharName = L"title";
sCharName += sNameStyle[1];
@ -313,6 +315,12 @@ CDocumentStyle::CDocumentStyle()
}
m_sId = oStyle.GetId();
if (!bIsPStyle && m_sId.find(L"-c") == std::wstring::npos)
{
m_sId += L"-c";
}
oXmlElement.SetStyleId(m_sId);
oXmlElement.SetName(m_sId);
oXmlElement.SetQFormat(true);
@ -454,38 +462,33 @@ CDocumentStyle::CDocumentStyle()
oXmlElement.SetContextualSpacing(true);
}
oXmlElement.SetColor(oStyle.GetColor());
}
void CDocumentStyle::WriteRStyle(NSCSS::CCompiledStyle &oStyle)
{
// if (!oStyle.GetBasedOn().empty())
// {
// m_sId = oStyle.GetBasedOn();
// return;
// }
if(oStyle.GetId().empty())
{
m_sId = L"normal";
m_sStyle.clear();
return;
}
// for (auto oItem : m_arStyleUsed)
// {
// if(!oItem.second && oItem.first == oStyle)
// {
// m_sId = oItem.first.GetId();
// m_sStyle.clear();
// return;
// }
// }
auto oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), std::make_pair(oStyle, false));
if (oItem != m_arStyleUsed.cend())
{
m_sId = oItem->first.GetId();
m_sStyle.clear();
if (m_sId.find(L"-c") == std::wstring::npos)
m_sId += L"-c";
return;
}
CXmlElement oXmlElement;
SetRStyle(oStyle, oXmlElement);
@ -493,14 +496,14 @@ CDocumentStyle::CDocumentStyle()
{
m_arStyleUsed.push_back(std::make_pair(oStyle, false));
// std::sort(m_arStyleUsed.begin(), m_arStyleUsed.end(), Comp);
std::sort(m_arStyleUsed.begin(), m_arStyleUsed.end(), Comp);
}
if (!oXmlElement.Empty())
m_sStyle += oXmlElement.GetRStyle();
m_sStyle += oXmlElement.GetRStyle();
}
void CDocumentStyle::WritePStyle(NSCSS::CCompiledStyle &oStyle)
{
{
if(oStyle.GetId().empty())
{
m_sId = L"normal";
@ -508,22 +511,11 @@ CDocumentStyle::CDocumentStyle()
return;
}
// for (auto oItem : m_arStyleUsed)
// {
// if(oItem.second && oItem.first == oStyle)
// {
// m_sId = oItem.first.GetId();
// m_sStyle.clear();
// return;
// }
// }
auto oItem = std::find(m_arStyleUsed.begin(), m_arStyleUsed.end(), std::make_pair(oStyle, true));
if (oItem != m_arStyleUsed.cend())
{
m_sId = oItem->first.GetId();
m_sStyle.clear();
return;
}
@ -534,9 +526,9 @@ CDocumentStyle::CDocumentStyle()
{
m_arStyleUsed.push_back(std::make_pair(oStyle, true));
// std::sort(m_arStyleUsed.begin(), m_arStyleUsed.end(), Comp);
std::sort(m_arStyleUsed.begin(), m_arStyleUsed.end(), Comp); // Оптимизировать сортировку (возможно и поиск (можно попробовать бинарный))
}
if (!oXmlElement.Empty())
m_sStyle += oXmlElement.GetPStyle();
m_sStyle += oXmlElement.GetPStyle();
}
}

View File

@ -9,7 +9,7 @@ bool IsDigit(std::wstring sValue)
if (sValue.empty())
return false;
for (auto cChar : sValue)
for (const wchar_t& cChar : sValue)
if (!iswdigit(cChar))
return false;
@ -27,22 +27,26 @@ CXmlElement::CXmlElement(std::wstring sNameDefaultElement)
bool CXmlElement::Empty() const
{
return m_sType.empty() && m_sStyleId.empty() && m_sDefault.empty() && m_sCustomStyle.empty() &&
m_sS.empty() && m_sName.empty() && m_sBasedOn.empty() && m_sLink.empty() && m_sUiPriority.empty() &&
!m_bQFormat && !m_bSemiHidden && !m_bUnhideWhenUsed && !m_bB && !m_bI && m_sU.empty() && m_sRFonts.empty() &&
m_sColor.empty() && m_sSz.empty() && !m_bKeepLines && !m_bKeepNext && m_sSpacing.empty() &&
m_sOutlineLvl.empty() && !m_bContextualSpacing && m_sInd.empty() && m_sJc.empty() &&
m_sTblInd.empty() && m_sCellTop.empty() && m_sCellLeft.empty() && m_sCellBottom.empty() &&
m_sCellRight.empty() && m_sBorderTop.empty() && m_sBorderLeft.empty() && m_sBorderBottom.empty() &&
m_sBorderRight.empty() && m_sBorderInsideH.empty() && m_sBorderInsideV.empty() && m_sShd.empty() &&
m_sTopBorder.empty() && m_sLeftBorder.empty() && m_sBottomBorder.empty() && m_sRightBorder.empty();
return m_bEmpty;
// return m_sType.empty() && m_sStyleId.empty() && m_sDefault.empty() && m_sCustomStyle.empty() &&
// m_sS.empty() && m_sName.empty() && m_sBasedOn.empty() && m_sLink.empty() && m_sUiPriority.empty() &&
// !m_bQFormat && !m_bSemiHidden && !m_bUnhideWhenUsed && !m_bB && !m_bI && m_sU.empty() && m_sRFonts.empty() &&
// m_sColor.empty() && m_sSz.empty() && !m_bKeepLines && !m_bKeepNext && m_sSpacing.empty() &&
// m_sOutlineLvl.empty() && !m_bContextualSpacing && m_sInd.empty() && m_sJc.empty() &&
// m_sTblInd.empty() && m_sCellTop.empty() && m_sCellLeft.empty() && m_sCellBottom.empty() &&
// m_sCellRight.empty() && m_sBorderTop.empty() && m_sBorderLeft.empty() && m_sBorderBottom.empty() &&
// m_sBorderRight.empty() && m_sBorderInsideH.empty() && m_sBorderInsideV.empty() && m_sShd.empty() &&
// m_sTopBorder.empty() && m_sLeftBorder.empty() && m_sBottomBorder.empty() && m_sRightBorder.empty();
}
void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
{
Clear();
if (!m_bEmpty)
Clear();
if (sNameDefaultElement == L"li")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"li");
SetName(L"List Paragraph");
@ -54,6 +58,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"h1")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"h1");
SetName(L"Heading 1");
@ -70,6 +75,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"h2")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"h2");
SetName(L"Heading 2");
@ -87,6 +93,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"h3")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"h3");
SetName(L"Heading 3");
@ -105,6 +112,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"h4")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"h4");
SetName(L"Heading 4");
@ -122,6 +130,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"h5")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"h5");
SetName(L"Heading 5");
@ -139,6 +148,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"h6")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"h6");
SetName(L"Heading 6");
@ -157,6 +167,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"title1-c")
{
m_bEmpty = false;
SetType(L"character");
SetStyleId(L"title1-c");
SetCustomStyle(L"1");
@ -168,6 +179,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"title2-c")
{
m_bEmpty = false;
SetType(L"character");
SetStyleId(L"title2-c");
SetCustomStyle(L"1");
@ -179,6 +191,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"title3-c")
{
m_bEmpty = false;
SetType(L"character");
SetStyleId(L"title3-c");
SetCustomStyle(L"1");
@ -190,6 +203,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"title4-c")
{
m_bEmpty = false;
SetType(L"character");
SetStyleId(L"title4-c");
SetCustomStyle(L"1");
@ -201,6 +215,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"title5-c")
{
m_bEmpty = false;
SetType(L"character");
SetStyleId(L"title5-c");
SetCustomStyle(L"1");
@ -212,6 +227,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"title6-c")
{
m_bEmpty = false;
SetType(L"character");
SetStyleId(L"title6-c");
SetCustomStyle(L"1");
@ -223,6 +239,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"p-c")
{
m_bEmpty = false;
SetType(L"character");
SetStyleId(L"p-c");
SetCustomStyle(L"1");
@ -232,6 +249,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"p")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"p");
SetCustomStyle(L"1");
@ -244,6 +262,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"div-c")
{
m_bEmpty = false;
SetType(L"character");
SetStyleId(L"div-c");
SetCustomStyle(L"1");
@ -253,6 +272,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"div")
{
m_bEmpty = false;
SetType(L"paragraph");
SetStyleId(L"div");
SetCustomStyle(L"1");
@ -265,6 +285,7 @@ void CXmlElement::CreateDefaultElement(const std::wstring sNameDefaultElement)
}
else if (sNameDefaultElement == L"a")
{
m_bEmpty = false;
SetType(L"character");
SetBasedOn(L"a-c");
SetStyleId(L"a");
@ -352,125 +373,196 @@ void CXmlElement::Clear()
// </tblBorders>
// </tblPr>
m_bEmpty = true;
}
void CXmlElement::SetType(std::wstring sType)
void CXmlElement::SetType(const std::wstring sType)
{
m_sType = sType;
if (!m_sType.empty())
m_bEmpty = false;
}
void CXmlElement::SetStyleId(std::wstring sStyleId)
void CXmlElement::SetStyleId(const std::wstring sStyleId)
{
m_sStyleId = sStyleId;
if (!m_sStyleId.empty())
m_bEmpty = false;
}
void CXmlElement::SetDefault(std::wstring sDefault)
void CXmlElement::SetDefault(const std::wstring sDefault)
{
m_sDefault = sDefault;
if (!m_sDefault.empty())
m_bEmpty = false;
}
void CXmlElement::SetCustomStyle(std::wstring sCustomStyle)
void CXmlElement::SetCustomStyle(const std::wstring sCustomStyle)
{
m_sCustomStyle = sCustomStyle;
if (!m_sCustomStyle.empty())
m_bEmpty = false;
}
void CXmlElement::SetS(std::wstring sS)
void CXmlElement::SetS(const std::wstring sS)
{
m_sS = sS;
if (!m_sS.empty())
m_bEmpty = false;
}
void CXmlElement::SetName(std::wstring sName)
void CXmlElement::SetName(const std::wstring sName)
{
m_sName = sName;
if (!m_sName.empty())
m_bEmpty = false;
}
void CXmlElement::SetBasedOn(std::wstring sBasedOn)
void CXmlElement::SetBasedOn(const std::wstring sBasedOn)
{
m_sBasedOn = sBasedOn;
if (!m_sBasedOn.empty())
m_bEmpty = false;
}
void CXmlElement::SetLink(std::wstring sLink)
void CXmlElement::SetLink(const std::wstring sLink)
{
m_sLink = sLink;
if (!m_sLink.empty())
m_bEmpty = false;
}
void CXmlElement::SetUiPriority(std::wstring sUiPriority)
void CXmlElement::SetUiPriority(const std::wstring sUiPriority)
{
m_sUiPriority = sUiPriority;
if (!m_sUiPriority.empty())
m_bEmpty = false;
}
void CXmlElement::SetQFormat(bool bQFormat)
void CXmlElement::SetQFormat(const bool bQFormat)
{
m_bQFormat = bQFormat;
if (m_bQFormat)
m_bEmpty = false;
}
void CXmlElement::SetUnhideWhenUsed(bool bUnhideWhenUsed)
void CXmlElement::SetUnhideWhenUsed(const bool bUnhideWhenUsed)
{
m_bUnhideWhenUsed = bUnhideWhenUsed;
if (m_bUnhideWhenUsed)
m_bEmpty = false;
}
void CXmlElement::SetB(bool bB)
void CXmlElement::SetB(const bool bB)
{
m_bB = bB;
if (m_bB)
m_bEmpty = false;
}
void CXmlElement::SetI(bool bI)
void CXmlElement::SetI(const bool bI)
{
m_bI = bI;
if (m_bI)
m_bEmpty = true;
}
void CXmlElement::SetU(std::wstring sU)
void CXmlElement::SetU(const std::wstring sU)
{
m_sU = sU;
if (!m_sUiPriority.empty())
m_bEmpty = false;
}
void CXmlElement::SetRFonts(std::wstring sRFonts)
void CXmlElement::SetRFonts(const std::wstring sRFonts)
{
m_sRFonts = sRFonts;
if (!m_sRFonts.empty())
m_bEmpty = false;
}
void CXmlElement::SetColor(std::wstring sColor)
void CXmlElement::SetColor(const std::wstring sColor)
{
m_sColor = sColor;
if (!m_sColor.empty())
m_bEmpty = false;
}
void CXmlElement::SetSz(std::wstring sSz)
void CXmlElement::SetSz(const std::wstring sSz)
{
if (IsDigit(sSz))
{
m_sSz = sSz;
if (!m_sSz.empty())
m_bEmpty = false;
}
}
void CXmlElement::SetKeepLines(bool bKeepLines)
void CXmlElement::SetKeepLines(const bool bKeepLines)
{
m_bKeepLines = bKeepLines;
if (m_bKeepLines)
m_bEmpty = false;
}
void CXmlElement::SetKeepNext(bool bKeepNext)
void CXmlElement::SetKeepNext(const bool bKeepNext)
{
m_bKeepNext = bKeepNext;
if (m_bKeepNext)
m_bEmpty = false;
}
void CXmlElement::SetSpacing(std::wstring sSpacing)
void CXmlElement::SetSpacing(const std::wstring sSpacing)
{
m_sSpacing = sSpacing;
if (!m_sSpacing.empty())
m_bEmpty = false;
}
void CXmlElement::SetOutlineLvl(std::wstring sOutlineLvl)
void CXmlElement::SetOutlineLvl(const std::wstring sOutlineLvl)
{
m_sOutlineLvl = sOutlineLvl;
if (!m_sOutlineLvl.empty())
m_bEmpty = false;
}
void CXmlElement::SetContextualSpacing(bool bContextualSpacing)
void CXmlElement::SetContextualSpacing(const bool bContextualSpacing)
{
m_bContextualSpacing = bContextualSpacing;
if (m_bContextualSpacing)
m_bEmpty = false;
}
void CXmlElement::SetInd(std::wstring sInd)
void CXmlElement::SetInd(const std::wstring sInd)
{
m_sInd = sInd;
if (!m_sUiPriority.empty())
m_bEmpty = false;
}
void CXmlElement::SetJc(std::wstring sJc)
void CXmlElement::SetJc(const std::wstring sJc)
{
std::wstring sNewJc = sJc;
std::transform(sNewJc.begin(), sNewJc.end(), sNewJc.begin(), towlower);
@ -483,35 +575,55 @@ void CXmlElement::SetJc(std::wstring sJc)
m_sJc = L"center";
else if (std::find(arValues.begin(), arValues.end(), sNewJc) != arValues.cend())
m_sJc = sNewJc;
if (!m_sJc.empty())
m_bEmpty = false;
}
void CXmlElement::SetShd(std::wstring sShd)
void CXmlElement::SetShd(const std::wstring sShd)
{
m_sShd = sShd;
if (!m_sShd.empty())
m_bEmpty = false;
}
void CXmlElement::SetTopBorder(std::wstring sTopBorder)
void CXmlElement::SetTopBorder(const std::wstring sTopBorder)
{
m_sTopBorder = sTopBorder;
if (!m_sTopBorder.empty())
m_bEmpty = false;
}
void CXmlElement::SetLeftBorder(std::wstring sLeftBorder)
void CXmlElement::SetLeftBorder(const std::wstring sLeftBorder)
{
m_sLeftBorder = sLeftBorder;
if (!m_sLeftBorder.empty())
m_bEmpty = true;
}
void CXmlElement::SetBottomBorder(std::wstring sBottomBorder)
void CXmlElement::SetBottomBorder(const std::wstring sBottomBorder)
{
m_sBottomBorder = sBottomBorder;
if (!m_sBottomBorder.empty())
m_bEmpty = false;
}
void CXmlElement::SetRightBorder(std::wstring sRightBorder)
void CXmlElement::SetRightBorder(const std::wstring sRightBorder)
{
m_sRightBorder = sRightBorder;
if (!m_sRightBorder.empty())
m_bEmpty = false;
}
CXmlElement& CXmlElement::operator+=(const CXmlElement &oElement)
{
if (!oElement.Empty())
m_bEmpty = false;
if (!oElement.m_sType.empty())
m_sType = oElement.m_sType;
@ -638,6 +750,8 @@ CXmlElement& CXmlElement::operator+=(const CXmlElement &oElement)
CXmlElement& CXmlElement::operator=(const CXmlElement &oElement)
{
// Clear();
m_bEmpty = oElement.m_bEmpty;
m_sType = oElement.m_sType;
m_sStyleId = oElement.m_sStyleId;
m_sDefault = oElement.m_sDefault;
@ -780,9 +894,7 @@ std::wstring CXmlElement::ConvertPStyle() const
if (sPPr.length() > 15)
sPStyle += sPPr;
if (!sPStyle.empty())
return sPStyle;
return L"";
return sPStyle;
}
std::wstring CXmlElement::ConvertRStyle() const
@ -817,9 +929,7 @@ std::wstring CXmlElement::ConvertRStyle() const
if (sRPr.length() > 15)
sRStyle += sRPr;
if (!sRStyle.empty())
return sRStyle;
return L"";
return sRStyle;
}
std::wstring CXmlElement::ConvertBasicInfoStyle() const
@ -934,6 +1044,7 @@ std::wstring CXmlElement::GetRStyle() const
sRStyle += ConvertRStyle();
sRStyle += L"</w:style>";
if (sRStyle.length() > 22)
return sRStyle;

View File

@ -5,6 +5,8 @@
class CXmlElement
{
bool m_bEmpty = false;
std::wstring m_sType;
std::wstring m_sStyleId;
std::wstring m_sDefault;
@ -79,62 +81,62 @@ public:
void CreateDefaultElement(const std::wstring sNameDefaultElement);
void Clear();
void SetType(std::wstring sType);
void SetStyleId(std::wstring sStyleId);
void SetDefault(std::wstring sDefault);
void SetCustomStyle(std::wstring sCustomStyle);
void SetS(std::wstring sS);
void SetType(const std::wstring sType);
void SetStyleId(const std::wstring sStyleId);
void SetDefault(const std::wstring sDefault);
void SetCustomStyle(const std::wstring sCustomStyle);
void SetS(const std::wstring sS);
void SetName(std::wstring sName);
void SetBasedOn(std::wstring sBasedOn);
void SetLink(std::wstring sLink);
void SetUiPriority(std::wstring sUiPriority);
void SetQFormat(bool bQFormat);
void SetUnhideWhenUsed(bool bUnhideWhenUsed);
void SetName(const std::wstring sName);
void SetBasedOn(const std::wstring sBasedOn);
void SetLink(const std::wstring sLink);
void SetUiPriority(const std::wstring sUiPriority);
void SetQFormat(const bool bQFormat);
void SetUnhideWhenUsed(const bool bUnhideWhenUsed);
// <rPr>
void SetB(bool bB);
void SetI(bool bI);
void SetU(std::wstring sU);
void SetRFonts(std::wstring sRFonts);
void SetColor(std::wstring sColor);
void SetSz(std::wstring sSz);
void SetB(const bool bB);
void SetI(const bool bI);
void SetU(const std::wstring sU);
void SetRFonts(const std::wstring sRFonts);
void SetColor(const std::wstring sColor);
void SetSz(const std::wstring sSz);
// </rPr>
// <pPr>
void SetKeepLines(bool bKeepLines);
void SetKeepNext(bool bKeepNext);
void SetContextualSpacing(bool bContextualSpacing);
void SetSpacing(std::wstring sSpacing);
void SetOutlineLvl(std::wstring sOutlineLvl);
void SetInd(std::wstring sInd);
void SetJc(std::wstring sJc);
void SetShd(std::wstring sShd);
void SetKeepLines(const bool bKeepLines);
void SetKeepNext(const bool bKeepNext);
void SetContextualSpacing(const bool bContextualSpacing);
void SetSpacing(const std::wstring sSpacing);
void SetOutlineLvl(const std::wstring sOutlineLvl);
void SetInd(const std::wstring sInd);
void SetJc(const std::wstring sJc);
void SetShd(const std::wstring sShd);
// <pBdr>
void SetTopBorder(std::wstring sTopBorder);
void SetLeftBorder(std::wstring sLeftBorder);
void SetBottomBorder(std::wstring sBottomBorder);
void SetRightBorder(std::wstring sRightBorder);
void SetTopBorder(const std::wstring sTopBorder);
void SetLeftBorder(const std::wstring sLeftBorder);
void SetBottomBorder(const std::wstring sBottomBorder);
void SetRightBorder(const std::wstring sRightBorder);
// </pBdr>
// </pPr>
// <tblPr>
void SetTblInd(std::wstring sTblInd);
void SetTblInd(const std::wstring sTblInd);
// <tblCellMar>
void SetCellTop(std::wstring sCellTop);
void SetCellLeft(std::wstring sCellLeft);
void SetCellBottom(std::wstring sCellBottom);
void SetCellRight(std::wstring sCellRight);
void SetCellTop(const std::wstring sCellTop);
void SetCellLeft(const std::wstring sCellLeft);
void SetCellBottom(const std::wstring sCellBottom);
void SetCellRight(const std::wstring sCellRight);
// <tblCellMar>
// <tblBorders>
void SetBorderTop(std::wstring sBorderTop);
void SetBorderLeft(std::wstring sBorderLeft);
void SetBorderBottom(std::wstring sBorderBottom);
void SetBorderRight(std::wstring sBorderRight);
void SetBorderInsideH(std::wstring sBorderInsideH);
void SetBorderInsideV(std::wstring sBorderInsideV);
void SetBorderTop(const std::wstring sBorderTop);
void SetBorderLeft(const std::wstring sBorderLeft);
void SetBorderBottom(const std::wstring sBorderBottom);
void SetBorderRight(const std::wstring sBorderRight);
void SetBorderInsideH(const std::wstring sBorderInsideH);
void SetBorderInsideV(const std::wstring sBorderInsideV);
// </tblBorders>
// </tblPr>

View File

@ -16,7 +16,7 @@ void CBookContentItem::Clear()
m_sLinear.clear();
}
bool CBookContentItem::ReadContentItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, int depth)
bool CBookContentItem::ReadContentItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, const int& depth)
{
if (!oXmlLiteReader.IsValid() || oXmlLiteReader.IsEmptyNode())
return false;
@ -29,9 +29,10 @@ bool CBookContentItem::ReadContentItem(XmlUtils::CXmlLiteReader &oXmlLiteReader,
oXmlLiteReader.MoveToFirstAttribute())
{
std::wstring sAttributeName = oXmlLiteReader.GetName();
while (!sAttributeName.empty())
{
std::wstring sAttributeValue = oXmlLiteReader.GetText();
const std::wstring& sAttributeValue = oXmlLiteReader.GetText();
if (sAttributeName == L"idref")
m_sID = sAttributeValue;

View File

@ -15,7 +15,7 @@ public:
void Clear();
bool ReadContentItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, int depth);
bool ReadContentItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, const int& depth);
};

View File

@ -29,10 +29,12 @@ bool CBookInfo::ReadInfo(XmlUtils::CXmlLiteReader &oXmlLiteReader)
if (!oXmlLiteReader.IsValid() || oXmlLiteReader.IsEmptyNode())
return false;
int nParentDepth = oXmlLiteReader.GetDepth();
const int& nParentDepth = oXmlLiteReader.GetDepth();
while(oXmlLiteReader.ReadNextSiblingNode(nParentDepth))
{
std::wstring sName = oXmlLiteReader.GetName();
const std::wstring& sName = oXmlLiteReader.GetName();
if (oXmlLiteReader.GetNamespacePrefix() == L"dc")
{
if (sName == L"dc:title")
@ -61,7 +63,7 @@ bool CBookInfo::ReadInfo(XmlUtils::CXmlLiteReader &oXmlLiteReader)
return true;
}
void CBookInfo::ShowInfo()
void CBookInfo::ShowInfo() const
{
std::wcout << "-----DATA-----" << std::endl;
@ -100,100 +102,112 @@ void CBookInfo::ShowInfo()
// std::wcout << m_vHrefs[i] << std::endl;
}
std::wstring CBookInfo::GetTitle()
const std::wstring CBookInfo::GetTitle() const
{
return m_sTitle;
}
std::wstring CBookInfo::GetCreators()
const std::wstring CBookInfo::GetCreators() const
{
if (m_arCreators.empty())
return L"";
std::wstring sCreators;
for (int i = 0; i < (int)m_arCreators.size() - 1; i++)
sCreators += m_arCreators[i] + L"; ";
sCreators += m_arCreators[m_arCreators.size() - 1];
for (const std::wstring& sCreator : m_arCreators)
sCreators += sCreator + L"; ";
sCreators.erase(sCreators.length() - 2, 2);
return sCreators;
}
std::wstring CBookInfo::GetPublishers()
const std::wstring CBookInfo::GetPublishers() const
{
if (m_arPublishers.empty())
return L"";
std::wstring sPublishers;
for (int i = 0; i < (int)m_arPublishers.size() - 1; i++)
sPublishers += m_arPublishers[i] + L", ";
sPublishers += m_arPublishers[m_arPublishers.size() - 1];
for (const std::wstring& sPublisher : m_arPublishers)
sPublishers += sPublisher + L", ";
sPublishers.erase(sPublishers.length() - 2, 2);
return sPublishers;
}
std::wstring CBookInfo::GetLanguages()
const std::wstring CBookInfo::GetLanguages() const
{
if (m_arLanguages.empty())
return L"";
std::wstring sLanguages;
for (int i = 0; i < (int)m_arLanguages.size() - 1; i++)
sLanguages += m_arLanguages[i] + L", ";
sLanguages += m_arLanguages[m_arLanguages.size() - 1];
for (const std::wstring& sLanguage : m_arLanguages)
sLanguages += sLanguage + L", ";
sLanguages.erase(sLanguages.length() - 2, 2);
return sLanguages;
}
std::wstring CBookInfo::GetContibutors()
const std::wstring CBookInfo::GetContibutors() const
{
if (m_arContributors.empty())
return L"";
std::wstring sContibutors;
for (int i = 0; i < (int)m_arContributors.size() - 1; i++)
sContibutors += m_arContributors[i] + L", ";
sContibutors += m_arContributors[m_arContributors.size() - 1];
for (const std::wstring& sContibutor : m_arContributors)
sContibutors += sContibutor + L", ";
sContibutors.erase(sContibutors.length() - 2, 2);
return sContibutors;
}
std::wstring CBookInfo::GetDescriptions()
const std::wstring CBookInfo::GetDescriptions() const
{
if (m_arDescriptions.empty())
return L"";
std::wstring sDescriptions;
for (int i = 0; i < (int)m_arDescriptions.size() - 1; i++)
sDescriptions += m_arDescriptions[i] + L", ";
sDescriptions += m_arDescriptions[m_arDescriptions.size() - 1];
for (const std::wstring& sDescription : m_arDescriptions)
sDescriptions += sDescription + L", ";
sDescriptions.erase(sDescriptions.length() - 2, 2);
return sDescriptions;
}
std::wstring CBookInfo::GetCoverage()
const std::wstring CBookInfo::GetCoverage() const
{
return m_sCoverage;
}
std::wstring CBookInfo::GetSubjects()
const std::wstring CBookInfo::GetSubjects() const
{
if (m_arSubjects.empty())
return L"";
std::wstring sSubjects;
for (int i = 0; i < (int)m_arSubjects.size() - 1; i++)
sSubjects += m_arSubjects[i] + L", ";
sSubjects += m_arSubjects[m_arSubjects.size() - 1];
for (const std::wstring& sSubject : m_arSubjects)
sSubjects += sSubject + L", ";
sSubjects.erase(sSubjects.length() - 2, 2);
return sSubjects;
}
std::wstring CBookInfo::GetIndentifier()
const std::wstring CBookInfo::GetIndentifier() const
{
return m_sIdentifier;
}
std::wstring CBookInfo::GetDate()
const std::wstring CBookInfo::GetDate() const
{
return m_sDate;
}

View File

@ -23,18 +23,18 @@ public:
void Clear();
bool ReadInfo(XmlUtils::CXmlLiteReader &oXmlLiteReader);
void ShowInfo();
void ShowInfo() const;
std::wstring GetTitle();
std::wstring GetCreators();
std::wstring GetPublishers();
std::wstring GetLanguages();
std::wstring GetContibutors();
std::wstring GetDescriptions();
std::wstring GetSubjects();
std::wstring GetCoverage();
std::wstring GetIndentifier();
std::wstring GetDate();
const std::wstring GetTitle() const;
const std::wstring GetCreators() const;
const std::wstring GetPublishers() const;
const std::wstring GetLanguages() const;
const std::wstring GetContibutors() const;
const std::wstring GetDescriptions() const;
const std::wstring GetSubjects() const;
const std::wstring GetCoverage() const;
const std::wstring GetIndentifier() const;
const std::wstring GetDate() const;
};
#endif // CBOOKINFO_H

View File

@ -18,7 +18,7 @@ void CBookItem::Clear()
m_eType = Default;
}
bool CBookItem::ReadItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, int depth)
bool CBookItem::ReadItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, const int& depth)
{
if (!oXmlLiteReader.IsValid() || oXmlLiteReader.IsEmptyNode())
return false;
@ -29,15 +29,19 @@ bool CBookItem::ReadItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, int depth)
oXmlLiteReader.MoveToFirstAttribute())
{
std::wstring sAttributeName = oXmlLiteReader.GetName();
while (!sAttributeName.empty())
{
std::wstring sAttributeValue = oXmlLiteReader.GetText();
const std::wstring& sAttributeValue = oXmlLiteReader.GetText();
if (sAttributeName == L"href")
{
if (sAttributeValue.find(L"/") == std::wstring::npos)
const auto& posLastSlash = sAttributeValue.find_last_of(L'/');
if (posLastSlash == std::wstring::npos)
m_sRef = sAttributeValue;
else
m_sRef = sAttributeValue.substr(sAttributeValue.find_last_of(L"/") + 1, sAttributeValue.length());
m_sRef = sAttributeValue.substr(posLastSlash + 1, sAttributeValue.length() - 1);
}
else if (sAttributeName == L"id")
m_sID = sAttributeValue;
@ -69,12 +73,12 @@ bool CBookItem::ReadItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, int depth)
return true;
}
std::wstring CBookItem::GetID()
const std::wstring CBookItem::GetID() const
{
return m_sID;
}
std::wstring CBookItem::GetRef()
const std::wstring CBookItem::GetRef() const
{
return m_sRef;
}

View File

@ -26,9 +26,9 @@ public:
~CBookItem();
void Clear();
bool ReadItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, int depth);
std::wstring GetID();
std::wstring GetRef();
bool ReadItem(XmlUtils::CXmlLiteReader &oXmlLiteReader, const int& depth);
const std::wstring GetID() const;
const std::wstring GetRef() const;
};
#endif // CBOOKITEM_H

View File

@ -16,11 +16,12 @@ bool CBookToc::ReadToc(XmlUtils::CXmlLiteReader &oXmlLiteReader)
if (!oXmlLiteReader.IsValid() || oXmlLiteReader.IsEmptyNode())
return false;
int nParentDepth = oXmlLiteReader.GetDepth();
const int& nParentDepth = oXmlLiteReader.GetDepth();
while(oXmlLiteReader.ReadNextSiblingNode(nParentDepth))
{
std::wstring sName = oXmlLiteReader.GetName();
const std::wstring& sName = oXmlLiteReader.GetName();
if (sName == L"docTitle")
ReadTitle(oXmlLiteReader);
else if(sName == L"navMap")
@ -49,7 +50,7 @@ bool CBookToc::ReadMap(XmlUtils::CXmlLiteReader &oXmlLiteReader)
ReadPoint(oXmlLiteReader);
}
std::wstring CBookToc::GetAttributeValue(XmlUtils::CXmlLiteReader &oXmlLiteReader, std::wstring sAttributeName)
std::wstring CBookToc::GetAttributeValue(XmlUtils::CXmlLiteReader &oXmlLiteReader, const std::wstring& sAttributeName) const
{
if (oXmlLiteReader.GetAttributesCount() > 0 &&
oXmlLiteReader.MoveToFirstAttribute())
@ -61,7 +62,12 @@ std::wstring CBookToc::GetAttributeValue(XmlUtils::CXmlLiteReader &oXmlLiteReade
if (_sAttributeName == sAttributeName)
{
std::wstring sText = oXmlLiteReader.GetText();
sText = sText.substr(sText.find_last_of(L"/") + 1, sText.length());
const auto& posLastSlash = sText.find_last_of(L"/");
if (posLastSlash != std::wstring::npos)
sText = sText.substr(posLastSlash + 1, sText.length() - 1);
oXmlLiteReader.MoveToElement();
return sText;
}
@ -81,17 +87,19 @@ void CBookToc::AddStruct()
if (m_arMap.size() == 4)
{
m_structData structData;
for (int i = 0; i < (int)m_arMap.size(); i++)
for (const std::pair<std::wstring, std::wstring>& sValue : m_arMap)
{
if (m_arMap[i].first == L"id")
structData.sID = m_arMap[i].second;
else if (m_arMap[i].first == L"playOrder")
structData.sPlayOrder = m_arMap[i].second;
else if (m_arMap[i].first == L"text")
structData.sText = m_arMap[i].second;
else if (m_arMap[i].first == L"src")
structData.sRef = m_arMap[i].second;
if (sValue.first == L"id")
structData.sID = sValue.second;
else if (sValue.first == L"playOrder")
structData.sPlayOrder = sValue.second;
else if (sValue.first == L"text")
structData.sText = sValue.second;
else if (sValue.first == L"src")
structData.sRef = sValue.second;
}
m_arData.push_back(structData);
m_arMap.clear();
}
@ -102,11 +110,11 @@ bool CBookToc::ReadPoint(XmlUtils::CXmlLiteReader &oXmlLiteReader)
if (!oXmlLiteReader.IsValid() || oXmlLiteReader.IsEmptyNode())
return false;
int nParentDepth = oXmlLiteReader.GetDepth();
const int& nParentDepth = oXmlLiteReader.GetDepth();
while (oXmlLiteReader.ReadNextSiblingNode(nParentDepth))
{
std::wstring sName = oXmlLiteReader.GetName();
const std::wstring& sName = oXmlLiteReader.GetName();
if (sName == L"navPoint")
{
@ -130,29 +138,29 @@ bool CBookToc::ReadPoint(XmlUtils::CXmlLiteReader &oXmlLiteReader)
}
}
void CBookToc::ShowToc()
void CBookToc::ShowToc() const
{
std::wcout << L"-----TOC-----" << std::endl;
std::wcout << "Title - " << m_sTitle << std::endl;
for (int i = 0; i < (int)m_arData.size(); i++)
for (const m_structData& oData : m_arData)
{
std::wcout << m_arData[i].sPlayOrder << " - " << m_arData[i].sID << " - " << m_arData[i].sText << " - " << m_arData[i].sRef << std::endl;
std::wcout << oData.sPlayOrder << " - " << oData.sID << " - " << oData.sText << " - " << oData.sRef << std::endl;
// std::wstring sl = m_arData[i].sText + L"\n";
// std::fputws(sl.c_str() , fl);
}
}
int CBookToc::GetCountToc()
int CBookToc::GetCountToc() const
{
return (int)m_arData.size();
return m_arData.size();
}
std::pair<std::wstring, std::wstring> CBookToc::GetTextAndRef(int nIndex)
const std::pair<std::wstring, std::wstring> CBookToc::GetTextAndRef(const int& nIndex) const
{
if (nIndex < 0 || nIndex > (int)m_arData.size())
return std::pair<std::wstring, std::wstring>(L"", L"");
if (nIndex < 0 || nIndex > GetCountToc())
return {L"", L""};
return std::pair<std::wstring, std::wstring>(m_arData[nIndex].sText, m_arData[nIndex].sRef);
return {m_arData[nIndex].sText, m_arData[nIndex].sRef};
}
void CBookToc::Clear()

View File

@ -23,16 +23,16 @@ class CBookToc
bool ReadTitle(XmlUtils::CXmlLiteReader &oXmlLiteReader);
bool ReadMap(XmlUtils::CXmlLiteReader &oXmlLiteReader);
bool ReadPoint(XmlUtils::CXmlLiteReader &oXmlLiteReader);
std::wstring GetAttributeValue(XmlUtils::CXmlLiteReader &oXmlLiteReader, std::wstring sAttributeName);
std::wstring GetAttributeValue(XmlUtils::CXmlLiteReader &oXmlLiteReader, const std::wstring& sAttributeName) const;
void AddStruct();
public:
CBookToc();
~CBookToc();
void Clear();
bool ReadToc(XmlUtils::CXmlLiteReader &oXmlLiteReader);
void ShowToc();
int GetCountToc();
std::pair<std::wstring, std::wstring> GetTextAndRef(int nIndex);
void ShowToc() const;
int GetCountToc() const;
const std::pair<std::wstring, std::wstring> GetTextAndRef(const int& nIndex) const;
};
#endif // CBOOKTOC_H

View File

@ -19,13 +19,14 @@ CEpubFile::~CEpubFile()
HRESULT CEpubFile::IsEbubFile(const std::wstring &sFileName)
{
auto posPoint = sFileName.find_last_of(L'.');
const auto& posPoint = sFileName.find_last_of(L'.');
if (posPoint == std::wstring::npos ||
sFileName.substr(posPoint + 1) != L"epub")
return S_FALSE;
COfficeUtils oOfficeUtils;
if (oOfficeUtils.IsArchive(sFileName) == S_OK &&
oOfficeUtils.IsFileExistInArchive(sFileName, L"META-INF/container.xml") == S_OK)
{
@ -49,10 +50,10 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
}
else
{
NSDirectory::CreateDirectories(m_sTempDir + L"/tmp");
SetTempDirectory(m_sTempDir + L"/tmp");
NSDirectory::CreateDirectories(m_sTempDir);
SetTempDirectory(m_sTempDir);
}
// NSDirectory::CreateDirectory(sOutputFile);
COfficeUtils oOfficeUtils;
wchar_t* password = NULL;
@ -65,10 +66,12 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
{
oXmlLiteReader.ReadNextNode();
int nParentDepth = oXmlLiteReader.GetDepth();
const int& nParentDepth = oXmlLiteReader.GetDepth();
while (oXmlLiteReader.ReadNextSiblingNode(nParentDepth))
{
std::wstring sName = oXmlLiteReader.GetName();
const std::wstring& sName = oXmlLiteReader.GetName();
if (sName == L"metadata")
{
m_oBookInfo.ReadInfo(oXmlLiteReader);
@ -78,19 +81,21 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
}
else if (sName == L"manifest")
{
int _nParentDepth = oXmlLiteReader.GetDepth();
const int& _nParentDepth = oXmlLiteReader.GetDepth();
while (true)
{
CBookItem oItem;
if (oItem.ReadItem(oXmlLiteReader, _nParentDepth))
m_mapRefs[oItem.GetID()] = oItem;
m_mapRefs.emplace(oItem.GetID(), oItem);
else
break;
}
}
else if (sName == L"spine")
{
int _nParentDepth = oXmlLiteReader.GetDepth();
const int& _nParentDepth = oXmlLiteReader.GetDepth();
while (true)
{
CBookContentItem oContentItem;
@ -113,20 +118,6 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
// m_oToc.ShowToc();
// #endif
// CDocxFile oDocxFile;
// oDocxFile.CreateTempFiles(sOutputFile, m_sTempDir);
// oDocxFile.AddBookToc(&m_oToc);
// std::wstring sTempDir = m_sTempDir + L"/docx";
// std::wstring _sOutputFile = sOutputFile + L"/test.docx";
// NSFile::CFileBinary oFileBinary;
// oFileBinary.CreateFileW(_sOutputFile);
// oFileBinary.CloseFile();
// oDocxFile.SaveToFile();
CHtmlFile2 oFile;
CHtmlParams oFileParams;
@ -137,15 +128,15 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s
oFileParams.SetDescription(m_oBookInfo.GetDescriptions());
std::wstring sDocxFileTempDir = m_sTempDir + L"/res";
const std::wstring& sDocxFileTempDir = m_sTempDir + L"/res";
NSDirectory::CreateDirectory(sDocxFileTempDir);
oFile.SetTmpDirectory(sDocxFileTempDir);
std::vector<std::wstring> arFiles;
for (size_t i = 0; i < m_arContents.size(); i++)
arFiles.push_back(m_sTempDir + L"\\" + m_mapRefs[m_arContents[i].m_sID].GetRef());
for (const CBookContentItem& oContent : m_arContents)
arFiles.push_back(m_sTempDir + L"\\" + m_mapRefs[oContent.m_sID].GetRef());
std::wcout << L"---The conversion process from Epub to Docx...---" << std::endl;
if (oFile.OpenBatch(arFiles, sDocxFileTempDir, &oFileParams) == S_OK)
@ -167,12 +158,14 @@ void CEpubFile::Clear()
m_mapRefs.clear();
m_oToc.Clear();
m_arContents.clear();
NSDirectory::DeleteDirectory(m_sTempDir);
if (!m_sTempDir.empty())
NSDirectory::DeleteDirectory(m_sTempDir);
}
void CEpubFile::ShowMap()
{
std::cout << "-----MAP-----" << std::endl;
for (size_t i = 0; i < m_arContents.size(); i++)
std::wcout << m_arContents[i].m_sID << " - " << m_mapRefs[m_arContents[i].m_sID].GetRef() << std::endl;
for (const CBookContentItem& oItem : m_arContents)
std::wcout << oItem.m_sID << L" - " << m_mapRefs[oItem.m_sID].GetRef() << std::endl;
}

View File

@ -12,6 +12,7 @@ int main(int argc, char *argv[])
std::wstring sOutputDirectory = NSFile::GetProcessDirectory() + L"/OutputFiles";
NSDirectory::CreateDirectory(sOutputDirectory);
clock_t tTime1 = clock();
//Русские символы в консоль не выводятся
for (std::wstring sFileName : arFiles)
{
@ -23,7 +24,7 @@ int main(int argc, char *argv[])
{
std::wstring sFile = sFileName.substr(0, sFileName.find_last_of(L'.'));
auto posLastSlash = sFile.find_last_of(L'/');
auto posLastSlash = sFile.find_last_of(L'\\');
if (posLastSlash != std::wstring::npos)
sFile = sFile.substr(posLastSlash + 1);
@ -41,5 +42,9 @@ int main(int argc, char *argv[])
std::wcout << (double)(tTimeEnd - tTimeBegin) / CLOCKS_PER_SEC << std::endl;
}
clock_t tTime2 = clock();
std::wcout << (double)(tTime2 - tTime1) / CLOCKS_PER_SEC << std::endl;
return 0;
}