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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-09-06 23:23:23 +0200
committerMartin Hořeňovský2026-09-11 11:15:58 +0200
commit6a5075bf73273ecb83fca61efdfde2fa1a2690bf (patch)
tree6b5f8e4a6c02d653caf57b0059bc25d2d5306d2a /src/catch2
parent15db9be53067d66ecd11a7ddd3097d412047130a (diff)
downloadcatch3-6a5075bf73273ecb83fca61efdfde2fa1a2690bf.tar.gz
Use locale-independent toLower
We generally do not even try to pretend to support more than plain ASCII, because doing unicode in old C++ standards is a pain and a half. For `toLower`, we used to wrap `std::tolower` with multiple casts to avoid UB, but calling into it is relatively slow, and it tries to handle different locales, which could cause unexpected results. In addition, the new implementation is significantly faster, which helps speed up the initial process bring up (as comparing tags, and thus test cases is now faster).
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/internal/catch_string_manip.cpp4
-rw-r--r--src/catch2/internal/catch_string_manip.hpp7
2 files changed, 6 insertions, 5 deletions
diff --git a/src/catch2/internal/catch_string_manip.cpp b/src/catch2/internal/catch_string_manip.cpp
index 68983787..ac88be2e 100644
--- a/src/catch2/internal/catch_string_manip.cpp
+++ b/src/catch2/internal/catch_string_manip.cpp
@@ -11,7 +11,6 @@
#include <ostream>
#include <cstring>
-#include <cctype>
#include <vector>
namespace Catch {
@@ -41,9 +40,6 @@ namespace Catch {
toLowerInPlace( lc );
return lc;
}
- char toLower(char c) {
- return static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
- }
std::string trim( std::string const& str ) {
static char const* whitespaceChars = "\n\r\t ";
diff --git a/src/catch2/internal/catch_string_manip.hpp b/src/catch2/internal/catch_string_manip.hpp
index 4251f83d..ce317c60 100644
--- a/src/catch2/internal/catch_string_manip.hpp
+++ b/src/catch2/internal/catch_string_manip.hpp
@@ -25,7 +25,12 @@ namespace Catch {
bool contains( std::string const& s, std::string const& infix );
void toLowerInPlace( std::string& s );
std::string toLower( std::string const& s );
- char toLower( char c );
+ //! ASCII only.
+ constexpr char toLower( char c ) {
+ const uint32_t as_number = static_cast<unsigned char>( c );
+ const bool isUpper = ( as_number - static_cast<uint32_t>( 'A' ) ) < 26u;
+ return static_cast<char>( as_number | ( isUpper << 5 ) );
+ }
//! Returns a new string without whitespace at the start/end
std::string trim( std::string const& str );
//! Returns a substring of the original ref without whitespace. Beware lifetimes!