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

Commitcf4fe6b

Browse files
committed
pcre.cpp
1 parent216ecb6 commitcf4fe6b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

‎CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
55

66
include_directories("$ENV{SUITE_BUILD}/include")
77

8+
set(LibPCRE_LIBRARY"$ENV{SUITE_BUILD}/lib/libpcre.dylib")
89
set(LibPCRE2_LIBRARY"$ENV{SUITE_BUILD}/lib/libpcre2-8.dylib")
910

1011
add_executable(std std.cpp)
12+
add_executable(pcre pcre.cpp)
1113
add_executable(pcre2 pcre2.cpp)
1214

1315
target_compile_features(stdPUBLIC cxx_std_17)
16+
target_compile_features(pcrePUBLIC cxx_std_17)
1417
target_compile_features(pcre2PUBLIC cxx_std_17)
1518

19+
target_link_libraries(pcrePRIVATE"${LibPCRE_LIBRARY}")
1620
target_link_libraries(pcre2PRIVATE"${LibPCRE2_LIBRARY}")
1721

1822
set_target_properties(std PROPERTIES CXX_EXTENSIONSOFF)
23+
set_target_properties(pcre PROPERTIES CXX_EXTENSIONSOFF)
1924
set_target_properties(pcre2 PROPERTIES CXX_EXTENSIONSOFF)

‎pcre.cpp‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#defineOVECCOUNT30
2+
3+
#include<iostream>
4+
#include<pcre.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+
constchar* error;
25+
int erroroffset;
26+
27+
constchar* pattern =R"(\[([^ ]{8}) \| ([^\]]{19})\] \((?:[^,]+, )?\d+\) [^ ]+ \[([^\]]+)\] RQST END \[[^\]]+\] *(\d+) ms)";
28+
pcre* re =pcre_compile(pattern,0, &error, &erroroffset,nullptr);
29+
30+
if (!re) {
31+
std::cout <<"PCRE compilation failed at offset" << erroroffset <<":" << error << std::endl;
32+
return1;
33+
}
34+
35+
for (auto line : lines) {
36+
int ovector[OVECCOUNT];
37+
constint rc =pcre_exec(re,nullptr, line.c_str(), line.size(),0,0, ovector, OVECCOUNT);
38+
39+
if (rc >1) {
40+
for (int i =1; i < rc; ++i) {
41+
constchar* substring_start = line.c_str() + ovector[2*i];
42+
constint substring_length = ovector[2*i +1] - ovector[2*i];
43+
const std::string_view s{substring_start, (std::size_t) substring_length};
44+
std::cout <<"MATCH" << i <<":\"" << s <<"\"" << std::endl;
45+
}
46+
}
47+
}
48+
49+
pcre_free(re);
50+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp