Skip to content

Commit ab6fae9

Browse files
committed
Added isWhitespaceOrEmpty template function
1 parent 4b470f1 commit ab6fae9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

include/libdbc/utils/utils.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ std::string trim(const T& value) {
6363
constexpr auto trim(const T& value, std::initializer_list<char>& trimChars) {
6464
#else
6565
template<typename T>
66-
std::string trim(const T& value, std::initializer_list<char>& trimChars) {
66+
std::string trim(const T& value, const std::initializer_list<char>& trimChars) {
6767
#endif // __cplusplus >= 201703
6868
T trimmedValue = value;
6969
trimmedValue.erase(trimmedValue.begin(), std::find_if(trimmedValue.begin(), trimmedValue.end(), [&trimChars](int ch) { return std::find(trimChars.begin(), trimChars.end(), static_cast<char>(ch)) == trimChars.end(); }));
@@ -80,6 +80,21 @@ std::string trim(const T& value, std::initializer_list<char>& trimChars) {
8080
constexpr auto trim(const T& value, const std::string_view& trimChars) { return trim(value, std::initializer_list<char>(trimChars.begin(), trimChars.end())); }
8181
#endif // __cplusplus >= 201703L
8282

83+
/**
84+
* @brief Checks if the given string is empty or contains only whitespace characters.
85+
*
86+
* @tparam T The typeparam; must be stringable.
87+
*
88+
* @param str The string to check against.
89+
*
90+
* @return true If the string is empty or consists only of whitespace.
91+
* @return false Otherwise.
92+
*/
93+
template<typename T>
94+
constexpr bool isWhitespaceOrEmpty(const T& str) {
95+
return std::all_of(str.begin(), str.end(), [](char c) { return std::isspace(c); });
96+
}
97+
8398
class String {
8499
public:
85100
static std::string trim(const std::string& line) { return Utils::trim(line); }

0 commit comments

Comments
 (0)