diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-06-05 16:52:24 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-06-05 16:52:24 +0000 |
commit | adf372651c4c2b8db07e9a29ed7c9d5132737ee8 (patch) | |
tree | 4ceb8cf5632274771b5e274f79067e533dffbab8 | |
parent | 4381bb63f57d7a542827f2481e8198313e4ff24a (diff) |
Comments here, too
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7239 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/command_parse.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 598585315..68b8b0bda 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -62,6 +62,9 @@ std::string InspIRCd::TimeString(time_t curtime) return std::string(ctime(&curtime),24); } +/** Refactored by Brain, Jun 2007. Much faster with some clever O(1) array + * lookups and pointer maths. + */ long InspIRCd::Duration(const char* str) { char n_field[MAXBUF]; @@ -70,19 +73,25 @@ long InspIRCd::Duration(const char* str) char* field_ptr = n_field; *n_field = 0; + /* Iterate each item in the string, looking for number or multiplier */ for (const char* i = str; *i; i++) { + /* Found a number, queue it onto the current number */ if ((*i >= '0') && (*i <= '9') && (field_ptr < maxsize)) *field_ptr++ = *i; else { + /* Found something thats not a number, find out how much + * it multiplies the built up number by, multiply the total + * and reset the built up number. + */ *field_ptr = 0; field_ptr = n_field; total += atoi(n_field) * duration_multi[(const unsigned char)*i]; *n_field = 0; } } - // add trailing seconds + /* Any trailing values built up are treated as raw seconds */ if (*n_field) { *field_ptr = 0; |