#include <algorithm>
#include <memory>
-
-#include <pcrecpp.h>
+#include <regex>
#ifdef APP_CONTROL_SETTINGS_SUPPORT
#include <appfw/app_control.h>
static bool IsValidAddress(const std::string& address) {
ScopeLogger();
- static pcrecpp::RE re("(([0-9a-zA-Z]+):)+([0-9a-zA-Z]+)");
- static std::string compare_address = "00:12:47:08:9A:A6";
+ const std::regex macAdressRegex {"([[:xdigit:]]{2}[:]){5}([[:xdigit:]]{2})"};
- if (!re.FullMatch(address)) {
- LoggerE("Invalid address");
- return false;
- }
- if (address.size() != compare_address.size()) {
- LoggerE("Invalid size");
- return false;
+ if (std::regex_match(address, macAdressRegex)) {
+ return true;
}
- return true;
+ LoggerE("Invalid MAC address: %s", address.c_str());
+ return false;
}
static bool IsValidUUID(const std::string& uuid) {
ScopeLogger();
- static pcrecpp::RE re("(([0-9a-zA-Z]+)-)+([0-9a-zA-Z]+)");
- static std::string compare_uuid = "00001101-0000-1000-8000-00805F9B34FB";
+ const std::regex uuidRegex {"[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}"};
- if (!re.FullMatch(uuid)) {
- LoggerE("Invalid UUID: %s", uuid.c_str());
- return false;
+ if (std::regex_match(uuid, uuidRegex)) {
+ return true;
}
-
- if (uuid.size() != compare_uuid.size()) {
- LoggerE("Invalid size: %s", uuid.c_str());
- return false;
- }
-
- return true;
+ LoggerE("Invalid UUID: %s", uuid.c_str());
+ return false;
}
void BluetoothAdapter::StateChangedCB(int result, bt_adapter_state_e state, void* user_data) {