Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb11b38f

Browse files
committed
pcre2_jit.cpp
1 parentb667cbe commitb11b38f

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

‎CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ add_executable(std std.cpp)
1212
add_executable(pcre pcre.cpp)
1313
add_executable(pcre2 pcre2.cpp)
1414
add_executable(pcre_jit pcre_jit.cpp)
15+
add_executable(pcre2_jit pcre2_jit.cpp)
1516

1617
target_compile_features(stdPUBLIC cxx_std_17)
1718
target_compile_features(pcrePUBLIC cxx_std_17)
1819
target_compile_features(pcre2PUBLIC cxx_std_17)
1920
target_compile_features(pcre_jitPUBLIC cxx_std_17)
21+
target_compile_features(pcre2_jitPUBLIC cxx_std_17)
2022

2123
target_link_libraries(pcrePRIVATE"${LibPCRE_LIBRARY}")
2224
target_link_libraries(pcre2PRIVATE"${LibPCRE2_LIBRARY}")
2325
target_link_libraries(pcre_jitPRIVATE"${LibPCRE_LIBRARY}")
26+
target_link_libraries(pcre2_jitPRIVATE"${LibPCRE2_LIBRARY}")
2427

2528
set_target_properties(std PROPERTIES CXX_EXTENSIONSOFF)
2629
set_target_properties(pcre PROPERTIES CXX_EXTENSIONSOFF)
2730
set_target_properties(pcre2 PROPERTIES CXX_EXTENSIONSOFF)
2831
set_target_properties(pcre_jit PROPERTIES CXX_EXTENSIONSOFF)
32+
set_target_properties(pcre2_jit PROPERTIES CXX_EXTENSIONSOFF)

‎pcre2_jit.cpp‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#definePCRE2_CODE_UNIT_WIDTH8
2+
3+
#include<iostream>
4+
#include<pcre2.h>
5+
#include<string>
6+
#include<vector>
7+
8+
intmain()
9+
{
10+
const std::vector<std::string> lines{
11+
"[05821BE4 | 2019-05-13 12:28:56] (13036) http://contiview.site/projects/cmd.php [co_project.view] RQST START",
12+
"[05821BE4 | 2019-05-13 12:28:56] (13036) http://contiview.site/projects/cmd.php [co_project.view] RQST END [normal] 402 ms",
13+
"[05671FA1 | 2019-04-17 14:08:03] (62931) http://contiview.site/projects/cmd.php [co_project.view] RQST START",
14+
"[05671FA1 | 2019-04-17 14:08:03] (62931) http://contiview.site/projects/cmd.php [co_project.view] RQST END [normal] 237 ms",
15+
"[05822AE4 | 2019-06-17 06:59:03] (15828) http://contiview.site/cmd.php [co_project.dialog_doc_details] RQST START",
16+
"[05822AE4 | 2019-06-17 06:59:03] (15828) http://contiview.site/cmd.php [co_project.dialog_doc_details] RQST END [normal] 318 ms",
17+
"[00180D0F | 2009-09-15 09:34:47] (193.98.108.243:39170, 879) /cmd.php [co_search.browse] RQST START",
18+
"[00180D0F | 2009-09-15 09:34:48] (193.98.108.243:39170, 879) /cmd.php [co_search.browse] RQST END [normal] 799 ms",
19+
"[00180D0D | 2009-09-15 09:34:19] (193.98.108.243:39169, 23727) /browse/ RQST START",
20+
"[00180D0D | 2009-09-15 09:34:19] (193.98.108.243:39169, 23727) /browse/ RQST END [normal] 35 ms",
21+
"[001F86EA | 2009-11-02 16:05:50] (193.98.108.243:1789, 10994) /cmd.php [co_doc.details] RQST START",
22+
"[001F86EA | 2009-11-02 16:05:50] (193.98.108.243:1789, 10994) /cmd.php [co_doc.details] RQST END [normal] 84 ms"};
23+
24+
int errorcode;
25+
PCRE2_SIZE erroroffset;
26+
27+
const PCRE2_SPTR pattern = (PCRE2_SPTR)R"(\[([^ ]{8}) \| ([^\]]{19})\] \((?:[^,]+, )?\d+\) [^ ]+ \[([^\]]+)\] RQST END \[[^\]]+\] *(\d+) ms)";
28+
pcre2_code* re =pcre2_compile(pattern, PCRE2_ZERO_TERMINATED,0, &errorcode, &erroroffset,nullptr);
29+
30+
if (!re) {
31+
PCRE2_UCHAR buffer[256];
32+
pcre2_get_error_message(errorcode, buffer,sizeof(buffer));
33+
std::cout <<"PCRE2 compilation failed at offset" << erroroffset <<":" << buffer << std::endl;
34+
return1;
35+
}
36+
37+
if ((errorcode =pcre2_jit_compile(re, PCRE2_JIT_COMPLETE)) <0) {
38+
PCRE2_UCHAR buffer[256];
39+
pcre2_get_error_message(errorcode, buffer,sizeof(buffer));
40+
std::cout <<"PCRE2 JIT compile error" << erroroffset <<":" << buffer << std::endl;
41+
return2;
42+
}
43+
44+
pcre2_match_context* mcontext =pcre2_match_context_create(nullptr);
45+
46+
if (!mcontext) {
47+
std::cout <<"PCRE2 unable to create match context" << std::endl;
48+
return3;
49+
}
50+
51+
pcre2_jit_stack* jit_stack =pcre2_jit_stack_create(32*1024,512*1024,nullptr);
52+
53+
if (!jit_stack) {
54+
std::cout <<"PCRE2 unable to create JIT stack" << std::endl;
55+
return4;
56+
}
57+
58+
pcre2_jit_stack_assign(mcontext,nullptr, jit_stack);
59+
60+
pcre2_match_data* match_data =pcre2_match_data_create_from_pattern(re,nullptr);
61+
62+
if (!match_data) {
63+
std::cout <<"PCRE2 unable to create match data" << std::endl;
64+
return5;
65+
}
66+
67+
for (auto line : lines) {
68+
const PCRE2_SPTR subject = (PCRE2_SPTR) line.c_str();
69+
constint rc =pcre2_jit_match(re, subject, line.size(),0,0, match_data, mcontext);
70+
71+
if (rc >1) {
72+
const PCRE2_SIZE* ovector =pcre2_get_ovector_pointer(match_data);
73+
74+
for (int i =1; i < rc; ++i) {
75+
const PCRE2_SPTR substring_start = subject + ovector[2*i];
76+
constint substring_length = ovector[2*i +1] - ovector[2*i];
77+
const std::string_view s{(constchar*) substring_start, (std::size_t) substring_length};
78+
std::cout <<"MATCH" << i <<":\"" << s <<"\"" << std::endl;
79+
}
80+
}
81+
}
82+
83+
pcre2_match_data_free(match_data);
84+
pcre2_jit_stack_free(jit_stack);
85+
pcre2_match_context_free(mcontext);
86+
pcre2_code_free(re);
87+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp