wx-compiler/src/wxss/css_tree_lib/css_syntax_tree.cpp
2023-08-19 23:08:08 +08:00

145 lines
4.4 KiB
C++

#include "../../include/wxss.h"
#include "../../include/wxml.h"
#include <sstream>
namespace WXSS
{
namespace CSSTreeLib
{
CSSSyntaxTree::CSSSyntaxTree(/* args */)
{
}
CSSSyntaxTree::~CSSSyntaxTree()
{
}
void CSSSyntaxTree::RenderCode(std::string & a2, bool a3)
{
if (this->offset_116)
{
if (!this->offset_172)
{
if (this->offset_132 && a3)
{
a2 += *this->offset_132;
}
else
{
a2 += this->offset_24.GetLiteral();
}
for (int i = 0; i < this->offset_120.size(); i++)
{
auto cur = this->offset_120[i];
if (
i
&& cur->offset_164 > this->offset_120[i - 1]->offset_168
&& a2[a2.length() - 1] != '\n'
)
{
a2 += " ";
}
cur->RenderCode(a2, a3);
}
if (this->offset_0 == "MEDIA_RULE" || this->offset_0 == "RULE" || this->offset_0 == "DIRECTIVE")
{
a2 += "\n";
}
}
}
}
/**
* offset_116等需要修正
*/
void CSSSyntaxTree::Print2Stream(int a2, std::stringstream & a3)
{
std::string v14;
for (int i = 0; i < a2; i++)
{
if (this->offset_116)
{
v14 = " ";
}
else
{
v14 = "- ";
}
a3 << v14;
}
if (this->offset_132)
{
a3 << this->offset_0 << ": " << this->offset_132;
}
else
{
a3 << this->offset_0 << ": ";
a3 << this->offset_24.GetLiteral();
}
a3 << std::endl;
for (int i = 0; i < this->offset_120.size(); i++)
{
this->offset_120[i]->Print2Stream(a2 + 1, a3);
}
}
void CSSSyntaxTree::GetHostRule(std::string & a2)
{
if (this->offset_172 == 1)
{
for (int i = 0; i < this->offset_120.size(); i++)
{
auto cur = this->offset_120[i];
if (cur->offset_0 == "SELECTORS")
{
auto v148 = this->offset_148.get();
std::string v14 = v148[0].substr(2, v148[0].length() - 7);
std::string v15 = WXML::Rewrite::ToStringCode2(v14);
v15.insert(0, "[is=\"");
v15.append("\"]");
a2 += v15;
}
else
{
cur->RenderCode(a2, true);
}
}
a2 += "\n";
return;
}
if (this->offset_172 == 2)
{
for (int i = 0; i < this->offset_120.size(); i++)
{
auto cur = this->offset_120[i];
if (cur->offset_0 != "SELECTORS")
{
cur->RenderCode(a2, true);
}
else
{
cur->RenderCode(a2, true);
auto v148 = this->offset_148.get();
std::string v14 = v148[0].substr(2, v148[0].length() - 7);
auto v15 = WXML::Rewrite::ToStringCode2(v14);
v15.insert(0, "[is=\"");
v15.append("\"]");
a2 += v15;
}
}
a2 += "\n";
return;
}
for (int i = 0; i < this->offset_120.size(); i++)
{
auto cur = this->offset_120[i];
cur->GetHostRule(a2);
}
}
}
} // namespace WXSS