mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-28 04:12:30 -06:00
ad712926d6
- Added IPv6 & Namespace support in direct connection Regex - Updated Tooltip for Direct Connect UI - Removed Dropdown Connection Type in Direct Connect
67 lines
2.8 KiB
C++
67 lines
2.8 KiB
C++
// SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <QRegularExpression>
|
|
#include <QString>
|
|
#include <QValidator>
|
|
|
|
class Validation {
|
|
public:
|
|
Validation()
|
|
: room_name(room_name_regex), nickname(nickname_regex), ip(ip_regex), port(0, UINT16_MAX) {}
|
|
|
|
~Validation() = default;
|
|
|
|
const QValidator* GetRoomName() const {
|
|
return &room_name;
|
|
}
|
|
const QValidator* GetNickname() const {
|
|
return &nickname;
|
|
}
|
|
const QValidator* GetIP() const {
|
|
return &ip;
|
|
}
|
|
const QValidator* GetPort() const {
|
|
return &port;
|
|
}
|
|
|
|
private:
|
|
/// room name can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
|
|
QRegularExpression room_name_regex =
|
|
QRegularExpression(QStringLiteral("^[a-zA-Z0-9._ -]{4,20}"));
|
|
QRegularExpressionValidator room_name;
|
|
|
|
/// nickname can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
|
|
const QRegularExpression nickname_regex =
|
|
QRegularExpression(QStringLiteral("^[a-zA-Z0-9._ -]{4,20}"));
|
|
QRegularExpressionValidator nickname;
|
|
|
|
/// ipv4 / ipv6 / hostnames
|
|
QRegularExpression ip_regex = QRegularExpression(QStringLiteral(
|
|
// IPv4 regex
|
|
"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|"
|
|
// IPv6 regex
|
|
"^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|"
|
|
"(([0-9A-Fa-f]{1,4}:){6}(:[0-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|
"\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?$|"
|
|
// Hostname regex
|
|
"^([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\\.)+[a-zA-Z]{2,}$"));
|
|
QRegularExpressionValidator ip;
|
|
|
|
/// port must be between 0 and 65535
|
|
QIntValidator port;
|
|
};
|