mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Use StringRef in pluralise implementation
This means that it can no longer be safely made ahead of time, but nothing in our existing code used it like that. Normally it is constructed and used in the same expression, which is now more efficient.
This commit is contained in:
parent
c0f866c7cf
commit
b3a84c7983
@ -94,11 +94,6 @@ namespace Catch {
|
||||
return subStrings;
|
||||
}
|
||||
|
||||
pluralise::pluralise( std::size_t count, std::string const& label )
|
||||
: m_count( count ),
|
||||
m_label( label )
|
||||
{}
|
||||
|
||||
std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
|
||||
os << pluraliser.m_count << ' ' << pluraliser.m_label;
|
||||
if( pluraliser.m_count != 1 )
|
||||
|
@ -32,13 +32,26 @@ namespace Catch {
|
||||
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::size_t count, std::string const& label );
|
||||
pluralise(std::size_t count, StringRef label):
|
||||
m_count(count),
|
||||
m_label(label)
|
||||
{}
|
||||
|
||||
friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
|
||||
|
||||
std::size_t m_count;
|
||||
std::string m_label;
|
||||
StringRef m_label;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user