while (end != std::string::npos) {
end = value.find_first_of(", ", start);
std::string token =
- Util::strip_whitespace(value.substr(start, end - start));
+ util::strip_whitespace(value.substr(start, end - start));
if (token == "file_stat_matches") {
result |= SLOPPY_FILE_STAT_MATCHES;
} else if (token == "file_stat_matches_ctime") {
std::string* value,
std::string* error_message)
{
- std::string stripped_line = Util::strip_whitespace(line);
+ std::string stripped_line = util::strip_whitespace(line);
if (stripped_line.empty() || stripped_line[0] == '#') {
return true;
}
}
*key = stripped_line.substr(0, equal_pos);
*value = stripped_line.substr(equal_pos + 1);
- *key = Util::strip_whitespace(*key);
- *value = Util::strip_whitespace(*value);
+ *key = util::strip_whitespace(*key);
+ *value = util::strip_whitespace(*value);
return true;
}
#include <core/wincompat.hpp>
#include <util/path_utils.hpp>
+#include <util/string_utils.hpp>
extern "C" {
#include "third_party/base32hex.h"
optional<int64_t> max_value,
string_view description)
{
- std::string stripped_value = strip_whitespace(value);
+ std::string stripped_value = util::strip_whitespace(value);
size_t end = 0;
long long result = 0;
string_view description,
int base)
{
- std::string stripped_value = strip_whitespace(value);
+ std::string stripped_value = util::strip_whitespace(value);
size_t end = 0;
unsigned long long result = 0;
return result;
}
-std::string
-strip_whitespace(string_view string)
-{
- auto is_space = [](int ch) { return std::isspace(ch); };
- auto start = std::find_if_not(string.begin(), string.end(), is_space);
- auto end = std::find_if_not(string.rbegin(), string.rend(), is_space).base();
- return start < end ? std::string(start, end) : std::string();
-}
-
std::string
to_lowercase(string_view string)
{
// Returns a copy of string with the specified ANSI CSI sequences removed.
[[nodiscard]] std::string strip_ansi_csi_seqs(nonstd::string_view string);
-// Strip whitespace from left and right side of a string.
-[[nodiscard]] std::string strip_whitespace(nonstd::string_view string);
-
// Convert a string to lowercase.
[[nodiscard]] std::string to_lowercase(nonstd::string_view string);
#include "Logging.hpp"
#include "Sloppiness.hpp"
#include "Stat.hpp"
+#include "Util.hpp"
#include "Win32Util.hpp"
#include "execute.hpp"
#include "fmtmacros.hpp"
#include "macroskip.hpp"
#include <core/wincompat.hpp>
+#include <util/string_utils.hpp>
#ifdef INODE_CACHE_SUPPORTED
# include "InodeCache.hpp"
const std::string& compiler)
{
#ifdef _WIN32
- std::string adjusted_command = Util::strip_whitespace(command);
+ std::string adjusted_command = util::strip_whitespace(command);
// Add "echo" command.
bool using_cmd_exe;
}
}
+std::string
+strip_whitespace(const nonstd::string_view string)
+{
+ const auto is_space = [](const int ch) { return std::isspace(ch); };
+ const auto start = std::find_if_not(string.begin(), string.end(), is_space);
+ const auto end =
+ std::find_if_not(string.rbegin(), string.rend(), is_space).base();
+ return start < end ? std::string(start, end) : std::string();
+}
+
} // namespace util
std::pair<nonstd::string_view, nonstd::optional<nonstd::string_view>>
split_once(nonstd::string_view string, char split_char);
+// Strip whitespace from left and right side of a string.
+[[nodiscard]] std::string strip_whitespace(nonstd::string_view string);
+
} // namespace util
CHECK_FALSE(Util::starts_with(std::string("x"), "xy"));
}
-TEST_CASE("Util::strip_whitespace")
-{
- CHECK(Util::strip_whitespace("") == "");
- CHECK(Util::strip_whitespace("x") == "x");
- CHECK(Util::strip_whitespace(" x") == "x");
- CHECK(Util::strip_whitespace("x ") == "x");
- CHECK(Util::strip_whitespace(" x ") == "x");
- CHECK(Util::strip_whitespace(" \n\tx \n\t") == "x");
- CHECK(Util::strip_whitespace(" x y ") == "x y");
-}
-
TEST_CASE("Util::to_lowercase")
{
CHECK(Util::to_lowercase("") == "");
return left.first == right.first && left.second == right.second;
}
+TEST_SUITE_BEGIN("util");
+
TEST_CASE("util::parse_umask")
{
CHECK(util::parse_umask("1") == 01u);
CHECK(split_once("a=b=c", '=') == make_pair("a", "b=c"));
CHECK(split_once("x y", ' ') == make_pair("x", "y"));
}
+
+TEST_CASE("util::strip_whitespace")
+{
+ CHECK(util::strip_whitespace("") == "");
+ CHECK(util::strip_whitespace("x") == "x");
+ CHECK(util::strip_whitespace(" x") == "x");
+ CHECK(util::strip_whitespace("x ") == "x");
+ CHECK(util::strip_whitespace(" x ") == "x");
+ CHECK(util::strip_whitespace(" \n\tx \n\t") == "x");
+ CHECK(util::strip_whitespace(" x y ") == "x y");
+}
+
+TEST_SUITE_END();