diff --git a/Jupiter/Readable_String.h b/Jupiter/Readable_String.h index bf90aad..c307e16 100644 --- a/Jupiter/Readable_String.h +++ b/Jupiter/Readable_String.h @@ -179,10 +179,10 @@ namespace Jupiter unsigned int wordCount(const T *whitespace) const; /** - * @brief Counts the number of occurances for a specific token. + * @brief Counts the number of token-deliminated strings in the string. * * @param token Token to scan for. - * @return Number of occurances of the specified token in the string. + * @return Number of token-deliminated strings in the string. */ size_t tokenCount(const T &token) const; size_t tokenCount(const Readable_String &token) const; diff --git a/Jupiter/Readable_String_Imp.h b/Jupiter/Readable_String_Imp.h index 0425cde..607d693 100644 --- a/Jupiter/Readable_String_Imp.h +++ b/Jupiter/Readable_String_Imp.h @@ -793,7 +793,10 @@ template unsigned int Jupiter::Readable_String::wordCount(const T template size_t Jupiter::Readable_String::tokenCount(const T &token) const { - size_t total = 0; + if (this->size() == 0) + return 0; + + size_t total = 1; for (size_t i = 0; i != this->size(); i++) if (this->get(i) == token) total++; @@ -812,23 +815,28 @@ template size_t Jupiter::Readable_String::tokenCount(const std::b template size_t Jupiter::Readable_String::tokenCount(const T *token, size_t tokenLength) const { - if (tokenLength == 0 || tokenLength > this->size()) - return 0; if (tokenLength == 1) return this->tokenCount(*token); + if (tokenLength == 0 || tokenLength > this->size()) + return 0; if (tokenLength == this->size()) return this->equals(token, tokenLength) ? 1 : 0; - size_t total = 0; + size_t total = 1; for (size_t i = 0, j; i != this->size() - tokenLength + 1; i++) { + Jupiter_Readable_String_tokenCount_skip_increment: j = 0; while (this->get(i + j) == token[j]) { if (++j == tokenLength) { + i += j; total++; - break; + if (i >= this->size() - tokenLength + 1) + return total; + + goto Jupiter_Readable_String_tokenCount_skip_increment; } } } diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index 78907da..968fb7d 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