mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
feat: wxml common
This commit is contained in:
parent
a6cab234b6
commit
440e8935ef
@ -52,6 +52,7 @@ add_executable(wcsc
|
|||||||
src/wcsc.cpp
|
src/wcsc.cpp
|
||||||
src/wcsc/usage.cpp
|
src/wcsc/usage.cpp
|
||||||
src/wxa/wxa.cpp
|
src/wxa/wxa.cpp
|
||||||
|
src/wxml/common.cpp
|
||||||
src/wxml/rewrite.cpp
|
src/wxml/rewrite.cpp
|
||||||
src/wxss/common.cpp
|
src/wxss/common.cpp
|
||||||
src/wxss/token.cpp
|
src/wxss/token.cpp
|
||||||
|
@ -13,6 +13,14 @@
|
|||||||
|
|
||||||
namespace WXML
|
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<WXML::STRTOKEN,std::string> &, std::stringstream &);
|
||||||
|
void StrSplitList4ClassSuffix(char const*,char const*,std::vector<std::pair<WXML::STRTOKEN,std::string>> &);
|
||||||
|
void StrSplitList4RPX(char const*, char const*, char const*, std::vector<std::pair<WXML::STRTOKEN, std::string>> &);
|
||||||
|
|
||||||
namespace Rewrite
|
namespace Rewrite
|
||||||
{
|
{
|
||||||
void ToStringCode(char const*, int, std::stringstream &ss);
|
void ToStringCode(char const*, int, std::stringstream &ss);
|
||||||
|
@ -0,0 +1,198 @@
|
|||||||
|
|
||||||
|
#include "../include/wxml.h"
|
||||||
|
|
||||||
|
namespace WXML {
|
||||||
|
void StrSplitList4ClassSuffix(
|
||||||
|
char const* a1,
|
||||||
|
char const* str,
|
||||||
|
std::vector<std::pair<WXML::STRTOKEN,std::string>> & 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<WXML::STRTOKEN,std::string> & 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<std::pair<WXML::STRTOKEN, std::string>> 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<std::pair<WXML::STRTOKEN,std::string>> 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<std::pair<WXML::STRTOKEN, std::string>> & 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
#include "../include/wxss.h"
|
#include "../include/wxss.h"
|
||||||
#include "../include/wxa.h"
|
#include "../include/wxa.h"
|
||||||
|
#include "../include/wxml.h"
|
||||||
|
|
||||||
namespace WXSS
|
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 &)
|
void XCompiler::GetHostRule(std::string &)
|
||||||
{
|
{
|
||||||
|
@ -10520,7 +10520,7 @@ char __cdecl WXML::IsFloat(WXML *this)
|
|||||||
char v2; // cl
|
char v2; // cl
|
||||||
char v3; // al
|
char v3; // al
|
||||||
|
|
||||||
v1 = ((*(_BYTE *)this - 43) & 0xFD) == 0;
|
v1 = ((*(_BYTE *)this - '+'/*43*/) & 0xFD) == 0;
|
||||||
v2 = 0;
|
v2 = 0;
|
||||||
while ( 1 )
|
while ( 1 )
|
||||||
{
|
{
|
||||||
@ -10532,7 +10532,7 @@ char __cdecl WXML::IsFloat(WXML *this)
|
|||||||
if ( v2 )
|
if ( v2 )
|
||||||
return 0;
|
return 0;
|
||||||
v2 = 1;
|
v2 = 1;
|
||||||
LABEL_7:
|
LABEL_7:
|
||||||
++v1;
|
++v1;
|
||||||
}
|
}
|
||||||
if ( (unsigned __int8)(v3 - 48) <= 9u )
|
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(v19);
|
||||||
std::string::_M_dispose(v16);
|
std::string::_M_dispose(v16);
|
||||||
}
|
}
|
||||||
|
|
||||||
a1 = &lpuexcpt[v7];
|
a1 = &lpuexcpt[v7];
|
||||||
Size = strstr(&lpuexcpt[v7], SubStr);
|
Size = strstr(&lpuexcpt[v7], SubStr);
|
||||||
if ( !Size )
|
if ( !Size )
|
||||||
@ -10607,8 +10608,8 @@ void __cdecl WXML::StrSplitList4RPX(char *a1, char *Str, char *SubStr, void **a4
|
|||||||
std::string::_M_construct<char const*>(&v10, (unsigned __int8 *)a1, (size_t)Size);
|
std::string::_M_construct<char const*>(&v10, (unsigned __int8 *)a1, (size_t)Size);
|
||||||
if ( WXML::IsFloat((int)&v10) )
|
if ( WXML::IsFloat((int)&v10) )
|
||||||
{
|
{
|
||||||
v14 = 0;
|
|
||||||
v13 = &v15;
|
v13 = &v15;
|
||||||
|
v14 = 0;
|
||||||
v15 = 0;
|
v15 = 0;
|
||||||
std::string::reserve(&v13, v11 + 3);
|
std::string::reserve(&v13, v11 + 3);
|
||||||
if ( (unsigned int)(0x3FFFFFFF - v14) <= 2 )
|
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);
|
std::string::_M_dispose(v6);
|
||||||
}
|
}
|
||||||
v8 = 0;
|
v8 = 0;
|
||||||
std::string::basic_string(v9, (char *)off_50F2CC);
|
std::string::basic_string(v9, (char *)off_50F2CC); // "[1]"
|
||||||
std::vector<std::pair<WXML::STRTOKEN,std::string>>::emplace_back<std::pair<WXML::STRTOKEN,std::string>>(a3, &v8);
|
std::vector<std::pair<WXML::STRTOKEN,std::string>>::emplace_back<std::pair<WXML::STRTOKEN,std::string>>(a3, &v8);
|
||||||
std::string::_M_dispose(v9);
|
std::string::_M_dispose(v9);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user