diff options
| author | 2024-08-29 14:35:21 +0100 | |
|---|---|---|
| committer | 2024-08-29 14:35:21 +0100 | |
| commit | 63e1cae6631efaaee0b1c27234081307d1eafc0d (patch) | |
| tree | ac74c8b4d789cfa7009a1b59fde1db646e7fdc62 /src/helperfuncs.cpp | |
| parent | Fix the case of some InspIRCd class member variables. (diff) | |
| parent | Use auto in GetLevelRequired and GetSyntax. (diff) | |
Merge branch 'insp4' into master.
Diffstat (limited to 'src/helperfuncs.cpp')
| -rw-r--r-- | src/helperfuncs.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index bd8f4a231..f0a94d7aa 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -119,7 +119,7 @@ void InspIRCd::StripColor(std::string& sentence) } } -void InspIRCd::ProcessColors(std::vector<std::string>& input) +void InspIRCd::ProcessColors(std::string& ret) { /* * Replace all color codes from the special[] array to actual @@ -148,7 +148,6 @@ void InspIRCd::ProcessColors(std::vector<std::string>& input) special_chars("", "") }; - for (auto& ret : input) { for(int i = 0; !special[i].character.empty(); ++i) { @@ -438,14 +437,21 @@ std::string Time::ToString(time_t curtime, const char* format, bool utc) return buffer; } -std::string InspIRCd::GenRandomStr(size_t length, bool printable) const +std::string InspIRCd::GenRandomStr(size_t length) const { - 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()); + 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; } // NOTE: this has a slight bias for lower values if max is not a power of 2. |
