Browse Source

Added Readable_String class and adapted implementations as neccessary

release/0.19
JustinAJ 10 years ago
parent
commit
7a2a8ac72d
  1. 2
      Jupiter/Jupiter.vcxproj
  2. 6
      Jupiter/Jupiter.vcxproj.filters
  3. 181
      Jupiter/Readable_String.h
  4. 746
      Jupiter/Readable_String_Imp.h
  5. 119
      Jupiter/String_Type.h
  6. 709
      Jupiter/String_Type_Imp.h
  7. BIN
      Release/Jupiter.lib

2
Jupiter/Jupiter.vcxproj

@ -132,6 +132,8 @@
<ClInclude Include="List.h" /> <ClInclude Include="List.h" />
<ClInclude Include="Plugin.h" /> <ClInclude Include="Plugin.h" />
<ClInclude Include="Queue.h" /> <ClInclude Include="Queue.h" />
<ClInclude Include="Readable_String.h" />
<ClInclude Include="Readable_String_Imp.h" />
<ClInclude Include="Rehash.h" /> <ClInclude Include="Rehash.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="SecureSocket.h" /> <ClInclude Include="SecureSocket.h" />

6
Jupiter/Jupiter.vcxproj.filters

@ -203,6 +203,12 @@
<ClInclude Include="String_Imp.h"> <ClInclude Include="String_Imp.h">
<Filter>Header Files\Strings</Filter> <Filter>Header Files\Strings</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Readable_String.h">
<Filter>Header Files\Strings</Filter>
</ClInclude>
<ClInclude Include="Readable_String_Imp.h">
<Filter>Header Files\Strings</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="Jupiter.rc"> <ResourceCompile Include="Jupiter.rc">

181
Jupiter/Readable_String.h

@ -0,0 +1,181 @@
/**
* Copyright (C) 2014 Justin James.
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#if !defined _READABLE_STRING_H_HEADER
#define _READABLE_STRING_H_HEADER
/**
* @file Readable_String.h
* @brief Defines several basic accessive and comparative virtual functions for strings.
*/
#include <cwchar> // wchar_t
#include <cstdio> // FILE
#include <string> // std::basic_string<T> type
namespace Jupiter
{
/**
* @brief Provides the basis for String classes by providing implementations for operators, comparative operations, and defining abstract functions.
* Note: This is an abstract type.
*
* @param T Element type which the String will store. Defaults to char.
*/
template<typename T = char> class Readable_String
{
public:
/**
* @brief Fetches an element from the string.
*
* @param index Index of the element to return.
* @return The element located at the specified index.
*/
virtual T &get(size_t index) const = 0;
/**
* @brief Returns the number of elements in the String.
*
* @return Number of elements in the string.
*/
virtual size_t size() const = 0;
/**
* @brief Returns a pointer to the underlying string of elements.
*
* @return Pointer to the underlying string of elements.
*/
virtual const T *ptr() const = 0;
/**
* @brief Checks if the string contains an element with the specified value.
*
* @param value Value of the element to search for.
* @return True if a match is found, false otherwise.
*/
bool contains(const T &value) const;
/**
* @brief Compares another string against the String.
*
* @param in String to compare against.
* @return 0 if the strings are equal, negative if the first mismatched character is greater in the String, or positive if it's less.
*/
int compare(const Readable_String<T> &in) const;
int compare(const std::basic_string<T> &in) const;
int compare(const T *in) const;
int compare(const T &in) const;
int compare(const std::nullptr_t) const;
/**
* @brief Checks if the strings are equal.
* Note: Case sensitive.
*
* @param in String to compare against.
* @return True if the contents of the strings are equal, false otherwise.
*/
bool equals(const Readable_String<T> &in) const;
bool equals(const std::basic_string<T> &in) const;
bool equals(const T *in) const;
bool equals(const T &in) const;
bool equals(const std::nullptr_t) const;
/**
* @brief Checks if the strings are equal.
* Note: Case insensitive. Returns false for any type other than char and wchar_t.
*
* @param in String to compare against.
* @return True if the contents of the strings are equal, false otherwise.
*/
bool equalsi(const Readable_String<T> &in) const;
bool equalsi(const std::basic_string<T> &in) const;
bool equalsi(const T *in) const;
bool equalsi(const T &in) const;
bool equalsi(const std::nullptr_t) const;
/**
* @brief Checks if the String matches a wildcard format.
* Note: Case sensitive.
*
* @param format Format that the string is compared against.
* @return True if the String matches the wildcard format, false otherwise.
*/
bool match(const Readable_String<T> &format) const;
bool match(const std::basic_string<T> &format) const;
bool match(const T *format) const;
/**
* @brief Checks if the CString matches a wildcard format.
* Note: Case insensitive. Returns false for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @return True if the CString matches the wildcard format, false otherwise.
*/
bool matchi(const Readable_String<T> &format) const;
bool matchi(const std::basic_string<T> &format) const;
bool matchi(const T *format) const;
/**
* @brief Counts the number of token deliminated words.
*
* @param whitespace A string of tokens used to deliminate words.
* @return Number of words found.
*/
unsigned int wordCount(const T *whitespace) const;
/**
* @brief Interprets the string as an integer.
* Note: This returns 0 on any value string type other than char.
*
* @param base Base of the string representation.
* @return Integer representation of the string.
*/
int asInt(int base = 0) const;
/**
* @brief Interprets the string as an integer.
* Note: This returns 0 on any value string type other than char.
*
* @param base Base of the string representation.
* @return Integer representation of the string.
*/
unsigned int asUnsignedInt(int base = 0) const;
/**
* @brief Outputs the string to a FILE stream.
*
* @param out Stream to output to.
* @return Number of elements written successfully.
*/
size_t print(FILE *out) const;
size_t print(std::basic_ostream<T> &out) const;
/**
* @brief Outputs the string and a newline to a FILE stream
*
* @param out Stream to output to.
* @param Number of elements written successfully.
*/
size_t println(FILE *out) const;
size_t println(std::basic_ostream<T> &out) const;
};
}
#include "Readable_String_Imp.h"
#endif // _READABLE_STRING_H_HEADER

