mu-utils: cleanups
Fix some types Improve error handling Remove dead/unused code
This commit is contained in:
@ -78,11 +78,6 @@ void mu_log(GLogLevelFlags level, fmt::format_string<T...> frm, T&&... args) noe
|
||||
g_log("mu", level, "%s", mu_format(frm, std::forward<T>(args)...).c_str());
|
||||
}
|
||||
|
||||
template<typename...T>
|
||||
void mu_none(fmt::format_string<T...>, T&&...) noexcept {
|
||||
// ignore
|
||||
}
|
||||
|
||||
template<typename...T>
|
||||
void mu_debug(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
mu_log(G_LOG_LEVEL_DEBUG, frm, std::forward<T>(args)...);
|
||||
@ -132,17 +127,6 @@ void mu_printerrln(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
fmt::println(stderr, frm, std::forward<T>(args)...);
|
||||
}
|
||||
|
||||
// null-stream
|
||||
class NullStream : public std::ostream {
|
||||
public:
|
||||
NullStream() : std::ostream(&buf_) {}
|
||||
private:
|
||||
struct NullBuffer : public std::streambuf {
|
||||
int overflow(int c) override { return c; }
|
||||
};
|
||||
NullBuffer buf_;
|
||||
};
|
||||
|
||||
/* stream print */
|
||||
template<typename...T>
|
||||
void mu_print(std::ostream& os, fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
@ -518,11 +502,6 @@ to_unit(Duration d)
|
||||
return duration_cast<Unit>(d).count();
|
||||
}
|
||||
|
||||
constexpr int64_t
|
||||
to_s(Duration d)
|
||||
{
|
||||
return to_unit<std::chrono::seconds>(d);
|
||||
}
|
||||
constexpr int64_t
|
||||
to_ms(Duration d)
|
||||
{
|
||||
@ -563,16 +542,6 @@ private:
|
||||
*/
|
||||
Option<int64_t> parse_size(const std::string& sizestr, bool first);
|
||||
|
||||
/**
|
||||
* Convert a size into a size in bytes string
|
||||
*
|
||||
* @param size the size
|
||||
* @param first
|
||||
*
|
||||
* @return the size expressed as a string with the decimal number of bytes
|
||||
*/
|
||||
std::string size_to_string(int64_t size);
|
||||
|
||||
/**
|
||||
* get a crude 'summary' of the string, ie. the first /n/ lines of the strings,
|
||||
* with all newlines removed, replaced by single spaces
|
||||
@ -649,21 +618,6 @@ to_string_gchar(gchar*&& str)
|
||||
g_free(str);
|
||||
return s;
|
||||
}
|
||||
/**
|
||||
* Consume a char* and return a std::string
|
||||
*
|
||||
* @param str a gchar* (consumed/freed with ::free())
|
||||
*
|
||||
* @return a std::string, empty if gchar was {}
|
||||
*/
|
||||
inline std::string
|
||||
to_string_char(char*&& str)
|
||||
{
|
||||
std::string s(str?str:"");
|
||||
::free(str);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shell-quote the given string (as per g_shell_quote())
|
||||
*
|
||||
@ -728,21 +682,6 @@ bool seq_some(const Sequence& seq, UnaryPredicate pred) {
|
||||
return seq_find_if(seq, pred) != seq.cend();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sequence that has all element of seq for which pred is true
|
||||
*
|
||||
* @param seq sequence
|
||||
* @param pred false
|
||||
*
|
||||
* @return sequence
|
||||
*/
|
||||
template<typename Sequence, typename UnaryPredicate>
|
||||
Sequence seq_filter(const Sequence& seq, UnaryPredicate pred) {
|
||||
Sequence res;
|
||||
std::copy_if(seq.begin(), seq.end(), std::back_inserter(res), pred);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sequence that has all element of seq for which pred is false
|
||||
*
|
||||
@ -762,20 +701,6 @@ template<typename Sequence, typename Compare>
|
||||
void seq_sort(Sequence& seq, Compare cmp) { std::sort(seq.begin(), seq.end(), cmp); }
|
||||
|
||||
|
||||
/**
|
||||
* Like std::accumulate, but using a sequence instead of a range.
|
||||
*
|
||||
* @param seq some std::accumulate compatible sequence
|
||||
* @param init the initial value
|
||||
* @param op binary operation to calculate the next element
|
||||
*
|
||||
* @return the result value.
|
||||
*/
|
||||
template<typename Sequence, typename ResultType, typename BinaryOp>
|
||||
ResultType seq_fold(const Sequence& seq, ResultType init, BinaryOp op) {
|
||||
return std::accumulate(seq.cbegin(), seq.cend(), init, op);
|
||||
}
|
||||
|
||||
template<typename Sequence, typename UnaryOp>
|
||||
void seq_for_each(const Sequence& seq, UnaryOp op) {
|
||||
std::for_each(seq.cbegin(), seq.cend(), op);
|
||||
|
||||
Reference in New Issue
Block a user