2020-08-30 15:43:45 +02:00
|
|
|
|
|
|
|
|
// Copyright Catch2 Authors
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0.
|
2022-10-28 11:22:53 +02:00
|
|
|
// (See accompanying file LICENSE.txt or copy at
|
2020-08-30 15:43:45 +02:00
|
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
2020-08-29 20:48:32 +02:00
|
|
|
#ifndef CATCH_STRING_MANIP_HPP_INCLUDED
|
|
|
|
|
#define CATCH_STRING_MANIP_HPP_INCLUDED
|
2017-07-25 21:57:35 +02:00
|
|
|
|
2020-05-10 10:09:01 +02:00
|
|
|
#include <catch2/internal/catch_stringref.hpp>
|
2019-04-25 10:32:55 +01:00
|
|
|
|
2023-01-08 02:03:32 +00:00
|
|
|
#include <cstdint>
|
2017-07-25 21:57:35 +02:00
|
|
|
#include <string>
|
|
|
|
|
#include <iosfwd>
|
2019-04-25 14:19:00 +01:00
|
|
|
#include <vector>
|
2017-07-25 21:57:35 +02:00
|
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
|
|
bool startsWith( std::string const& s, std::string const& prefix );
|
2021-09-27 14:52:44 +02:00
|
|
|
bool startsWith( StringRef s, char prefix );
|
2017-07-25 21:57:35 +02:00
|
|
|
bool endsWith( std::string const& s, std::string const& suffix );
|
|
|
|
|
bool endsWith( std::string const& s, char suffix );
|
|
|
|
|
bool contains( std::string const& s, std::string const& infix );
|
|
|
|
|
void toLowerInPlace( std::string& s );
|
|
|
|
|
std::string toLower( std::string const& s );
|
2021-11-08 23:58:09 +01:00
|
|
|
char toLower( char c );
|
2019-09-07 11:31:00 +02:00
|
|
|
//! Returns a new string without whitespace at the start/end
|
2017-07-25 21:57:35 +02:00
|
|
|
std::string trim( std::string const& str );
|
2019-09-07 11:31:00 +02:00
|
|
|
//! Returns a substring of the original ref without whitespace. Beware lifetimes!
|
|
|
|
|
StringRef trim(StringRef ref);
|
2019-04-21 20:03:44 +03:00
|
|
|
|
|
|
|
|
// !!! Be aware, returns refs into original string - make sure original string outlives them
|
|
|
|
|
std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
|
2017-07-25 21:57:35 +02:00
|
|
|
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
|
|
|
|
|
|
2021-09-08 00:24:36 +02:00
|
|
|
/**
|
|
|
|
|
* Helper for streaming a "count [maybe-plural-of-label]" human-friendly string
|
|
|
|
|
*
|
|
|
|
|
* Usage example:
|
|
|
|
|
* ```cpp
|
|
|
|
|
* std::cout << "Found " << pluralise(count, "error") << '\n';
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* **Important:** The provided string must outlive the instance
|
|
|
|
|
*/
|
2022-04-11 20:37:54 +02:00
|
|
|
class pluralise {
|
|
|
|
|
std::uint64_t m_count;
|
|
|
|
|
StringRef m_label;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
constexpr pluralise(std::uint64_t count, StringRef label):
|
2021-09-08 00:24:36 +02:00
|
|
|
m_count(count),
|
|
|
|
|
m_label(label)
|
|
|
|
|
{}
|
2017-07-25 21:57:35 +02:00
|
|
|
|
|
|
|
|
friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-29 20:48:32 +02:00
|
|
|
#endif // CATCH_STRING_MANIP_HPP_INCLUDED
|