review fixes
This commit is contained in:
@@ -23,8 +23,8 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef pijsonserialization_H
|
#ifndef PIJSONSERIALIZATION_H
|
||||||
#define pijsonserialization_H
|
#define PIJSONSERIALIZATION_H
|
||||||
|
|
||||||
#include "pijson.h"
|
#include "pijson.h"
|
||||||
|
|
||||||
@@ -191,8 +191,8 @@ inline PIJSON piSerializeJSON(const PIDeque<T> & v) {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline PIJSON piSerializeJSON(const PIVector2D<T> & v) {
|
inline PIJSON piSerializeJSON(const PIVector2D<T> & v) {
|
||||||
PIJSON ret;
|
PIJSON ret;
|
||||||
ret["cols"] = v.cols();
|
ret["cols"] = static_cast<uint>(v.cols());
|
||||||
ret["rows"] = v.rows();
|
ret["rows"] = static_cast<uint>(v.rows());
|
||||||
ret["mat"] = piSerializeJSON(v.plainVector());
|
ret["mat"] = piSerializeJSON(v.plainVector());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -255,10 +255,9 @@ inline void piDeserializeJSON(PIVariant & v, const PIJSON & js) {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void piDeserializeJSON(complex<T> & v, const PIJSON & js) {
|
inline void piDeserializeJSON(complex<T> & v, const PIJSON & js) {
|
||||||
T c[2];
|
if (!js.isArray()) return;
|
||||||
piDeserializeJSON(c[0], js[0]);
|
piDeserializeJSON(reinterpret_cast<T(&)[2]>(v)[0], js[0]);
|
||||||
piDeserializeJSON(c[1], js[1]);
|
piDeserializeJSON(reinterpret_cast<T(&)[2]>(v)[1], js[1]);
|
||||||
v = complex<T>(c[0], c[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -366,10 +365,10 @@ template<typename T>
|
|||||||
inline void piDeserializeJSON(PIVector2D<T> & v, const PIJSON & js) {
|
inline void piDeserializeJSON(PIVector2D<T> & v, const PIJSON & js) {
|
||||||
v.clear();
|
v.clear();
|
||||||
if (!js.isObject()) return;
|
if (!js.isObject()) return;
|
||||||
v.resize(js["rows"].toInt(), js["cols"].toInt());
|
|
||||||
const auto & mat(js["mat"]);
|
const auto & mat(js["mat"]);
|
||||||
if (!mat.isArray()) return;
|
if (!mat.isArray()) return;
|
||||||
piDeserializeJSON(v.plainVector(), mat);
|
piDeserializeJSON(v.plainVector(), mat);
|
||||||
|
v.resize(js["rows"].toInt(), js["cols"].toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -412,4 +411,4 @@ T PIJSON::deserialize(const PIJSON & json) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // pijsonserialization_h
|
#endif // PIJSONSERIALIZATION_H
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ PRIVATE_DEFINITION_START(PIRegularExpression)
|
|||||||
|
|
||||||
PIString getNEString(const void * ptr, uint32_t max_size) {
|
PIString getNEString(const void * ptr, uint32_t max_size) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
auto * cptr = (PIChar *)ptr;
|
const auto * cptr = static_cast<const PIChar *>(ptr);
|
||||||
uint32_t sz = 0;
|
uint32_t sz = 0;
|
||||||
while (*cptr != PIChar()) {
|
while (*cptr != PIChar()) {
|
||||||
ret.append(*cptr);
|
ret.append(*cptr);
|
||||||
cptr++;
|
cptr++;
|
||||||
@@ -64,15 +64,14 @@ PRIVATE_DEFINITION_START(PIRegularExpression)
|
|||||||
bool compile(PIString & pat, Options opt) {
|
bool compile(PIString & pat, Options opt) {
|
||||||
free();
|
free();
|
||||||
if (pat.isEmpty()) return false;
|
if (pat.isEmpty()) return false;
|
||||||
auto * pat_ptr = &(pat[0]);
|
const auto * pat_ptr = &pat.front();
|
||||||
int error_number = 0;
|
int error_number = 0;
|
||||||
compiled = pcre2_compile((PCRE2_SPTR)pat_ptr, pat.size(), convertOptions(opt), &error_number, &error_offset, nullptr);
|
compiled = pcre2_compile((PCRE2_SPTR)pat_ptr, pat.size(), convertOptions(opt), &error_number, &error_offset, nullptr);
|
||||||
if (!compiled) {
|
if (!compiled) {
|
||||||
PIChar buffer[256];
|
PIChar buffer[256];
|
||||||
int sz = pcre2_get_error_message(error_number, (PCRE2_UCHAR16 *)buffer, sizeof(buffer));
|
const int sz = pcre2_get_error_message(error_number, reinterpret_cast<PCRE2_UCHAR16 *>(buffer), sizeof(buffer));
|
||||||
error_msg = PIString(buffer, sz);
|
error_msg = PIString(buffer, sz);
|
||||||
return false;
|
return false;
|
||||||
// printf("PCRE2 compilation failed at offset %d: %s\n", (int)erroroffset, buffer);
|
|
||||||
}
|
}
|
||||||
error_msg.clear();
|
error_msg.clear();
|
||||||
match_data = pcre2_match_data_create_from_pattern(compiled, nullptr);
|
match_data = pcre2_match_data_create_from_pattern(compiled, nullptr);
|
||||||
@@ -86,7 +85,7 @@ PRIVATE_DEFINITION_START(PIRegularExpression)
|
|||||||
capture_count = cap_cout;
|
capture_count = cap_cout;
|
||||||
auto tabptr = name_table;
|
auto tabptr = name_table;
|
||||||
for (uint32_t i = 0; i < namecount; i++) {
|
for (uint32_t i = 0; i < namecount; i++) {
|
||||||
int gnum = *(ushort *)tabptr;
|
const int gnum = *tabptr;
|
||||||
PIString gname = getNEString(tabptr + 1, name_entry_size);
|
PIString gname = getNEString(tabptr + 1, name_entry_size);
|
||||||
named_group_index[gname] = gnum;
|
named_group_index[gname] = gnum;
|
||||||
named_group_name[gnum] = gname;
|
named_group_name[gnum] = gname;
|
||||||
@@ -97,26 +96,25 @@ PRIVATE_DEFINITION_START(PIRegularExpression)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void match(Matcher & ret) {
|
void match(Matcher & ret) {
|
||||||
int rc = pcre2_match(compiled,
|
const int rc = pcre2_match(compiled,
|
||||||
(PCRE2_SPTR)ret.subjectPtr(),
|
(PCRE2_SPTR)ret.subjectPtr(),
|
||||||
ret.subject->size(),
|
ret.subject->size(),
|
||||||
ret.start_offset,
|
ret.start_offset,
|
||||||
PCRE2_NO_UTF_CHECK,
|
PCRE2_NO_UTF_CHECK,
|
||||||
match_data,
|
match_data,
|
||||||
nullptr);
|
nullptr);
|
||||||
ret.has_match = ret.is_error = false;
|
ret.has_match = ret.is_error = false;
|
||||||
ret.groups.clear();
|
ret.groups.clear();
|
||||||
if (rc == PCRE2_ERROR_NOMATCH) return;
|
if (rc == PCRE2_ERROR_NOMATCH) return;
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
ret.is_error = true;
|
ret.is_error = true;
|
||||||
} else {
|
} else {
|
||||||
ret.has_match = true;
|
ret.has_match = true;
|
||||||
auto ovector = pcre2_get_ovector_pointer(match_data);
|
const auto ovector = pcre2_get_ovector_pointer(match_data);
|
||||||
for (int i = 0; i < rc; i++) {
|
for (int i = 0; i < rc; i++) {
|
||||||
Matcher::Group g;
|
Matcher::Group g;
|
||||||
g.index = ovector[2 * i];
|
g.index = ovector[2 * i];
|
||||||
g.size = ovector[2 * i + 1] - ovector[2 * i];
|
g.size = ovector[2 * i + 1] - ovector[2 * i];
|
||||||
// g.string = PIString(&(sub_ptr[g.index]), g.size);
|
|
||||||
ret.groups << g;
|
ret.groups << g;
|
||||||
}
|
}
|
||||||
ret.start_offset = ovector[1];
|
ret.start_offset = ovector[1];
|
||||||
@@ -194,7 +192,7 @@ int PIRegularExpression::captureGroupIndex(const PIString & gname) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIRegularExpression::Matcher PIRegularExpression::makeMatcher(PIString & subject, size_t offset) {
|
PIRegularExpression::Matcher PIRegularExpression::matchIterator(PIString & subject, size_t offset) {
|
||||||
PIRegularExpression::Matcher ret(this);
|
PIRegularExpression::Matcher ret(this);
|
||||||
ret.start_offset = offset;
|
ret.start_offset = offset;
|
||||||
ret.subject = &subject;
|
ret.subject = &subject;
|
||||||
@@ -202,7 +200,16 @@ PIRegularExpression::Matcher PIRegularExpression::makeMatcher(PIString & subject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIRegularExpression::Matcher PIRegularExpression::makeMatcher(const PIString & subject, size_t offset) {
|
PIRegularExpression::Matcher PIRegularExpression::matchIterator(PIString && subject, size_t offset) {
|
||||||
|
PIRegularExpression::Matcher ret(this);
|
||||||
|
ret.start_offset = offset;
|
||||||
|
ret.subject_own = std::move(subject);
|
||||||
|
ret.subject = &ret.subject_own;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIRegularExpression::Matcher PIRegularExpression::matchIterator(const PIString & subject, size_t offset) {
|
||||||
PIRegularExpression::Matcher ret(this);
|
PIRegularExpression::Matcher ret(this);
|
||||||
ret.start_offset = offset;
|
ret.start_offset = offset;
|
||||||
ret.subject_own = subject;
|
ret.subject_own = subject;
|
||||||
@@ -212,14 +219,21 @@ PIRegularExpression::Matcher PIRegularExpression::makeMatcher(const PIString & s
|
|||||||
|
|
||||||
|
|
||||||
PIRegularExpression::Matcher PIRegularExpression::match(PIString & subject, size_t offset) {
|
PIRegularExpression::Matcher PIRegularExpression::match(PIString & subject, size_t offset) {
|
||||||
PIRegularExpression::Matcher ret = makeMatcher(subject, offset);
|
PIRegularExpression::Matcher ret = matchIterator(subject, offset);
|
||||||
|
PRIVATE->match(ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIRegularExpression::Matcher PIRegularExpression::match(PIString && subject, size_t offset) {
|
||||||
|
PIRegularExpression::Matcher ret = matchIterator(std::move(subject), offset);
|
||||||
PRIVATE->match(ret);
|
PRIVATE->match(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIRegularExpression::Matcher PIRegularExpression::match(const PIString & subject, size_t offset) {
|
PIRegularExpression::Matcher PIRegularExpression::match(const PIString & subject, size_t offset) {
|
||||||
PIRegularExpression::Matcher ret = makeMatcher(subject, offset);
|
PIRegularExpression::Matcher ret = matchIterator(subject, offset);
|
||||||
PRIVATE->match(ret);
|
PRIVATE->match(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -230,7 +244,7 @@ PIRegularExpression::Matcher::Matcher(PIRegularExpression * p): parent(p) {}
|
|||||||
|
|
||||||
PIChar * PIRegularExpression::Matcher::subjectPtr() const {
|
PIChar * PIRegularExpression::Matcher::subjectPtr() const {
|
||||||
if (!subject) return nullptr;
|
if (!subject) return nullptr;
|
||||||
return &(*subject)[0];
|
return &subject->front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -248,8 +262,9 @@ bool PIRegularExpression::Matcher::next() {
|
|||||||
PIStringList PIRegularExpression::Matcher::matchedStrings() const {
|
PIStringList PIRegularExpression::Matcher::matchedStrings() const {
|
||||||
if (!subject) return {};
|
if (!subject) return {};
|
||||||
PIStringList ret;
|
PIStringList ret;
|
||||||
for (const auto & g: groups)
|
for (const auto & g: groups) {
|
||||||
ret << subject->mid(g.index, g.size);
|
ret << subject->mid(g.index, g.size);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,19 +319,19 @@ PIRegularExpression PIRegularExpression::fromPOSIX(const PIString & pattern, Opt
|
|||||||
|
|
||||||
void PIRegularExpression::convertFrom(const PIString & pattern, uint type, Options opt) {
|
void PIRegularExpression::convertFrom(const PIString & pattern, uint type, Options opt) {
|
||||||
if (pattern.isEmpty()) return;
|
if (pattern.isEmpty()) return;
|
||||||
PIChar * cptr = &((PIString &)pattern)[0];
|
const auto cptr = &const_cast<PIString &>(pattern).front();
|
||||||
PCRE2_UCHAR * out = nullptr;
|
PCRE2_UCHAR * out = nullptr;
|
||||||
PCRE2_SIZE out_size = 0;
|
PCRE2_SIZE out_size = 0;
|
||||||
int rc = pcre2_pattern_convert((PCRE2_SPTR)cptr,
|
const int rc = pcre2_pattern_convert((PCRE2_SPTR)cptr,
|
||||||
pattern.size_s(),
|
pattern.size_s(),
|
||||||
type | PCRE2_CONVERT_UTF | PCRE2_CONVERT_NO_UTF_CHECK,
|
type | PCRE2_CONVERT_UTF | PCRE2_CONVERT_NO_UTF_CHECK,
|
||||||
&out,
|
&out,
|
||||||
&out_size,
|
&out_size,
|
||||||
nullptr);
|
nullptr);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
piCout << "PIRegularExpression::convertFrom error" << rc;
|
piCout << "PIRegularExpression::convertFrom error" << rc;
|
||||||
} else {
|
} else {
|
||||||
setPattern(PIString((PIChar *)out, out_size), opt);
|
setPattern(PIString(reinterpret_cast<PIChar *>(out), out_size), opt);
|
||||||
}
|
}
|
||||||
pcre2_converted_pattern_free(out);
|
pcre2_converted_pattern_free(out);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,10 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef piregularexpression_h
|
#ifndef PIREGULAREXPRESSION_H
|
||||||
#define piregularexpression_h
|
#define PIREGULAREXPRESSION_H
|
||||||
|
|
||||||
#include <pistring.h>
|
#include "pistring.h"
|
||||||
|
|
||||||
class PIP_EXPORT PIRegularExpression {
|
class PIP_EXPORT PIRegularExpression {
|
||||||
public:
|
public:
|
||||||
@@ -105,9 +105,11 @@ public:
|
|||||||
|
|
||||||
Matcher match(const PIString & subject, size_t offset = 0);
|
Matcher match(const PIString & subject, size_t offset = 0);
|
||||||
Matcher match(PIString & subject, size_t offset = 0);
|
Matcher match(PIString & subject, size_t offset = 0);
|
||||||
|
Matcher match(PIString && subject, size_t offset = 0);
|
||||||
|
|
||||||
Matcher makeMatcher(const PIString & subject, size_t offset = 0);
|
Matcher matchIterator(const PIString & subject, size_t offset = 0);
|
||||||
Matcher makeMatcher(PIString & subject, size_t offset = 0);
|
Matcher matchIterator(PIString & subject, size_t offset = 0);
|
||||||
|
Matcher matchIterator(PIString && subject, size_t offset = 0);
|
||||||
|
|
||||||
static PIRegularExpression fromGlob(const PIString & pattern, Options opt = None);
|
static PIRegularExpression fromGlob(const PIString & pattern, Options opt = None);
|
||||||
static PIRegularExpression fromPOSIX(const PIString & pattern, Options opt = None);
|
static PIRegularExpression fromPOSIX(const PIString & pattern, Options opt = None);
|
||||||
@@ -116,8 +118,8 @@ private:
|
|||||||
void convertFrom(const PIString & pattern, uint type, Options opt);
|
void convertFrom(const PIString & pattern, uint type, Options opt);
|
||||||
|
|
||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
PIString pat_, subj_own;
|
PIString pat_;
|
||||||
Options opt_;
|
Options opt_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // PIREGULAREXPRESSION_H
|
||||||
|
|||||||
271
main.cpp
271
main.cpp
@@ -1,118 +1,205 @@
|
|||||||
#include "libs/http_client/curl_thread_pool_p.h"
|
#include "libs/http_client/curl_thread_pool_p.h"
|
||||||
|
#include "picodeparser.h"
|
||||||
#include "pidigest.h"
|
#include "pidigest.h"
|
||||||
#include "pihttpclient.h"
|
#include "pihttpclient.h"
|
||||||
#include "pip.h"
|
#include "pip.h"
|
||||||
|
#include "pivaluetree_conversions.h"
|
||||||
|
|
||||||
using namespace PICoutManipulators;
|
using namespace PICoutManipulators;
|
||||||
using namespace PIHTTP;
|
using namespace PIHTTP;
|
||||||
|
|
||||||
|
|
||||||
class PIThreadPoolLoopNW {
|
struct SN {
|
||||||
public:
|
int _ii;
|
||||||
PIThreadPoolLoopNW(int thread_cnt = -1) {
|
complexf _co;
|
||||||
if (thread_cnt <= 0) thread_cnt = piMaxi(1, PISystemInfo::instance()->processorsCount);
|
PIIODevice::DeviceMode m;
|
||||||
piForTimes(thread_cnt) {
|
};
|
||||||
auto * t = new PIThread([this]() {
|
struct S {
|
||||||
while (true) {
|
bool _b;
|
||||||
sem_exec.acquire();
|
int _i;
|
||||||
if (is_destroy) return;
|
float _f;
|
||||||
int cc = counter.fetch_add(1);
|
PIString str;
|
||||||
func(cc);
|
// SN _sn;
|
||||||
sem_done.release();
|
PIVector2D<bool> v2d;
|
||||||
}
|
PIByteArray ba;
|
||||||
});
|
PISystemTime st;
|
||||||
threads << t;
|
PINetworkAddress na;
|
||||||
}
|
PIPointd po;
|
||||||
for (auto * t: threads)
|
PILined li;
|
||||||
t->start();
|
PIRectd re;
|
||||||
// piCout << "PIThreadPoolLoop" << proc_cnt << "threads";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~PIThreadPoolLoopNW() {
|
|
||||||
is_destroy = true;
|
|
||||||
for (auto * t: threads)
|
|
||||||
t->stop();
|
|
||||||
sem_exec.release(threads.size());
|
|
||||||
for (auto * t: threads) {
|
|
||||||
if (!t->waitForFinish(100_ms)) t->terminate();
|
|
||||||
delete t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFunction(std::function<void(int)> f) { func = f; }
|
|
||||||
|
|
||||||
void wait() {
|
|
||||||
// piCout << "wait" << wait_count;
|
|
||||||
if (wait_count <= 0) return;
|
|
||||||
sem_done.acquire(wait_count);
|
|
||||||
wait_count = 0;
|
|
||||||
// piCout << "wait done";
|
|
||||||
}
|
|
||||||
|
|
||||||
void start(int index_start, int index_count) {
|
|
||||||
counter = index_start;
|
|
||||||
wait_count = index_count;
|
|
||||||
sem_exec.release(index_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void exec(int index_start, int index_count) {
|
|
||||||
start(index_start, index_count);
|
|
||||||
wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
void exec(int index_start, int index_count, std::function<void(int)> f) {
|
|
||||||
setFunction(f);
|
|
||||||
exec(index_start, index_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
PIVector<PIThread *> threads;
|
|
||||||
std::function<void(int)> func;
|
|
||||||
PISemaphore sem_exec, sem_done;
|
|
||||||
std::atomic_bool is_destroy = {false};
|
|
||||||
std::atomic_int counter = {0}, wait_count = {0};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
PIJSON piSerializeJSON(const SN & v) {
|
||||||
|
PIJSON ret;
|
||||||
|
ret["_ii"] = piSerializeJSON(v._ii);
|
||||||
|
ret["_co"] = piSerializeJSON(v._co);
|
||||||
|
ret["m"] = piSerializeJSON(v.m);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
PIJSON piSerializeJSON(const S & v) {
|
||||||
|
PIJSON ret;
|
||||||
|
ret["_b"] = piSerializeJSON(v._b);
|
||||||
|
ret["_i"] = piSerializeJSON(v._i);
|
||||||
|
ret["_f"] = piSerializeJSON(v._f);
|
||||||
|
ret["str"] = piSerializeJSON(v.str);
|
||||||
|
// ret["_sn"] = piSerializeJSON(v._sn);
|
||||||
|
ret["v2d"] = piSerializeJSON(v.v2d);
|
||||||
|
ret["ba"] = piSerializeJSON(v.ba);
|
||||||
|
ret["st"] = piSerializeJSON(v.st);
|
||||||
|
ret["na"] = piSerializeJSON(v.na);
|
||||||
|
ret["po"] = piSerializeJSON(v.po);
|
||||||
|
ret["li"] = piSerializeJSON(v.li);
|
||||||
|
ret["re"] = piSerializeJSON(v.re);
|
||||||
|
|
||||||
// PIKbdListener kbd;
|
return ret;
|
||||||
PIVector<int> vec;
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
void piDeserializeJSON(SN & v, const PIJSON & js) {
|
||||||
|
v = {};
|
||||||
|
piDeserializeJSON(v._ii, js["_ii"]);
|
||||||
|
piDeserializeJSON(v._co, js["_co"]);
|
||||||
|
piDeserializeJSON(v.m, js["m"]);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void piDeserializeJSON(S & v, const PIJSON & js) {
|
||||||
|
v = {};
|
||||||
|
piDeserializeJSON(v._b, js["_b"]);
|
||||||
|
piDeserializeJSON(v._i, js["_i"]);
|
||||||
|
piDeserializeJSON(v._f, js["_f"]);
|
||||||
|
piDeserializeJSON(v.str, js["str"]);
|
||||||
|
// piDeserializeJSON(v._sn, js["_sn"]);
|
||||||
|
piDeserializeJSON(v.v2d, js["v2d"]);
|
||||||
|
piDeserializeJSON(v.ba, js["ba"]);
|
||||||
|
piDeserializeJSON(v.st, js["st"]);
|
||||||
|
piDeserializeJSON(v.na, js["na"]);
|
||||||
|
piDeserializeJSON(v.po, js["po"]);
|
||||||
|
piDeserializeJSON(v.li, js["li"]);
|
||||||
|
piDeserializeJSON(v.re, js["re"]);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
vec.resize(16);
|
// PIRegularExpression pire("привет"_u8, PIRegularExpression::CaseInsensitive);
|
||||||
vec.fill([](int i) { return i; });
|
// PIString subj = "the dog ПриВет sat on the cat"_u8;
|
||||||
piCout << vec;
|
// PIRegularExpression pire("^(?<date>\\d\\d)/(?<month>\\d\\d)/(?<year>\\d\\d\\d\\d)$"_u8);
|
||||||
|
// PIString subj = "08/12/1985"_u8;
|
||||||
|
|
||||||
PIThreadPoolLoop tpl(8);
|
PIString pat = "*.Exe";
|
||||||
tpl.setFunction([](int i) { vec[i]++; });
|
PIRegularExpression re_g = PIRegularExpression::fromGlob(pat, PIRegularExpression::CaseInsensitive);
|
||||||
|
PIRegularExpression re_p = PIRegularExpression::fromPOSIX(pat, PIRegularExpression::CaseInsensitive);
|
||||||
const int count = 10000;
|
PIStringList files = {
|
||||||
PITimeMeasurer tm;
|
"(Audio) 20250318-0852-16.8641941.m4a",
|
||||||
piForTimes(count) {
|
"dxwebsetup.exe",
|
||||||
tpl.exec(0, 16);
|
"Firefox Installer.exe",
|
||||||
|
"LTA8092XS8_R8.pdf",
|
||||||
|
"SteamSetup.exe",
|
||||||
|
"TBT_1.41.1325.0.exe",
|
||||||
|
};
|
||||||
|
piCout << " src pat" << pat.quoted();
|
||||||
|
piCout << " Glob pat" << re_g.pattern().quoted();
|
||||||
|
piCout << "POSIX pat" << re_p.pattern().quoted();
|
||||||
|
piCout << "\nG P File";
|
||||||
|
for (auto f: files) {
|
||||||
|
piCout << (re_g.match(f) ? 1 : 0) << (re_p.match(f) ? 1 : 0) << f;
|
||||||
|
}
|
||||||
|
// return 0;
|
||||||
|
PIRegularExpression pire("(?:\\/\\/\\s*)?.*\\n?(?:\\bfunction\\b)\\s*(?<name>\\b\\w+\\b)\\s*(?:\\((?<args>[^;()]*?)\\))",
|
||||||
|
PIRegularExpression::Multiline);
|
||||||
|
PIString subj = PIString::fromUTF8(PIFile::readAll("telegram.qs", false));
|
||||||
|
|
||||||
|
piCout << "Pattern:" << pire.pattern();
|
||||||
|
piCout << "Valid:" << pire.isValid();
|
||||||
|
piCout << "Error at" << pire.errorPosition() << ":" << pire.errorString();
|
||||||
|
piCout << "Groups count:" << pire.captureGroupsCount();
|
||||||
|
piCout << "Named groups:" << pire.captureGroupNames();
|
||||||
|
piCout << "";
|
||||||
|
|
||||||
|
auto mr = pire.matchIterator(subj);
|
||||||
|
auto pire2 = pire;
|
||||||
|
|
||||||
|
while (mr.next()) {
|
||||||
|
// piCout << "Subject" << subj;
|
||||||
|
piCout << "Matched:" << mr.hasMatch();
|
||||||
|
|
||||||
|
piCout << "By number";
|
||||||
|
for (int i = 0; i <= pire.captureGroupsCount(); ++i)
|
||||||
|
piCout << i << "=" << mr.matchedString(i).trimmed();
|
||||||
|
|
||||||
|
piCout << "By name";
|
||||||
|
for (auto g: pire.captureGroupNames())
|
||||||
|
piCout << g.quoted() << "=" << mr.matchedString(g);
|
||||||
|
|
||||||
|
piCout << "";
|
||||||
|
}
|
||||||
|
|
||||||
|
piCout << "!!!!!!!!!!!!!!!!!";
|
||||||
|
|
||||||
|
pire.match("vfsmndvbjbdlgdvb gdgf");
|
||||||
|
pire.match(subj);
|
||||||
|
|
||||||
|
{
|
||||||
|
PIVector<complexf> vec;
|
||||||
|
vec << complexf{0.1, 0.2} << complexf{-1, 0.5};
|
||||||
|
auto js = PIJSON::serialize(vec);
|
||||||
|
piCout << vec;
|
||||||
|
piCout << js;
|
||||||
|
piCout << PIJSON::deserialize<typeof(vec)>(js);
|
||||||
}
|
}
|
||||||
// tpl.exec(0, 16);
|
|
||||||
auto el = tm.elapsed().toMilliseconds();
|
|
||||||
piCout << "el" << el << "ms," << (el / count * 1000) << "us per round";
|
|
||||||
|
|
||||||
// tpl.wait();
|
|
||||||
piCout << vec;
|
|
||||||
return 0;
|
return 0;
|
||||||
|
/*PICodeParser parser;
|
||||||
|
parser.parseFile("c:/work/shstk/pip/test_header.h", false);
|
||||||
|
|
||||||
/*piForTimes(10) {
|
for (const auto * e: parser.entities) {
|
||||||
PIThread t;
|
piCout << e->type << e->name << "{";
|
||||||
t.setName("thread____");
|
for (const auto & m: e->members) {
|
||||||
t.startOnce([]() {
|
piCout << " " << m.type << m.name;
|
||||||
// piCout << "thread";
|
}
|
||||||
piMSleep(2.);
|
piCout << "}";
|
||||||
});
|
|
||||||
PITimeMeasurer tm;
|
|
||||||
t.stopAndWait();
|
|
||||||
auto el = tm.elapsed();
|
|
||||||
piCout << el.toMilliseconds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;*/
|
return 0;*/
|
||||||
|
|
||||||
|
// PIJSON j = piSerializeJSON(s);
|
||||||
|
// piDeserializeJSON(s, j);
|
||||||
|
PIVector<complexf> vec;
|
||||||
|
vec << complexf{0.1, 0.2} << complexf{-1, 0.5};
|
||||||
|
auto js = PIJSON::serialize(vec);
|
||||||
|
piCout << vec;
|
||||||
|
piCout << js;
|
||||||
|
piCout << PIJSON::deserialize<typeof(vec)>(js);
|
||||||
|
|
||||||
|
/*PIVector<S> s;
|
||||||
|
s << S{false, 0, 0.1} << S{true, 1, -10.1};
|
||||||
|
PIMap<int, S> m;
|
||||||
|
m[1] = S{false, 0, 0.15};
|
||||||
|
m[2] = S{true, 1, -10.1};
|
||||||
|
// m[1]._sn._co = {3, 4};
|
||||||
|
PIJSON j = piSerializeJSON(m);
|
||||||
|
piCout << j;
|
||||||
|
piDeserializeJSON(m, j);
|
||||||
|
piCout << m[1]._f;*/
|
||||||
|
// piCout << m[1]._sn._co;
|
||||||
|
|
||||||
|
/*PIVector<int> v({-1, 0, 10, 200});
|
||||||
|
PIMap<int, float> m({
|
||||||
|
{-1, -0.1 },
|
||||||
|
{0, 0.1 },
|
||||||
|
{100, 200.2}
|
||||||
|
});
|
||||||
|
|
||||||
|
piCout << v;
|
||||||
|
piCout << piSerializeJSON(v);
|
||||||
|
piDeserializeJSON(v, piSerializeJSON(v));
|
||||||
|
piCout << v;
|
||||||
|
piCout << m;
|
||||||
|
piDeserializeJSON(m, piSerializeJSON(m));
|
||||||
|
piCout << piSerializeJSON(m);*/
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
/*auto src = PIByteArray::fromAscii("The quick brown fox jumps over the lazy dog");
|
/*auto src = PIByteArray::fromAscii("The quick brown fox jumps over the lazy dog");
|
||||||
auto key = PIByteArray::fromAscii("key");
|
auto key = PIByteArray::fromAscii("key");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user