diff options
| author | Vincent Richard <[email protected]> | 2004-12-21 10:04:19 +0100 |
|---|---|---|
| committer | Vincent Richard <[email protected]> | 2004-12-21 10:04:19 +0100 |
| commit | 706c270073daeb2b303ab34b7c5c9862da62b1ae (patch) | |
| tree | cc081dd5ac849d27ea825b6ddc958c76818ab24a /src/utility | |
| parent | Added component::getChildComponents() function. (diff) | |
| download | vmime-706c270073daeb2b303ab34b7c5c9862da62b1ae.tar.gz vmime-706c270073daeb2b303ab34b7c5c9862da62b1ae.zip | |
Fixed ',2' in filename/flags + fixed file renaming when moving from 'new' to 'cur' + new functions random::getString() and maildirUtils::generateId().
Diffstat (limited to 'src/utility')
| -rw-r--r-- | src/utility/random.cpp | 20 | ||||
| -rw-r--r-- | src/utility/random.hpp | 12 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/utility/random.cpp b/src/utility/random.cpp index b2a935d8..cefaea3e 100644 --- a/src/utility/random.cpp +++ b/src/utility/random.cpp @@ -55,5 +55,25 @@ const unsigned int random::getProcess() } +const string random::getString(const int length, const string& randomChars) +{ + string res; + res.resize(length); + + const unsigned int x = randomChars.length(); + int c = 0; + + while (c < length) + { + for (unsigned int n = random::getNext() ; n != 0 ; n /= x) + { + res[c++] = randomChars[n % x]; + } + } + + return (res); +} + + } // utility } // vmime diff --git a/src/utility/random.hpp b/src/utility/random.hpp index 70ae6716..442905a5 100644 --- a/src/utility/random.hpp +++ b/src/utility/random.hpp @@ -21,6 +21,9 @@ #define VMIME_UTILITY_RANDOM_HPP_INCLUDED +#include "types.hpp" + + namespace vmime { namespace utility { @@ -52,6 +55,15 @@ public: */ static const unsigned int getProcess(); + /** Return a random character string with the specified length. + * + * @param length length of the string to generate + * @param randomChars list of characters to use + * @return random string + */ + static const string getString(const int length, const string& randomChars + = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + protected: static unsigned int m_next; |
