Skip to content

Commit 5e95143

Browse files
committed
fable: Add ends_with and starts_with helper functions
1 parent df5f761 commit 5e95143

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fable/include/fable/utility/string.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,23 @@
2020
* \see fable/utility/string.cpp
2121
*/
2222

23+
#pragma once
24+
2325
#include <string> // for string
2426
#include <string_view> // for string_view
2527
#include <vector> // for vector<>
2628

2729
namespace fable {
2830

31+
inline bool starts_with(std::string_view s, std::string_view prefix) {
32+
return s.size() >= prefix.size() && s.compare(0, prefix.size(), prefix) == 0;
33+
}
34+
35+
inline bool ends_with(std::string_view s, std::string_view suffix) {
36+
return s.size() >= suffix.size() &&
37+
s.compare(s.size() - suffix.size(), std::string::npos, suffix) == 0;
38+
}
39+
2940
std::string join_vector(const std::vector<std::string>& v, std::string_view sep);
3041

3142
/**

0 commit comments

Comments
 (0)