ft_irc 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Replies.cpp
[詳解]
1
8#include "Replies.hpp"
9#include <cstdarg>
10#include <cstdio>
11#include <cstring>
12
13// Simple version for replies without extra parameters
14std::string formatReply(const std::string &serverName, const std::string &clientNickname,
15 const std::string &replyCodeAndText) {
16 size_t firstSpace = replyCodeAndText.find(' ');
17 std::string code = replyCodeAndText.substr(0, firstSpace);
18 std::string text = replyCodeAndText.substr(firstSpace + 1);
19 return ":" + serverName + " " + code + " " + clientNickname + " " + text;
20}
21
22// Version for replies with variable arguments, formatted like printf
23std::string formatReply(const std::string &serverName, const std::string &clientNickname,
24 const std::string &replyCodeAndFormat, const std::vector<std::string> &args) {
25 // Extract code and format string
26 size_t firstSpace = replyCodeAndFormat.find(' ');
27 std::string code = replyCodeAndFormat.substr(0, firstSpace);
28 std::string format = replyCodeAndFormat.substr(firstSpace + 1);
29
30 // Manually replace placeholders
31 std::string result = format;
32 for (size_t i = 0; i < args.size(); ++i) {
33 size_t pos = result.find("%s");
34 if (pos != std::string::npos) {
35 result.replace(pos, 2, args[i]);
36 }
37 }
38
39 return ":" + serverName + " " + code + " " + clientNickname + " " + result;
40}
std::string formatReply(const std::string &serverName, const std::string &clientNickname, const std::string &replyCodeAndText)
Formats an IRC reply message without extra parameters.
Definition Replies.cpp:14
Defines IRC numeric replies and error messages.
T find(T... args)
T replace(T... args)
T size(T... args)
T substr(T... args)