Move regex constants to swipe_gesture static class member
This commit is contained in:
parent
30e4a57b62
commit
3e96172a73
@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <iostream> // std::cout, std::endl
|
||||
#include "../index.hpp"
|
||||
#include "xdo_gesture.h"
|
||||
|
||||
extern "C"
|
||||
|
||||
@ -19,11 +19,6 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <xdo.h> // 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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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__ */
|
||||
@ -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<std::string, std::string> read_config_file(const char*);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
#include <cassert>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user