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

Commit8fb14be

Browse files
committed
re2.cpp
1 parenta386a58 commit8fb14be

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

‎CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ find_package(Boost REQUIRED COMPONENTS headers regex)
77

88
include_directories("$ENV{SUITE_BUILD}/include")
99

10+
set(LibRE2_LIBRARY"$ENV{SUITE_BUILD}/lib/libre2.a")
1011
set(LibPCRE_LIBRARY"$ENV{SUITE_BUILD}/lib/libpcre.dylib")
1112
set(LibPCRE2_LIBRARY"$ENV{SUITE_BUILD}/lib/libpcre2-8.dylib")
1213

1314
add_executable(std std.cpp)
1415
add_executable(boost boost.cpp)
1516
add_executable(pcre pcre.cpp)
17+
add_executable(re2 re2.cpp)
1618
add_executable(pcre2 pcre2.cpp)
1719
add_executable(pcre_jit pcre_jit.cpp)
1820
add_executable(pcre2_jit pcre2_jit.cpp)
1921

2022
target_compile_features(stdPUBLIC cxx_std_17)
2123
target_compile_features(boostPUBLIC cxx_std_17)
24+
target_compile_features(re2PUBLIC cxx_std_17)
2225
target_compile_features(pcrePUBLIC cxx_std_17)
2326
target_compile_features(pcre2PUBLIC cxx_std_17)
2427
target_compile_features(pcre_jitPUBLIC cxx_std_17)
@@ -29,13 +32,15 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
2932
endif()
3033

3134
target_link_libraries(boostPRIVATE${Boost_LIBRARIES} Boost::regex)
35+
target_link_libraries(re2PRIVATE"${LibRE2_LIBRARY}")
3236
target_link_libraries(pcrePRIVATE"${LibPCRE_LIBRARY}")
3337
target_link_libraries(pcre2PRIVATE"${LibPCRE2_LIBRARY}")
3438
target_link_libraries(pcre_jitPRIVATE"${LibPCRE_LIBRARY}")
3539
target_link_libraries(pcre2_jitPRIVATE"${LibPCRE2_LIBRARY}")
3640

3741
set_target_properties(std PROPERTIES CXX_EXTENSIONSOFF)
3842
set_target_properties(boost PROPERTIES CXX_EXTENSIONSOFF)
43+
set_target_properties(re2 PROPERTIES CXX_EXTENSIONSOFF)
3944
set_target_properties(pcre PROPERTIES CXX_EXTENSIONSOFF)
4045
set_target_properties(pcre2 PROPERTIES CXX_EXTENSIONSOFF)
4146
set_target_properties(pcre_jit PROPERTIES CXX_EXTENSIONSOFF)

‎re2.cpp‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include<iostream>
2+
#include<re2/re2.h>
3+
#include<string>
4+
#include<vector>
5+
6+
intmain()
7+
{
8+
const std::vector<std::string> lines{
9+
"[05821BE4 | 2019-05-13 12:28:56] (13036) http://contiview.site/projects/cmd.php [co_project.view] RQST START",
10+
"[05821BE4 | 2019-05-13 12:28:56] (13036) http://contiview.site/projects/cmd.php [co_project.view] RQST END [normal] 402 ms",
11+
"[05671FA1 | 2019-04-17 14:08:03] (62931) http://contiview.site/projects/cmd.php [co_project.view] RQST START",
12+
"[05671FA1 | 2019-04-17 14:08:03] (62931) http://contiview.site/projects/cmd.php [co_project.view] RQST END [normal] 237 ms",
13+
"[05822AE4 | 2019-06-17 06:59:03] (15828) http://contiview.site/cmd.php [co_project.dialog_doc_details] RQST START",
14+
"[05822AE4 | 2019-06-17 06:59:03] (15828) http://contiview.site/cmd.php [co_project.dialog_doc_details] RQST END [normal] 318 ms",
15+
"[00180D0F | 2009-09-15 09:34:47] (193.98.108.243:39170, 879) /cmd.php [co_search.browse] RQST START",
16+
"[00180D0F | 2009-09-15 09:34:48] (193.98.108.243:39170, 879) /cmd.php [co_search.browse] RQST END [normal] 799 ms",
17+
"[00180D0D | 2009-09-15 09:34:19] (193.98.108.243:39169, 23727) /browse/ RQST START",
18+
"[00180D0D | 2009-09-15 09:34:19] (193.98.108.243:39169, 23727) /browse/ RQST END [normal] 35 ms",
19+
"[001F86EA | 2009-11-02 16:05:50] (193.98.108.243:1789, 10994) /cmd.php [co_doc.details] RQST START",
20+
"hello",
21+
"[001F86EA | 2009-11-02 16:05:50] (193.98.108.243:1789, 10994) /cmd.php [co_doc.details] RQST END [normal] 84 ms"};
22+
23+
24+
const RE2 re{R"(\[([^ ]{8}) \| ([^\]]{19})\] \((?:[^,]+, )?\d+\) [^ ]+ \[([^\]]+)\] RQST END \[[^\]]+\] *(\d+) ms)"};
25+
26+
if (!re.ok())
27+
return1;
28+
29+
std::size_t args_count = re.NumberOfCapturingGroups();
30+
31+
std::vector<RE2::Arg>arguments(args_count);
32+
std::vector<RE2::Arg*>arguments_ptrs(args_count);
33+
std::vector<std::string>results(args_count);
34+
35+
for (auto i =0; i < args_count; ++i) {
36+
arguments[i] = &results[i];
37+
arguments_ptrs[i] = &arguments[i];
38+
}
39+
40+
for (auto line : lines)
41+
if (RE2::FullMatchN(line, re, arguments_ptrs.data(), args_count))
42+
for (auto i =0; i < args_count; ++i)
43+
std::cout <<"MATCH" << i <<":\"" << results[i] <<"\"" << std::endl;
44+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp