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
This commit is contained in:
Rico Tiongson 2019-02-07 22:01:03 +08:00 committed by GitHub
parent 30e4a57b62
commit b5c701994b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 24 deletions

View File

@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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 <http://www.gnu.org/licenses/>.
#include "util/autostart_filename.cpp"
#include "util/conf_filename.cpp"
#include "util/read_config_file.cpp"
#include "util/regex.cpp"
#endif /* __COMFORTABLE_SWIPE__ */

View File

@ -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"

View File

@ -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;
};
}

View File

@ -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__ */

View File

@ -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*);

View File

@ -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

View File

@ -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);