From 440e8935ef77f50e8cc53dd267aa7deb0d6fdbac Mon Sep 17 00:00:00 2001 From: msojocs Date: Sun, 6 Aug 2023 22:41:22 +0800 Subject: [PATCH] feat: wxml common --- CMakeLists.txt | 1 + src/include/wxml.h | 8 ++ src/wxml/common.cpp | 198 ++++++++++++++++++++++++++++++++++++++ src/wxss/x_compiler.cpp | 7 +- test/wcsc.disassembly.cpp | 9 +- 5 files changed, 217 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d25a41..62c97da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ add_executable(wcsc src/wcsc.cpp src/wcsc/usage.cpp src/wxa/wxa.cpp + src/wxml/common.cpp src/wxml/rewrite.cpp src/wxss/common.cpp src/wxss/token.cpp diff --git a/src/include/wxml.h b/src/include/wxml.h index 94331ad..d9c53d9 100644 --- a/src/include/wxml.h +++ b/src/include/wxml.h @@ -13,6 +13,14 @@ namespace WXML { + using STRTOKEN = int; + void GetStrForMakingCSS(std::string const&,std::stringstream &); + bool IsFloat(char const*); + bool IsFloat(std::string const&); + void RenderStrToken(std::pair &, std::stringstream &); + void StrSplitList4ClassSuffix(char const*,char const*,std::vector> &); + void StrSplitList4RPX(char const*, char const*, char const*, std::vector> &); + namespace Rewrite { void ToStringCode(char const*, int, std::stringstream &ss); diff --git a/src/wxml/common.cpp b/src/wxml/common.cpp index e69de29..088bce3 100644 --- a/src/wxml/common.cpp +++ b/src/wxml/common.cpp @@ -0,0 +1,198 @@ + +#include "../include/wxml.h" + +namespace WXML { + void StrSplitList4ClassSuffix( + char const* a1, + char const* str, + std::vector> & a3 + ) + { + const char* lt = nullptr; + const char* v3 = nullptr; + if (a1 && str) + { + for (int i = strlen(str); ; a1 = v3 + i) + { + v3 = strstr(a1, str); + if (!v3) + { + break; + } + if (a1 != v3) + { + std::string v6(a1, v3); + a3.emplace_back(1, v6); + } + a3.emplace_back(0, "[1]"); + + } + if (*a1) + { + a3.emplace_back(1, a1); + } + + } + } + void RenderStrToken(std::pair & a1, std::stringstream & a2) + { + if (a1.first) + { + if (a1.first != 1) + { + return ; + } + a2 << "\"" << a1.second << "\","; + } + else + { + a2 << a1.second << ","; + } + } + + bool IsFloat(char const* t) + { + int v1 = ((t[0] - '+') & 0xFD) == 0; + bool v2 = false; + // while (true) + // { + // char v3 = t[v1]; + // if (!v3) + // { + // return true; + // } + // if (v3 != '.') + // { + // if (v3 - '0' <= 9) + // { + // v1++; + // continue; + // } + // break; + // } + // if (v2) + // { + // return false; + // } + // v2 = true; + // v1++; + // } + // return false; + int len = strlen(t); + for (int i = v1; i < len; i++) + { + if (t[i] == '.') + { + if (v2) + { + // 有两个小数点 + return false; + } + v2 = true; // 标记有小数点 + continue; + } + if (t[i] - '0' > 9 || t[i] - '0' < 0) + { + // 非数字 + return false; + } + } + + return true; + } + bool IsFloat(std::string const& a1) + { + if (a1.length()) + { + return IsFloat(a1.data()); + } + else + { + return false; + } + } + void GetStrForMakingCSS(std::string const& a1, std::stringstream & a2) + { + std::vector> v7; + WXML::StrSplitList4RPX(a1.data(), "%%?", "rpx?%%", v7); + for (int i = 0; i < v7.size(); i++) + { + auto cur = v7[i]; + if (cur.first == 1) + { + std::vector> v10; + WXML::StrSplitList4ClassSuffix(cur.second.data(), "%%HERESUFFIX%%", v10); + for (int j=0; j < v10.size(); j++) + { + WXML::RenderStrToken(v10[i], a2); + } + } + else if (!cur.first) + { + WXML::RenderStrToken(cur, a2); + } + } + + } + + void StrSplitList4RPX(char const* a1, char const* str, char const* subStr, std::vector> & a4) + { + if (subStr != nullptr && str != nullptr && a1) + { + int v7 = strlen(str); + int v6 = strlen(subStr); + while (true) + { + const char* v4 = strstr(a1, str); + if (!v4) + { + break; + } + int v18 = 0; + if (a1 != v4) + { + std::string v16(a1, v4); + v18 = 1; + a4.emplace_back(v18, v16); + } + + a1 = &v4[v7]; + const char* size = strstr(&v4[v7], subStr); + if (!size) + { + std::string v16(v4); + v18 = 1; + a4.emplace_back(v18, v16); + return ; + } + std::string v10(a1, size); + if (WXML::IsFloat(v10)) + { + std::string v13; + // v13.reserve( + 3); + v13.append("[0,"); + v13.append(v10); + v13.append("]"); + int v18 = 0; + a4.emplace_back(v18, v13); + a1 = &size[v6]; + } + else + { + std::string v16(v4, a1); + int v18 = 1; + a4.emplace_back(v18, v16); + + } + } + if (!*a1) + { + return; + } + std::string v16(a1); + int v18 = 1; + a4.emplace_back(v18, v16); + + } + } +} \ No newline at end of file diff --git a/src/wxss/x_compiler.cpp b/src/wxss/x_compiler.cpp index 420b053..a967878 100644 --- a/src/wxss/x_compiler.cpp +++ b/src/wxss/x_compiler.cpp @@ -1,5 +1,6 @@ #include "../include/wxss.h" #include "../include/wxa.h" +#include "../include/wxml.h" namespace WXSS { @@ -140,9 +141,11 @@ namespace WXSS { } - void XCompiler::DealRPX(std::string &, std::stringstream &) + void XCompiler::DealRPX(std::string & a1, std::stringstream & a2) { - throw "not implement"; + std::string v3 = WXML::Rewrite::ToStringCode2(a1); + WXML::GetStrForMakingCSS(v3, a2); + a1 = ""; } void XCompiler::GetHostRule(std::string &) { diff --git a/test/wcsc.disassembly.cpp b/test/wcsc.disassembly.cpp index 7b69e20..0b36acc 100644 --- a/test/wcsc.disassembly.cpp +++ b/test/wcsc.disassembly.cpp @@ -10520,7 +10520,7 @@ char __cdecl WXML::IsFloat(WXML *this) char v2; // cl char v3; // al - v1 = ((*(_BYTE *)this - 43) & 0xFD) == 0; + v1 = ((*(_BYTE *)this - '+'/*43*/) & 0xFD) == 0; v2 = 0; while ( 1 ) { @@ -10532,7 +10532,7 @@ char __cdecl WXML::IsFloat(WXML *this) if ( v2 ) return 0; v2 = 1; -LABEL_7: + LABEL_7: ++v1; } if ( (unsigned __int8)(v3 - 48) <= 9u ) @@ -10591,6 +10591,7 @@ void __cdecl WXML::StrSplitList4RPX(char *a1, char *Str, char *SubStr, void **a4 std::string::_M_dispose(v19); std::string::_M_dispose(v16); } + a1 = &lpuexcpt[v7]; Size = strstr(&lpuexcpt[v7], SubStr); if ( !Size ) @@ -10607,8 +10608,8 @@ void __cdecl WXML::StrSplitList4RPX(char *a1, char *Str, char *SubStr, void **a4 std::string::_M_construct(&v10, (unsigned __int8 *)a1, (size_t)Size); if ( WXML::IsFloat((int)&v10) ) { - v14 = 0; v13 = &v15; + v14 = 0; v15 = 0; std::string::reserve(&v13, v11 + 3); if ( (unsigned int)(0x3FFFFFFF - v14) <= 2 ) @@ -10683,7 +10684,7 @@ void __cdecl WXML::StrSplitList4ClassSuffix(char *a1, char *Str, void **a3) std::string::_M_dispose(v6); } v8 = 0; - std::string::basic_string(v9, (char *)off_50F2CC); + std::string::basic_string(v9, (char *)off_50F2CC); // "[1]" std::vector>::emplace_back>(a3, &v8); std::string::_M_dispose(v9); }