PIRegularExpression::from static constructor
This commit is contained in:
@@ -52,7 +52,8 @@ template<typename T,
|
|||||||
typename std::enable_if<!std::is_enum<T>::value, int>::type = 0,
|
typename std::enable_if<!std::is_enum<T>::value, int>::type = 0,
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, int>::type = 0>
|
typename std::enable_if<!std::is_arithmetic<T>::value, int>::type = 0>
|
||||||
inline PIJSON piSerializeJSON(const T & v) {
|
inline PIJSON piSerializeJSON(const T & v) {
|
||||||
static_assert(false, "[piSerializeJSON] Error: using undeclared piSerializeJSON() for complex type!");
|
static_assert(std::is_enum<T>::value || std::is_arithmetic<T>::value,
|
||||||
|
"[piSerializeJSON] Error: using undeclared piSerializeJSON() for complex type!");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +240,8 @@ template<typename T,
|
|||||||
typename std::enable_if<!std::is_enum<T>::value, int>::type = 0,
|
typename std::enable_if<!std::is_enum<T>::value, int>::type = 0,
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, int>::type = 0>
|
typename std::enable_if<!std::is_arithmetic<T>::value, int>::type = 0>
|
||||||
inline void piDeserializeJSON(T & v, const PIJSON & js) {
|
inline void piDeserializeJSON(T & v, const PIJSON & js) {
|
||||||
static_assert(false, "[piDeserializeJSON] Error: using undeclared piDeserializeJSON() for complex type!");
|
static_assert(std::is_enum<T>::value || std::is_arithmetic<T>::value,
|
||||||
|
"[piDeserializeJSON] Error: using undeclared piDeserializeJSON() for complex type!");
|
||||||
v = {};
|
v = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -286,3 +286,37 @@ int PIRegularExpression::Matcher::matchedStart(const PIString & gname) const {
|
|||||||
int PIRegularExpression::Matcher::matchedSize(const PIString & gname) const {
|
int PIRegularExpression::Matcher::matchedSize(const PIString & gname) const {
|
||||||
return matchedSize(parent->PRIVATEWB->named_group_index.value(gname));
|
return matchedSize(parent->PRIVATEWB->named_group_index.value(gname));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIRegularExpression PIRegularExpression::fromGlob(const PIString & pattern, Options opt) {
|
||||||
|
PIRegularExpression ret;
|
||||||
|
ret.convertFrom(pattern, PCRE2_CONVERT_GLOB, opt);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIRegularExpression PIRegularExpression::fromPOSIX(const PIString & pattern, Options opt) {
|
||||||
|
PIRegularExpression ret;
|
||||||
|
ret.convertFrom(pattern, PCRE2_CONVERT_POSIX_BASIC, opt);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIRegularExpression::convertFrom(const PIString & pattern, uint type, Options opt) {
|
||||||
|
if (pattern.isEmpty()) return;
|
||||||
|
PIChar * cptr = &((PIString &)pattern)[0];
|
||||||
|
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);
|
||||||
|
if (rc != 0) {
|
||||||
|
piCout << "PIRegularExpression::convertFrom error" << rc;
|
||||||
|
} else {
|
||||||
|
setPattern(PIString((PIChar *)out, out_size), opt);
|
||||||
|
}
|
||||||
|
pcre2_converted_pattern_free(out);
|
||||||
|
}
|
||||||
|
|||||||
@@ -109,7 +109,12 @@ public:
|
|||||||
Matcher makeMatcher(const PIString & subject, size_t offset = 0);
|
Matcher makeMatcher(const PIString & subject, size_t offset = 0);
|
||||||
Matcher makeMatcher(PIString & subject, size_t offset = 0);
|
Matcher makeMatcher(PIString & subject, size_t offset = 0);
|
||||||
|
|
||||||
|
static PIRegularExpression fromGlob(const PIString & pattern, Options opt = None);
|
||||||
|
static PIRegularExpression fromPOSIX(const PIString & pattern, Options opt = None);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void convertFrom(const PIString & pattern, uint type, Options opt);
|
||||||
|
|
||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
PIString pat_, subj_own;
|
PIString pat_, subj_own;
|
||||||
Options opt_;
|
Options opt_;
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
#include "picli.h"
|
||||||
|
#include "picloudclient.h"
|
||||||
|
#include "picloudserver.h"
|
||||||
|
#include "pikbdlistener.h"
|
||||||
#include "piliterals_time.h"
|
#include "piliterals_time.h"
|
||||||
#include "pip.h"
|
#include "pitimer.h"
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
PIByteArray rnd;
|
PIByteArray rnd;
|
||||||
|
|||||||
Reference in New Issue
Block a user