diff options
Diffstat (limited to 'src/helperfuncs.cpp')
| -rw-r--r-- | src/helperfuncs.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 5ebb6e44d..5ccb8ed6c 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -443,13 +443,31 @@ std::string Time::ToString(time_t curtime, const char* format, bool utc) return buffer; } +std::string InspIRCd::GenRandomStr(size_t length) const +{ + static const char chars[] = { + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + }; + + std::string buf; + buf.reserve(length); + for (size_t idx = 0; idx < length; ++idx) + buf.push_back(chars[GenRandomInt(std::size(chars))]); + return buf; +} + std::string InspIRCd::GenRandomStr(size_t length, bool printable) const { + if (printable) + return GenRandomStr(length); + + // DEPRECATED std::vector<char> str(length); GenRandom(str.data(), length); - if (printable) - for (size_t i = 0; i < length; i++) - str[i] = 0x3F + (str[i] & 0x3F); return std::string(str.data(), str.size()); } |