746
Jupiter/Readable_String_Imp.h

@ -0,0 +1,746 @@
/**
* Copyright (C) 2014 Justin James.
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#if !defined _READABLE_STRING_IMP_H_HEADER
#define _READABLE_STRING_IMP_H_HEADER
/**
* @file Readable_String_Imp.h
* @brief Provides the implementations for Readable_String functions.
* Note: Modification of this file is not supported in any way.
*/
#include "Readable_String.h"
#include "Functions.h"
/**
* IMPLEMENTATION:
* Readable_String
*/
// contains
template<typename T> bool Jupiter::Readable_String<T>::contains(const T &value) const
{
for (size_t i = 0; i != this->size(); i++) if (this->get(i) == value) return true;
return false;
}
// compare()
template<typename T> int Jupiter::Readable_String<T>::compare(const Jupiter::Readable_String<T> &in) const
{
// rewrite to compare multiple bytes at a time.
size_t index = 0;
while (this->get(index) == in.get(index))
{
index++;
if (index == in.size())
{
if (index == this->size()) return 0;
return 1;
}
if (index == this->size()) return 0 - in.get(index);
}
return this->get(index) - in.get(index);
}
template<typename T> int Jupiter::Readable_String<T>::compare(const std::basic_string<T> &in) const
{
// rewrite to compare multiple bytes at a time.
size_t index = 0;
while (this->get(index) == in.at(index))
{
index++;
if (index == in.size())
{
if (index == this->size()) return 0;
return 1;
}
if (index == this->size()) return 0 - in.at(index);
}
return this->get(index) - in.at(index);
}
template<typename T> int Jupiter::Readable_String<T>::compare(const T *s2) const
{
if (this->size() == 0) return 0 - *s2;
size_t index = 0;
while (this->get(index) == *s2)
{
index++;
if (*s2 == 0)
{
if (index == this->size()) return 0;
return 1;
}
s2++;
if (index == this->size()) return 0 - *s2;
}
return this->get(index) - *s2;
}
template<typename T> int Jupiter::Readable_String<T>::compare(const T &in) const
{
if (this->size() == 0) return 0 - in;
return this->get(0) - in;
}
template<typename T> int Jupiter::Readable_String<T>::compare(const std::nullptr_t) const
{
if (this->size() == 0) return true;
return this->get(0);
}
// equals()
template<typename T> bool Jupiter::Readable_String<T>::equals(const Jupiter::Readable_String<T> &in) const
{
if (this->size() != in.size()) return false;
// rewrite to compare multiple bytes at a time.
size_t index = 0;
while (index != this->size())
{
if (this->get(index) != in.get(index)) return false;
index++;
}
return true;
}
template<typename T> bool Jupiter::Readable_String<T>::equals(const std::basic_string<T> &in) const
{
if (this->size() != in.size()) return false;
// rewrite to compare multiple bytes at a time.
size_t index = 0;
while (index != this->size())
{
if (this->get(index) != in.at(index)) return false;
index++;
}
return true;
}
template<typename T> bool Jupiter::Readable_String<T>::equals(const T *in) const
{
if (in == nullptr) return this->size() == 0;
for (size_t index = 0; index != this->size(); index++)
{
if (*in == 0 || this->get(index) != *in) return false;
in++;
}
return *in == 0;
}
template<typename T> bool Jupiter::Readable_String<T>::equals(const T &in) const
{
return this->size() == 1 && this->get(0) == in;
}
template<typename T> bool Jupiter::Readable_String<T>::equals(std::nullptr_t) const
{
return this->size() == 0;
}
// equalsi()
template<> bool inline Jupiter::Readable_String<char>::equalsi(const Jupiter::Readable_String<char> &in) const
{
if (this->size() != in.size()) return false;
for (size_t index = 0; index != this->size(); index++)
{
if (toupper(this->get(index)) != toupper(in.get(index))) return false;
}
return true;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::equalsi(const Jupiter::Readable_String<wchar_t> &in) const
{
if (this->size() != in.size()) return false;
for (size_t index = 0; index != this->size(); index++)
{
if (towupper(this->get(index)) != towupper(in.get(index))) return false;
}
return true;
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const Jupiter::Readable_String<T> &in) const
{
return this->equals(in); // Concept of "case" not supported for type.
}
template<> bool inline Jupiter::Readable_String<char>::equalsi(const std::basic_string<char> &in) const
{
if (this->size() != in.size()) return false;
for (size_t index = 0; index != this->size(); index++)
{
if (toupper(this->get(index)) != toupper(in.at(index))) return false;
}
return true;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::equalsi(const std::basic_string<wchar_t> &in) const
{
if (this->size() != in.size()) return false;
for (size_t index = 0; index != this->size(); index++)
{
if (towupper(this->get(index)) != towupper(in.at(index))) return false;
}
return true;
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const std::basic_string<T> &in) const
{
return this->equals(in); // Concept of "case" not supported for type.
}
template<> bool inline Jupiter::Readable_String<char>::equalsi(const char *in) const
{
if (in == nullptr) return this->size() == 0;
for (size_t index = 0; index != this->size(); index++)
{
if (*in == 0 || toupper(this->get(index)) != toupper(*in)) return false;
in++;
}
return *in == 0;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::equalsi(const wchar_t *in) const
{
if (in == nullptr) return this->size() == 0;
for (size_t index = 0; index != this->size(); index++)
{
if (*in == 0 || towupper(this->get(index)) != towupper(*in)) return false;
in++;
}
return *in == 0;
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const T *in) const
{
return this->equals(in); // Concept of "case" not supported for type.
}
template<> bool inline Jupiter::Readable_String<char>::equalsi(const char &in) const
{
return this->size() == 1 && toupper(this->get(0)) == toupper(in);
}
template<> bool inline Jupiter::Readable_String<wchar_t>::equalsi(const wchar_t &in) const
{
return this->size() == 1 && towupper(this->get(0)) == towupper(in);
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const T &in) const
{
return this->equals(in); // Concept of "case" not supported for type.
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const std::nullptr_t) const
{
return this->size() == 0;
}
// match()
template<> bool inline Jupiter::Readable_String<char>::match(const Jupiter::Readable_String<char> &format) const
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.get(formatIndex) == '*')
{
formatIndex++;
while (format.get(formatIndex) == '?')
{
if (this->get(index) == 0) return false;
formatIndex++;
index++;
}
if (format.get(formatIndex) == 0) return true;
if (format.get(formatIndex) == '*') continue;
while (format.get(formatIndex) != this->get(index))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (format.get(formatIndex) != '?' && format.get(formatIndex) != this->get(index)) return false;
formatIndex++;
index++;
}
return index == this->size();
}
template<> bool inline Jupiter::Readable_String<wchar_t>::match(const Jupiter::Readable_String<wchar_t> &format) const
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.get(formatIndex) == '*')
{
formatIndex++;
while (format.get(formatIndex) == '?')
{
if (this->get(index) == 0) return false;
formatIndex++;
index++;
}
if (format.get(formatIndex) == 0) return true;
if (format.get(formatIndex) == '*') continue;
while (format.get(formatIndex) != this->get(index))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (format.get(formatIndex) != '?' && format.get(formatIndex) != this->get(index)) return false;
formatIndex++;
index++;
}
return index == this->size();
}
template<typename T> bool Jupiter::Readable_String<T>::match(const Jupiter::Readable_String<T> &format) const
{
return false; // Wildcard matching not supported for type.
}
template<> bool inline Jupiter::Readable_String<char>::match(const std::basic_string<char> &format) const
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == '*')
{
formatIndex++;
while (format.at(formatIndex) == '?')
{
if (this->get(index) == 0) return false;
formatIndex++;
index++;
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
while (format.at(formatIndex) != this->get(index))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (format.at(formatIndex) != '?' && format.at(formatIndex) != this->get(index)) return false;
formatIndex++;
index++;
}
return index == this->size();
}
template<> bool inline Jupiter::Readable_String<wchar_t>::match(const std::basic_string<wchar_t> &format) const
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == '*')
{
formatIndex++;
while (format.at(formatIndex) == '?')
{
if (this->get(index) == 0) return false;
formatIndex++;
index++;
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
while (format.at(formatIndex) != this->get(index))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (format.at(formatIndex) != '?' && format.at(formatIndex) != this->get(index)) return false;
formatIndex++;
index++;
}
return index == this->size();
}
template<typename T> bool Jupiter::Readable_String<T>::match(const std::basic_string<T> &format) const
{
return false; // Wildcard matching not supported for type.
}
template<> inline bool Jupiter::Readable_String<char>::match(const char *format) const
{
size_t index = 0;
while (*format != 0)
{
if (*format == '*')
{
format++;
while (*format == '?')
{
if (this->get(index) == 0) return false;
format++;
index++;
}
if (*format == 0) return true;
if (*format == '*') continue;
while (*format != this->get(index))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (*format != '?' && *format != this->get(index)) return false;
format++;
index++;
}
return index == this->size();
}
template<> inline bool Jupiter::Readable_String<wchar_t>::match(const wchar_t *format) const
{
size_t index = 0;
while (*format != 0)
{
if (*format == L'*')
{
format++;
while (*format == L'?')
{
if (this->get(index) == 0) return false;
format++;
index++;
}
if (*format == 0) return true;
if (*format == L'*') continue;
while (*format != this->get(index))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (*format != L'?' && *format != this->get(index)) return false;
format++;
index++;
}
return index == this->size();
}
template<typename T> bool Jupiter::Readable_String<T>::match(const T *format) const
{
return false; // Wildcard matching not supported for type.
}
// matchi()
template<> bool inline Jupiter::Readable_String<char>::matchi(const Jupiter::Readable_String<char> &format) const
{
int fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.get(formatIndex) == L'*')
{
formatIndex++;
while (format.get(formatIndex) == L'?')
{
if (this->get(index) == 0) return false;
formatIndex++;
index++;
}
if (format.get(formatIndex) == 0) return true;
if (format.get(formatIndex) == '*') continue;
fUpper = toupper(format.get(formatIndex));
while (fUpper != toupper(this->get(index)))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (format.get(formatIndex) != L'?' && toupper(format.get(formatIndex)) != toupper(this->get(index))) return false;
formatIndex++;
index++;
}
return index == this->size();
}
template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const Jupiter::Readable_String<wchar_t> &format) const
{
wint_t fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.get(formatIndex) == L'*')
{
formatIndex++;
while (format.get(formatIndex) == L'?')
{
if (this->get(index) == 0) return false;
formatIndex++;
index++;
}
if (format.get(formatIndex) == 0) return true;
if (format.get(formatIndex) == '*') continue;
fUpper = towupper(format.get(formatIndex));
while (fUpper != towupper(this->get(index)))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (format.get(formatIndex) != L'?' && towupper(format.get(formatIndex)) != towupper(this->get(index))) return false;
formatIndex++;
index++;
}
return index == this->size();
}
template<typename T> bool Jupiter::Readable_String<T>::matchi(const Jupiter::Readable_String<T> &format) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
}
template<> bool inline Jupiter::Readable_String<char>::matchi(const std::basic_string<char> &format) const
{
int fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == L'*')
{
formatIndex++;
while (format.at(formatIndex) == L'?')
{
if (this->get(index) == 0) return false;
formatIndex++;
index++;
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
fUpper = toupper(format.at(formatIndex));
while (fUpper != toupper(this->get(index)))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (format.at(formatIndex) != L'?' && toupper(format.at(formatIndex)) != toupper(this->get(index))) return false;
formatIndex++;
index++;
}
return index == this->size();
}
template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const std::basic_string<wchar_t> &format) const
{
wint_t fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == L'*')
{
formatIndex++;
while (format.at(formatIndex) == L'?')
{
if (this->get(index) == 0) return false;
formatIndex++;
index++;
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
fUpper = towupper(format.at(formatIndex));
while (fUpper != towupper(this->get(index)))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (format.at(formatIndex) != L'?' && towupper(format.at(formatIndex)) != towupper(this->get(index))) return false;
formatIndex++;
index++;
}
return index == this->size();
}
template<typename T> bool Jupiter::Readable_String<T>::matchi(const std::basic_string<T> &format) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
}
template<> bool inline Jupiter::Readable_String<char>::matchi(const char *format) const
{
int fUpper;
size_t index = 0;
while (*format != 0)
{
if (*format == '*')
{
format++;
while (*format == '?')
{
if (this->get(index) == 0) return false;
format++;
index++;
}
if (*format == 0) return true;
if (*format == '*') continue;
fUpper = toupper(*format);
while (fUpper != toupper(this->get(index)))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (*format != '?' && toupper(*format) != toupper(this->get(index))) return false;
format++;
index++;
}
return index == this->size();
}
template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const wchar_t *format) const
{
wint_t fUpper;
size_t index = 0;
while (*format != 0)
{
if (*format == L'*')
{
format++;
while (*format == L'?')
{
if (this->get(index) == 0) return false;
format++;
index++;
}
if (*format == 0) return true;
if (*format == '*') continue;
fUpper = towupper(*format);
while (fUpper != towupper(this->get(index)))
{
if (this->get(index) == 0) return false;
index++;
}
}
else if (*format != L'?' && towupper(*format) != towupper(this->get(index))) return false;
format++;
index++;
}
return index == this->size();
}
template<typename T> bool Jupiter::Readable_String<T>::matchi(const T *format) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
}
// wordCount()
template<typename T> unsigned int Jupiter::Readable_String<T>::wordCount(const T *whitespace) const
{
unsigned int result = 0;
const T *p = this->ptr();
bool prev = true;
while (*p != 0)
{
if (Jupiter::strpbrk<T>(whitespace, *p) == nullptr) // This isn't whitespace!
{
if (prev == true) // We just left whitespace!
{
prev = false;
result++;
}
}
else prev = true; // This is whitespace!
p++;
}
return result;
}
// as<type>
template<> unsigned int inline Jupiter::Readable_String<char>::asUnsignedInt(int base) const
{
return strtoui_s(this->ptr(), this->size(), base);
}
template<typename T> unsigned int Jupiter::Readable_String<T>::asUnsignedInt(int base) const
{
return 0;
}
template<> int inline Jupiter::Readable_String<char>::asInt(int base) const
{
return strtoi_s(this->ptr(), this->size(), base);
}
template<typename T> int Jupiter::Readable_String<T>::asInt(int base) const
{
return 0;
}
// Stream output
template<typename T> size_t Jupiter::Readable_String<T>::print(FILE *out) const
{
return fwrite(this->ptr(), sizeof(T), this->size(), out);
}
template<> size_t inline Jupiter::Readable_String<wchar_t>::print(FILE *out) const
{
size_t index = 0;
while (index != this->size() && fputwc(this->get(index), out) != WEOF) index++;
return index;
}
template<typename T> size_t Jupiter::Readable_String<T>::print(std::basic_ostream<T> &out) const
{
size_t index = 0;
while (index != this->size())
{
out << this->get(index);
index++;
}
return index;
}
template<typename T> size_t Jupiter::Readable_String<T>::println(FILE *out) const
{
size_t r = this->print(out);
if (r != this->size()) return r;
if (fputs("\r\n", out) != EOF) r += 2;
return r;
}
template<typename T> size_t Jupiter::Readable_String<T>::println(std::basic_ostream<T> &out) const
{
size_t r = this->print(out);
if (r != this->size()) return r;
out << std::endl;
return r;
}
#endif // _READABLE_STRING_IMP_H_HEADER

