mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Report benchmark durations in natural units
(and extended StringRef to be able to report utf8 char lengths
This commit is contained in:
@@ -64,6 +64,9 @@ namespace Catch {
|
||||
auto String::size() const noexcept -> size_type {
|
||||
return m_data->size;
|
||||
}
|
||||
auto String::numberOfCharacters() const noexcept -> size_type {
|
||||
return StringRef( *this ).numberOfCharacters();
|
||||
}
|
||||
auto String::c_str() const noexcept -> char const* {
|
||||
return m_data->chars;
|
||||
}
|
||||
|
@@ -40,6 +40,8 @@ namespace Catch {
|
||||
|
||||
auto empty() const noexcept -> bool;
|
||||
auto size() const noexcept -> size_type;
|
||||
auto numberOfCharacters() const noexcept -> size_type;
|
||||
|
||||
auto c_str() const noexcept -> char const*;
|
||||
};
|
||||
|
||||
|
@@ -136,7 +136,23 @@ namespace Catch {
|
||||
auto StringRef::size() const noexcept -> size_type {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
auto StringRef::numberOfCharacters() const noexcept -> size_type {
|
||||
size_type noChars = m_size;
|
||||
// Make adjustments for uft encodings
|
||||
for( size_type i=0; i < m_size; ++i ) {
|
||||
char c = m_start[i];
|
||||
if( ( c & 0b11000000 ) == 0b11000000 ) {
|
||||
if( ( c & 0b11100000 ) == 0b11000000 )
|
||||
noChars--;
|
||||
else if( ( c & 0b11110000 ) == 0b11100000 )
|
||||
noChars-=2;
|
||||
else if( ( c & 0b11111000 ) == 0b11110000 )
|
||||
noChars-=3;
|
||||
}
|
||||
}
|
||||
return noChars;
|
||||
}
|
||||
|
||||
auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> String {
|
||||
StringBuilder buf;
|
||||
buf.reserve( lhs.size() + rhs.size() );
|
||||
|
@@ -56,6 +56,7 @@ namespace Catch {
|
||||
public: // named queries
|
||||
auto empty() const noexcept -> bool;
|
||||
auto size() const noexcept -> size_type;
|
||||
auto numberOfCharacters() const noexcept -> size_type;
|
||||
auto c_str() const -> char const*;
|
||||
|
||||
public: // substrings and searches
|
||||
|
Reference in New Issue
Block a user