Skip to content

Commit caeffff

Browse files
committed
Add string StartsWith
1 parent 1402bff commit caeffff

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Firestore/core/src/firebase/firestore/util/string_util.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ std::string ImmediateSuccessor(absl::string_view s) {
4848
return out;
4949
}
5050

51+
bool StartsWith(const std::string &value, const std::string &prefix) {
52+
return prefix.size() <= value.size() &&
53+
std::equal(prefix.begin(), prefix.end(), value.begin());
54+
}
55+
5156
} // namespace util
5257
} // namespace firestore
5358
} // namespace firebase

Firestore/core/src/firebase/firestore/util/string_util.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace firebase {
3232
namespace firestore {
3333
namespace util {
3434

35-
/*
35+
/**
3636
* Returns the smallest lexicographically larger string of equal or smaller
3737
* length. Returns an empty string if there is no such successor (if the input
3838
* is empty or consists entirely of 0xff bytes).
@@ -44,7 +44,7 @@ namespace util {
4444
*/
4545
std::string PrefixSuccessor(absl::string_view prefix);
4646

47-
/*
47+
/**
4848
* Returns the immediate lexicographically-following string. This is useful to
4949
* turn an inclusive range into something that can be used with Bigtable's
5050
* SetLimitRow():
@@ -65,6 +65,11 @@ std::string PrefixSuccessor(absl::string_view prefix);
6565
*/
6666
std::string ImmediateSuccessor(absl::string_view s);
6767

68+
/**
69+
* Returns true if the given value starts with the given prefix.
70+
*/
71+
bool StartsWith(const std::string &value, const std::string &prefix);
72+
6873
} // namespace util
6974
} // namespace firestore
7075
} // namespace firebase

0 commit comments

Comments
 (0)