From b5c701994bf8fa3923ef2a483c84bdacaba6c35a Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Thu, 7 Feb 2019 22:01:03 +0800 Subject: [PATCH] Move regex constants to swipe_gesture static class member (#44) * Move regex constants to swipe_gesture static class member * Unlink util/regex from library index --- src/lib/comfortable_swipe | 2 +- src/lib/gesture/pinch_gesture.cpp | 0 src/lib/gesture/pinch_gesture.h | 0 src/lib/gesture/swipe_gesture.cpp | 1 - src/lib/gesture/swipe_gesture.h | 9 ++++----- .../regex.cpp => gesture/swipe_gesture.regex.cpp} | 14 +++++++------- src/lib/index.hpp | 3 --- src/lib/service/buffer.cpp | 6 +++--- tests/test_regex.cpp | 9 +++++---- 9 files changed, 20 insertions(+), 24 deletions(-) delete mode 100644 src/lib/gesture/pinch_gesture.cpp delete mode 100644 src/lib/gesture/pinch_gesture.h rename src/lib/{util/regex.cpp => gesture/swipe_gesture.regex.cpp} (89%) diff --git a/src/lib/comfortable_swipe b/src/lib/comfortable_swipe index ae8de7d..eaa0a08 100644 --- a/src/lib/comfortable_swipe +++ b/src/lib/comfortable_swipe @@ -27,6 +27,7 @@ along with this program. If not, see . #include "gesture/xdo_gesture.cpp" #include "gesture/swipe_gesture.cpp" +#include "gesture/swipe_gesture.regex.cpp" #include "service/autostart.cpp" #include "service/buffer.cpp" #include "service/help.cpp" @@ -36,6 +37,5 @@ along with this program. If not, see . #include "util/autostart_filename.cpp" #include "util/conf_filename.cpp" #include "util/read_config_file.cpp" -#include "util/regex.cpp" #endif /* __COMFORTABLE_SWIPE__ */ diff --git a/src/lib/gesture/pinch_gesture.cpp b/src/lib/gesture/pinch_gesture.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/gesture/pinch_gesture.h b/src/lib/gesture/pinch_gesture.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/gesture/swipe_gesture.cpp b/src/lib/gesture/swipe_gesture.cpp index d2e57fd..53ab535 100644 --- a/src/lib/gesture/swipe_gesture.cpp +++ b/src/lib/gesture/swipe_gesture.cpp @@ -20,7 +20,6 @@ along with this program. If not, see . */ #include // std::cout, std::endl -#include "../index.hpp" #include "xdo_gesture.h" extern "C" diff --git a/src/lib/gesture/swipe_gesture.h b/src/lib/gesture/swipe_gesture.h index 2c3a360..4061aec 100644 --- a/src/lib/gesture/swipe_gesture.h +++ b/src/lib/gesture/swipe_gesture.h @@ -19,11 +19,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -extern "C" -{ - #include // xdo_t -} - #include "xdo_gesture.h" #ifdef __cplusplus @@ -77,6 +72,10 @@ namespace comfortable_swipe::gesture static const int MSK_VERTICAL; static const int FRESH; static const char * const command_map[8]; + // regex patterns + static const char* GESTURE_BEGIN_REGEX_PATTERN; + static const char* GESTURE_UPDATE_REGEX_PATTERN; + static const char* GESTURE_END_REGEX_PATTERN; }; } diff --git a/src/lib/util/regex.cpp b/src/lib/gesture/swipe_gesture.regex.cpp similarity index 89% rename from src/lib/util/regex.cpp rename to src/lib/gesture/swipe_gesture.regex.cpp index b0556ce..a39fbeb 100644 --- a/src/lib/util/regex.cpp +++ b/src/lib/gesture/swipe_gesture.regex.cpp @@ -1,5 +1,5 @@ -#ifndef __COMFORTABLE_SWIPE__util_regex__ -#define __COMFORTABLE_SWIPE__util_regex__ +#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__ +#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__ /* Comfortable Swipe @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -namespace comfortable_swipe::util +namespace comfortable_swipe::gesture { /** * Regex pattern for the libinput entry for start of swipe. @@ -29,7 +29,7 @@ namespace comfortable_swipe::util * ^ * fingers */ - const char* GESTURE_SWIPE_BEGIN_REGEX_PATTERN = + const char* swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN = "^" // start of string "[ -]event\\d+" // event "\\s+GESTURE_SWIPE_BEGIN" // gesture @@ -46,7 +46,7 @@ namespace comfortable_swipe::util * ^ * fingers */ - const char* GESTURE_SWIPE_END_REGEX_PATTERN = + const char* swipe_gesture::GESTURE_END_REGEX_PATTERN = "^" // start of string "[ -]event\\d+" // event "\\s+GESTURE_SWIPE_END" // gesture @@ -69,7 +69,7 @@ namespace comfortable_swipe::util * ^ ^ ^ ^ ^ * fingers dx dy udx udy */ - const char* GESTURE_SWIPE_UPDATE_REGEX_PATTERN = + const char* swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN = "^" // start of string "[ -]event\\d+" // event "\\s+GESTURE_SWIPE_UPDATE" // gesture @@ -86,4 +86,4 @@ namespace comfortable_swipe::util #undef CF_NUMBER_REGEX } -#endif /* __COMFORTABLE_SWIPE__util_regex__ */ +#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__ */ diff --git a/src/lib/index.hpp b/src/lib/index.hpp index feda26f..b0c7e2e 100644 --- a/src/lib/index.hpp +++ b/src/lib/index.hpp @@ -42,9 +42,6 @@ extern "C" { namespace util { - extern const char* GESTURE_SWIPE_BEGIN_REGEX_PATTERN; - extern const char* GESTURE_SWIPE_UPDATE_REGEX_PATTERN; - extern const char* GESTURE_SWIPE_END_REGEX_PATTERN; const char* autostart_filename(); constexpr const char* conf_filename(); std::map read_config_file(const char*); diff --git a/src/lib/service/buffer.cpp b/src/lib/service/buffer.cpp index 4d71f16..f3c9517 100644 --- a/src/lib/service/buffer.cpp +++ b/src/lib/service/buffer.cpp @@ -35,9 +35,9 @@ namespace comfortable_swipe::service auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename()); // pre-compile regex patterns - static const std::regex gesture_swipe_begin(comfortable_swipe::util::GESTURE_SWIPE_BEGIN_REGEX_PATTERN); - static const std::regex gesture_swipe_update(comfortable_swipe::util::GESTURE_SWIPE_UPDATE_REGEX_PATTERN); - static const std::regex gesture_swipe_end(comfortable_swipe::util::GESTURE_SWIPE_END_REGEX_PATTERN); + static const std::regex gesture_swipe_begin(comfortable_swipe::gesture::swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN); + static const std::regex gesture_swipe_update(comfortable_swipe::gesture::swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN); + static const std::regex gesture_swipe_end(comfortable_swipe::gesture::swipe_gesture::GESTURE_END_REGEX_PATTERN); // initialize swipe gesture handler comfortable_swipe::gesture::swipe_gesture swipe diff --git a/tests/test_regex.cpp b/tests/test_regex.cpp index a4dc2a5..a54fd2f 100644 --- a/tests/test_regex.cpp +++ b/tests/test_regex.cpp @@ -2,7 +2,8 @@ #include #include #include -#include "../src/lib/util/regex.cpp" +#include "../src/lib/gesture/swipe_gesture.h" +#include "../src/lib/gesture/swipe_gesture.regex.cpp" /* Comfortable Swipe @@ -59,7 +60,7 @@ namespace test void gesture_begin_should_match_regex() { - std::regex matcher(comfortable_swipe::util::GESTURE_SWIPE_BEGIN_REGEX_PATTERN); + std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN); test::gesture_begin_test(matcher, " event15 GESTURE_SWIPE_BEGIN +34.33s 3\n", "3"); test::gesture_begin_test(matcher, "-event4 GESTURE_SWIPE_BEGIN +3.12s 4\n", "4"); test::gesture_begin_test(matcher, "-event7 GESTURE_SWIPE_BEGIN +4.72s 3\n", "3"); @@ -69,7 +70,7 @@ namespace test void gesture_update_should_match_regex() { const char* data = " event15 GESTURE_SWIPE_UPDATE +34.70s 3 -0.12/ 4.99 (-0.33/13.50 unaccelerated)\n"; - std::regex matcher(comfortable_swipe::util::GESTURE_SWIPE_UPDATE_REGEX_PATTERN); + std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN); std::cmatch matches; auto result = std::regex_match(data, matches, matcher); assert(result != 0); @@ -83,7 +84,7 @@ namespace test void gesture_end_should_match_regex() { const char* data = " event15 GESTURE_SWIPE_END +35.03s 3\n"; - std::regex matcher(comfortable_swipe::util::GESTURE_SWIPE_END_REGEX_PATTERN); + std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_END_REGEX_PATTERN); std::cmatch matches; auto result = std::regex_match(data, matches, matcher); assert(result != 0);