This commit is contained in:
aozhiwei 2021-09-07 16:29:54 +08:00
parent af799ef1bd
commit c4479f4473

View File

@ -2,6 +2,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <regex.h>
#include <regex>
@ -53,6 +54,49 @@ static void ParseElemets(const std::string& textid,
const char* pcurr = text.c_str();
const char* pend = text.c_str() + text.length();
while (pcurr < pend) {
#if 1
int pos = 0;
int length = 0;
bool match_ok = false;
std::string m_str;
{
const char* tmp_curr = pcurr;
while (*tmp_curr) {
if (tmp_curr[0] == '$' && tmp_curr[1] == '{') {
int i = 2;
while (tmp_curr[i] != '}') {
if (tmp_curr[i] == '\0') {
break;
}
++i;
}
if (tmp_curr[i] == '}') {
pos = tmp_curr - pcurr;
length = i + 1;
m_str = std::string(tmp_curr, length);
match_ok = true;
break;
} else {
++tmp_curr;
}
} else {
++tmp_curr;
}
}
}
if (match_ok) {
if (pos > 0) {
auto& e = a8::FastAppend(elements);
e = std::make_tuple(kTextElement, std::string(pcurr, pos));
}
parsevar_cb(m_str, elements);
pcurr += pos + length;
} else {
auto& e = a8::FastAppend(elements);
e = std::make_tuple(kTextElement, std::string(pcurr, pend - pcurr));
pcurr = pend;
}
#else
std::cmatch m;
if (std::regex_search(pcurr, m, re)) {
if (m.position() > 0) {
@ -67,6 +111,7 @@ static void ParseElemets(const std::string& textid,
e = std::make_tuple(kTextElement, std::string(pcurr, pend - pcurr));
pcurr = pend;
}
#endif
}
{
@ -76,12 +121,12 @@ static void ParseElemets(const std::string& textid,
a8::MutableXObject* obj_el = a8::MutableXObject::NewObject();
obj_el->SetVal("type", std::get<0>(e));
obj_el->SetVal("val", std::get<1>(e));
arr->Push(obj_el);
arr->Push(*obj_el);
}
obj->SetVal("text", text);
obj->SetVal("elemets", arr);
obj->SetVal("elemets", *arr);
a8::UdpLog::Instance()->Info
("load textid:%s ",
("load textid:%s %s",
{
textid,
obj->ToJsonStr()