diff --git a/Jupiter/Jupiter.vcxproj b/Jupiter/Jupiter.vcxproj index b81cc9d..b32e5a2 100644 --- a/Jupiter/Jupiter.vcxproj +++ b/Jupiter/Jupiter.vcxproj @@ -134,6 +134,8 @@ + + diff --git a/Jupiter/Jupiter.vcxproj.filters b/Jupiter/Jupiter.vcxproj.filters index fe61b68..1a6b281 100644 --- a/Jupiter/Jupiter.vcxproj.filters +++ b/Jupiter/Jupiter.vcxproj.filters @@ -209,6 +209,12 @@ Header Files\Strings + + Header Files\Strings + + + Header Files\Strings + diff --git a/Jupiter/Reference_String.h b/Jupiter/Reference_String.h new file mode 100644 index 0000000..6d01b7f --- /dev/null +++ b/Jupiter/Reference_String.h @@ -0,0 +1,211 @@ +/** + * Copyright (C) 2013-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 + */ + +#if !defined _REFERENCE_STRING_H_HEADER +#define _REFERENCE_STRING_H_HEADER + +/** + * @file Reference_String.h + * @brief Provides the basis for String types, of any implementation. + * 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 "Readable_String.h" + +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 class Reference_String : public Jupiter::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. + */ + const T &get(size_t index) const; + + /** + * @brief Returns the number of elements in the String. + * + * @return Number of elements in the string. + */ + size_t size() const; + + /** + * @brief Returns a pointer to the underlying string of elements. + * + * @return Pointer to the underlying string of elements. + */ + const T *ptr() const; + + /** + * @brief Creates a partial copy of the string. + * + * @param pos Position in the string to start copying from. + * @return String containing a partial copy of the original string. + */ + Reference_String substring(size_t pos) const; + + /** + * @brief Creates a partial copy of the string. + * + * @param pos Position in the string to start copying from. + * @param length Number of characters to copy. + * @return String containing a partial copy of the original string. + */ + Reference_String substring(size_t pos, size_t length) const; + + /** + * @brief Creates a partial copy of the string. + * + * @param in String to get a partial copy of. + * @param pos Position in the string to start copying from. + * @return String containing a partial copy of the original string. + */ + static Reference_String substring(const Jupiter::Readable_String &in, size_t pos); + static Reference_String substring(const T *in, size_t pos); + + /** + * @brief Creates a partial copy of the string. + * + * @param in String to get a partial copy of. + * @param pos Position in the string to start copying from. + * @param length Number of characters to copy. + * @return String containing a partial copy of the original string. + */ + static Reference_String substring(const Jupiter::Readable_String &in, size_t pos, size_t length); + static Reference_String substring(const T *in, size_t pos, size_t length); + + /** + * @brief Creates a partial copy of the string, based on a set of tokens. + * + * @param pos Position of word in the string to start copying from. + * @param whitespace A string of tokens used to deliminate words. + * @return String containing a partial copy of the original string. + */ + Reference_String getWord(size_t pos, const T *whitespace) const; + + /** + * @brief Creates a partial copy of an input string, based on a set of tokens. + * + * @param in String to get a partial copy of. + * @param pos Position of word in the string to start copying from. + * @param whitespace A string of tokens used to deliminate words. + * @return String containing a partial copy of the original string. + */ + static Reference_String getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); + + /** + * @brief Creates a partial copy of an input string, based on a set of tokens. + * + * @param in C-Style string to get a partial copy of. + * @param pos Position of word in the string to start copying from. + * @param whitespace A string of tokens used to deliminate words. + * @return String containing a partial copy of the original string. + */ + static Reference_String getWord(const T *in, size_t pos, const T *whitespace); + + /** + * @brief Creates a partial copy of the string, based on a set of tokens. + * + * @param pos Position in the string to start copying from. + * @param whitespace A string of tokens used to deliminate words. + * @return String containing a partial copy of the original string. + */ + Reference_String gotoWord(size_t pos, const T *whitespace) const; + + /** + * @brief Creates a partial copy of the string, based on a set of tokens. + * + * @param in String to get a partial copy of. + * @param pos Position in the string to start copying from. + * @param whitespace A string of tokens used to deliminate words. + * @return String containing a partial copy of the original string. + */ + static Reference_String gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace); + + /** + * @brief Creates a partial copy of the string, based on a set of tokens. + * + * @param in C-Style string to get a partial copy of. + * @param pos Position in the string to start copying from. + * @param whitespace A string of tokens used to deliminate words. + * @return String containing a partial copy of the original string. + */ + static Reference_String gotoWord(const T *in, size_t pos, const T *whitespace); + + /** + * @brief Default constructor for the Reference_String class. + */ + Reference_String(); + + /** + * @brief Creates a reference to a C-Style string. + * + * @param in String to get a reference of. + */ + Reference_String(const T *in); + + /** + * @brief Creates a reference to a string. + * + * @param in String to get a reference of. + * @param len Length of the string to track. + */ + Reference_String(const T *in, size_t len); + + /** + * @brief Move constructor for the Reference_String class. + */ + Reference_String(Jupiter::Reference_String &&source); + + /** + * @brief Constructor for the Refererence_String class to create a reference to an existing string. + */ + Reference_String(const Jupiter::Readable_String &in); + + /** + * @brief Copy constructor for the Reference_String class. + */ + Reference_String(const Jupiter::Reference_String &in); + + protected: + + const T *str; /** Pointer for the underlying string of elements */ + size_t length; /** Number of representable elements in the string */ + }; + + /** Generic Reference String Type */ + typedef Reference_String ReferenceString; + + /** Generic Wide Reference String Type */ + typedef Reference_String ReferenceWString; + +} + +#include "Reference_String_Imp.h" + +#endif // _REFERENCE_STRING_H_HEADER \ No newline at end of file diff --git a/Jupiter/Reference_String_Imp.h b/Jupiter/Reference_String_Imp.h new file mode 100644 index 0000000..5ee158a --- /dev/null +++ b/Jupiter/Reference_String_Imp.h @@ -0,0 +1,146 @@ +/** + * 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 + */ + +#if !defined _REFERENCE_STRING_IMP_H_HEADER +#define _REFERENCE_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 "Reference_String.h" +#include "Functions.h" + +/** +* IMPLEMENTATION: +* Reference_String +*/ + +template Jupiter::Reference_String::Reference_String() +{ + Jupiter::Reference_String::str = ""; + Jupiter::Reference_String::length = 0; +} + +template Jupiter::Reference_String::Reference_String(const T *in) +{ + Jupiter::Reference_String::str = in; + Jupiter::Reference_String::length = Jupiter::strlen(in); +} + +template Jupiter::Reference_String::Reference_String(const T *in, size_t len) +{ + Jupiter::Reference_String::str = in; + Jupiter::Reference_String::length = len; +} + +template Jupiter::Reference_String::Reference_String(Jupiter::Reference_String &&source) +{ + Jupiter::Reference_String::str = source.str; + Jupiter::Reference_String::length = source.length; + source.length = 0; + source.str = ""; +} + +template Jupiter::Reference_String::Reference_String(const Jupiter::Readable_String &in) : Reference_String(in.ptr(), in.size()) +{ +} + +template Jupiter::Reference_String::Reference_String(const Jupiter::Reference_String &in) : Reference_String(in.str, in.length) +{ +} + +template const T &Jupiter::Reference_String::get(size_t index) const +{ + return Jupiter::Reference_String::str[index]; +} + +template size_t Jupiter::Reference_String::size() const +{ + return Jupiter::Reference_String::length; +} + +template const T *Jupiter::Reference_String::ptr() const +{ + return Jupiter::Reference_String::str; +} + +template Jupiter::Reference_String Jupiter::Reference_String::substring(size_t pos) const +{ + return Jupiter::Reference_String::substring(*this, pos); +} + +template Jupiter::Reference_String Jupiter::Reference_String::substring(size_t pos, size_t len) const +{ + return Jupiter::Reference_String::substring(*this, pos, len); +} + +template Jupiter::Reference_String Jupiter::Reference_String::substring(const Jupiter::Readable_String &in, size_t pos) +{ + if (pos > in.size()) pos = in.size(); + return Jupiter::Reference_String(in.ptr() + pos, in.size() - pos); +} + +template Jupiter::Reference_String Jupiter::Reference_String::substring(const T *in, size_t pos) +{ + return Jupiter::Reference_String(in + pos); +} + +template Jupiter::Reference_String Jupiter::Reference_String::substring(const Jupiter::Readable_String &in, size_t pos, size_t len) +{ + if (pos + len > in.size()) return Jupiter::Reference_String::substring(in, pos); + return Jupiter::Reference_String(in.ptr() + pos, len); +} + +template Jupiter::Reference_String Jupiter::Reference_String::substring(const T *in, size_t pos, size_t len) +{ + return Jupiter::Reference_String(in + pos, len); +} + +template Jupiter::Reference_String Jupiter::Reference_String::getWord(size_t pos, const T *whitespace) const +{ + return Jupiter::Reference_String::getWord(*this, pos, whitespace); +} + +template Jupiter::Reference_String Jupiter::Reference_String::getWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) +{ + return Jupiter::Readable_String::getWord(in, pos, whitespace); +} + +template Jupiter::Reference_String Jupiter::Reference_String::getWord(const T *in, size_t pos, const T *whitespace) +{ + return Jupiter::Readable_String::getWord(in, pos, whitespace); +} + +template Jupiter::Reference_String Jupiter::Reference_String::gotoWord(size_t pos, const T *whitespace) const +{ + return Jupiter::Reference_String::gotoWord(*this, pos, whitespace); +} + +template Jupiter::Reference_String Jupiter::Reference_String::gotoWord(const Jupiter::Readable_String &in, size_t pos, const T *whitespace) +{ + return Jupiter::Readable_String::gotoWord(in, pos, whitespace); +} + +template Jupiter::Reference_String Jupiter::Reference_String::gotoWord(const T *in, size_t pos, const T *whitespace) +{ + return Jupiter::Readable_String::gotoWord(in, pos, whitespace); +} + +#endif // _REFERENCE_STRING_IMP \ No newline at end of file diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index 086217a..e741f72 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