Browse Source

Added tokenCount() functions.

release/0.19
JustinAJ 10 years ago
parent
commit
a0ab6376f8
  1. 11
      Jupiter/Readable_String.h
  2. 44
      Jupiter/Readable_String_Imp.h
  3. BIN
      Release/Jupiter.lib

11
Jupiter/Readable_String.h

@ -178,6 +178,17 @@ namespace Jupiter
*/
unsigned int wordCount(const T *whitespace) const;
/**
* @brief Counts the number of occurances for a specific token.
*
* @param token Token to scan for.
* @return Number of occurances of the specified token in the string.
*/
size_t tokenCount(const T &token) const;
size_t tokenCount(const Readable_String<T> &token) const;
size_t tokenCount(const std::basic_string<T> &token) const;
size_t tokenCount(const T *token, size_t tokenLength) const;
/**
* @brief Interprets the string as a bool.
*

44
Jupiter/Readable_String_Imp.h

@ -789,6 +789,50 @@ template<typename T> unsigned int Jupiter::Readable_String<T>::wordCount(const T
return result;
}
// tokenCount()
template<typename T> size_t Jupiter::Readable_String<T>::tokenCount(const T &token) const
{
size_t total = 0;
for (size_t i = 0; i != this->size(); i++)
if (this->get(i) == token)
total++;
return total;
}
template<typename T> size_t Jupiter::Readable_String<T>::tokenCount(const Jupiter::Readable_String<T> &token) const
{
return this->tokenCount(token.ptr(), token.size());
}
template<typename T> size_t Jupiter::Readable_String<T>::tokenCount(const std::basic_string<T> &token) const
{
return this->tokenCount(token.data(), token.size());
}
template<typename T> size_t Jupiter::Readable_String<T>::tokenCount(const T *token, size_t tokenLength) const
{
if (tokenLength == 0 || tokenLength > this->size())
return 0;
if (tokenLength == this->size())
return this->equals(token, tokenLength) ? 1 : 0;
size_t total = 0;
for (size_t i = 0, j; i != this->size() - tokenLength + 1; i++)
{
j = 0;
while (this->get(i + j) == token[j])
{
if (++j == tokenLength)
{
total++;
break;
}
}
}
return total;
}
// as<type>
template<> bool inline Jupiter::Readable_String<char>::asBool() const

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save