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
14
std::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
23
std::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
}
formatReply
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
Replies.hpp
Defines IRC numeric replies and error messages.
std::string
cstdarg
cstdio
cstring
std::string::find
T find(T... args)
std::string::replace
T replace(T... args)
std::vector::size
T size(T... args)
std::string::substr
T substr(T... args)
std::vector
src
Replies.cpp
構築:
1.9.8