From 238f8fb592f4cfae8ac8f598a83649fbeaee1100 Mon Sep 17 00:00:00 2001 From: BO41 Date: Tue, 14 Aug 2018 23:31:44 +0200 Subject: [PATCH] refactor: Simplify if statements (#1381) --- src/components/config.cpp | 12 +----------- src/drawtypes/progressbar.cpp | 6 +----- src/ipc.cpp | 10 +--------- src/x11/cursor.cpp | 4 +--- 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/components/config.cpp b/src/components/config.cpp index ad31bbfc..2e29a5ad 100644 --- a/src/components/config.cpp +++ b/src/components/config.cpp @@ -238,17 +238,7 @@ template <> bool config::convert(string&& value) const { string lower{string_util::lower(forward(value))}; - if (lower == "true") { - return true; - } else if (lower == "yes") { - return true; - } else if (lower == "on") { - return true; - } else if (lower == "1") { - return true; - } else { - return false; - } + return (lower == "true" || lower == "yes" || lower == "on" || lower == "1"); } template <> diff --git a/src/drawtypes/progressbar.cpp b/src/drawtypes/progressbar.cpp index 6bb7a325..0c96ed00 100644 --- a/src/drawtypes/progressbar.cpp +++ b/src/drawtypes/progressbar.cpp @@ -34,11 +34,7 @@ namespace drawtypes { void progressbar::set_colors(vector&& colors) { m_colors = forward(colors); - if (m_colors.empty()) { - m_colorstep = 1; - } else { - m_colorstep = m_width / m_colors.size(); - } + m_colorstep = m_colors.empty() ? 1 : m_width / m_colors.size(); } string progressbar::output(float percentage) { diff --git a/src/ipc.cpp b/src/ipc.cpp index d084e32e..7252da40 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -38,15 +38,7 @@ void remove_pipe(const string& handle) { } bool validate_type(const string& type) { - if (type == "action") { - return true; - } else if (type == "cmd") { - return true; - } else if (type == "hook") { - return true; - } else { - return false; - } + return (type == "action" || type == "cmd" || type == "hook"); } int main(int argc, char** argv) { diff --git a/src/x11/cursor.cpp b/src/x11/cursor.cpp index 8ecdcb1d..253b1ea0 100644 --- a/src/x11/cursor.cpp +++ b/src/x11/cursor.cpp @@ -4,9 +4,7 @@ POLYBAR_NS namespace cursor_util { bool valid(string name) { - if (cursors.find(name) != cursors.end()) - return true; - return false; + return (cursors.find(name) != cursors.end()); } bool set_cursor(xcb_connection_t *c, xcb_screen_t *screen, xcb_window_t w, string name) {