1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-05-01 13:03:51 +00:00
Catch2/src/catch2/internal/catch_string_manip.hpp
Martin Hořeňovský dcf9479c85
Counts internally use uint64_t instead of size_t
This ensures that even for 32 bit platforms, the assertion count
should not plausibly overflow.
2021-12-06 20:42:51 +01:00

60 lines
2.0 KiB
C++

// Copyright Catch2 Authors
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0
#ifndef CATCH_STRING_MANIP_HPP_INCLUDED
#define CATCH_STRING_MANIP_HPP_INCLUDED
#include <catch2/internal/catch_stringref.hpp>
#include <string>
#include <iosfwd>
#include <vector>
namespace Catch {
bool startsWith( std::string const& s, std::string const& prefix );
bool startsWith( StringRef s, char prefix );
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 );
char toLower( char c );
//! Returns a new string without whitespace at the start/end
std::string trim( std::string const& str );
//! Returns a substring of the original ref without whitespace. Beware lifetimes!
StringRef trim(StringRef ref);
// !!! Be aware, returns refs into original string - make sure original string outlives them
std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
/**
* 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
*/
struct pluralise {
pluralise(std::uint64_t count, StringRef label):
m_count(count),
m_label(label)
{}
friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
std::uint64_t m_count;
StringRef m_label;
};
}
#endif // CATCH_STRING_MANIP_HPP_INCLUDED