Report benchmark durations in natural units

(and extended StringRef to be able to report utf8 char lengths
This commit is contained in:
Phil Nash 2017-08-05 21:41:56 +01:00
parent 4421672fb8
commit 519db85758
5 changed files with 106 additions and 8 deletions

View file

@ -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() );