Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:50

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_STRING_MANIP_HPP_INCLUDED
0009 #define CATCH_STRING_MANIP_HPP_INCLUDED
0010 
0011 #include <cstdint>
0012 #include <catch2/internal/catch_stringref.hpp>
0013 
0014 #include <cstdint>
0015 #include <string>
0016 #include <iosfwd>
0017 #include <vector>
0018 
0019 namespace Catch {
0020 
0021     bool startsWith( std::string const& s, std::string const& prefix );
0022     bool startsWith( StringRef s, char prefix );
0023     bool endsWith( std::string const& s, std::string const& suffix );
0024     bool endsWith( std::string const& s, char suffix );
0025     bool contains( std::string const& s, std::string const& infix );
0026     void toLowerInPlace( std::string& s );
0027     std::string toLower( std::string const& s );
0028     char toLower( char c );
0029     //! Returns a new string without whitespace at the start/end
0030     std::string trim( std::string const& str );
0031     //! Returns a substring of the original ref without whitespace. Beware lifetimes!
0032     StringRef trim(StringRef ref);
0033 
0034     // !!! Be aware, returns refs into original string - make sure original string outlives them
0035     std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
0036     bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
0037 
0038     /**
0039      * Helper for streaming a "count [maybe-plural-of-label]" human-friendly string
0040      *
0041      * Usage example:
0042      * ```cpp
0043      * std::cout << "Found " << pluralise(count, "error") << '\n';
0044      * ```
0045      *
0046      * **Important:** The provided string must outlive the instance
0047      */
0048     class pluralise {
0049         std::uint64_t m_count;
0050         StringRef m_label;
0051 
0052     public:
0053         constexpr pluralise(std::uint64_t count, StringRef label):
0054             m_count(count),
0055             m_label(label)
0056         {}
0057 
0058         friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
0059     };
0060 }
0061 
0062 #endif // CATCH_STRING_MANIP_HPP_INCLUDED