summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-07-27 19:37:48 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-07-27 19:39:23 +0300
commit8d3b65c5d83c0499ac5c18513323fbd204b2d2c1 (patch)
tree98bde0bdd447a5460930c7ab37d270960c840450
parent28ea23a2a3494b7f1081deaaa307389e817868c9 (diff)
utils: refactor count_nl from mu-cmd-find
And update users. Please enter the commit message for your changes. Lines starting
-rw-r--r--lib/utils/mu-test-utils.hh18
-rw-r--r--mu/mu-cmd-find.cc8
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/utils/mu-test-utils.hh b/lib/utils/mu-test-utils.hh
index f6f5e78..0774f79 100644
--- a/lib/utils/mu-test-utils.hh
+++ b/lib/utils/mu-test-utils.hh
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 2008-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+** Copyright (C) 2008-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@@ -22,6 +22,7 @@
#include <initializer_list>
#include <string>
+#include <algorithm>
#include <utils/mu-utils.hh>
#include <utils/mu-result.hh>
@@ -77,6 +78,21 @@ const char* set_tz(const char* tz);
bool set_en_us_utf8_locale();
+
+/**
+ * Count new lines in string.
+ *
+ * @param s string
+ *
+ * @return number of newlines
+ */
+static inline size_t count_nl(const std::string& s) {
+ return std::count(s.begin(), s.end(), '\n');
+}
+
+
+
+
/**
* For unit tests, assert two std::string's are equal.
*
diff --git a/mu/mu-cmd-find.cc b/mu/mu-cmd-find.cc
index 3556b45..d4c7e17 100644
--- a/mu/mu-cmd-find.cc
+++ b/mu/mu-cmd-find.cc
@@ -533,14 +533,6 @@ Mu::mu_cmd_find(const Store& store, const Options& opts)
static std::string test_mu_home;
-auto count_nl(const std::string& s)->size_t {
- size_t n{};
- for (auto&& c: s)
- if (c == '\n')
- ++n;
- return n;
-}
-
static size_t
search_func(const std::string& expr, size_t expected)
{