Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_stringref.cpp
diff options
context:
space:
mode:
authorPhil Nash2017-08-05 21:41:56 +0100
committerPhil Nash2017-08-05 21:41:56 +0100
commit519db85758220faa34b587249c335dcc79b0192a (patch)
tree344b7247a6bf0ec9d82382c3ba2a1f85bbc7d4d3 /include/internal/catch_stringref.cpp
parent4421672fb869318d3445a80deb5de09761f8a119 (diff)
downloadcatch3-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.cpp18
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() );