Skip to content

Commit 31f5c29

Browse files
Avoid warnings about "unsecure stdlib" code
1 parent a6bbdfb commit 31f5c29

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/stdx/string_view.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#pragma once
1616

17+
#include <algorithm>
1718
#include <cstddef>
1819
#include <ios>
1920
#include <iosfwd>
@@ -369,14 +370,14 @@ class basic_string_view : detail::equality_operators, detail::ordering_operators
369370
* @brief Test whether the string starts-with the given prefix string
370371
*/
371372
constexpr bool starts_with(self_type pfx) const noexcept {
372-
return size() >= pfx.size() && std::equal(begin(), begin() + pfx.size(), pfx.begin());
373+
return pfx == substr(0, pfx.size());
373374
}
374375

375376
/**
376377
* @brief Test whether the string ends-with the given suffix string
377378
*/
378379
constexpr bool ends_with(self_type sfx) const noexcept {
379-
return size() >= sfx.size() && std::equal(rbegin(), rbegin() + sfx.size(), sfx.rbegin());
380+
return size() >= sfx.size() && substr(size() - sfx.size()) == sfx;
380381
}
381382

382383
/**
@@ -405,12 +406,7 @@ class basic_string_view : detail::equality_operators, detail::ordering_operators
405406

406407
// Implementation of equality comparison
407408
constexpr friend bool tag_invoke(detail::equal_to, self_type left, self_type right) noexcept {
408-
return left.size() == right.size() &&
409-
std::equal(
410-
left.begin(),
411-
left.end(),
412-
right.begin(),
413-
[](value_type l, value_type r) noexcept -> bool { return Traits::eq(l, r); });
409+
return left.size() == right.size() && left.compare(right) == 0;
414410
}
415411

416412
// Implementation of a three-way-comparison

0 commit comments

Comments
 (0)