Public Access
lib/irc: IrcMessage parse/serialize, base64, ReconnectPolicy (5 s .. 5 min), IrcConfig (validated, persisted) and IrcSession: registration with SASL PLAIN or NickServ, nick fallback, PING, Buffers capped at 50 lines with unread counts, Mentions, CTCP ACTION/VERSION, topics, /names on request only, others' join/part/quit hidden, user commands, and rejoining after a pause. No networking: the session returns lines to send, Log entries and Notifications. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
32 lines
962 B
C++
32 lines
962 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
|
|
namespace roro {
|
|
|
|
inline std::string base64Encode(const std::string& in) {
|
|
static const char* kAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
std::string out;
|
|
size_t i = 0;
|
|
while (i + 2 < in.size()) {
|
|
uint32_t n = (static_cast<uint8_t>(in[i]) << 16) | (static_cast<uint8_t>(in[i + 1]) << 8) | static_cast<uint8_t>(in[i + 2]);
|
|
out += kAlphabet[n >> 18];
|
|
out += kAlphabet[(n >> 12) & 63];
|
|
out += kAlphabet[(n >> 6) & 63];
|
|
out += kAlphabet[n & 63];
|
|
i += 3;
|
|
}
|
|
size_t rest = in.size() - i;
|
|
if (rest) {
|
|
uint32_t n = static_cast<uint8_t>(in[i]) << 16;
|
|
if (rest == 2) n |= static_cast<uint8_t>(in[i + 1]) << 8;
|
|
out += kAlphabet[n >> 18];
|
|
out += kAlphabet[(n >> 12) & 63];
|
|
out += rest == 2 ? kAlphabet[(n >> 6) & 63] : '=';
|
|
out += '=';
|
|
}
|
|
return out;
|
|
}
|
|
|
|
} // namespace roro
|