mirror of https://github.com/JAJames/Jupiter.git
Jessica James
3 years ago
36 changed files with 277 additions and 2053 deletions
@ -1,61 +0,0 @@ |
|||
/**
|
|||
* Copyright (C) 2014-2015 Jessica James. |
|||
* |
|||
* Permission to use, copy, modify, and/or distribute this software for any |
|||
* purpose with or without fee is hereby granted, provided that the above |
|||
* copyright notice and this permission notice appear in all copies. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
* |
|||
* Written by Jessica James <jessica.aj@outlook.com> |
|||
*/ |
|||
|
|||
#if !defined _INVALIDINDEX_H_HEADER |
|||
#define _INVALIDINDEX_H_HEADER |
|||
|
|||
/**
|
|||
* @file InvalidIndex.h |
|||
* @brief Defines some constants for invalid indexes for unsigned types. |
|||
*/ |
|||
|
|||
#if defined __cplusplus |
|||
#include <cstdint> |
|||
#include <climits> |
|||
|
|||
namespace Jupiter |
|||
{ |
|||
static const size_t INVALID_INDEX = SIZE_MAX; |
|||
static const uint32_t INVALID_INDEX32 = UINT32_MAX; |
|||
static const uint64_t INVALID_INDEX64 = UINT64_MAX; |
|||
|
|||
static const unsigned int ERROR_INDICATOR = UINT_MAX; |
|||
static const uint32_t ERROR_INDICATOR32 = INVALID_INDEX32; |
|||
static const uint64_t ERROR_INDICATOR64 = INVALID_INDEX32; |
|||
} |
|||
|
|||
extern "C" |
|||
{ |
|||
#else |
|||
#include <stdint.h> |
|||
#include <limits.h> |
|||
#endif // __cplusplus
|
|||
|
|||
static const size_t JUPITER_INVALID_INDEX = SIZE_MAX; |
|||
static const uint32_t JUPITER_INVALID_INDEX32 = UINT32_MAX; |
|||
static const uint64_t JUPITER_INVALID_INDEX64 = UINT64_MAX; |
|||
|
|||
static const unsigned int JUPITER_ERROR_INDICATOR = UINT_MAX; |
|||
static const uint32_t JUPITER_ERROR_INDICATOR32 = JUPITER_INVALID_INDEX32; |
|||
static const uint64_t JUPITER_ERROR_INDICATOR64 = JUPITER_INVALID_INDEX32; |
|||
|
|||
#if defined __cplusplus |
|||
} |
|||
#endif // __cplusplus
|
|||
|
|||
#endif // _INVALIDINDEX_H_HEADER
|
@ -1,45 +0,0 @@ |
|||
/**
|
|||
* Copyright (C) 2014-2017 Jessica James. |
|||
* |
|||
* Permission to use, copy, modify, and/or distribute this software for any |
|||
* purpose with or without fee is hereby granted, provided that the above |
|||
* copyright notice and this permission notice appear in all copies. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
* |
|||
* Written by Jessica James <jessica.aj@outlook.com> |
|||
*/ |
|||
|
|||
#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: DEPRECATED |
|||
*/ |
|||
|
|||
#include <string_view> |
|||
#include "Readable_String.h" |
|||
|
|||
namespace Jupiter { |
|||
/** DEPRECATED: Generic Reference String Type */ |
|||
using ReferenceString = std::string_view; |
|||
|
|||
namespace literals { |
|||
/** DEPRECATED: Reference_String literals */ |
|||
inline constexpr std::string_view operator"" _jrs(const char *str, size_t len) { return { str, len }; } |
|||
} |
|||
} |
|||
|
|||
/** DEPRECATED */ |
|||
#define STRING_LITERAL_AS_REFERENCE(str) Jupiter::literals::operator"" _jrs(str, sizeof(str) - 1) |
|||
#define STRING_LITERAL_AS_NAMED_REFERENCE(name, str) Jupiter::ReferenceString name = STRING_LITERAL_AS_REFERENCE(str) |
|||
|
|||
#endif // _REFERENCE_STRING_H_HEADER
|
@ -1,114 +0,0 @@ |
|||
/**
|
|||
* Copyright (C) 2014-2015 Jessica James. |
|||
* |
|||
* Permission to use, copy, modify, and/or distribute this software for any |
|||
* purpose with or without fee is hereby granted, provided that the above |
|||
* copyright notice and this permission notice appear in all copies. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
* |
|||
* Written by Jessica James <jessica.aj@outlook.com> |
|||
*/ |
|||
|
|||
#if !defined _SHIFT_STRING_H_HEADER |
|||
#define _SHIFT_STRING_H_HEADER |
|||
|
|||
/**
|
|||
* @file Shift_String.h |
|||
* @brief Allows for separation of a string's representation from its memory base. |
|||
*/ |
|||
|
|||
#include "String_Type.h" |
|||
|
|||
/** Disable warning 4458 */ |
|||
#if defined _MSC_VER |
|||
#pragma warning(push) |
|||
#pragma warning(disable: 4458) // declaration of 'length' hides class member
|
|||
#endif |
|||
|
|||
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 Shift_String_Type : public Jupiter::String_Type<T> |
|||
{ |
|||
public: |
|||
|
|||
/**
|
|||
* @brief Removes the first instance of an element from the string. |
|||
* |
|||
* @param value Value of the element to remove. |
|||
* @return True if an element was removed, false otherwise. |
|||
*/ |
|||
virtual bool remove(const T &value) override; |
|||
|
|||
/**
|
|||
* @brief Removes a number of elements starting at an index. |
|||
* |
|||
* @param index Index to start removing elements at. |
|||
* @param length Number of elements to remove. |
|||
*/ |
|||
virtual void remove(size_t index, size_t length) override; |
|||
|
|||
/**
|
|||
* @brief Removes all elements from the string. |
|||
*/ |
|||
void clear() override; |
|||
|
|||
/**
|
|||
* @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. |
|||
* |
|||
* @param len Minimum number of elements the string buffer must be able to hold. |
|||
* @return True if a new buffer was allocated, false otherwise. |
|||
*/ |
|||
virtual bool setBufferSize(size_t len) override; |
|||
|
|||
/**
|
|||
* @brief Empties the string, and sets the internal buffer to be at least large enough to old a specified number of elements. |
|||
* Note: This still empties the string if len is less than the string's current length. |
|||
* |
|||
* @param len Minimum number of elements the string buffer must be able to hold. |
|||
* @return True if a new buffer was allocated, false otherwise. |
|||
*/ |
|||
virtual bool setBufferSizeNoCopy(size_t len) override; |
|||
|
|||
/**
|
|||
* @brief Default constructor for the Shift_String_Type class. |
|||
*/ |
|||
Shift_String_Type() {} |
|||
|
|||
/**
|
|||
* @brief Move constructor for the Shift_String_Type class. |
|||
*/ |
|||
Shift_String_Type(Jupiter::Shift_String_Type<T> &&source); |
|||
|
|||
/**
|
|||
* @brief Destructor for the Shift_String_Type class. |
|||
*/ |
|||
virtual ~Shift_String_Type(); |
|||
|
|||
protected: |
|||
T *base{ nullptr }; /** Base pointer for the underlying String's memory allocation */ |
|||
}; |
|||
} |
|||
|
|||
/** Re-enable warning */ |
|||
#if defined _MSC_VER |
|||
#pragma warning(pop) |
|||
#endif |
|||
|
|||
#include "Shift_String_Imp.h" |
|||
|
|||
#endif // _SHIFT_STRING_H_HEADER
|
@ -1,102 +0,0 @@ |
|||
/**
|
|||
* Copyright (C) 2014-2015 Jessica James. |
|||
* |
|||
* Permission to use, copy, modify, and/or distribute this software for any |
|||
* purpose with or without fee is hereby granted, provided that the above |
|||
* copyright notice and this permission notice appear in all copies. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
* |
|||
* Written by Jessica James <jessica.aj@outlook.com> |
|||
*/ |
|||
|
|||
#if !defined _SHIFT_STRING_IMP_H_HEADER |
|||
#define _SHIFT_STRING_IMP_H_HEADER |
|||
|
|||
/**
|
|||
* @file Shift_String_Imp.h |
|||
* @brief Provides the implementations for Shift_String_Type functions. |
|||
* Note: Modification of this file is not supported in any way. |
|||
*/ |
|||
|
|||
template<typename T> Jupiter::Shift_String_Type<T>::Shift_String_Type(Jupiter::Shift_String_Type<T> &&source) : Jupiter::String_Type<T>(std::move(source)) |
|||
{ |
|||
Jupiter::Shift_String_Type<T>::base = source.base; |
|||
source.base = nullptr; |
|||
} |
|||
|
|||
template<typename T> Jupiter::Shift_String_Type<T>::~Shift_String_Type() |
|||
{ |
|||
if (Jupiter::Shift_String_Type<T>::base != nullptr) delete[] Jupiter::Shift_String_Type<T>::base; |
|||
} |
|||
|
|||
template<typename T> bool Jupiter::Shift_String_Type<T>::remove(const T &value) |
|||
{ |
|||
if (Jupiter::String_Type<T>::length == 0) return false; |
|||
if (*Jupiter::String_Type<T>::str == value) |
|||
{ |
|||
if (Jupiter::String_Type<T>::length == 1) this->truncate(1); |
|||
else { |
|||
++Jupiter::String_Type<T>::str; |
|||
--Jupiter::String_Type<T>::length; |
|||
} |
|||
return true; |
|||
} |
|||
return Jupiter::String_Type<T>::remove(value); |
|||
} |
|||
|
|||
template<typename T> void Jupiter::Shift_String_Type<T>::remove(size_t index, size_t len) |
|||
{ |
|||
Jupiter::String_Type<T>::remove(index, len); |
|||
} |
|||
|
|||
template<typename T> void Jupiter::Shift_String_Type<T>::clear() |
|||
{ |
|||
Jupiter::String_Type<T>::clear(); |
|||
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; |
|||
} |
|||
|
|||
template<typename T> bool Jupiter::Shift_String_Type<T>::setBufferSize(size_t len) |
|||
{ |
|||
if (len > Jupiter::String_Type<T>::length) |
|||
{ |
|||
T *ptr = new T[len]; |
|||
for (unsigned int i = 0; i < Jupiter::String_Type<T>::length; i++) ptr[i] = Jupiter::String_Type<T>::str[i]; |
|||
delete[] Jupiter::Shift_String_Type<T>::base; |
|||
Jupiter::Shift_String_Type<T>::base = ptr; |
|||
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
template<typename T> bool Jupiter::Shift_String_Type<T>::setBufferSizeNoCopy(size_t len) |
|||
{ |
|||
if (len > Jupiter::String_Type<T>::length) |
|||
{ |
|||
Jupiter::String_Type<T>::length = 0; |
|||
delete[] Jupiter::Shift_String_Type<T>::base; |
|||
Jupiter::Shift_String_Type<T>::base = new T[len]; |
|||
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; |
|||
return true; |
|||
} |
|||
Jupiter::String_Type<T>::length = 0; |
|||
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; |
|||
return false; |
|||
} |
|||
|
|||
// Jupiter::DataBuffer specialization
|
|||
|
|||
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Shift_String_Type> { |
|||
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::Shift_String_Type<Y> *data) { |
|||
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Type>::push<Y>(buffer, data); |
|||
}; |
|||
}; |
|||
|
|||
#endif // _SHIFT_STRING_IMP_H_HEADER
|
@ -1,185 +0,0 @@ |
|||
/**
|
|||
* Copyright (C) 2013-2017 Jessica James. |
|||
* |
|||
* Permission to use, copy, modify, and/or distribute this software for any |
|||
* purpose with or without fee is hereby granted, provided that the above |
|||
* copyright notice and this permission notice appear in all copies. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
* |
|||
* Written by Jessica James <jessica.aj@outlook.com> |
|||
*/ |
|||
|
|||
#if !defined _STRING_H_HEADER |
|||
#define _STRING_H_HEADER |
|||
|
|||
/**
|
|||
* @file String.h |
|||
* @brief Defines the base String_Base, as well as a series of String types. |
|||
* Note: Functions which take "case" or "wildcards" into consideration will only function |
|||
* for types char and wchar_t; inputs with other types will simply return false. |
|||
*/ |
|||
|
|||
#include "Shift_String.h" |
|||
#include "Hash.h" |
|||
|
|||
/** Disable warning 4458 */ |
|||
#if defined _MSC_VER |
|||
#pragma warning(push) |
|||
#pragma warning(disable: 4458) // declaration of 'length' hides class member
|
|||
#endif |
|||
|
|||
namespace Jupiter |
|||
{ |
|||
|
|||
/**
|
|||
* @brief Provides a minimal String implementation (i.e: no extra variables). |
|||
* |
|||
* @param T Element type which the String will store. Defaults to char. |
|||
*/ |
|||
template<typename T = char> class String_Strict : public Shift_String_Type<T> |
|||
{ |
|||
public: |
|||
|
|||
/**
|
|||
* @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. |
|||
*/ |
|||
typename Jupiter::template String_Strict<T> 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. |
|||
*/ |
|||
typename Jupiter::template String_Strict<T> 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 typename Jupiter::template String_Strict<T> substring(const Jupiter::Readable_String<T> &in, size_t pos); |
|||
static typename Jupiter::template String_Strict<T> 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 typename Jupiter::template String_Strict<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length); |
|||
static typename Jupiter::template String_Strict<T> substring(const T *in, size_t pos, size_t length); |
|||
|
|||
/** Default Constructor */ |
|||
String_Strict(); |
|||
|
|||
/**
|
|||
* @brief Size hint constructor. |
|||
* Note: For the String_Strict base class, this is only truly useful internally. |
|||
* |
|||
* @param size Minimum number of elements the string must be able to hold. |
|||
*/ |
|||
String_Strict(size_t size); |
|||
|
|||
/** Move Constructor */ |
|||
String_Strict(String_Strict<T> &&source); |
|||
|
|||
/** Copy Constructors */ |
|||
String_Strict(const String_Strict<T> &in); |
|||
String_Strict(const Readable_String<T> &in); |
|||
String_Strict(const std::basic_string<T> &in); |
|||
String_Strict(const T *in, size_t len); |
|||
String_Strict(const T *in); |
|||
String_Strict(const Jupiter::DataBuffer &in); |
|||
|
|||
/** Concatenation Constructors */ |
|||
String_Strict(const Readable_String<T> &lhs, const T &rhs); |
|||
String_Strict(const Readable_String<T> &lhs, const Readable_String<T> &rhs); |
|||
String_Strict(const Readable_String<T> &lhs, const std::basic_string<T> &rhs); |
|||
String_Strict(const Readable_String<T> &lhs, const T *rhs); |
|||
String_Strict(const Readable_String<T> &lhs, const T *rhs, size_t rhs_size); |
|||
|
|||
/** Addition Operators */ |
|||
inline String_Strict<T> operator+(const T &rhs) const; |
|||
inline String_Strict<T> operator+(const String_Strict<T> &rhs) const; |
|||
inline String_Strict<T> operator+(const Readable_String<T> &rhs) const; |
|||
inline String_Strict<T> operator+(const std::basic_string<T> &rhs) const; |
|||
inline String_Strict<T> operator+(const T *rhs) const; |
|||
|
|||
/** Assignment Operators */ |
|||
inline String_Strict<T> &operator=(const String_Strict<T> &right) { this->set(right); return *this; }; |
|||
inline String_Strict<T> &operator=(const Readable_String<T> &right) { this->set(right); return *this; }; |
|||
inline String_Strict<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; }; |
|||
inline String_Strict<T> &operator=(const T *right) { this->set(right); return *this; }; |
|||
inline String_Strict<T> &operator=(const T right) { this->set(right); return *this; }; |
|||
}; |
|||
|
|||
/** String_Strict<T> Addition Operators */ |
|||
template<typename T> static inline Jupiter::String_Strict<T> operator+(const Jupiter::String_Type<T> &lhs, const Jupiter::String_Type<T> &rhs); |
|||
template<typename T> static inline Jupiter::String_Strict<T> operator+(const Jupiter::String_Type<T> &lhs, const T &rhs); |
|||
template<typename T> static inline Jupiter::String_Strict<T> operator+(const Jupiter::String_Type<T> &lhs, const Jupiter::String_Type<T> &rhs); |
|||
template<typename T> static inline Jupiter::String_Strict<T> operator+(const Jupiter::String_Type<T> &lhs, const std::basic_string<T> &rhs); |
|||
template<typename T> static inline Jupiter::String_Strict<T> operator+(const Jupiter::String_Type<T> &lhs, const std::basic_string_view<T> &rhs); |
|||
template<typename T> static inline Jupiter::String_Strict<T> operator+(const Jupiter::String_Type<T> &lhs, const T *rhs); |
|||
|
|||
/** Definition of a Strict String. */ |
|||
typedef String_Strict<char> StringS; |
|||
|
|||
/** Definition of a Loose String. */ |
|||
typedef String_Strict<char> StringL; |
|||
|
|||
/** Definition of a String. */ |
|||
typedef StringS String; |
|||
|
|||
namespace literals { |
|||
/** String_Strict literals */ |
|||
inline Jupiter::StringS operator""_jss(const char *str, size_t len) { return Jupiter::StringS(str, len); } |
|||
} |
|||
|
|||
template<typename CharT> |
|||
struct str_hash { |
|||
using is_transparent = std::true_type; |
|||
|
|||
// C++17 introduces a requirement that these two operators return the same values for same CharT type, but not
|
|||
// any requirement that std::hash<> be able to accept both key types. This just ties them for convenience
|
|||
auto operator()(std::basic_string_view<CharT> in_key) const noexcept { |
|||
return std::hash<std::basic_string_view<CharT>>()(in_key); |
|||
} |
|||
|
|||
auto operator()(const std::basic_string<CharT>& in_key) const noexcept { |
|||
return std::hash<std::basic_string<CharT>>()(in_key); |
|||
} |
|||
|
|||
// DEPRECATED:
|
|||
auto operator()(const String_Type<CharT>& in_key) const noexcept { |
|||
return operator()(static_cast<std::basic_string_view<CharT>>(in_key)); |
|||
} |
|||
}; |
|||
|
|||
using default_hash_function = str_hash<char>; |
|||
} |
|||
|
|||
/** Re-enable warning */ |
|||
#if defined _MSC_VER |
|||
#pragma warning(pop) |
|||
#endif |
|||
|
|||
/** Implementation for String_Strict and String_Loose. Very scary. */ |
|||
#include "String_Imp.h" |
|||
|
|||
#endif // _STRING_H_HEADER
|
@ -1,250 +0,0 @@ |
|||
/**
|
|||
* Copyright (C) 2013-2017 Jessica James. |
|||
* |
|||
* Permission to use, copy, modify, and/or distribute this software for any |
|||
* purpose with or without fee is hereby granted, provided that the above |
|||
* copyright notice and this permission notice appear in all copies. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
* |
|||
* Written by Jessica James <jessica.aj@outlook.com> |
|||
*/ |
|||
|
|||
#if !defined _STRING_IMP_H_HEADER |
|||
#define _STRING_IMP_H_HEADER |
|||
|
|||
/**
|
|||
* @file String_Imp.h |
|||
* @brief Provides the implementations for String_Strict and String_Loose. |
|||
*/ |
|||
|
|||
#include "String.hpp" |
|||
|
|||
/**
|
|||
* IMPLEMENTATION: |
|||
* String_Strict |
|||
*/ |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict() |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(size_t len) |
|||
{ |
|||
Jupiter::Shift_String_Type<T>::base = new T[len]; |
|||
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; |
|||
Jupiter::String_Type<T>::length = 0; |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(Jupiter::String_Strict<T> &&source) : Jupiter::Shift_String_Type<T>(std::move(source)) |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::String_Strict<T> &in) : Jupiter::String_Strict<T>::String_Strict( |
|||
in.data(), in.size()) |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &in) : Jupiter::String_Strict<T>::String_Strict( |
|||
in.data(), in.size()) |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const std::basic_string<T> &in) : Jupiter::String_Strict<T>::String_Strict(in.data(), in.size()) |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const T *in, size_t len) : Jupiter::String_Strict<T>::String_Strict(len) |
|||
{ |
|||
while (Jupiter::String_Type<T>::length != len) |
|||
{ |
|||
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = *in; |
|||
Jupiter::String_Type<T>::length++; |
|||
in++; |
|||
} |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const T *in) |
|||
{ |
|||
if (in == nullptr) Jupiter::String_Type<T>::length = 0; |
|||
else Jupiter::String_Type<T>::length = Jupiter::strlen<T>(in); |
|||
|
|||
Jupiter::Shift_String_Type<T>::base = new T[Jupiter::String_Type<T>::length]; |
|||
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; |
|||
for (size_t index = 0; index != Jupiter::String_Type<T>::length; index++, in++) Jupiter::String_Type<T>::str[index] = *in; |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::DataBuffer &in) : String_Strict(reinterpret_cast<T *>(in.getHead()), in.size() / sizeof(T)) |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &lhs, const T &rhs) : String_Strict<T>(lhs.size() + 1) |
|||
{ |
|||
const T *itr; |
|||
const T *end; |
|||
|
|||
if (!lhs.empty()) |
|||
{ |
|||
itr = lhs.data(); |
|||
end = itr + lhs.size(); |
|||
*Jupiter::String_Type<T>::str = *itr; |
|||
while (++itr != end) |
|||
*++Jupiter::String_Type<T>::str = *itr; |
|||
++Jupiter::String_Type<T>::str; |
|||
} |
|||
|
|||
*Jupiter::String_Type<T>::str = rhs; |
|||
|
|||
Jupiter::String_Type<T>::length = Jupiter::String_Type<T>::str - Jupiter::Shift_String_Type<T>::base + 1; |
|||
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &rhs) : String_Strict<T>(lhs, |
|||
rhs.data(), rhs.size()) |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &lhs, const std::basic_string<T> &rhs) : String_Strict<T>(lhs, rhs.data(), rhs.size()) |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &lhs, const T *rhs) : String_Strict<T>(lhs, rhs, Jupiter::strlen<T>(rhs)) |
|||
{ |
|||
} |
|||
|
|||
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &lhs, const T *rhs, size_t rhs_size) : String_Strict<T>(lhs.size() + rhs_size) |
|||
{ |
|||
const T *itr; |
|||
const T *end; |
|||
|
|||
if (!lhs.empty()) |
|||
{ |
|||
itr = lhs.data(); |
|||
end = itr + lhs.size(); |
|||
*Jupiter::String_Type<T>::str = *itr; |
|||
while (++itr != end) |
|||
*++Jupiter::String_Type<T>::str = *itr; |
|||
++Jupiter::String_Type<T>::str; |
|||
} |
|||
|
|||
if (rhs_size != 0) |
|||
{ |
|||
itr = rhs; |
|||
end = itr + rhs_size; |
|||
*Jupiter::String_Type<T>::str = *itr; |
|||
while (++itr != end) |
|||
*++Jupiter::String_Type<T>::str = *itr; |
|||
++Jupiter::String_Type<T>::str; |
|||
} |
|||
|
|||
Jupiter::String_Type<T>::length = Jupiter::String_Type<T>::str - Jupiter::Shift_String_Type<T>::base; |
|||
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; |
|||
} |
|||
|
|||
template<typename T> typename Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(size_t pos) const |
|||
{ |
|||
return Jupiter::String_Strict<T>::substring(*this, pos); |
|||
} |
|||
|
|||
template<typename T> typename Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(size_t pos, size_t len) const |
|||
{ |
|||
return Jupiter::String_Strict<T>::substring(*this, pos, len); |
|||
} |
|||
|
|||
template<typename T> typename Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos) |
|||
{ |
|||
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Strict>(in, pos); |
|||
} |
|||
|
|||
template<typename T> typename Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(const T *in, size_t pos) |
|||
{ |
|||
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Strict>(in, pos); |
|||
} |
|||
|
|||
template<typename T> typename Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len) |
|||
{ |
|||
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Strict>(in, pos, len); |
|||
} |
|||
|
|||
template<typename T> typename Jupiter::String_Strict<T> Jupiter::String_Strict<T>::substring(const T *in, size_t pos, size_t len) |
|||
{ |
|||
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Strict>(in, pos, len); |
|||
} |
|||
|
|||
// Operators
|
|||
|
|||
template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>::operator+(const T &rhs) const |
|||
{ |
|||
return Jupiter::operator+(*this, rhs); |
|||
} |
|||
|
|||
template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>::operator+(const Jupiter::String_Strict<T> &rhs) const |
|||
{ |
|||
return Jupiter::String_Strict<T>::operator+(reinterpret_cast<const Jupiter::Readable_String<T> &>(rhs)); |
|||
} |
|||
|
|||
template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>::operator+(const Jupiter::Readable_String<T> &rhs) const |
|||
{ |
|||
return Jupiter::operator+(*this, rhs); |
|||
} |
|||
|
|||
template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>::operator+(const std::basic_string<T> &rhs) const |
|||
{ |
|||
return Jupiter::operator+(*this, rhs); |
|||
} |
|||
|
|||
template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>::operator+(const T *rhs) const |
|||
{ |
|||
return Jupiter::operator+(*this, rhs); |
|||
} |
|||
|
|||
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::String_Type<T> &lhs, const T &rhs) |
|||
{ |
|||
return Jupiter::String_Strict<T>(lhs, rhs); |
|||
} |
|||
|
|||
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::String_Type<T> &lhs, const Jupiter::String_Type<T> &rhs) |
|||
{ |
|||
return Jupiter::String_Strict<T>(lhs, rhs); |
|||
} |
|||
|
|||
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::String_Type<T> &lhs, const std::basic_string<T> &rhs) |
|||
{ |
|||
return Jupiter::String_Strict<T>(lhs, rhs); |
|||
} |
|||
|
|||
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::String_Type<T> &lhs, const std::basic_string_view<T> &rhs) |
|||
{ |
|||
return Jupiter::String_Strict<T>(lhs, rhs); |
|||
} |
|||
|
|||
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::String_Type<T> &lhs, const T *rhs) |
|||
{ |
|||
return Jupiter::String_Strict<T>(lhs, rhs); |
|||
} |
|||
|
|||
// Jupiter::DataBuffer specialization
|
|||
|
|||
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Strict> |
|||
{ |
|||
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Strict<Y> *data) { |
|||
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Type>::push<Y>(buffer, data); |
|||
}; |
|||
|
|||
template<typename Y> static Jupiter::String_Strict<Y> interpret(uint8_t *&head) |
|||
{ |
|||
size_t size_ = *reinterpret_cast<size_t *>(head); |
|||
head += sizeof(size_t); |
|||
Jupiter::String_Strict<Y> r = Jupiter::String_Strict<Y>(reinterpret_cast<Y *>(head), size_); |
|||
head += size_; |
|||
return r; |
|||
} |
|||
}; |
|||
|
|||
#endif // _STRING_IMP_H_HEADER
|
@ -1,326 +0,0 @@ |
|||
/**
|
|||
* Copyright (C) 2013-2015 Jessica James. |
|||
* |
|||
* Permission to use, copy, modify, and/or distribute this software for any |
|||
* purpose with or without fee is hereby granted, provided that the above |
|||
* copyright notice and this permission notice appear in all copies. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
* |
|||
* Written by Jessica James <jessica.aj@outlook.com> |
|||
*/ |
|||
|
|||
#if !defined _STRING_TYPE_H_HEADER |
|||
#define _STRING_TYPE_H_HEADER |
|||
|
|||
/**
|
|||
* @file String_Type.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 <cstdarg> // va_list |
|||
#include "Readable_String.h" |
|||
|
|||
/** Disable warning 4458 */ |
|||
#if defined _MSC_VER |
|||
#pragma warning(push) |
|||
#pragma warning(disable: 4458) // declaration of 'length' hides class member
|
|||
#endif |
|||
|
|||
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 String_Type |
|||
{ |
|||
public: |
|||
|
|||
/**
|
|||
* @brief Returns the number of elements in the String. |
|||
* |
|||
* @return Number of elements in the string. |
|||
*/ |
|||
size_t size() const; |
|||
|
|||
/**
|
|||
* @brief Returns the maximum number of elements the String can contain, |
|||
* without expanding the socket buffer. This is generally the size of the |
|||
* underlying memory buffer. |
|||
* |
|||
* @return Number of elements the string can contain without reallocation. |
|||
*/ |
|||
virtual size_t capacity() const; |
|||
|
|||
/**
|
|||
* @brief Returns a pointer to the underlying string of elements. |
|||
* |
|||
* @return Pointer to the underlying string of elements. |
|||
*/ |
|||
const T *data() const; |
|||
|
|||
/**
|
|||
* @brief Truncates the string by a specified number of elements. |
|||
* |
|||
* @param n Number of elements to remove from the tail. |
|||
* @return New size of the String. |
|||
*/ |
|||
virtual size_t truncate(size_t n); |
|||
|
|||
/**
|
|||
* @brief Removes the first instance of an element from the string. |
|||
* |
|||
* @param value Value of the element to remove. |
|||
* @return True if an element was removed, false otherwise. |
|||
*/ |
|||
virtual bool remove(const T &value); |
|||
|
|||
/**
|
|||
* @brief Removes a number of elements starting at an index. |
|||
* |
|||
* @param index Index to start removing elements at. |
|||
* @param length Number of elements to remove. |
|||
*/ |
|||
virtual void remove(size_t index, size_t length); |
|||
|
|||
/**
|
|||
* @brief Removes all elements from the string. |
|||
*/ |
|||
virtual void clear(); |
|||
|
|||
/**
|
|||
* @brief Sets the value of an element at the specified index. |
|||
* Note: If the index is not in the string, it will be added. |
|||
* |
|||
* @param index Index of element to replace. |
|||
* @param in Value to set element to. |
|||
* @return New size of the String. |
|||
*/ |
|||
virtual size_t set(size_t index, const T &in); |
|||
virtual size_t set(size_t index, const T *in, size_t inSize); |
|||
virtual size_t set(size_t index, const Jupiter::Readable_String<T> &in); |
|||
virtual size_t set(size_t index, const std::basic_string<T> &in); |
|||
virtual size_t set(size_t index, const T *in); |
|||
|
|||
/**
|
|||
* @brief Copies the data from the input string to the String. |
|||
* |
|||
* @param in String containing the data to be copied. |
|||
* @return New size of the String. |
|||
*/ |
|||
virtual size_t set(const T *in, size_t inSize); |
|||
virtual size_t set(const Jupiter::Readable_String<T> &in); |
|||
virtual size_t set(const std::basic_string<T> &in); |
|||
virtual size_t set(const T *in); |
|||
virtual size_t set(const T &in); |
|||
|
|||
/**
|
|||
* @brief Inserts data into a position in the string. |
|||
* |
|||
* @param index Index to insert data to. |
|||
* @param value Value to insert. |
|||
*/ |
|||
virtual size_t insert(size_t index, const T &value); |
|||
virtual size_t insert(size_t index, const Jupiter::Readable_String<T> &value); |
|||
|
|||
/**
|
|||
* @brief Replaces data at an index with a specified value. |
|||
* |
|||
* @param index Index to start replacing at. |
|||
* @param length Number of elements to replace. |
|||
* @param value Value to write over the elements. |
|||
* @return New size of the string. |
|||
*/ |
|||
virtual size_t replace(size_t index, size_t length, const T &value); |
|||
virtual size_t replace(size_t index, size_t length, const T *value, size_t valueSize); |
|||
virtual size_t replace(size_t index, size_t length, std::basic_string_view<T> value); |
|||
|
|||
/**
|
|||
* @brief Replaces all instances of one value with another value. |
|||
* |
|||
* @param target Target to search for and replace. |
|||
* @param value Value to replace the target with. |
|||
* @return New size of the string. |
|||
*/ |
|||
virtual size_t replace(const T &target, const T &value); |
|||
virtual size_t replace(const T *target, size_t targetSize, const T &value); |
|||
virtual size_t replace(const Jupiter::Readable_String<T> &target, const T &value); |
|||
|
|||
virtual size_t replace(const T *target, size_t targetSize, const T *value, size_t valueSize); |
|||
virtual size_t replace(const T *target, size_t targetSize, const Jupiter::Readable_String<T> &value); |
|||
virtual size_t replace(const Jupiter::Readable_String<T> &target, const T *value, size_t valueSize); |
|||
virtual size_t replace(std::basic_string_view<T> target, std::basic_string_view<T> value); |
|||
|
|||
/**
|
|||
* @brief Copies the data from the input string and concatenates it to the end of String. |
|||
* |
|||
* @param in String containing the data to be concatenated. |
|||
* @return New size of the String. |
|||
*/ |
|||
virtual size_t concat(const T *in, size_t inSize); |
|||
virtual size_t concat(const Jupiter::Readable_String<T> &in); |
|||
virtual size_t concat(const std::basic_string<T> &in); |
|||
virtual size_t concat(const T *in); |
|||
virtual size_t concat(const T &in); |
|||
|
|||
/**
|
|||
* @brief Copies a part of 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 Position to start copying from. |
|||
* @return Partial copy of the input string. |
|||
*/ |
|||
template<template<typename> class R> static R<T> substring(const Jupiter::Readable_String<T> &in, size_t pos); // REPLACE
|
|||
template<template<typename> class R> static R<T> substring(const T *in, size_t pos); // REPLACE
|
|||
|
|||
/**
|
|||
* @brief Copies a part of 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 Position to start copying from. |
|||
* @param len Number of elements to copy. |
|||
* @return Partial copy of the input string. |
|||
*/ |
|||
template<template<typename> class R> static R<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len); // REPLACE
|
|||
template<template<typename> class R> static R<T> substring(const T *in, size_t pos, size_t len); // REPLACE
|
|||
|
|||
/** Mutative operators */ |
|||
inline String_Type<T> &operator+=(const String_Type<T> &right) { this->concat(right); return *this; }; |
|||
inline String_Type<T> &operator+=(const std::basic_string<T> &right) { this->concat(right); return *this; }; |
|||
inline String_Type<T> &operator+=(const std::basic_string_view<T> &right) { this->concat(right); return *this; }; |
|||
inline String_Type<T> &operator+=(const T *right) { this->concat(right); return *this; }; |
|||
inline String_Type<T> &operator+=(const T right) { this->concat(right); return *this; }; |
|||
inline String_Type<T> &operator-=(size_t right) { this->truncate(right); return *this; }; |
|||
inline String_Type<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; }; |
|||
inline String_Type<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; }; |
|||
inline String_Type<T> &operator=(const std::basic_string_view<T> &right) { this->set(right.data(), right.size()); return *this; }; |
|||
inline String_Type<T> &operator=(const T *right) { this->set(right); return *this; }; |
|||
inline String_Type<T> &operator=(const T right) { this->set(right); return *this; }; |
|||
|
|||
/**
|
|||
* @brief Default constructor for the String_Type class. |
|||
*/ |
|||
String_Type() {} |
|||
|
|||
/**
|
|||
* @brief Move constructor for the String_Type class. |
|||
*/ |
|||
String_Type(Jupiter::String_Type<T> &&source); |
|||
|
|||
/**
|
|||
* The following constructors should exist: |
|||
* A default constructor |
|||
* A copy constructor for the same class. |
|||
* A copy constructor for Readable_String. |
|||
* A copy constructor for std::basic_string<T>. |
|||
* A copy constructor for C-style strings. |
|||
* A copy constructor for memory array strings. |
|||
* A conversion constructor for Jupiter::DataBuffer |
|||
*/ |
|||
|
|||
/**
|
|||
* @brief Destructor for the String_Type class. |
|||
*/ |
|||
virtual ~String_Type() = default; |
|||
|
|||
/**
|
|||
* Necessities when removing Readable_String & Reference_String |
|||
*/ |
|||
bool empty() const { return size() == 0; }; // KEEP
|
|||
|
|||
/** Access operator */ |
|||
inline const T &operator[](size_t index) const { return this->data()[index]; }; |
|||
|
|||
/** Conversion operators */ |
|||
explicit inline operator std::basic_string<T>() const { return std::basic_string<T>(this->data(), this->size()); } |
|||
inline operator std::basic_string_view<T>() const { return std::basic_string_view<T>(this->data(), this->size()); } |
|||
|
|||
/** Comparative operators */ |
|||
inline bool operator==(const String_Type<T>& right)const{ return operator==(std::basic_string_view<T>{right}); } |
|||
inline bool operator==(const std::basic_string<T>& right)const{ return operator==(std::basic_string_view<T>{right}); } |
|||
inline bool operator==(const std::basic_string_view<T>& right)const{ return std::basic_string_view<T>(data(), size()) == right; } |
|||
inline bool operator==(const T right)const{ return this->size() == 1 && this->get(0) == right; } |
|||
inline bool operator==(std::nullptr_t) = delete; |
|||
inline bool operator!=(const String_Type<T> &right)const{ return !operator==(right); } |
|||
inline bool operator!=(const std::basic_string<T> &right)const{ return !operator==(right); } |
|||
inline bool operator!=(const T right)const{ return !operator==(right); } |
|||
inline bool operator!=(std::nullptr_t) = delete; |
|||
inline bool operator<(const String_Type<T> &right)const{ return this->compare(right) < 0; } |
|||
inline bool operator<(const std::basic_string<T> &right)const{ return this->compare(right) < 0; } |
|||
inline bool operator<(const T right)const{ return this->compare(right) < 0; } |
|||
inline bool operator>(const String_Type<T> &right)const{ return this->compare(right) > 0; } |
|||
inline bool operator>(const std::basic_string<T> &right)const{ return this->compare(right) > 0; } |
|||
inline bool operator>(const T right)const{ return this->compare(right) > 0; } |
|||
inline bool operator<=(const String_Type<T> &right)const{ return !operator>(right); } |
|||
inline bool operator<=(const std::basic_string<T> &right)const{ return !operator>(right); } |
|||
inline bool operator<=(const T right)const{ return !operator>(right); } |
|||
inline bool operator>=(const String_Type<T> &right)const{ return !operator<(right); } |
|||
inline bool operator>=(const std::basic_string<T> &right)const{ return !operator<(right); } |
|||
inline bool operator>=(const T right)const{ return !operator<(right); } |
|||
|
|||
protected: // Things which cannot be removed right now
|
|||
T *str{}; /** Pointer for the underlying string of elements */ |
|||
size_t length{}; /** Number of representable elements in the string */ |
|||
|
|||
/**
|
|||
* @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. |
|||
* |
|||
* @param len Minimum number of elements the string buffer must be able to hold. |
|||
* @return True if a new buffer was allocated, false otherwise. |
|||
*/ |
|||
virtual bool setBufferSize(size_t len) = 0; |
|||
|
|||
/**
|
|||
* @brief Empties the string, and 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. |
|||
* |
|||
* @param len Minimum number of elements the string buffer must be able to hold. |
|||
* @return True if a new buffer was allocated, false otherwise. |
|||
*/ |
|||
virtual bool setBufferSizeNoCopy(size_t len) = 0; |
|||
}; |
|||
|
|||
namespace literals { |
|||
// Not truly a literal, but I just want this available in places I'm using literals
|
|||
template<typename T> |
|||
static inline std::basic_string<T> operator+(std::basic_string<T> lhs, std::basic_string_view<T> rhs) { |
|||
lhs += rhs; |
|||
return lhs; |
|||
} |
|||
|
|||
template<typename T> |
|||
static inline std::basic_string<T> operator+(std::basic_string<T> lhs, const String_Type<T>& rhs) { |
|||
lhs += std::basic_string_view<T>{rhs}; |
|||
return lhs; |
|||
} |
|||
} |
|||
|
|||
/** Generic String Type */ |
|||
typedef String_Type<char> StringType; |
|||
} |
|||
|
|||
/** Re-enable warning */ |
|||
#if defined _MSC_VER |
|||
#pragma warning(pop) |
|||
#endif |
|||
|
|||
/** Implementation for String_Type. */ |
|||
#include "String_Type_Imp.h" |
|||
|
|||
#endif // _STRING_TYPE_H_HEADER
|
@ -1,593 +0,0 @@ |
|||
/**
|
|||
* Copyright (C) 2014-2016 Jessica James. |
|||
* |
|||
* Permission to use, copy, modify, and/or distribute this software for any |
|||
* purpose with or without fee is hereby granted, provided that the above |
|||
* copyright notice and this permission notice appear in all copies. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
* |
|||
* Written by Jessica James <jessica.aj@outlook.com> |
|||
*/ |
|||
|
|||
#if !defined _STRING_TYPE_IMP_H_HEADER |
|||
#define _STRING_TYPE_IMP_H_HEADER |
|||
|
|||
/**
|
|||
* @file String_Type_Imp.h |
|||
* @brief Provides the implementations for String_Type functions. |
|||
* Note: Modification of this file is not supported in any way. |
|||
*/ |
|||
|
|||
#include "String_Type.h" |
|||
#include "Functions.h" |
|||
|
|||
/**
|
|||
* IMPLEMENTATION: |
|||
* String_Type |
|||
*/ |
|||
|
|||
template<typename T> Jupiter::String_Type<T>::String_Type(Jupiter::String_Type<T> &&source) |
|||
{ |
|||
Jupiter::String_Type<T>::str = source.str; |
|||
Jupiter::String_Type<T>::length = source.length; |
|||
source.length = 0; |
|||
source.str = nullptr; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::size() const |
|||
{ |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::capacity() const |
|||
{ |
|||
return this->size(); |
|||
} |
|||
|
|||
template<typename T> const T *Jupiter::String_Type<T>::data() const |
|||
{ |
|||
return Jupiter::String_Type<T>::str; |
|||
} |
|||
|
|||
// truncate base
|
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::truncate(size_t n) |
|||
{ |
|||
if (n >= Jupiter::String_Type<T>::length) return (Jupiter::String_Type<T>::length = 0); |
|||
return (Jupiter::String_Type<T>::length -= n); |
|||
} |
|||
|
|||
// remove base
|
|||
|
|||
template<typename T> bool Jupiter::String_Type<T>::remove(const T &value) |
|||
{ |
|||
for (size_t i = 0; i < Jupiter::String_Type<T>::length - 1; i++) |
|||
{ |
|||
if (Jupiter::String_Type<T>::str[i] == value) |
|||
{ |
|||
while (i < Jupiter::String_Type<T>::length) |
|||
{ |
|||
i++; |
|||
Jupiter::String_Type<T>::str[i - 1] = Jupiter::String_Type<T>::str[i]; |
|||
} |
|||
Jupiter::String_Type<T>::length--; |
|||
return true; |
|||
} |
|||
} |
|||
if (Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length - 1] == value) |
|||
{ |
|||
this->truncate(1); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
template<typename T> void Jupiter::String_Type<T>::remove(size_t index, size_t len) |
|||
{ |
|||
if (index >= Jupiter::String_Type<T>::length) |
|||
return; |
|||
|
|||
if (index + len >= Jupiter::String_Type<T>::length) |
|||
Jupiter::String_Type<T>::length = index; |
|||
else |
|||
{ |
|||
Jupiter::String_Type<T>::length -= len; |
|||
len += index; |
|||
|
|||
Jupiter::String_Type<T>::str[index] = Jupiter::String_Type<T>::str[len]; |
|||
while (++index != Jupiter::String_Type<T>::length) |
|||
Jupiter::String_Type<T>::str[index] = Jupiter::String_Type<T>::str[++len]; |
|||
} |
|||
} |
|||
|
|||
// erase
|
|||
|
|||
template<typename T> void Jupiter::String_Type<T>::clear() |
|||
{ |
|||
Jupiter::String_Type<T>::length = 0; |
|||
} |
|||
|
|||
// set
|
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const T &in) |
|||
{ |
|||
if (index == Jupiter::String_Type<T>::length) |
|||
return this->concat(in); |
|||
|
|||
if (index > Jupiter::String_Type<T>::length) |
|||
{ |
|||
this->setBufferSize(index + 1); |
|||
while (Jupiter::String_Type<T>::length != index) |
|||
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length++] = 0; |
|||
Jupiter::String_Type<T>::length++; |
|||
} |
|||
Jupiter::String_Type<T>::str[index] = in; |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const T *in, size_t inSize) |
|||
{ |
|||
if (index == Jupiter::String_Type<T>::length) |
|||
return this->concat(in); |
|||
|
|||
if (index > Jupiter::String_Type<T>::length) |
|||
{ |
|||
this->setBufferSize(index + inSize); |
|||
while (Jupiter::String_Type<T>::length != index) |
|||
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length++] = 0; |
|||
index = 0; |
|||
while (index != inSize) |
|||
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length++] = in[index]; |
|||
} |
|||
else |
|||
{ |
|||
index += inSize; |
|||
if (index > Jupiter::String_Type<T>::length) |
|||
{ |
|||
this->setBufferSize(index); |
|||
Jupiter::String_Type<T>::length = index; |
|||
} |
|||
while (inSize != 0) |
|||
Jupiter::String_Type<T>::str[--index] = in[--inSize]; |
|||
} |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const Jupiter::Readable_String<T> &in) |
|||
{ |
|||
return this->set(index, in.data(), in.size()); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const std::basic_string<T> &in) |
|||
{ |
|||
return this->set(index, in.c_str(), in.size()); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const T *in) |
|||
{ |
|||
return this->set(index, in, Jupiter::strlen<T>(in)); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(const T *in, size_t inSize) |
|||
{ |
|||
this->setBufferSizeNoCopy(inSize); |
|||
Jupiter::String_Type<T>::length = inSize; |
|||
while (inSize-- != 0) |
|||
*Jupiter::String_Type<T>::str++ = *in++; |
|||
Jupiter::String_Type<T>::str -= Jupiter::String_Type<T>::length; |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(const Jupiter::Readable_String<T> &in) |
|||
{ |
|||
return this->set(in.data(), in.size()); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(const std::basic_string<T> &in) |
|||
{ |
|||
return this->set(in.c_str(), in.size()); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(const T *in) |
|||
{ |
|||
return this->set(in, Jupiter::strlen<T>(in)); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::set(const T &in) |
|||
{ |
|||
this->setBufferSizeNoCopy(1); |
|||
*Jupiter::String_Type<T>::str = in; |
|||
return Jupiter::String_Type<T>::length = 1; |
|||
} |
|||
|
|||
// insert
|
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::insert(size_t index, const T &value) |
|||
{ |
|||
if (index >= Jupiter::String_Type<T>::length) |
|||
return this->concat(value); |
|||
|
|||
this->setBufferSize(Jupiter::String_Type<T>::length + 1); |
|||
for (size_t i = Jupiter::String_Type<T>::length; i != index; i--) |
|||
Jupiter::String_Type<T>::str[i] = operator[](i-1); |
|||
|
|||
Jupiter::String_Type<T>::str[index] = value; |
|||
return ++Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::insert(size_t index, const Jupiter::Readable_String<T> &value) |
|||
{ |
|||
if (index >= Jupiter::String_Type<T>::length) |
|||
return this->concat(value); |
|||
|
|||
if (value.empty()) |
|||
return Jupiter::String_Type<T>::length; |
|||
|
|||
if (value.size() == 1) |
|||
return this->insert(index, value[0]); |
|||
|
|||
this->setBufferSize(Jupiter::String_Type<T>::length + value.size()); |
|||
size_t i; |
|||
for (i = Jupiter::String_Type<T>::length + value.size() - 1; i != index + value.size() - 1; i--) |
|||
Jupiter::String_Type<T>::str[i] = operator[](i - value.size()); |
|||
|
|||
while (i != index) |
|||
{ |
|||
Jupiter::String_Type<T>::str[i] = value[i - index]; |
|||
i--; |
|||
} |
|||
Jupiter::String_Type<T>::str[index] = value[0]; |
|||
|
|||
return Jupiter::String_Type<T>::length += value.size(); |
|||
} |
|||
|
|||
// replace
|
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, const T &value) |
|||
{ |
|||
if (targetSize != 0) |
|||
{ |
|||
if (index >= Jupiter::String_Type<T>::length) |
|||
return this->set(index, value); |
|||
|
|||
if (index + targetSize > Jupiter::String_Type<T>::length) |
|||
{ |
|||
Jupiter::String_Type<T>::str[index] = value; |
|||
return Jupiter::String_Type<T>::length = index + 1; |
|||
} |
|||
|
|||
if (targetSize == 1) |
|||
return this->set(index, value); |
|||
|
|||
Jupiter::String_Type<T>::str[index] = value; |
|||
Jupiter::String_Type<T>::length -= targetSize - 1; |
|||
while (++index != Jupiter::String_Type<T>::length) |
|||
Jupiter::String_Type<T>::str[index] = Jupiter::String_Type<T>::str[index + targetSize - 1]; |
|||
} |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, const T *value, size_t valueSize) |
|||
{ |
|||
if (valueSize == 1) |
|||
return this->replace(index, targetSize, *value); |
|||
|
|||
if (valueSize == 0) |
|||
{ |
|||
this->remove(index, targetSize); |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
if (targetSize != 0) |
|||
{ |
|||
if (index >= Jupiter::String_Type<T>::length) |
|||
return this->set(index, value); |
|||
|
|||
if (index + targetSize > Jupiter::String_Type<T>::length) |
|||
{ |
|||
if (index + valueSize > Jupiter::String_Type<T>::length) |
|||
this->setBufferSize(index + valueSize); |
|||
|
|||
Jupiter::String_Type<T>::length = index + valueSize; |
|||
Jupiter::String_Type<T>::str[index] = *value; |
|||
while (++index != Jupiter::String_Type<T>::length) |
|||
Jupiter::String_Type<T>::str[index] = *++value; |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
if (targetSize == valueSize) |
|||
return this->set(index, value, valueSize); |
|||
|
|||
if (valueSize < targetSize) |
|||
{ |
|||
targetSize -= valueSize; |
|||
Jupiter::String_Type<T>::length -= targetSize; |
|||
|
|||
Jupiter::String_Type<T>::str[index] = *value; |
|||
while (--valueSize != 0) |
|||
Jupiter::String_Type<T>::str[++index] = *++value; |
|||
|
|||
while (++index != Jupiter::String_Type<T>::length) |
|||
Jupiter::String_Type<T>::str[index] = Jupiter::String_Type<T>::str[index + targetSize]; |
|||
} |
|||
else |
|||
{ |
|||
size_t i = Jupiter::String_Type<T>::length; |
|||
valueSize -= targetSize; |
|||
this->setBufferSize(Jupiter::String_Type<T>::length + valueSize); |
|||
Jupiter::String_Type<T>::length += valueSize; |
|||
|
|||
index += targetSize; |
|||
while (i-- != index) |
|||
Jupiter::String_Type<T>::str[i + valueSize] = Jupiter::String_Type<T>::str[i]; |
|||
index -= targetSize; |
|||
valueSize += targetSize; |
|||
|
|||
Jupiter::String_Type<T>::str[index] = *value; |
|||
while (--valueSize != 0) |
|||
Jupiter::String_Type<T>::str[++index] = *++value; |
|||
} |
|||
} |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, std::basic_string_view<T> value) { |
|||
return this->replace(index, targetSize, value.data(), value.size()); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(const T &target, const T &value) |
|||
{ |
|||
for (size_t i = 0; i != Jupiter::String_Type<T>::length; i++) |
|||
{ |
|||
if (operator[](i) == target) |
|||
Jupiter::String_Type<T>::str[i] = value; |
|||
} |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const T &value) |
|||
{ |
|||
if (targetSize != 0) |
|||
{ |
|||
if (targetSize == 1) |
|||
return this->replace(*target, value); |
|||
|
|||
if (targetSize < Jupiter::String_Type<T>::length) |
|||
{ |
|||
size_t i = 0, j = 0, k; |
|||
while (j <= Jupiter::String_Type<T>::length - targetSize) |
|||
{ |
|||
k = 0; |
|||
while (operator[](j + k) == target[k]) |
|||
{ |
|||
if (++k == targetSize) // match found
|
|||
{ |
|||
Jupiter::String_Type<T>::str[i] = value; |
|||
i += 1; |
|||
j += k; |
|||
break; |
|||
} |
|||
} |
|||
if (k != targetSize) |
|||
Jupiter::String_Type<T>::str[i++] = Jupiter::String_Type<T>::str[j++]; |
|||
} |
|||
while (j < Jupiter::String_Type<T>::length) |
|||
Jupiter::String_Type<T>::str[i++] = Jupiter::String_Type<T>::str[j++]; |
|||
|
|||
Jupiter::String_Type<T>::length = i; |
|||
} |
|||
else if (targetSize == Jupiter::String_Type<T>::length && *this == std::basic_string_view<T>(target, targetSize)) |
|||
return this->set(value); |
|||
} |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const T &value) |
|||
{ |
|||
return this->replace(target.data(), target.size(), value); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const T *value, size_t valueSize) |
|||
{ |
|||
if (valueSize == 1) |
|||
return this->replace(target, targetSize, *value); |
|||
|
|||
if (targetSize != 0) |
|||
{ |
|||
//if (targetSize == 1)
|
|||
// return this->replace(*target, value, valueSize);
|
|||
|
|||
if (targetSize < Jupiter::String_Type<T>::length) |
|||
{ |
|||
if (valueSize > targetSize) |
|||
{ |
|||
size_t instancesSize = 4; |
|||
size_t *instances = new size_t[instancesSize]; |
|||
// pass 1 (count instances)
|
|||
size_t instanceCount = 0, i = 0, j; |
|||
while (i <= Jupiter::String_Type<T>::length - targetSize) |
|||
{ |
|||
j = 0; |
|||
while (operator[](i + j) == target[j]) |
|||
{ |
|||
if (++j == targetSize) |
|||
{ |
|||
i += targetSize; |
|||
if (instanceCount == instancesSize) |
|||
{ |
|||
size_t *tInstances = new size_t[instancesSize * 2]; |
|||
for (instanceCount = 0; instanceCount != instancesSize; instanceCount++) |
|||
tInstances[instanceCount] = instances[instanceCount]; |
|||
delete[] instances; |
|||
instances = tInstances; |
|||
instancesSize *= 2; |
|||
} |
|||
instances[instanceCount] = i; |
|||
instanceCount++; |
|||
break; |
|||
} |
|||
} |
|||
if (j != targetSize) |
|||
i++; |
|||
} |
|||
|
|||
if (instanceCount != 0) |
|||
{ |
|||
// pass 2 (adjust string and replace values)
|
|||
size_t endSize = Jupiter::String_Type<T>::length + (valueSize - targetSize) * instanceCount; |
|||
this->setBufferSize(endSize); |
|||
instancesSize = endSize; // Repurposing. Now used as just another index.
|
|||
j = Jupiter::String_Type<T>::length; |
|||
while (instanceCount != 0) |
|||
{ |
|||
i = instances[--instanceCount]; |
|||
while (j != i) |
|||
Jupiter::String_Type<T>::str[--instancesSize] = Jupiter::String_Type<T>::str[--j]; |
|||
|
|||
j = valueSize; |
|||
while (j != 0) |
|||
Jupiter::String_Type<T>::str[--instancesSize] = value[--j]; |
|||
j = i - targetSize; |
|||
} |
|||
Jupiter::String_Type<T>::length = endSize; |
|||
} |
|||
delete[] instances; |
|||
} |
|||
else |
|||
{ |
|||
size_t i = 0, j = 0, k, l; |
|||
while (j <= Jupiter::String_Type<T>::length - targetSize) |
|||
{ |
|||
k = 0; |
|||
while (operator[](j + k) == target[k]) |
|||
{ |
|||
if (++k == targetSize) // match found
|
|||
{ |
|||
for (l = 0; l != valueSize; l++) |
|||
Jupiter::String_Type<T>::str[i + l] = value[l]; |
|||
i += valueSize; |
|||
j += k; |
|||
break; |
|||
} |
|||
} |
|||
if (k != targetSize) |
|||
Jupiter::String_Type<T>::str[i++] = Jupiter::String_Type<T>::str[j++]; |
|||
} |
|||
while (j < Jupiter::String_Type<T>::length) |
|||
Jupiter::String_Type<T>::str[i++] = Jupiter::String_Type<T>::str[j++]; |
|||
|
|||
Jupiter::String_Type<T>::length = i; |
|||
} |
|||
} |
|||
else if (targetSize == Jupiter::String_Type<T>::length && *this == std::basic_string_view<T>(target, targetSize)) |
|||
return this->set(value); |
|||
} |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const Jupiter::Readable_String<T> &value) |
|||
{ |
|||
return this->replace(target, targetSize, value.data(), value.size()); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const T *value, size_t valueSize) |
|||
{ |
|||
return this->replace(target.data(), target.size(), value, valueSize); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::replace(std::basic_string_view<T> target, std::basic_string_view<T> value) |
|||
{ |
|||
return this->replace(target.data(), target.size(), value.data(), value.size()); |
|||
} |
|||
|
|||
// concat
|
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::concat(const T *in, size_t inSize) |
|||
{ |
|||
this->setBufferSize(Jupiter::String_Type<T>::length + inSize); |
|||
while (inSize-- != 0) |
|||
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length++] = *in++; |
|||
return Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::concat(const Jupiter::Readable_String<T> &in) |
|||
{ |
|||
return this->concat(in.data(), in.size()); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::concat(const std::basic_string<T> &in) |
|||
{ |
|||
return this->concat(in.c_str(), in.size()); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::concat(const T *in) |
|||
{ |
|||
return this->concat(in, Jupiter::strlen<T>(in)); |
|||
} |
|||
|
|||
template<typename T> size_t Jupiter::String_Type<T>::concat(const T &c) |
|||
{ |
|||
this->setBufferSize(Jupiter::String_Type<T>::length + 1); |
|||
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = c; |
|||
return ++Jupiter::String_Type<T>::length; |
|||
} |
|||
|
|||
/**
|
|||
* IMPLEMENTATION: |
|||
* String helper templates |
|||
*/ |
|||
|
|||
// substring
|
|||
|
|||
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos) |
|||
{ |
|||
if (pos >= in.size()) return R<T>(); |
|||
R<T> r = R<T>(in.size() - pos); |
|||
for (r.length = 0; pos + r.length != in.size(); r.length++) r.str[r.length] = in[pos + r.length]; |
|||
return r; |
|||
} |
|||
|
|||
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len) |
|||
{ |
|||
if (pos + len >= in.size()) return R<T>::substring(in, pos); |
|||
R<T> r = R<T>(len); |
|||
for (r.length = 0; r.length != len; r.length++) r.str[r.length] = in[pos + r.length]; |
|||
return r; |
|||
} |
|||
|
|||
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::substring(const T *in, size_t pos) |
|||
{ |
|||
size_t strLen = Jupiter::strlen<T>(in); |
|||
if (pos >= strLen) return R<T>(); |
|||
R<T> r = R<T>(strLen - pos); |
|||
in += pos; |
|||
for (r.length = 0; *in != 0; r.length++, in++) r.str[r.length] = *in; |
|||
return r; |
|||
} |
|||
|
|||
template<typename T> template<template<typename> class R> R<T> Jupiter::String_Type<T>::substring(const T *in, size_t pos, size_t len) |
|||
{ |
|||
R<T> r = R<T>(len); |
|||
in += pos; |
|||
for (r.length = 0; r.length != len; r.length++, in++) r.str[r.length] = *in; |
|||
return r; |
|||
} |
|||
|
|||
// Jupiter::DataBuffer specialization
|
|||
|
|||
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Type> { |
|||
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Type<Y> *data) { |
|||
buffer->secure(sizeof(size_t) + data->size() * sizeof(Y)); |
|||
buffer->push<size_t>(data->size()); |
|||
buffer->push(reinterpret_cast<const uint8_t *>(data->data()), data->size() * sizeof(Y)); |
|||
}; |
|||
}; |
|||
|
|||
#endif // _STRING_TYPE_IMP_H_HEADER
|
@ -1 +1 @@ |
|||
Subproject commit d7e4f337c786184a68b095449176261ce1700295 |
|||
Subproject commit bce3bfefc6323754656d8153630b80155e4644e2 |
Loading…
Reference in new issue