Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
f0438265
Commit
f0438265
authored
Jul 30, 2014
by
Matt Clarkson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C++11 regular expressions
parent
edfa60a1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
3 deletions
+68
-3
CMakeLists.txt
src/CMakeLists.txt
+11
-1
re.h
src/re.h
+12
-2
re_posix.cc
src/re_posix.cc
+0
-0
re_std.cc
src/re_std.cc
+45
-0
No files found.
src/CMakeLists.txt
View file @
f0438265
# Define the source files
# Define the source files
set
(
SOURCE_FILES
"benchmark.cc"
"colorprint.cc"
"commandlineflags.cc"
"sleep.cc"
"sysinfo.cc"
"walltime.cc"
)
set
(
SOURCE_FILES
"benchmark.cc"
"colorprint.cc"
"commandlineflags.cc"
"sleep.cc"
"sysinfo.cc"
"walltime.cc"
)
set
(
RE_FILES
"re.cc"
)
# Determine the correct regular expression engine to use
if
(
HAVE_STD_REGEX
)
set
(
RE_FILES
"re_std.cc"
)
elseif
(
HAVE_GNU_POSIX_REGEX
)
set
(
RE_FILES
"re_posix.cc"
)
elseif
(
HAVE_POSIX_REGEX
)
set
(
RE_FILES
"re_posix.cc"
)
else
()
message
(
FATAL_ERROR
"Failed to determine the source files for the regular expression backend"
)
endif
()
# Build a regular expression library
# Build a regular expression library
add_library
(
benchmark_re
${
RE_FILES
}
)
add_library
(
benchmark_re
${
RE_FILES
}
)
...
...
src/re.h
View file @
f0438265
...
@@ -15,10 +15,14 @@
...
@@ -15,10 +15,14 @@
#ifndef BENCHMARK_RE_H_
#ifndef BENCHMARK_RE_H_
#define BENCHMARK_RE_H_
#define BENCHMARK_RE_H_
#if defined OS_FREEBSD
#if defined(HAVE_STD_REGEX)
#include <regex>
#elif defined(HAVE_GNU_POSIX_REGEX)
#include <gnuregex.h>
#include <gnuregex.h>
#el
se
#el
if defined(HAVE_POSIX_REGEX)
#include <regex.h>
#include <regex.h>
#else
#error No regular expression backend was found!
#endif
#endif
#include <string>
#include <string>
...
@@ -42,7 +46,13 @@ class Regex {
...
@@ -42,7 +46,13 @@ class Regex {
private
:
private
:
bool
init_
;
bool
init_
;
// Underlying regular expression object
// Underlying regular expression object
#if defined(HAVE_STD_REGEX)
std
::
regex
re_
;
#elif defined(HAVE_POSIX_REGEX) || defined(HAVE_GNU_POSIX_REGEX)
regex_t
re_
;
regex_t
re_
;
#else
# error No regular expression backend implementation available
#endif
};
};
}
// end namespace benchmark
}
// end namespace benchmark
...
...
src/re.cc
→
src/re
_posix
.cc
View file @
f0438265
File moved
src/re_std.cc
0 → 100644
View file @
f0438265
// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <benchmark/macros.h>
#include "re.h"
namespace
benchmark
{
Regex
::
Regex
()
:
init_
(
false
)
{
}
bool
Regex
::
Init
(
const
std
::
string
&
spec
,
std
::
string
*
error
)
{
try
{
re_
=
std
::
regex
(
spec
,
std
::
regex_constants
::
extended
);
init_
=
true
;
}
catch
(
const
std
::
regex_error
&
e
)
{
if
(
error
)
{
*
error
=
e
.
what
();
}
}
return
init_
;
}
Regex
::~
Regex
()
{
}
bool
Regex
::
Match
(
const
std
::
string
&
str
)
{
if
(
!
init_
)
{
return
false
;
}
return
std
::
regex_search
(
str
,
re_
);
}
}
// end namespace benchmark
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment