diff options
| author | Phil Nash | 2017-08-05 21:41:56 +0100 |
|---|---|---|
| committer | Phil Nash | 2017-08-05 21:41:56 +0100 |
| commit | 519db85758220faa34b587249c335dcc79b0192a (patch) | |
| tree | 344b7247a6bf0ec9d82382c3ba2a1f85bbc7d4d3 /include/internal/catch_stringref.cpp | |
| parent | 4421672fb869318d3445a80deb5de09761f8a119 (diff) | |
| download | catch3-519db85758220faa34b587249c335dcc79b0192a.tar.gz | |
Report benchmark durations in natural units
(and extended StringRef to be able to report utf8 char lengths
Diffstat (limited to 'include/internal/catch_stringref.cpp')
| -rw-r--r-- | include/internal/catch_stringref.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp index 9572c56f..44db6858 100644 --- a/include/internal/catch_stringref.cpp +++ b/include/internal/catch_stringref.cpp @@ -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() ); |