Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
520414ca
There was an error fetching the commit references. Please try again later.
Commit
520414ca
authored
4 years ago
by
Jakub Klinkovský
Browse files
Options
Downloads
Patches
Plain Diff
Added methods startsWith and endsWith to String
parent
cfa5cc0a
No related branches found
No related tags found
1 merge request
!57
Small fixes
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/TNL/String.h
+10
-0
10 additions, 0 deletions
src/TNL/String.h
src/TNL/String.hpp
+16
-0
16 additions, 0 deletions
src/TNL/String.hpp
src/UnitTests/StringTest.cpp
+57
-1
57 additions, 1 deletion
src/UnitTests/StringTest.cpp
with
83 additions
and
1 deletion
src/TNL/String.h
+
10
−
0
View file @
520414ca
...
...
@@ -342,6 +342,16 @@ class String
* \include StringExampleSplit.out
*/
std
::
vector
<
String
>
split
(
const
char
separator
=
' '
,
SplitSkip
skipEmpty
=
SplitSkip
::
NoSkip
)
const
;
/**
* \brief Checks if the string starts with given prefix.
*/
bool
startsWith
(
const
String
&
prefix
)
const
;
/**
* \brief Checks if the string ends with given suffix.
*/
bool
endsWith
(
const
String
&
suffix
)
const
;
};
/**
...
...
This diff is collapsed.
Click to expand it.
src/TNL/String.hpp
+
16
−
0
View file @
520414ca
...
...
@@ -223,6 +223,22 @@ String::split( const char separator, SplitSkip skip ) const
return
parts
;
}
inline
bool
String
::
startsWith
(
const
String
&
prefix
)
const
{
if
(
prefix
.
getSize
()
>
getSize
())
return
false
;
return
std
::
equal
(
prefix
.
begin
(),
prefix
.
end
(),
begin
()
);
}
inline
bool
String
::
endsWith
(
const
String
&
suffix
)
const
{
if
(
suffix
.
getSize
()
>
getSize
())
return
false
;
return
std
::
equal
(
suffix
.
rbegin
(),
suffix
.
rend
(),
rbegin
()
);
}
inline
String
operator
+
(
char
string1
,
const
String
&
string2
)
{
return
convertToString
(
string1
)
+
string2
;
...
...
This diff is collapsed.
Click to expand it.
src/UnitTests/StringTest.cpp
+
57
−
1
View file @
520414ca
...
...
@@ -317,7 +317,63 @@ TEST( StringTest, SaveLoad )
EXPECT_EQ
(
str1
,
str2
);
EXPECT_EQ
(
std
::
remove
(
TEST_FILE_NAME
),
0
);
};
}
TEST
(
StringTest
,
startsWith
)
{
String
str
(
"abracadabra"
);
EXPECT_TRUE
(
str
.
startsWith
(
"a"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"ab"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abr"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abra"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abrac"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abraca"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abracad"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abracada"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abracadab"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abracadabr"
)
);
EXPECT_TRUE
(
str
.
startsWith
(
"abracadabra"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"b"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"aa"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"aba"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abrb"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abrad"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abracb"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abracaa"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abracadb"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abracadaa"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abracadaba"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abracadabrb"
)
);
EXPECT_FALSE
(
str
.
startsWith
(
"abracadabrab"
)
);
}
TEST
(
StringTest
,
endsWith
)
{
String
str
(
"abracadabra"
);
EXPECT_TRUE
(
str
.
endsWith
(
"a"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"ra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"bra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"abra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"dabra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"adabra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"cadabra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"acadabra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"racadabra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"bracadabra"
)
);
EXPECT_TRUE
(
str
.
endsWith
(
"abracadabra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"b"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"ba"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"ara"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"bbra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"babra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"bdabra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"badabra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"bcadabra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"aacadabra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"aracadabra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"bbracadabra"
)
);
EXPECT_FALSE
(
str
.
endsWith
(
"babracadabra"
)
);
}
#endif
#include
"main.h"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment