mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 13:35:12 +00:00
IRCClient: Add is_channel_prefix to check if string is a channel name
This commit is contained in:
parent
57f72f2982
commit
6bf47252dc
Notes:
sideshowbarker
2024-07-19 07:59:26 +09:00
Author: https://github.com/bcoles Commit: https://github.com/SerenityOS/serenity/commit/6bf47252dcb Pull-request: https://github.com/SerenityOS/serenity/pull/1580 Reviewed-by: https://github.com/awesomekling
2 changed files with 21 additions and 6 deletions
|
@ -388,7 +388,7 @@ void IRCClient::handle_user_input_in_server(const String& input)
|
|||
return handle_user_command(input);
|
||||
}
|
||||
|
||||
bool IRCClient::is_nick_prefix(char ch) const
|
||||
bool IRCClient::is_nick_prefix(char ch)
|
||||
{
|
||||
switch (ch) {
|
||||
case '@':
|
||||
|
@ -401,6 +401,18 @@ bool IRCClient::is_nick_prefix(char ch) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool IRCClient::is_channel_prefix(char ch)
|
||||
{
|
||||
switch (ch) {
|
||||
case '&':
|
||||
case '#':
|
||||
case '+':
|
||||
case '!':
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool has_ctcp_payload(const StringView& string)
|
||||
{
|
||||
return string.length() >= 2 && string[0] == 0x01 && string[string.length() - 1] == 0x01;
|
||||
|
@ -742,9 +754,10 @@ void IRCClient::handle_user_command(const String& input)
|
|||
if (command == "/TOPIC") {
|
||||
if (parts.size() < 2)
|
||||
return;
|
||||
if (parts[1].is_empty())
|
||||
return;
|
||||
|
||||
// FIXME: channel name validation should be abstracted away into a validation function
|
||||
if (parts[1].starts_with("&") || parts[1].starts_with("#") || parts[1].starts_with("+") || parts[1].starts_with("!")) {
|
||||
if (is_channel_prefix(parts[1][0])) {
|
||||
if (parts.size() < 3)
|
||||
return;
|
||||
auto channel = parts[1];
|
||||
|
@ -763,9 +776,10 @@ void IRCClient::handle_user_command(const String& input)
|
|||
if (command == "/KICK") {
|
||||
if (parts.size() < 2)
|
||||
return;
|
||||
if (parts[1].is_empty())
|
||||
return;
|
||||
|
||||
// FIXME: channel name validation should be abstracted away into a validation function
|
||||
if (parts[1].starts_with("&") || parts[1].starts_with("#") || parts[1].starts_with("+") || parts[1].starts_with("!")) {
|
||||
if (is_channel_prefix(parts[1][0])) {
|
||||
if (parts.size() < 3)
|
||||
return;
|
||||
auto channel = parts[1];
|
||||
|
|
|
@ -60,7 +60,8 @@ public:
|
|||
void part_channel(const String&);
|
||||
void change_nick(const String&);
|
||||
|
||||
bool is_nick_prefix(char) const;
|
||||
static bool is_nick_prefix(char);
|
||||
static bool is_channel_prefix(char);
|
||||
|
||||
IRCWindow* current_window() { return aid_get_active_window(); }
|
||||
const IRCWindow* current_window() const { return aid_get_active_window(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue