Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
folly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
folly
Commits
7154531b
Commit
7154531b
authored
Mar 24, 2014
by
Tom Jackson
Committed by
Dave Watson
Mar 31, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Range::contains(x)
Test Plan: Unit tests Reviewed By: marcelo.juchem@fb.com FB internal diff: D1236630
parent
922f80e0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
folly/Range.h
folly/Range.h
+13
-0
folly/test/RangeTest.cpp
folly/test/RangeTest.cpp
+4
-0
No files found.
folly/Range.h
View file @
7154531b
...
@@ -501,6 +501,19 @@ public:
...
@@ -501,6 +501,19 @@ public:
return
find
(
c
,
pos
);
return
find
(
c
,
pos
);
}
}
/**
* Determine whether the range contains the given subrange or item.
*
* Note: Call find() directly if the index is needed.
*/
bool
contains
(
const
Range
&
other
)
const
{
return
find
(
other
)
!=
std
::
string
::
npos
;
}
bool
contains
(
const
value_type
&
other
)
const
{
return
find
(
other
)
!=
std
::
string
::
npos
;
}
void
swap
(
Range
&
rhs
)
{
void
swap
(
Range
&
rhs
)
{
std
::
swap
(
b_
,
rhs
.
b_
);
std
::
swap
(
b_
,
rhs
.
b_
);
std
::
swap
(
e_
,
rhs
.
e_
);
std
::
swap
(
e_
,
rhs
.
e_
);
...
...
folly/test/RangeTest.cpp
View file @
7154531b
...
@@ -116,6 +116,7 @@ TEST(StringPiece, All) {
...
@@ -116,6 +116,7 @@ TEST(StringPiece, All) {
EXPECT_EQ
(
s
.
find
(
'y'
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find
(
'y'
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find
(
'y'
,
1
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find
(
'y'
,
1
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find
(
'o'
,
4
),
StringPiece
::
npos
);
// starting position too far
EXPECT_EQ
(
s
.
find
(
'o'
,
4
),
StringPiece
::
npos
);
// starting position too far
EXPECT_TRUE
(
s
.
contains
(
'z'
));
// starting pos that is obviously past the end -- This works for std::string
// starting pos that is obviously past the end -- This works for std::string
EXPECT_EQ
(
s
.
toString
().
find
(
'y'
,
55
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
toString
().
find
(
'y'
,
55
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find
(
'z'
,
s
.
size
()),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find
(
'z'
,
s
.
size
()),
StringPiece
::
npos
);
...
@@ -123,6 +124,7 @@ TEST(StringPiece, All) {
...
@@ -123,6 +124,7 @@ TEST(StringPiece, All) {
// null char
// null char
EXPECT_EQ
(
s
.
find
(
'\0'
),
std
::
string
().
find
(
'\0'
));
EXPECT_EQ
(
s
.
find
(
'\0'
),
std
::
string
().
find
(
'\0'
));
EXPECT_EQ
(
s
.
find
(
'\0'
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find
(
'\0'
),
StringPiece
::
npos
);
EXPECT_FALSE
(
s
.
contains
(
'\0'
));
// single char rfinds
// single char rfinds
EXPECT_EQ
(
s
.
rfind
(
'b'
),
6
);
EXPECT_EQ
(
s
.
rfind
(
'b'
),
6
);
...
@@ -139,8 +141,10 @@ TEST(StringPiece, All) {
...
@@ -139,8 +141,10 @@ TEST(StringPiece, All) {
EXPECT_EQ
(
s
.
find_first_of
(
"bar"
),
3
);
EXPECT_EQ
(
s
.
find_first_of
(
"bar"
),
3
);
EXPECT_EQ
(
s
.
find_first_of
(
"ba"
,
3
),
3
);
EXPECT_EQ
(
s
.
find_first_of
(
"ba"
,
3
),
3
);
EXPECT_EQ
(
s
.
find_first_of
(
"ba"
,
4
),
4
);
EXPECT_EQ
(
s
.
find_first_of
(
"ba"
,
4
),
4
);
EXPECT_TRUE
(
s
.
contains
(
"bar"
));
EXPECT_EQ
(
s
.
find_first_of
(
"xyxy"
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find_first_of
(
"xyxy"
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find_first_of
(
"xyxy"
,
1
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find_first_of
(
"xyxy"
,
1
),
StringPiece
::
npos
);
EXPECT_FALSE
(
s
.
contains
(
"xyxy"
));
// starting position too far
// starting position too far
EXPECT_EQ
(
s
.
find_first_of
(
"foo"
,
4
),
StringPiece
::
npos
);
EXPECT_EQ
(
s
.
find_first_of
(
"foo"
,
4
),
StringPiece
::
npos
);
// starting pos that is obviously past the end -- This works for std::string
// starting pos that is obviously past the end -- This works for std::string
...
...
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