Browse Source

Remove getToken, gotoToken, tokenCount

task/remove_strings
Jessica James 3 years ago
parent
commit
5715a041d2
  1. 37
      src/include/Jupiter/Readable_String.h
  2. 144
      src/include/Jupiter/Readable_String_Imp.h
  3. 42
      src/include/Jupiter/Reference_String.h
  4. 32
      src/include/Jupiter/Reference_String_Imp.h
  5. 84
      src/include/Jupiter/String.hpp
  6. 80
      src/include/Jupiter/String_Imp.h

37
src/include/Jupiter/Readable_String.h

@ -192,17 +192,6 @@ namespace Jupiter
*/
unsigned int wordCount(const T *whitespace) const;
/**
* @brief Counts the number of token-deliminated strings in the string.
*
* @param token Token to scan for.
* @return Number of token-deliminated strings 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.
*
@ -262,19 +251,6 @@ namespace Jupiter
template<template<typename> class R> static R<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
template<template<typename> class R> static R<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Copies a the elements between two tokens from an input string and returns it in an output type.
*
* @param R Type to return. Must be a subclass of String_Type.
*
* @param in String to get a partial copy of.
* @param pos Index of the token to copy.
* @param token Token to scan for.
* @return Copy of the token at the specified index on success, an empty string otherwise.
*/
template<template<typename> class R> static R<T> getToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token);
template<template<typename> class R> static R<T> getToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token);
/**
* @brief Copies a part of an input string starting at a specified "word" and returns it in an output type.
*
@ -288,19 +264,6 @@ namespace Jupiter
template<template<typename> class R> static R<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
template<template<typename> class R> static R<T> gotoWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Copies a part of an input string starting at a specified token and returns it in an output type.
*
* @param R Type to return. Must be a subclass of String_Type.
*
* @param in String to get a partial copy of.
* @param pos Index of the word to start copying from.
* @param token Token to scan for.
* @return Copy of the string starting at the specified word on success, an empty string otherwise.
*/
template<template<typename> class R> static R<T> gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token);
template<template<typename> class R> static R<T> gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token);
/**
* @brief Destructor for the Readable_String class.
*/

144
src/include/Jupiter/Readable_String_Imp.h

@ -888,60 +888,6 @@ 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
{
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++;
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 == 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 = 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++;
if (i >= this->size() - tokenLength + 1)
return total;
goto Jupiter_Readable_String_tokenCount_skip_increment;
}
}
}
return total;
}
// as<type>
template<> bool inline Jupiter::Readable_String<char>::asBool() const
@ -1131,59 +1077,6 @@ template<typename T> template<template<typename> class R> R<T> Jupiter::Readable
return R<T>::substring(in, 0, pos);
}
// getToken
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::getToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token)
{
size_t x, y;
for (x = 0; x != in.size() && pos != 0; x++)
if (in.get(x) == token)
pos--;
for (y = x; y != in.size() && in.get(y) != token; y++);
return R<T>::substring(in, x, y - x);
}
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::getToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token)
{
if (token.isEmpty())
return R<T>(in);
if (token.size() == 1)
return Jupiter::Readable_String<T>::getToken<R>(in, pos, token.get(0));
if (pos == 0)
return R<T>::substring(in, 0, in.find(token));
size_t i, j;
for (i = 0; i != in.size(); i++)
{
Jupiter_Readable_String_getToken_skip_increment:
j = 0;
while (in.get(i + j) == token.get(j))
{
if (++j == token.size())
{
i += j;
if (--pos == 0)
{
size_t k;
for (j = i; j != in.size(); j++)
{
k = 0;
while (in.get(j + k) == token.get(k))
if (++k == token.size())
return R<T>::substring(in, i, j - i);
}
return R<T>::substring(in, i);
}
else
goto Jupiter_Readable_String_getToken_skip_increment;
break;
}
}
}
return R<T>();
}
// gotoWord
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
@ -1234,43 +1127,6 @@ template<typename T> template<template<typename> class R> R<T> Jupiter::Readable
return R<T>::substring(in, x);
}
// gotoToken
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token)
{
size_t i;
for (i = 0; i != in.size() && pos != 0; i++)
if (in.get(i) == token)
pos--;
return R<T>::substring(in, i);
}
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token)
{
if (pos == 0 || token.isEmpty())
return R<T>(in);
if (token.size() == 1)
return Jupiter::Readable_String<T>::gotoToken<R>(in, pos, token.get(0));
size_t i, j;
for (i = 0; i != in.size(); i++)
{
j = 0;
while (in.get(i + j) == token.get(j))
{
if (++j == token.size())
{
if (--pos == 0)
return R<T>::substring(in, i + token.size());
break;
}
}
}
return R<T>();
}
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>

