From e01df6385ef2ad1c0a78ccdd08af9af3ce688264 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 20 May 2013 20:15:50 +0100 Subject: Convert User::SendText to use std::string. --- src/users.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/users.cpp b/src/users.cpp index e0d420311..468c2aa36 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1159,28 +1159,21 @@ void User::SendText(const char *text, ...) SendText(line); } -void User::SendText(const std::string &LinePrefix, std::stringstream &TextStream) -{ - char line[MAXBUF]; - int start_pos = LinePrefix.length(); - int pos = start_pos; - memcpy(line, LinePrefix.data(), pos); - std::string Word; - while (TextStream >> Word) +void User::SendText(const std::string& linePrefix, std::stringstream& textStream) +{ + std::string line; + std::string word; + while (textStream >> word) { - int len = Word.length(); - if (pos + len + 12 > MAXBUF) + size_t lineLength = linePrefix.length() + line.length() + word.length() + 3; // "\s\n\r" + if (lineLength > ServerInstance->Config->Limits.MaxLine) { - line[pos] = '\0'; - SendText(std::string(line)); - pos = start_pos; + SendText(linePrefix + line); + line.clear(); } - line[pos] = ' '; - memcpy(line + pos + 1, Word.data(), len); - pos += len + 1; + line += " " + word; } - line[pos] = '\0'; - SendText(std::string(line)); + SendText(linePrefix + line); } /* return 0 or 1 depending if users u and u2 share one or more common channels -- cgit v1.2.3