From adf372651c4c2b8db07e9a29ed7c9d5132737ee8 Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 5 Jun 2007 16:52:24 +0000 Subject: Comments here, too git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7239 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/command_parse.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3