119
Jupiter/String_Type.h

@ -24,11 +24,8 @@
* Note: Some methods are commented out. This means that they should be implemented, but could not be put declared in this template (return of abstract type). * Note: Some methods are commented out. This means that they should be implemented, but could not be put declared in this template (return of abstract type).
*/ */
#include "Jupiter.h"
#include <string> // std::basic_string<T> type
#include <cstdarg> // va_list #include <cstdarg> // va_list
#include <cwchar> #include "Readable_String.h"
#include <cstdio>
namespace Jupiter namespace Jupiter
{ {
@ -39,7 +36,7 @@ namespace Jupiter
* *
* @param T Element type which the String will store. Defaults to char. * @param T Element type which the String will store. Defaults to char.
*/ */
template<typename T = char> class String_Type template<typename T = char> class String_Type : public Jupiter::Readable_String<T>
{ {
public: public:
@ -65,100 +62,6 @@ namespace Jupiter
*/ */
const T *ptr() const; const T *ptr() const;
/**
* @brief Checks if the string contains an element with the specified value.
*
* @param value Value of the element to search for.
* @return True if a match is found, false otherwise.
*/
bool contains(const T &value) const;
/**
* @brief Compares another string against the String.
*
* @param in String to compare against.
* @return 0 if the strings are equal, negative if the first mismatched character is greater in the String, or positive if it's less.
*/
int compare(const String_Type<T> &in) const;
int compare(const std::basic_string<T> &in) const;
int compare(const T *in) const;
int compare(const T &in) const;
int compare(const std::nullptr_t) const;
/**
* @brief Checks if the strings are equal.
* Note: Case sensitive.
*
* @param in String to compare against.
* @return True if the contents of the strings are equal, false otherwise.
*/
bool equals(const String_Type<T> &in) const;
bool equals(const std::basic_string<T> &in) const;
bool equals(const T *in) const;
bool equals(const T &in) const;
bool equals(const std::nullptr_t) const;
/**
* @brief Checks if the strings are equal.
* Note: Case insensitive. Returns false for any type other than char and wchar_t.
*
* @param in String to compare against.
* @return True if the contents of the strings are equal, false otherwise.
*/
bool equalsi(const String_Type<T> &in) const;
bool equalsi(const std::basic_string<T> &in) const;
bool equalsi(const T *in) const;
bool equalsi(const T &in) const;
bool equalsi(const std::nullptr_t) const;
/**
* @brief Checks if the String matches a wildcard format.
* Note: Case sensitive.
*
* @param format Format that the string is compared against.
* @return True if the String matches the wildcard format, false otherwise.
*/
bool match(const String_Type<T> &format) const;
bool match(const std::basic_string<T> &format) const;
bool match(const T *format) const;
/**
* @brief Checks if the CString matches a wildcard format.
* Note: Case insensitive. Returns false for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @return True if the CString matches the wildcard format, false otherwise.
*/
bool matchi(const String_Type<T> &format) const;
bool matchi(const std::basic_string<T> &format) const;
bool matchi(const T *format) const;
/**
* @brief Counts the number of token deliminated words.
*
* @param whitespace A string of tokens used to deliminate words.
* @return Number of words found.
*/
unsigned int wordCount(const T *whitespace) const;
/**
* @brief Interprets the string as an integer.
* Note: This returns 0 on any value string type other than char.
*
* @param base Base of the string representation.
* @return Integer representation of the string.
*/
int asInt(int base = 0) const;
/**
* @brief Interprets the string as an integer.
* Note: This returns 0 on any value string type other than char.
*
* @param base Base of the string representation.
* @return Integer representation of the string.
*/
unsigned int asUnsignedInt(int base = 0) const;
/** /**
* @brief Returns a C-Style string version of the String. * @brief Returns a C-Style string version of the String.
* *
@ -166,24 +69,6 @@ namespace Jupiter
*/ */
virtual const T *c_str() const = 0; virtual const T *c_str() const = 0;
/**
* @brief Outputs the string to a FILE stream.
*
* @param out Stream to output to.
* @return Number of elements written successfully.
*/
size_t print(FILE *out) const;
size_t print(std::basic_ostream<T> &out) const;
/**
* @brief Outputs the string and a newline to a FILE stream
*
* @param out Stream to output to.
* @param Number of elements written successfully.
*/
size_t println(FILE *out) const;
size_t println(std::basic_ostream<T> &out) const;
/** /**
* @brief Sets the CString's contents based on the format string and input variables. * @brief Sets the CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t. * Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.

709
Jupiter/String_Type_Imp.h

@ -55,715 +55,6 @@ template<typename T> const T *Jupiter::String_Type<T>::ptr() const
return Jupiter::String_Type<T>::str; return Jupiter::String_Type<T>::str;
} }
template<typename T> bool Jupiter::String_Type<T>::contains(const T &value) const
{
for (unsigned int i = 0; i < Jupiter::String_Type<T>::length; i++) if (Jupiter::String_Type<T>::str[i] == value) return true;
return false;
}
// compare()
template<typename T> int Jupiter::String_Type<T>::compare(const Jupiter::String_Type<T> &in) const
{
// rewrite to compare multiple bytes at a time.
size_t index = 0;
while (Jupiter::String_Type<T>::str[index] == in.get(index))
{
index++;
if (index == in.size())
{
if (index == Jupiter::String_Type<T>::length) return 0;
return 1;
}
if (index == Jupiter::String_Type<T>::length) return 0 - in.get(index);
}
return Jupiter::String_Type<T>::str[index] - in.get(index);
}
template<typename T> int Jupiter::String_Type<T>::compare(const std::basic_string<T> &in) const
{
// rewrite to compare multiple bytes at a time.
size_t index = 0;
while (Jupiter::String_Type<T>::str[index] == in.at(index))
{
index++;
if (index == in.size())
{
if (index == Jupiter::String_Type<T>::length) return 0;
return 1;
}
if (index == Jupiter::String_Type<T>::length) return 0 - in.at(index);
}
return Jupiter::String_Type<T>::str[index] - in.at(index);
}
template<typename T> int Jupiter::String_Type<T>::compare(const T *s2) const
{
if (Jupiter::String_Type<T>::length == 0) return 0 - *s2;
size_t index = 0;
while (Jupiter::String_Type<T>::str[index] == *s2)
{
index++;
if (*s2 == 0)
{
if (index == Jupiter::String_Type<T>::length) return 0;
return 1;
}
s2++;
if (index == Jupiter::String_Type<T>::length) return 0 - *s2;
}
return Jupiter::String_Type<T>::str[index] - *s2;
}
template<typename T> int Jupiter::String_Type<T>::compare(const T &in) const
{
if (Jupiter::String_Type<T>::length == 0) return 0 - in;
return *Jupiter::String_Type<T>::str - in;
}
template<typename T> int Jupiter::String_Type<T>::compare(const std::nullptr_t) const
{
if (Jupiter::String_Type<T>::length == 0) return true;
return *Jupiter::String_Type<T>::str;
}
// equals()
template<typename T> bool Jupiter::String_Type<T>::equals(const Jupiter::String_Type<T> &in) const
{
if (Jupiter::String_Type<T>::length != in.size()) return false;
// rewrite to compare multiple bytes at a time.
size_t index = 0;
while (index != Jupiter::String_Type<T>::length)
{
if (Jupiter::String_Type<T>::str[index] != in.str[index]) return false;
index++;
}
return true;
}
template<typename T> bool Jupiter::String_Type<T>::equals(const std::basic_string<T> &in) const
{
if (Jupiter::String_Type<T>::length != in.size()) return false;
// rewrite to compare multiple bytes at a time.
size_t index = 0;
while (index != Jupiter::String_Type<T>::length)
{
if (Jupiter::String_Type<T>::str[index] != in.at(index)) return false;
index++;
}
return true;
}
template<typename T> bool Jupiter::String_Type<T>::equals(const T *in) const
{
if (in == nullptr) return Jupiter::String_Type<T>::length == 0;
for (size_t index = 0; index != Jupiter::String_Type<T>::length; index++)
{
if (*in == 0 || Jupiter::String_Type<T>::str[index] != *in) return false;
in++;
}
return *in == 0;
}
template<typename T> bool Jupiter::String_Type<T>::equals(const T &in) const
{
return Jupiter::String_Type<T>::length == 1 && *Jupiter::String_Type<T>::str == in;
}
template<typename T> bool Jupiter::String_Type<T>::equals(std::nullptr_t) const
{
return Jupiter::String_Type<T>::length == 0;
}
// equalsi()
template<> bool inline Jupiter::String_Type<char>::equalsi(const Jupiter::String_Type<char> &in) const
{
if (Jupiter::String_Type<char>::length != in.size()) return false;
for (size_t index = 0; index != Jupiter::String_Type<char>::length; index++)
{
if (toupper(Jupiter::String_Type<char>::str[index]) != toupper(in.str[index])) return false;
}
return true;
}
template<> bool inline Jupiter::String_Type<wchar_t>::equalsi(const Jupiter::String_Type<wchar_t> &in) const
{
if (Jupiter::String_Type<wchar_t>::length != in.size()) return false;
for (size_t index = 0; index != Jupiter::String_Type<wchar_t>::length; index++)
{
if (towupper(Jupiter::String_Type<wchar_t>::str[index]) != towupper(in.str[index])) return false;
}
return true;
}
template<typename T> bool Jupiter::String_Type<T>::equalsi(const Jupiter::String_Type<T> &in) const
{
return Jupiter::String_Type<T>::equals(in); // Concept of "case" not supported for type.
}
template<> bool inline Jupiter::String_Type<char>::equalsi(const std::basic_string<char> &in) const
{
if (Jupiter::String_Type<char>::length != in.size()) return false;
for (size_t index = 0; index != Jupiter::String_Type<char>::length; index++)
{
if (toupper(Jupiter::String_Type<char>::str[index]) != toupper(in.at(index))) return false;
}
return true;
}
template<> bool inline Jupiter::String_Type<wchar_t>::equalsi(const std::basic_string<wchar_t> &in) const
{
if (Jupiter::String_Type<wchar_t>::length != in.size()) return false;
for (size_t index = 0; index != Jupiter::String_Type<wchar_t>::length; index++)
{
if (towupper(Jupiter::String_Type<wchar_t>::str[index]) != towupper(in.at(index))) return false;
}
return true;
}
template<typename T> bool Jupiter::String_Type<T>::equalsi(const std::basic_string<T> &in) const
{
return Jupiter::String_Type<T>::equals(in); // Concept of "case" not supported for type.
}
template<> bool inline Jupiter::String_Type<char>::equalsi(const char *in) const
{
if (in == nullptr) return Jupiter::String_Type<char>::length == 0;
for (size_t index = 0; index != Jupiter::String_Type<char>::length; index++)
{
if (*in == 0 || toupper(Jupiter::String_Type<char>::str[index]) != toupper(*in)) return false;
in++;
}
return *in == 0;
}
template<> bool inline Jupiter::String_Type<wchar_t>::equalsi(const wchar_t *in) const
{
if (in == nullptr) return Jupiter::String_Type<wchar_t>::length == 0;
for (size_t index = 0; index != Jupiter::String_Type<wchar_t>::length; index++)
{
if (*in == 0 || towupper(Jupiter::String_Type<wchar_t>::str[index]) != towupper(*in)) return false;
in++;
}
return *in == 0;
}
template<typename T> bool Jupiter::String_Type<T>::equalsi(const T *in) const
{
return Jupiter::String_Type<T>::equals(in); // Concept of "case" not supported for type.
}
template<> bool inline Jupiter::String_Type<char>::equalsi(const char &in) const
{
return Jupiter::String_Type<char>::length == 1 && toupper(*Jupiter::String_Type<char>::str) == toupper(in);
}
template<> bool inline Jupiter::String_Type<wchar_t>::equalsi(const wchar_t &in) const
{
return Jupiter::String_Type<wchar_t>::length == 1 && towupper(*Jupiter::String_Type<wchar_t>::str) == towupper(in);
}
template<typename T> bool Jupiter::String_Type<T>::equalsi(const T &in) const
{
return Jupiter::String_Type<T>::equals(in); // Concept of "case" not supported for type.
}
template<typename T> bool Jupiter::String_Type<T>::equalsi(const std::nullptr_t) const
{
return Jupiter::String_Type<T>::length == 0;
}
// match()
template<> bool inline Jupiter::String_Type<char>::match(const Jupiter::String_Type<char> &format) const
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.str[formatIndex] == '*')
{
formatIndex++;
while (format.str[formatIndex] == '?')
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
formatIndex++;
index++;
}
if (format.str[formatIndex] == 0) return true;
if (format.str[formatIndex] == '*') continue;
while (format.str[formatIndex] != Jupiter::String_Type<char>::str[index])
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
index++;
}
}
else if (format.str[formatIndex] != '?' && format.str[formatIndex] != Jupiter::String_Type<char>::str[index]) return false;
formatIndex++;
index++;
}
return index == Jupiter::String_Type<char>::length;
}
template<> bool inline Jupiter::String_Type<wchar_t>::match(const Jupiter::String_Type<wchar_t> &format) const
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.str[formatIndex] == '*')
{
formatIndex++;
while (format.str[formatIndex] == '?')
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
formatIndex++;
index++;
}
if (format.str[formatIndex] == 0) return true;
if (format.str[formatIndex] == '*') continue;
while (format.str[formatIndex] != Jupiter::String_Type<wchar_t>::str[index])
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
index++;
}
}
else if (format.str[formatIndex] != '?' && format.str[formatIndex] != Jupiter::String_Type<wchar_t>::str[index]) return false;
formatIndex++;
index++;
}
return index == Jupiter::String_Type<wchar_t>::length;
}
template<typename T> bool Jupiter::String_Type<T>::match(const Jupiter::String_Type<T> &format) const
{
return false; // Wildcard matching not supported for type.
}
template<> bool inline Jupiter::String_Type<char>::match(const std::basic_string<char> &format) const
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == '*')
{
formatIndex++;
while (format.at(formatIndex) == '?')
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
formatIndex++;
index++;
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
while (format.at(formatIndex) != Jupiter::String_Type<char>::str[index])
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
index++;
}
}
else if (format.at(formatIndex) != '?' && format.at(formatIndex) != Jupiter::String_Type<char>::str[index]) return false;
formatIndex++;
index++;
}
return index == Jupiter::String_Type<char>::length;
}
template<> bool inline Jupiter::String_Type<wchar_t>::match(const std::basic_string<wchar_t> &format) const
{
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == '*')
{
formatIndex++;
while (format.at(formatIndex) == '?')
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
formatIndex++;
index++;
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
while (format.at(formatIndex) != Jupiter::String_Type<wchar_t>::str[index])
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
index++;
}
}
else if (format.at(formatIndex) != '?' && format.at(formatIndex) != Jupiter::String_Type<wchar_t>::str[index]) return false;
formatIndex++;
index++;
}
return index == Jupiter::String_Type<wchar_t>::length;
}
template<typename T> bool Jupiter::String_Type<T>::match(const std::basic_string<T> &format) const
{
return false; // Wildcard matching not supported for type.
}
template<> inline bool Jupiter::String_Type<char>::match(const char *format) const
{
size_t index = 0;
while (*format != 0)
{
if (*format == '*')
{
format++;
while (*format == '?')
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
format++;
index++;
}
if (*format == 0) return true;
if (*format == '*') continue;
while (*format != Jupiter::String_Type<char>::str[index])
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
index++;
}
}
else if (*format != '?' && *format != Jupiter::String_Type<char>::str[index]) return false;
format++;
index++;
}
return index == Jupiter::String_Type<char>::length;
}
template<> inline bool Jupiter::String_Type<wchar_t>::match(const wchar_t *format) const
{
size_t index = 0;
while (*format != 0)
{
if (*format == L'*')
{
format++;
while (*format == L'?')
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
format++;
index++;
}
if (*format == 0) return true;
if (*format == L'*') continue;
while (*format != Jupiter::String_Type<wchar_t>::str[index])
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
index++;
}
}
else if (*format != L'?' && *format != Jupiter::String_Type<wchar_t>::str[index]) return false;
format++;
index++;
}
return index == Jupiter::String_Type<wchar_t>::length;
}
template<typename T> bool Jupiter::String_Type<T>::match(const T *format) const
{
return false; // Wildcard matching not supported for type.
}
// matchi()
template<> bool inline Jupiter::String_Type<char>::matchi(const Jupiter::String_Type<char> &format) const
{
int fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.get(formatIndex) == L'*')
{
formatIndex++;
while (format.get(formatIndex) == L'?')
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
formatIndex++;
index++;
}
if (format.get(formatIndex) == 0) return true;
if (format.get(formatIndex) == '*') continue;
fUpper = toupper(format.get(formatIndex));
while (fUpper != toupper(Jupiter::String_Type<char>::str[index]))
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
index++;
}
}
else if (format.get(formatIndex) != L'?' && toupper(format.get(formatIndex)) != toupper(Jupiter::String_Type<char>::str[index])) return false;
formatIndex++;
index++;
}
return index == Jupiter::String_Type<char>::length;
}
template<> bool inline Jupiter::String_Type<wchar_t>::matchi(const Jupiter::String_Type<wchar_t> &format) const
{
wint_t fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.get(formatIndex) == L'*')
{
formatIndex++;
while (format.get(formatIndex) == L'?')
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
formatIndex++;
index++;
}
if (format.get(formatIndex) == 0) return true;
if (format.get(formatIndex) == '*') continue;
fUpper = towupper(format.get(formatIndex));
while (fUpper != towupper(Jupiter::String_Type<wchar_t>::str[index]))
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
index++;
}
}
else if (format.get(formatIndex) != L'?' && towupper(format.get(formatIndex)) != towupper(Jupiter::String_Type<wchar_t>::str[index])) return false;
formatIndex++;
index++;
}
return index == Jupiter::String_Type<wchar_t>::length;
}
template<typename T> bool Jupiter::String_Type<T>::matchi(const Jupiter::String_Type<T> &format) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
}
template<> bool inline Jupiter::String_Type<char>::matchi(const std::basic_string<char> &format) const
{
int fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == L'*')
{
formatIndex++;
while (format.at(formatIndex) == L'?')
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
formatIndex++;
index++;
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
fUpper = toupper(format.at(formatIndex));
while (fUpper != toupper(Jupiter::String_Type<char>::str[index]))
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
index++;
}
}
else if (format.at(formatIndex) != L'?' && toupper(format.at(formatIndex)) != toupper(Jupiter::String_Type<char>::str[index])) return false;
formatIndex++;
index++;
}
return index == Jupiter::String_Type<char>::length;
}
template<> bool inline Jupiter::String_Type<wchar_t>::matchi(const std::basic_string<wchar_t> &format) const
{
wint_t fUpper;
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != format.size())
{
if (format.at(formatIndex) == L'*')
{
formatIndex++;
while (format.at(formatIndex) == L'?')
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
formatIndex++;
index++;
}
if (format.at(formatIndex) == 0) return true;
if (format.at(formatIndex) == '*') continue;
fUpper = towupper(format.at(formatIndex));
while (fUpper != towupper(Jupiter::String_Type<wchar_t>::str[index]))
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
index++;
}
}
else if (format.at(formatIndex) != L'?' && towupper(format.at(formatIndex)) != towupper(Jupiter::String_Type<wchar_t>::str[index])) return false;
formatIndex++;
index++;
}
return index == Jupiter::String_Type<wchar_t>::length;
}
template<typename T> bool Jupiter::String_Type<T>::matchi(const std::basic_string<T> &format) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
}
template<> bool inline Jupiter::String_Type<char>::matchi(const char *format) const
{
int fUpper;
size_t index = 0;
while (*format != 0)
{
if (*format == '*')
{
format++;
while (*format == '?')
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
format++;
index++;
}
if (*format == 0) return true;
if (*format == '*') continue;
fUpper = toupper(*format);
while (fUpper != toupper(Jupiter::String_Type<char>::str[index]))
{
if (Jupiter::String_Type<char>::str[index] == 0) return false;
index++;
}
}
else if (*format != '?' && toupper(*format) != toupper(Jupiter::String_Type<char>::str[index])) return false;
format++;
index++;
}
return index == Jupiter::String_Type<char>::length;
}
template<> bool inline Jupiter::String_Type<wchar_t>::matchi(const wchar_t *format) const
{
wint_t fUpper;
size_t index = 0;
while (*format != 0)
{
if (*format == L'*')
{
format++;
while (*format == L'?')
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
format++;
index++;
}
if (*format == 0) return true;
if (*format == '*') continue;
fUpper = towupper(*format);
while (fUpper != towupper(Jupiter::String_Type<wchar_t>::str[index]))
{
if (Jupiter::String_Type<wchar_t>::str[index] == 0) return false;
index++;
}
}
else if (*format != L'?' && towupper(*format) != towupper(Jupiter::String_Type<wchar_t>::str[index])) return false;
format++;
index++;
}
return index == Jupiter::String_Type<wchar_t>::length;
}
template<typename T> bool Jupiter::String_Type<T>::matchi(const T *format) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
}
// wordCount()
template<typename T> unsigned int Jupiter::String_Type<T>::wordCount(const T *whitespace) const
{
unsigned int result = 0;
T *p = Jupiter::String_Type<T>::str;
bool prev = true;
while (*p != 0)
{
if (Jupiter::strpbrk<T>(whitespace, *p) == nullptr) // This isn't whitespace!
{
if (prev == true) // We just left whitespace!
{
prev = false;
result++;
}
}
else prev = true; // This is whitespace!
p++;
}
return result;
}
// as<type>
template<> unsigned int inline Jupiter::String_Type<char>::asUnsignedInt(int base) const
{
return strtoui_s(Jupiter::String_Type<char>::str, Jupiter::String_Type<char>::length, base);
}
template<typename T> unsigned int Jupiter::String_Type<T>::asUnsignedInt(int base) const
{
return 0;
}
template<> int inline Jupiter::String_Type<char>::asInt(int base) const
{
return strtoi_s(Jupiter::String_Type<char>::str, Jupiter::String_Type<char>::length, base);
}
template<typename T> int Jupiter::String_Type<T>::asInt(int base) const
{
return 0;
}
// Stream output
template<typename T> size_t Jupiter::String_Type<T>::print(FILE *out) const
{
return fwrite(Jupiter::String_Type<T>::str, sizeof(T), Jupiter::String_Type<T>::length, out);
}
template<> size_t inline Jupiter::String_Type<wchar_t>::print(FILE *out) const
{
size_t index = 0;
while (index != Jupiter::String_Type<wchar_t>::length && fputwc(Jupiter::String_Type<wchar_t>::str[index], out) != WEOF) index++;
return index;
}
template<typename T> size_t Jupiter::String_Type<T>::print(std::basic_ostream<T> &out) const
{
size_t index = 0;
while (index != Jupiter::String_Type<T>::length)
{
out << Jupiter::String_Type<T>::str[index];
index++;
}
return index;
}
template<typename T> size_t Jupiter::String_Type<T>::println(FILE *out) const
{
size_t r = Jupiter::String_Type<T>::print(out);
if (r != Jupiter::String_Type<T>::length) return r;
if (fputs("\r\n", out) != EOF) r += 2;
return r;
}
template<typename T> size_t Jupiter::String_Type<T>::println(std::basic_ostream<T> &out) const
{
size_t r = Jupiter::String_Type<T>::print(out);
if (r != Jupiter::String_Type<T>::length) return r;
out << std::endl;
return r;
}
// format forwards // format forwards
template<typename T> size_t Jupiter::String_Type<T>::format(const String_Type<T> &format, ...) template<typename T> size_t Jupiter::String_Type<T>::format(const String_Type<T> &format, ...)

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save