Skip to content

Commit a3fa2ef

Browse files
author
Mariusz Pasinski
committed
feat: add startsWith() helper function
1 parent 1709acb commit a3fa2ef

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/react-native-node-api-modules/cpp/CxxNodeApiHostModule.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <utility> // std::move, std::pair, std::make_pair
22
#include <vector> // std::vector
33
#include <string> // std::string
4-
#include <algorithm> // std::all_of
4+
#include <algorithm> // std::equal, std::all_of
55
#include <cctype> // std::isalnum
66
#include "CxxNodeApiHostModule.hpp"
77
#include "Logger.hpp"
@@ -10,6 +10,15 @@ using namespace facebook;
1010

1111
namespace {
1212

13+
bool startsWith(const std::string &str, const std::string &prefix) {
14+
#if __cplusplus >= 202002L // __cpp_lib_starts_ends_with
15+
return str.starts_with(prefix);
16+
#else
17+
return str.size() >= prefix.size()
18+
&& std::equal(prefix.begin(), prefix.end(), str.begin());
19+
#endif // __cplusplus >= 202002L
20+
}
21+
1322
bool isModulePathLike(const std::string_view &path) {
1423
return std::all_of(path.begin(), path.end(), [](unsigned char c) {
1524
return std::isalnum(c) || '_' == c || '-' == c

0 commit comments

Comments
 (0)