diff --git a/libs/main/serialization/pijsonserialization.h b/libs/main/serialization/pijsonserialization.h
index 1edf7c00..20d16610 100644
--- a/libs/main/serialization/pijsonserialization.h
+++ b/libs/main/serialization/pijsonserialization.h
@@ -23,8 +23,8 @@
along with this program. If not, see .
*/
-#ifndef pijsonserialization_H
-#define pijsonserialization_H
+#ifndef PIJSONSERIALIZATION_H
+#define PIJSONSERIALIZATION_H
#include "pijson.h"
@@ -191,8 +191,8 @@ inline PIJSON piSerializeJSON(const PIDeque & v) {
template
inline PIJSON piSerializeJSON(const PIVector2D & v) {
PIJSON ret;
- ret["cols"] = v.cols();
- ret["rows"] = v.rows();
+ ret["cols"] = static_cast(v.cols());
+ ret["rows"] = static_cast(v.rows());
ret["mat"] = piSerializeJSON(v.plainVector());
return ret;
}
@@ -255,10 +255,9 @@ inline void piDeserializeJSON(PIVariant & v, const PIJSON & js) {
template
inline void piDeserializeJSON(complex & v, const PIJSON & js) {
- T c[2];
- piDeserializeJSON(c[0], js[0]);
- piDeserializeJSON(c[1], js[1]);
- v = complex(c[0], c[1]);
+ if (!js.isArray()) return;
+ piDeserializeJSON(reinterpret_cast(v)[0], js[0]);
+ piDeserializeJSON(reinterpret_cast(v)[1], js[1]);
}
template
@@ -366,10 +365,10 @@ template
inline void piDeserializeJSON(PIVector2D & v, const PIJSON & js) {
v.clear();
if (!js.isObject()) return;
- v.resize(js["rows"].toInt(), js["cols"].toInt());
const auto & mat(js["mat"]);
if (!mat.isArray()) return;
piDeserializeJSON(v.plainVector(), mat);
+ v.resize(js["rows"].toInt(), js["cols"].toInt());
}
template
@@ -412,4 +411,4 @@ T PIJSON::deserialize(const PIJSON & json) {
}
-#endif // pijsonserialization_h
+#endif // PIJSONSERIALIZATION_H
diff --git a/libs/main/text/piregularexpression.cpp b/libs/main/text/piregularexpression.cpp
index 82772a22..04bc4b74 100644
--- a/libs/main/text/piregularexpression.cpp
+++ b/libs/main/text/piregularexpression.cpp
@@ -39,8 +39,8 @@ PRIVATE_DEFINITION_START(PIRegularExpression)
PIString getNEString(const void * ptr, uint32_t max_size) {
PIString ret;
- auto * cptr = (PIChar *)ptr;
- uint32_t sz = 0;
+ const auto * cptr = static_cast(ptr);
+ uint32_t sz = 0;
while (*cptr != PIChar()) {
ret.append(*cptr);
cptr++;
@@ -64,15 +64,14 @@ PRIVATE_DEFINITION_START(PIRegularExpression)
bool compile(PIString & pat, Options opt) {
free();
if (pat.isEmpty()) return false;
- auto * pat_ptr = &(pat[0]);
- int error_number = 0;
- compiled = pcre2_compile((PCRE2_SPTR)pat_ptr, pat.size(), convertOptions(opt), &error_number, &error_offset, nullptr);
+ const auto * pat_ptr = &pat.front();
+ int error_number = 0;
+ compiled = pcre2_compile((PCRE2_SPTR)pat_ptr, pat.size(), convertOptions(opt), &error_number, &error_offset, nullptr);
if (!compiled) {
PIChar buffer[256];
- int sz = pcre2_get_error_message(error_number, (PCRE2_UCHAR16 *)buffer, sizeof(buffer));
- error_msg = PIString(buffer, sz);
+ const int sz = pcre2_get_error_message(error_number, reinterpret_cast(buffer), sizeof(buffer));
+ error_msg = PIString(buffer, sz);
return false;
- // printf("PCRE2 compilation failed at offset %d: %s\n", (int)erroroffset, buffer);
}
error_msg.clear();
match_data = pcre2_match_data_create_from_pattern(compiled, nullptr);
@@ -86,7 +85,7 @@ PRIVATE_DEFINITION_START(PIRegularExpression)
capture_count = cap_cout;
auto tabptr = name_table;
for (uint32_t i = 0; i < namecount; i++) {
- int gnum = *(ushort *)tabptr;
+ const int gnum = *tabptr;
PIString gname = getNEString(tabptr + 1, name_entry_size);
named_group_index[gname] = gnum;
named_group_name[gnum] = gname;
@@ -97,26 +96,25 @@ PRIVATE_DEFINITION_START(PIRegularExpression)
}
void match(Matcher & ret) {
- int rc = pcre2_match(compiled,
- (PCRE2_SPTR)ret.subjectPtr(),
- ret.subject->size(),
- ret.start_offset,
- PCRE2_NO_UTF_CHECK,
- match_data,
- nullptr);
+ const int rc = pcre2_match(compiled,
+ (PCRE2_SPTR)ret.subjectPtr(),
+ ret.subject->size(),
+ ret.start_offset,
+ PCRE2_NO_UTF_CHECK,
+ match_data,
+ nullptr);
ret.has_match = ret.is_error = false;
ret.groups.clear();
if (rc == PCRE2_ERROR_NOMATCH) return;
if (rc < 0) {
ret.is_error = true;
} else {
- ret.has_match = true;
- auto ovector = pcre2_get_ovector_pointer(match_data);
+ ret.has_match = true;
+ const auto ovector = pcre2_get_ovector_pointer(match_data);
for (int i = 0; i < rc; i++) {
Matcher::Group g;
g.index = 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.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);
ret.start_offset = offset;
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);
ret.start_offset = offset;
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 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);
return ret;
}
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);
return ret;
}
@@ -230,7 +244,7 @@ PIRegularExpression::Matcher::Matcher(PIRegularExpression * p): parent(p) {}
PIChar * PIRegularExpression::Matcher::subjectPtr() const {
if (!subject) return nullptr;
- return &(*subject)[0];
+ return &subject->front();
}
@@ -248,8 +262,9 @@ bool PIRegularExpression::Matcher::next() {
PIStringList PIRegularExpression::Matcher::matchedStrings() const {
if (!subject) return {};
PIStringList ret;
- for (const auto & g: groups)
+ for (const auto & g: groups) {
ret << subject->mid(g.index, g.size);
+ }
return ret;
}
@@ -304,19 +319,19 @@ PIRegularExpression PIRegularExpression::fromPOSIX(const PIString & pattern, Opt
void PIRegularExpression::convertFrom(const PIString & pattern, uint type, Options opt) {
if (pattern.isEmpty()) return;
- PIChar * cptr = &((PIString &)pattern)[0];
+ const auto cptr = &const_cast(pattern).front();
PCRE2_UCHAR * out = nullptr;
PCRE2_SIZE out_size = 0;
- int rc = pcre2_pattern_convert((PCRE2_SPTR)cptr,
- pattern.size_s(),
- type | PCRE2_CONVERT_UTF | PCRE2_CONVERT_NO_UTF_CHECK,
- &out,
- &out_size,
- nullptr);
+ const int rc = pcre2_pattern_convert((PCRE2_SPTR)cptr,
+ pattern.size_s(),
+ type | PCRE2_CONVERT_UTF | PCRE2_CONVERT_NO_UTF_CHECK,
+ &out,
+ &out_size,
+ nullptr);
if (rc != 0) {
piCout << "PIRegularExpression::convertFrom error" << rc;
} else {
- setPattern(PIString((PIChar *)out, out_size), opt);
+ setPattern(PIString(reinterpret_cast(out), out_size), opt);
}
pcre2_converted_pattern_free(out);
}
diff --git a/libs/main/text/piregularexpression.h b/libs/main/text/piregularexpression.h
index 82c39bf6..bff92c71 100644
--- a/libs/main/text/piregularexpression.h
+++ b/libs/main/text/piregularexpression.h
@@ -23,10 +23,10 @@
along with this program. If not, see .
*/
-#ifndef piregularexpression_h
-#define piregularexpression_h
+#ifndef PIREGULAREXPRESSION_H
+#define PIREGULAREXPRESSION_H
-#include
+#include "pistring.h"
class PIP_EXPORT PIRegularExpression {
public:
@@ -105,9 +105,11 @@ public:
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 makeMatcher(const PIString & subject, size_t offset = 0);
- Matcher makeMatcher(PIString & subject, size_t offset = 0);
+ Matcher matchIterator(const 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 fromPOSIX(const PIString & pattern, Options opt = None);
@@ -116,8 +118,8 @@ private:
void convertFrom(const PIString & pattern, uint type, Options opt);
PRIVATE_DECLARATION(PIP_EXPORT)
- PIString pat_, subj_own;
+ PIString pat_;
Options opt_;
};
-#endif
+#endif // PIREGULAREXPRESSION_H
diff --git a/main.cpp b/main.cpp
index 576012bc..dd358052 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,283 +1,370 @@
-#include "libs/http_client/curl_thread_pool_p.h"
-#include "pidigest.h"
-#include "pihttpclient.h"
-#include "pip.h"
-
-using namespace PICoutManipulators;
-using namespace PIHTTP;
-
-
-class PIThreadPoolLoopNW {
-public:
- PIThreadPoolLoopNW(int thread_cnt = -1) {
- if (thread_cnt <= 0) thread_cnt = piMaxi(1, PISystemInfo::instance()->processorsCount);
- piForTimes(thread_cnt) {
- auto * t = new PIThread([this]() {
- while (true) {
- sem_exec.acquire();
- if (is_destroy) return;
- int cc = counter.fetch_add(1);
- func(cc);
- sem_done.release();
- }
- });
- threads << t;
- }
- for (auto * t: threads)
- t->start();
- // 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 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 f) {
- setFunction(f);
- exec(index_start, index_count);
- }
-
-private:
- PIVector threads;
- std::function func;
- PISemaphore sem_exec, sem_done;
- std::atomic_bool is_destroy = {false};
- std::atomic_int counter = {0}, wait_count = {0};
-};
-
-
-// PIKbdListener kbd;
-PIVector vec;
-
-int main(int argc, char * argv[]) {
- vec.resize(16);
- vec.fill([](int i) { return i; });
- piCout << vec;
-
- PIThreadPoolLoop tpl(8);
- tpl.setFunction([](int i) { vec[i]++; });
-
- const int count = 10000;
- PITimeMeasurer tm;
- piForTimes(count) {
- tpl.exec(0, 16);
- }
- // 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;
-
- /*piForTimes(10) {
- PIThread t;
- t.setName("thread____");
- t.startOnce([]() {
- // piCout << "thread";
- piMSleep(2.);
- });
- PITimeMeasurer tm;
- t.stopAndWait();
- auto el = tm.elapsed();
- piCout << el.toMilliseconds();
- }
-
- return 0;*/
-
- /*auto src = PIByteArray::fromAscii("The quick brown fox jumps over the lazy dog");
- auto key = PIByteArray::fromAscii("key");
-
- PIStringList tnl;
- int max_size = 0;
- for (int t = 0; t < (int)PIDigest::Type::C ount; ++t) {
- tnl << PIDigest::typeName((PIDigest::Type)t);
- max_size = piMaxi(max_size, tnl.back().size_s());
- }
- PIByteArray hs;
- piCout << PIString::fromAscii(src);
- for (int t = 0; t < (int)PIDigest::Type::Count; ++t) {
- hs = PIDigest::calculate(src, (PIDigest::Type)t);
- piCout << tnl[t].expandLeftTo(max_size, ' ') << "->" << hs.toHex();
- }
- for (int t = 0; t < (int)PIDigest::Type::Count; ++t) {
- const int bench_count = 100000;
- PITimeMeasurer tm;
- piForTimes(bench_count) {
- hs = PIDigest::calculate(src, (PIDigest::Type)t);
- }
- auto el = tm.elapsed();
- piCout << tnl[t].expandLeftTo(max_size, ' ') << "time" << el.toMilliseconds();
- }
-
- // src.clear();
- // crypto_hash_sha512(sout.data(), src.data(), src.size());
- // piCout << "sod:" << sout.toHex();
- // piCout << "512:" << sha5xx(src, initial_512, 64).toHex();
- return 0;*/
-
- /*PIHTTPServer server;
- server.listen({"127.0.0.1:7777"});
- // server.setBasicAuthRealm("pip");
- // server.setBasicAuthEnabled(true);
- // server.setBasicAuthCallback([](const PIString & u, const PIString & p) -> bool {
- // piCout << "basic auth" << u << p;
- // return (u == "u" && p == "p");
- // });
- server.registerPath("sendMessage", Method::Post, [](const PIHTTP::MessageConst & msg) -> PIHTTP::MessageMutable {
- return MessageMutable().setCode(Code::Accepted);
- });
- server.registerUnhandled([](const PIHTTP::MessageConst & msg) -> PIHTTP::MessageMutable {
- PIHTTP::MessageMutable ret;
- piCout << "server rec:\n\tpath: %1\n\tmethod: %2\n\targs: %3\n\theaders: %4\n\tbody: %5\n"_a.arg(msg.path())
- .arg(PIHTTP::methodName(msg.method()))
- .arg(piStringify(msg.arguments()))
- .arg(PIStringList(msg.headers().map([](PIString k, PIString v) { return k + " = " + v; })).join("\n\t\t "))
- .arg(PIString::fromUTF8(msg.body()));
- ret.setCode(PIHTTP::Code::BadRequest);
- ret.setBody(PIByteArray::fromAscii("hello client! 0123456789"));
- piSleep(5.);
- return ret;
- });
- kbd.waitForFinish();
- return 0;*/
-
- /*PIHTTP::MessageMutable req;
- req.setBody(PIByteArray::fromAscii("hello server!")).addArgument("a0", "val.0").addArgument("a~r1", "знач,1"_u8);
- auto * c = PIHTTPClient::create("http://u:p@127.0.0.1:7777/api", PIHTTP::Method::Get, req);
- c->onFinish([](PIHTTP::MessageConst msg) {
- piCout << "client rec:\n\tpath: %1\n\tmethod: %2\n\targs: %3\n\theaders: %4\n\tbody: %5\n"_a.arg(msg.path())
- .arg(PIHTTP::methodName(msg.method()))
- .arg(piStringify(msg.arguments()))
- .arg(
- PIStringList(msg.headers().map([](PIString k, PIString v) { return k + " = " + v; })).join("\n\t\t
- ")) .arg(PIString::fromUTF8(msg.body()));
- })
- ->onError([c](PIHTTP::MessageConst r) {
- piCout << "error" << (int)r.code();
- piCout << "msg" << c->lastError();
- })
- ->onAbort([c](PIHTTP::MessageConst r) {
- piCout << "abort" << (int)r.code();
- piCout << "msg" << c->lastError();
- })
- ->start();*/
- auto * c = PIHTTPClient::create(
- PIString("127.0.0.1:7777/%1").arg("sendMessag"),
- Method::Post,
- MessageMutable().addHeader(Header::ContentType, "application/json").setBody(PIByteArray::fromAscii("{hello}")));
- c->onFinish([](const PIHTTP::MessageConst & msg) { piCout << "message finish" << (int)msg.code() << PIString::fromUTF8(msg.body()); })
- ->onError([c](const PIHTTP::MessageConst & msg) { piCout << "message error" << c->lastError(); })
- ->onAbort([c](const PIHTTP::MessageConst & msg) { piCout << "aborted"; })
- ->start();
-
- piMSleep(1000);
- // CurlThreadPool::instance()->destroy();
- // kbd.enableExitCapture();
- // WAIT_FOR_EXIT
- // kbd.stopAndWait();
-
- // server.stop();
- c->abort();
- piMSleep(10);
-
- return 0;
-
- // piCout << PIString::readableSize(PISystemMonitor::usedRAM());
-
- /*PIVector vi;
- piForTimes(10) {
- piSleep(2.);
- vi.enlarge(1000000);
- piCout << "now" << vi.size() << vi.capacity();
- }
-
- piSleep(5.);*/
- /*kbd.enableExitCapture();
-
- PIHTTPServer server;
-
- server.setFavicon(PIFile::readAll("logo.png", false));
- // server.setOption(MicrohttpdServer::Option::HTTPSEnabled, true);
- server.listen({"127.0.0.1", 7777});
- // server.listen({"192.168.1.10", 7778});
-
- server.registerPath("/", MicrohttpdServer::Method::Get, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
- MicrohttpdServer::Reply ret;
- ret.setBody(PIByteArray::fromAscii(pageTitle));
- return ret;
- });
-
- server.registerPath("/html", MicrohttpdServer::Method::Get, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
- MicrohttpdServer::Reply ret;
- ret.setBody("arg=%1
"_a.arg(r.args.value("a0")).toUTF8());
- return ret;
- });
-
- server.registerPath("/api", MicrohttpdServer::Method::Put, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
- MicrohttpdServer::Reply ret;
- ret.setBody(PIByteArray::fromAscii("API"));
- return ret;
- });
-
- server.registerPath("/api/", MicrohttpdServer::Method::Post, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
- MicrohttpdServer::Reply ret;
- ret.setBody("API etry %1"_a.arg(r.path).toUTF8());
- ret.setCode(405);
- return ret;
- });
-
- server.registerUnhandled([](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
- MicrohttpdServer::Reply ret;
- ret.setBody("Unknown"_a.arg(r.path).toUTF8());
- ret.setCode(404);
- return ret;
- });*/
-
- /*server.setRequestCallback([](MicrohttpdServer::Request r) -> MicrohttpdServer::Reply {
- MicrohttpdServer::Reply rep;
- piCout << "request" << r.path;
- piCout << " header" << r.headers;
- piCout << " args" << r.args;
- piCout << " body" << r.body;
- piCout << "";
- rep.setBody(PIByteArray::fromAscii("[{\"value1\": true, \"value2\": \"ыекштп\"}]"));
- return rep;
- });*/
-
- /*piCout << "start" << server.isListen();
-
- WAIT_FOR_EXIT
-
- server.stop();*/
-
- return 0;
-}
+#include "libs/http_client/curl_thread_pool_p.h"
+#include "picodeparser.h"
+#include "pidigest.h"
+#include "pihttpclient.h"
+#include "pip.h"
+#include "pivaluetree_conversions.h"
+
+using namespace PICoutManipulators;
+using namespace PIHTTP;
+
+
+struct SN {
+ int _ii;
+ complexf _co;
+ PIIODevice::DeviceMode m;
+};
+struct S {
+ bool _b;
+ int _i;
+ float _f;
+ PIString str;
+ // SN _sn;
+ PIVector2D v2d;
+ PIByteArray ba;
+ PISystemTime st;
+ PINetworkAddress na;
+ PIPointd po;
+ PILined li;
+ PIRectd re;
+};
+
+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);
+
+ return ret;
+}
+
+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[]) {
+ // PIRegularExpression pire("привет"_u8, PIRegularExpression::CaseInsensitive);
+ // PIString subj = "the dog ПриВет sat on the cat"_u8;
+ // PIRegularExpression pire("^(?\\d\\d)/(?\\d\\d)/(?\\d\\d\\d\\d)$"_u8);
+ // PIString subj = "08/12/1985"_u8;
+
+ PIString pat = "*.Exe";
+ PIRegularExpression re_g = PIRegularExpression::fromGlob(pat, PIRegularExpression::CaseInsensitive);
+ PIRegularExpression re_p = PIRegularExpression::fromPOSIX(pat, PIRegularExpression::CaseInsensitive);
+ PIStringList files = {
+ "(Audio) 20250318-0852-16.8641941.m4a",
+ "dxwebsetup.exe",
+ "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*(?\\b\\w+\\b)\\s*(?:\\((?[^;()]*?)\\))",
+ 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 vec;
+ vec << complexf{0.1, 0.2} << complexf{-1, 0.5};
+ auto js = PIJSON::serialize(vec);
+ piCout << vec;
+ piCout << js;
+ piCout << PIJSON::deserialize(js);
+ }
+
+ return 0;
+ /*PICodeParser parser;
+ parser.parseFile("c:/work/shstk/pip/test_header.h", false);
+
+ for (const auto * e: parser.entities) {
+ piCout << e->type << e->name << "{";
+ for (const auto & m: e->members) {
+ piCout << " " << m.type << m.name;
+ }
+ piCout << "}";
+ }
+
+ return 0;*/
+
+ // PIJSON j = piSerializeJSON(s);
+ // piDeserializeJSON(s, j);
+ PIVector vec;
+ vec << complexf{0.1, 0.2} << complexf{-1, 0.5};
+ auto js = PIJSON::serialize(vec);
+ piCout << vec;
+ piCout << js;
+ piCout << PIJSON::deserialize(js);
+
+ /*PIVector s;
+ s << S{false, 0, 0.1} << S{true, 1, -10.1};
+ PIMap 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 v({-1, 0, 10, 200});
+ PIMap 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 key = PIByteArray::fromAscii("key");
+
+ PIStringList tnl;
+ int max_size = 0;
+ for (int t = 0; t < (int)PIDigest::Type::C ount; ++t) {
+ tnl << PIDigest::typeName((PIDigest::Type)t);
+ max_size = piMaxi(max_size, tnl.back().size_s());
+ }
+ PIByteArray hs;
+ piCout << PIString::fromAscii(src);
+ for (int t = 0; t < (int)PIDigest::Type::Count; ++t) {
+ hs = PIDigest::calculate(src, (PIDigest::Type)t);
+ piCout << tnl[t].expandLeftTo(max_size, ' ') << "->" << hs.toHex();
+ }
+ for (int t = 0; t < (int)PIDigest::Type::Count; ++t) {
+ const int bench_count = 100000;
+ PITimeMeasurer tm;
+ piForTimes(bench_count) {
+ hs = PIDigest::calculate(src, (PIDigest::Type)t);
+ }
+ auto el = tm.elapsed();
+ piCout << tnl[t].expandLeftTo(max_size, ' ') << "time" << el.toMilliseconds();
+ }
+
+ // src.clear();
+ // crypto_hash_sha512(sout.data(), src.data(), src.size());
+ // piCout << "sod:" << sout.toHex();
+ // piCout << "512:" << sha5xx(src, initial_512, 64).toHex();
+ return 0;*/
+
+ /*PIHTTPServer server;
+ server.listen({"127.0.0.1:7777"});
+ // server.setBasicAuthRealm("pip");
+ // server.setBasicAuthEnabled(true);
+ // server.setBasicAuthCallback([](const PIString & u, const PIString & p) -> bool {
+ // piCout << "basic auth" << u << p;
+ // return (u == "u" && p == "p");
+ // });
+ server.registerPath("sendMessage", Method::Post, [](const PIHTTP::MessageConst & msg) -> PIHTTP::MessageMutable {
+ return MessageMutable().setCode(Code::Accepted);
+ });
+ server.registerUnhandled([](const PIHTTP::MessageConst & msg) -> PIHTTP::MessageMutable {
+ PIHTTP::MessageMutable ret;
+ piCout << "server rec:\n\tpath: %1\n\tmethod: %2\n\targs: %3\n\theaders: %4\n\tbody: %5\n"_a.arg(msg.path())
+ .arg(PIHTTP::methodName(msg.method()))
+ .arg(piStringify(msg.arguments()))
+ .arg(PIStringList(msg.headers().map([](PIString k, PIString v) { return k + " = " + v; })).join("\n\t\t "))
+ .arg(PIString::fromUTF8(msg.body()));
+ ret.setCode(PIHTTP::Code::BadRequest);
+ ret.setBody(PIByteArray::fromAscii("hello client! 0123456789"));
+ piSleep(5.);
+ return ret;
+ });
+ kbd.waitForFinish();
+ return 0;*/
+
+ /*PIHTTP::MessageMutable req;
+ req.setBody(PIByteArray::fromAscii("hello server!")).addArgument("a0", "val.0").addArgument("a~r1", "знач,1"_u8);
+ auto * c = PIHTTPClient::create("http://u:p@127.0.0.1:7777/api", PIHTTP::Method::Get, req);
+ c->onFinish([](PIHTTP::MessageConst msg) {
+ piCout << "client rec:\n\tpath: %1\n\tmethod: %2\n\targs: %3\n\theaders: %4\n\tbody: %5\n"_a.arg(msg.path())
+ .arg(PIHTTP::methodName(msg.method()))
+ .arg(piStringify(msg.arguments()))
+ .arg(
+ PIStringList(msg.headers().map([](PIString k, PIString v) { return k + " = " + v; })).join("\n\t\t
+ ")) .arg(PIString::fromUTF8(msg.body()));
+ })
+ ->onError([c](PIHTTP::MessageConst r) {
+ piCout << "error" << (int)r.code();
+ piCout << "msg" << c->lastError();
+ })
+ ->onAbort([c](PIHTTP::MessageConst r) {
+ piCout << "abort" << (int)r.code();
+ piCout << "msg" << c->lastError();
+ })
+ ->start();*/
+ auto * c = PIHTTPClient::create(
+ PIString("127.0.0.1:7777/%1").arg("sendMessag"),
+ Method::Post,
+ MessageMutable().addHeader(Header::ContentType, "application/json").setBody(PIByteArray::fromAscii("{hello}")));
+ c->onFinish([](const PIHTTP::MessageConst & msg) { piCout << "message finish" << (int)msg.code() << PIString::fromUTF8(msg.body()); })
+ ->onError([c](const PIHTTP::MessageConst & msg) { piCout << "message error" << c->lastError(); })
+ ->onAbort([c](const PIHTTP::MessageConst & msg) { piCout << "aborted"; })
+ ->start();
+
+ piMSleep(1000);
+ // CurlThreadPool::instance()->destroy();
+ // kbd.enableExitCapture();
+ // WAIT_FOR_EXIT
+ // kbd.stopAndWait();
+
+ // server.stop();
+ c->abort();
+ piMSleep(10);
+
+ return 0;
+
+ // piCout << PIString::readableSize(PISystemMonitor::usedRAM());
+
+ /*PIVector vi;
+ piForTimes(10) {
+ piSleep(2.);
+ vi.enlarge(1000000);
+ piCout << "now" << vi.size() << vi.capacity();
+ }
+
+ piSleep(5.);*/
+ /*kbd.enableExitCapture();
+
+ PIHTTPServer server;
+
+ server.setFavicon(PIFile::readAll("logo.png", false));
+ // server.setOption(MicrohttpdServer::Option::HTTPSEnabled, true);
+ server.listen({"127.0.0.1", 7777});
+ // server.listen({"192.168.1.10", 7778});
+
+ server.registerPath("/", MicrohttpdServer::Method::Get, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
+ MicrohttpdServer::Reply ret;
+ ret.setBody(PIByteArray::fromAscii(pageTitle));
+ return ret;
+ });
+
+ server.registerPath("/html", MicrohttpdServer::Method::Get, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
+ MicrohttpdServer::Reply ret;
+ ret.setBody("arg=%1
"_a.arg(r.args.value("a0")).toUTF8());
+ return ret;
+ });
+
+ server.registerPath("/api", MicrohttpdServer::Method::Put, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
+ MicrohttpdServer::Reply ret;
+ ret.setBody(PIByteArray::fromAscii("API"));
+ return ret;
+ });
+
+ server.registerPath("/api/", MicrohttpdServer::Method::Post, [](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
+ MicrohttpdServer::Reply ret;
+ ret.setBody("API etry %1"_a.arg(r.path).toUTF8());
+ ret.setCode(405);
+ return ret;
+ });
+
+ server.registerUnhandled([](const MicrohttpdServer::Request & r) -> MicrohttpdServer::Reply {
+ MicrohttpdServer::Reply ret;
+ ret.setBody("Unknown"_a.arg(r.path).toUTF8());
+ ret.setCode(404);
+ return ret;
+ });*/
+
+ /*server.setRequestCallback([](MicrohttpdServer::Request r) -> MicrohttpdServer::Reply {
+ MicrohttpdServer::Reply rep;
+ piCout << "request" << r.path;
+ piCout << " header" << r.headers;
+ piCout << " args" << r.args;
+ piCout << " body" << r.body;
+ piCout << "";
+ rep.setBody(PIByteArray::fromAscii("[{\"value1\": true, \"value2\": \"ыекштп\"}]"));
+ return rep;
+ });*/
+
+ /*piCout << "start" << server.isListen();
+
+ WAIT_FOR_EXIT
+
+ server.stop();*/
+
+ return 0;
+}