Added string_view::contains methods.

These methods were added in C++23.

Also updated string_view/ref tests:

- Added tests for string_view::contains.
- Added missing includes.
- Added missing std:: qualification.
- Removed tabs.
- Fixed misleading indentation (fixes gcc warnings).
- Fixed decrementing pointer before beginning of the string.

Closes https://github.com/boostorg/utility/issues/93.
This commit is contained in:
Andrey Semashev
2022-05-04 00:32:30 +03:00
parent 0106ffda5f
commit c63d36cf5b
6 changed files with 99 additions and 53 deletions
+9 -8
View File
@@ -7,6 +7,7 @@
For more information, see http://www.boost.org
*/
#include <cstddef>
#include <iostream>
#include <algorithm>
#include <string>
@@ -41,30 +42,30 @@ void null_tests ( const char *p ) {
// make sure that substrings work just like strings
void test_substr ( const std::string &str ) {
const size_t sz = str.size ();
const std::size_t sz = str.size ();
string_ref ref ( str );
// Substrings at the end
for ( size_t i = 0; i <= sz; ++ i )
for ( std::size_t i = 0; i <= sz; ++ i )
interop ( str.substr ( i ), ref.substr ( i ));
// Substrings at the beginning
for ( size_t i = 0; i <= sz; ++ i )
for ( std::size_t i = 0; i <= sz; ++ i )
interop ( str.substr ( 0, i ), ref.substr ( 0, i ));
// All possible substrings
for ( size_t i = 0; i < sz; ++i )
for ( size_t j = i; j < sz; ++j )
for ( std::size_t i = 0; i < sz; ++i )
for ( std::size_t j = i; j < sz; ++j )
interop ( str.substr ( i, j ), ref.substr ( i, j ));
}
// make sure that removing prefixes and suffixes work just like strings
void test_remove ( const std::string &str ) {
const size_t sz = str.size ();
const std::size_t sz = str.size ();
std::string work;
string_ref ref;
for ( size_t i = 1; i <= sz; ++i ) {
for ( std::size_t i = 1; i <= sz; ++i ) {
work = str;
ref = str;
while ( ref.size () >= i ) {
@@ -74,7 +75,7 @@ void test_remove ( const std::string &str ) {
}
}
for ( size_t i = 1; i < sz; ++ i ) {
for ( std::size_t i = 1; i < sz; ++ i ) {
work = str;
ref = str;
while ( ref.size () >= i ) {