42
src/include/Jupiter/Reference_String.h

@ -170,27 +170,6 @@ namespace Jupiter
*/
static Reference_String<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param pos Position of the token in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> getToken(size_t pos, const T &token) const;
Reference_String<T> getToken(size_t pos, const Jupiter::Readable_String<T> &token) const;
/**
* @brief Creates a partial copy of an input string, based on a token.
*
* @param in String to get a partial copy of.
* @param pos Position of the token in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> getToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token);
static Reference_String<T> getToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
@ -220,27 +199,6 @@ namespace Jupiter
*/
static Reference_String<T> gotoWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param pos Position in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> gotoToken(size_t pos, const T &token) const;
Reference_String<T> gotoToken(size_t pos, const Jupiter::Readable_String<T> &token) const;
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token);
static Reference_String<T> gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token);
/** Mutative operators */
inline Reference_String<T>& operator-=(size_t right) { this->truncate(right); return *this; };
inline Reference_String<T>& operator=(const Readable_String<T> &right) { std::basic_string_view<T>::operator=({right.ptr(), right.size()}); return *this; };

32
src/include/Jupiter/Reference_String_Imp.h

@ -154,22 +154,6 @@ template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::
return Jupiter::Readable_String<T>::template getWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getToken(size_t pos, const T &token) const {
return Jupiter::Reference_String<T>::getToken(*this, pos, token);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getToken(size_t pos, const Jupiter::Readable_String<T> &token) const {
return Jupiter::Reference_String<T>::getToken(*this, pos, token);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token) {
return Jupiter::Readable_String<T>::template getToken<Jupiter::Reference_String>(in, pos, token);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token) {
return Jupiter::Readable_String<T>::template getToken<Jupiter::Reference_String>(in, pos, token);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoWord(size_t pos, const T *whitespace) const {
return Jupiter::Reference_String<T>::gotoWord(*this, pos, whitespace);
}
@ -182,22 +166,6 @@ template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::
return Jupiter::Readable_String<T>::template gotoWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoToken(size_t pos, const T &token) const {
return Jupiter::Reference_String<T>::gotoToken(*this, pos, token);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoToken(size_t pos, const Jupiter::Readable_String<T> &token) const {
return Jupiter::Reference_String<T>::gotoToken(*this, pos, token);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token) {
return Jupiter::Readable_String<T>::template gotoToken<Jupiter::Reference_String>(in, pos, token);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token) {
return Jupiter::Readable_String<T>::template gotoToken<Jupiter::Reference_String>(in, pos, token);
}
template<typename T> const Jupiter::Reference_String<T> Jupiter::Reference_String<T>::empty = Jupiter::Reference_String<T>();
// Jupiter::DataBuffer specialization

84
src/include/Jupiter/String.hpp

@ -144,27 +144,6 @@ namespace Jupiter
*/
static String_Strict<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param pos Position of the token in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
String_Strict<T> getToken(size_t pos, const T &token) const;
String_Strict<T> getToken(size_t pos, const Jupiter::Readable_String<T> &token) const;
/**
* @brief Creates a partial copy of an input string, based on a token.
*
* @param in String to get a partial copy of.
* @param pos Position of the token in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
static String_Strict<T> getToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token);
static String_Strict<T> getToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
@ -184,27 +163,6 @@ namespace Jupiter
*/
static String_Strict<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param pos Position in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
String_Strict<T> gotoToken(size_t pos, const T &token) const;
String_Strict<T> gotoToken(size_t pos, const Jupiter::Readable_String<T> &token) const;
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
static String_Strict<T> gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token);
static String_Strict<T> gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token);
/** Default Constructor */
String_Strict();
@ -379,27 +337,6 @@ namespace Jupiter
*/
static String_Loose<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param pos Position of the token in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
String_Loose<T> getToken(size_t pos, const T &token) const;
String_Loose<T> getToken(size_t pos, const Jupiter::Readable_String<T> &token) const;
/**
* @brief Creates a partial copy of an input string, based on a token.
*
* @param in String to get a partial copy of.
* @param pos Position of the token in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
static String_Loose<T> getToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token);
static String_Loose<T> getToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
@ -419,27 +356,6 @@ namespace Jupiter
*/
static String_Loose<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param pos Position in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
String_Loose<T> gotoToken(size_t pos, const T &token) const;
String_Loose<T> gotoToken(size_t pos, const Jupiter::Readable_String<T> &token) const;
/**
* @brief Creates a partial copy of the string, based on a token.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param token Token to scan for.
* @return String containing a partial copy of the original string.
*/
static String_Loose<T> gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token);
static String_Loose<T> gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token);
/**
* @brief Sets the internal buffer to be at least large enough to old a specified number of elements.
* Note: This does nothing if len is less than the string's current length.

80
src/include/Jupiter/String_Imp.h

@ -298,26 +298,6 @@ template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWor
return Jupiter::Readable_String<T>::template getWord<Jupiter::template String_Strict>(in, pos, whitespace);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getToken(size_t pos, const T &token) const
{
return Jupiter::String_Strict<T>::getToken(*this, pos, token);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getToken(size_t pos, const Jupiter::Readable_String<T> &token) const
{
return Jupiter::String_Strict<T>::getToken(*this, pos, token);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token)
{
return Jupiter::Readable_String<T>::template getToken<Jupiter::template String_Strict>(in, pos, token);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token)
{
return Jupiter::Readable_String<T>::template getToken<Jupiter::template String_Strict>(in, pos, token);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWord(size_t pos, const T *whitespace) const
{
return Jupiter::String_Strict<T>::gotoWord(*this, pos, whitespace);
@ -328,26 +308,6 @@ template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWo
return Jupiter::Readable_String<T>::template gotoWord<Jupiter::template String_Strict>(in, pos, whitespace);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoToken(size_t pos, const T &token) const
{
return Jupiter::String_Strict<T>::gotoToken(*this, pos, token);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoToken(size_t pos, const Jupiter::Readable_String<T> &token) const
{
return Jupiter::String_Strict<T>::gotoToken(*this, pos, token);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token)
{
return Jupiter::Readable_String<T>::template gotoToken<Jupiter::template String_Strict>(in, pos, token);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token)
{
return Jupiter::Readable_String<T>::template gotoToken<Jupiter::template String_Strict>(in, pos, token);
}
// Operators
template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>::operator+(const T &rhs) const
@ -752,26 +712,6 @@ template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(
return Jupiter::Readable_String<T>::template getWord<Jupiter::template String_Loose>(in, pos, whitespace);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getToken(size_t pos, const T &token) const
{
return Jupiter::String_Loose<T>::getToken(*this, pos, token);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getToken(size_t pos, const Jupiter::Readable_String<T> &token) const
{
return Jupiter::String_Loose<T>::getToken(*this, pos, token);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token)
{
return Jupiter::Readable_String<T>::template getToken<Jupiter::template String_Loose>(in, pos, token);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token)
{
return Jupiter::Readable_String<T>::template getToken<Jupiter::template String_Loose>(in, pos, token);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord(size_t pos, const T *whitespace) const
{
return Jupiter::String_Loose<T>::gotoWord(*this, pos, whitespace);
@ -782,26 +722,6 @@ template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord
return Jupiter::Readable_String<T>::template gotoWord<Jupiter::template String_Loose>(in, pos, whitespace);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoToken(size_t pos, const T &token) const
{
return Jupiter::String_Loose<T>::gotoToken(*this, pos, token);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoToken(size_t pos, const Jupiter::Readable_String<T> &token) const
{
return Jupiter::String_Loose<T>::gotoToken(*this, pos, token);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const T &token)
{
return Jupiter::Readable_String<T>::template gotoToken<Jupiter::template String_Loose>(in, pos, token);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoToken(const Jupiter::Readable_String<T> &in, size_t pos, const Jupiter::Readable_String<T> &token)
{
return Jupiter::Readable_String<T>::template gotoToken<Jupiter::template String_Loose>(in, pos, token);
}
// Operators
template<typename T> inline Jupiter::String_Loose<T> Jupiter::String_Loose<T>::operator+(const T &rhs) const

Loading…
Cancel
Save