Browse Source

Initial removal of Reference_String and Readable_String classes

task/remove_strings
Jessica James 3 years ago
parent
commit
dbb4d0d147
  1. 21
      src/common/HTTP_Server.cpp
  2. 26
      src/common/IRC_Client.cpp
  3. 4
      src/common/Socket.cpp
  4. 1
      src/include/Jupiter/HTTP_QueryString.h
  5. 10
      src/include/Jupiter/HTTP_Server.h
  6. 2
      src/include/Jupiter/IRC_Client.h
  7. 105
      src/include/Jupiter/Readable_String.h
  8. 137
      src/include/Jupiter/Readable_String_Imp.h
  9. 82
      src/include/Jupiter/Reference_String.h
  10. 78
      src/include/Jupiter/Reference_String_Imp.h
  11. 8
      src/include/Jupiter/Shift_String_Imp.h
  12. 1
      src/include/Jupiter/Socket.h
  13. 33
      src/include/Jupiter/String.hpp
  14. 20
      src/include/Jupiter/String_Imp.h
  15. 66
      src/include/Jupiter/String_Type.h
  16. 19
      src/include/Jupiter/String_Type_Imp.h

21
src/common/HTTP_Server.cpp

@ -75,7 +75,7 @@ Jupiter::HTTP::Server::Content::Content(std::string in_name, Jupiter::HTTP::Serv
Jupiter::HTTP::Server::Content::name_checksum = calc_checksum(name); // switch to calcChecksumi to make case-insensitive Jupiter::HTTP::Server::Content::name_checksum = calc_checksum(name); // switch to calcChecksumi to make case-insensitive
} }
Jupiter::ReadableString *Jupiter::HTTP::Server::Content::execute(std::string_view query_string) { std::string* Jupiter::HTTP::Server::Content::execute(std::string_view query_string) {
return Jupiter::HTTP::Server::Content::function(query_string); return Jupiter::HTTP::Server::Content::function(query_string);
} }
@ -216,7 +216,7 @@ Jupiter::HTTP::Server::Content *Jupiter::HTTP::Server::Directory::find(std::stri
return nullptr; // No such directory return nullptr; // No such directory
} }
Jupiter::ReadableString* Jupiter::HTTP::Server::Directory::execute(std::string_view in_name, std::string_view query_string) { std::string* Jupiter::HTTP::Server::Directory::execute(std::string_view in_name, std::string_view query_string) {
Jupiter::HTTP::Server::Content *content_ptr = find(in_name); Jupiter::HTTP::Server::Content *content_ptr = find(in_name);
if (content_ptr == nullptr) if (content_ptr == nullptr)
return nullptr; return nullptr;
@ -273,8 +273,8 @@ struct Jupiter::HTTP::Server::Data {
Jupiter::HTTP::Server::Host *find_host(std::string_view name); Jupiter::HTTP::Server::Host *find_host(std::string_view name);
Content* find(std::string_view name); Content* find(std::string_view name);
Content* find(std::string_view hostname, std::string_view name); Content* find(std::string_view hostname, std::string_view name);
Jupiter::ReadableString *execute(std::string_view name, std::string_view query_string); std::string* execute(std::string_view name, std::string_view query_string);
Jupiter::ReadableString *execute(std::string_view hostname, std::string_view name, std::string_view query_string); std::string* execute(std::string_view hostname, std::string_view name, std::string_view query_string);
int process_request(HTTPSession &session); int process_request(HTTPSession &session);
@ -391,7 +391,7 @@ Jupiter::HTTP::Server::Content *Jupiter::HTTP::Server::Data::find(std::string_vi
return host->find(name); return host->find(name);
} }
Jupiter::ReadableString *Jupiter::HTTP::Server::Data::execute(std::string_view name, std::string_view query_string) { std::string* Jupiter::HTTP::Server::Data::execute(std::string_view name, std::string_view query_string) {
Jupiter::HTTP::Server::Content *content = find(name); Jupiter::HTTP::Server::Content *content = find(name);
if (content == nullptr) if (content == nullptr)
return nullptr; return nullptr;
@ -399,7 +399,7 @@ Jupiter::ReadableString *Jupiter::HTTP::Server::Data::execute(std::string_view n
return content->execute(query_string); return content->execute(query_string);
} }
Jupiter::ReadableString *Jupiter::HTTP::Server::Data::execute(std::string_view hostname, std::string_view name, std::string_view query_string) { std::string* Jupiter::HTTP::Server::Data::execute(std::string_view hostname, std::string_view name, std::string_view query_string) {
Jupiter::HTTP::Server::Content *content = find(hostname, name); Jupiter::HTTP::Server::Content *content = find(hostname, name);
if (content == nullptr) if (content == nullptr)
return nullptr; return nullptr;
@ -442,7 +442,8 @@ int Jupiter::HTTP::Server::Data::process_request(HTTPSession &session) {
if (!line.empty()) // end of http request if (!line.empty()) // end of http request
{ {
Jupiter::String result(256); std::string result;
result.reserve(256);
switch (command) switch (command)
{ {
case HTTPCommand::GET: case HTTPCommand::GET:
@ -451,7 +452,7 @@ int Jupiter::HTTP::Server::Data::process_request(HTTPSession &session) {
{ {
// 200 (success) // 200 (success)
// TODO: remove referencestring warpper // TODO: remove referencestring warpper
Jupiter::ReadableString *content_result = content->execute(Jupiter::ReferenceString{query_string}); std::string* content_result = content->execute(Jupiter::ReferenceString{query_string});
switch (session.version) switch (session.version)
{ {
@ -703,11 +704,11 @@ Jupiter::HTTP::Server::Content *Jupiter::HTTP::Server::find(std::string_view hos
return m_data->find(host, name); return m_data->find(host, name);
} }
Jupiter::ReadableString *Jupiter::HTTP::Server::execute(std::string_view name, std::string_view query_string) { std::string* Jupiter::HTTP::Server::execute(std::string_view name, std::string_view query_string) {
return m_data->execute(name, query_string); return m_data->execute(name, query_string);
} }
Jupiter::ReadableString *Jupiter::HTTP::Server::execute(std::string_view host, std::string_view name, std::string_view query_string) { std::string* Jupiter::HTTP::Server::execute(std::string_view host, std::string_view name, std::string_view query_string) {
return m_data->execute(host, name, query_string); return m_data->execute(host, name, query_string);
} }

26
src/common/IRC_Client.cpp

@ -445,7 +445,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
case Error::UNKNOWNCOMMAND: // 421 case Error::UNKNOWNCOMMAND: // 421
{ {
Jupiter::ReferenceString command = getLineToken(2); Jupiter::ReferenceString command = getLineToken(2);
if (command.equalsi("STARTTLS")) { // Server doesn't support STARTTLS if (jessilib::equalsi(command, "STARTTLS"sv)) { // Server doesn't support STARTTLS
Client::startCAP(); Client::startCAP();
} }
} }
@ -492,7 +492,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
switch (numeric) switch (numeric)
{ {
case 0: case 0:
if (getLineToken(1).equalsi("CAP")) if (jessilib::equalsi(getLineToken(1), "CAP"sv))
{ {
Jupiter::ReferenceString w4 = getLineToken(3); Jupiter::ReferenceString w4 = getLineToken(3);
if (w4 == "LS"sv) if (w4 == "LS"sv)
@ -577,7 +577,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
m_nickname = configNick; m_nickname = configNick;
m_nickname += "1"; m_nickname += "1";
m_socket->send("NICK "_jrs + m_nickname + ENDL); m_socket->send("NICK "s + m_nickname + ENDL);
} }
else if (jessilib::equalsi(m_nickname, configNick)) // The config nick failed else if (jessilib::equalsi(m_nickname, configNick)) // The config nick failed
{ {
@ -591,7 +591,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
else else
m_nickname = altNick; m_nickname = altNick;
m_socket->send("NICK "_jrs + m_nickname + ENDL); m_socket->send("NICK "s + m_nickname + ENDL);
} }
// Note: Add a series of contains() functions to String_Type. // Note: Add a series of contains() functions to String_Type.
else else
@ -604,7 +604,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
m_nickname = configNick; m_nickname = configNick;
m_nickname += std::to_string(n + 1); m_nickname += std::to_string(n + 1);
m_socket->send("NICK "_jrs + m_nickname + ENDL); m_socket->send("NICK "s + m_nickname + ENDL);
} }
else else
{ {
@ -612,7 +612,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
// This can be somewhat edgy -- this will only trigger if someone rehashes AND the new nickname is shorter. // This can be somewhat edgy -- this will only trigger if someone rehashes AND the new nickname is shorter.
// However, it won't be fatal even if the new nickname's length is >= the old. // However, it won't be fatal even if the new nickname's length is >= the old.
m_nickname = configNick; m_nickname = configNick;
m_socket->send("NICK "_jrs + m_nickname + ENDL); m_socket->send("NICK "s + m_nickname + ENDL);
} }
} }
else else
@ -817,7 +817,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
if (!newnick.empty() && newnick[0] == ':') { if (!newnick.empty() && newnick[0] == ':') {
newnick.remove_prefix(1); newnick.remove_prefix(1);
} }
if (nick.equalsi(m_nickname)) { if (jessilib::equalsi(nick, m_nickname)) {
m_nickname = newnick; m_nickname = newnick;
} }
auto user = Client::findUser(nick); auto user = Client::findUser(nick);
@ -884,7 +884,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
plugin->OnPart(this, channel_name, nick, reason); plugin->OnPart(this, channel_name, nick, reason);
} }
if (nick.equalsi(m_nickname)) if (jessilib::equalsi(nick, m_nickname))
Client::delChannel(channel_name); Client::delChannel(channel_name);
if (user->getChannelCount() == 0) if (user->getChannelCount() == 0)
@ -1092,7 +1092,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
Jupiter::StringS auth_str = m_nickname + '\0' + m_sasl_account + '\0' + m_sasl_password; Jupiter::StringS auth_str = m_nickname + '\0' + m_sasl_account + '\0' + m_sasl_password;
char *enc = Jupiter::base64encode(auth_str.data(), auth_str.size()); char *enc = Jupiter::base64encode(auth_str.data(), auth_str.size());
m_socket->send("AUTHENTICATE "_jrs + enc + ENDL); m_socket->send("AUTHENTICATE "s + enc + ENDL);
delete[] enc; delete[] enc;
} }
m_socket->send("CAP END" ENDL); m_socket->send("CAP END" ENDL);
@ -1519,8 +1519,12 @@ void Jupiter::IRC::Client::Channel::addUserPrefix(std::string_view in_nickname,
void Jupiter::IRC::Client::Channel::delUserPrefix(std::string_view in_nickname, char prefix) { void Jupiter::IRC::Client::Channel::delUserPrefix(std::string_view in_nickname, char prefix) {
auto user = getUser(in_nickname); auto user = getUser(in_nickname);
if (user != nullptr) if (user != nullptr) {
user->m_prefixes.remove(prefix); size_t prefix_pos = user->m_prefixes.find(prefix);
if (prefix_pos != std::string::npos) {
user->m_prefixes.erase(prefix_pos, 1);
}
}
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::getName() const { const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::getName() const {

4
src/common/Socket.cpp

@ -501,10 +501,6 @@ int Jupiter::Socket::send(const char *data, size_t datalen) {
return ::send(Jupiter::Socket::data_->rawSock, data, datalen, 0); return ::send(Jupiter::Socket::data_->rawSock, data, datalen, 0);
} }
int Jupiter::Socket::send(const Jupiter::ReadableString &str) {
return this->send(str.data(), str.size());
}
int Jupiter::Socket::send(std::string_view str) { int Jupiter::Socket::send(std::string_view str) {
return this->send(str.data(), str.size()); return this->send(str.data(), str.size());
} }

1
src/include/Jupiter/HTTP_QueryString.h

@ -52,7 +52,6 @@ namespace Jupiter
public: public:
HTMLFormResponse() = delete; HTMLFormResponse() = delete;
inline HTMLFormResponse(std::string_view query_string) : HTMLFormResponse(query_string.data(), query_string.size()) {} inline HTMLFormResponse(std::string_view query_string) : HTMLFormResponse(query_string.data(), query_string.size()) {}
inline HTMLFormResponse(const Jupiter::ReadableString &query_string) : HTMLFormResponse(query_string.data(), query_string.size()) {}
inline HTMLFormResponse(const char *ptr, size_t str_size); inline HTMLFormResponse(const char *ptr, size_t str_size);
using TableType = std::unordered_map<std::string, std::string, Jupiter::str_hash<char>, std::equal_to<>>; using TableType = std::unordered_map<std::string, std::string, Jupiter::str_hash<char>, std::equal_to<>>;
#ifdef __cpp_lib_generic_unordered_lookup #ifdef __cpp_lib_generic_unordered_lookup

10
src/include/Jupiter/HTTP_Server.h

@ -45,7 +45,7 @@ namespace Jupiter
virtual int think(); virtual int think();
public: // Server public: // Server
typedef Jupiter::ReadableString *HTTPFunction(std::string_view query_string); typedef std::string* HTTPFunction(std::string_view query_string);
static const Jupiter::ReadableString &global_namespace; static const Jupiter::ReadableString &global_namespace;
static const Jupiter::ReadableString &server_string; static const Jupiter::ReadableString &server_string;
@ -59,7 +59,7 @@ namespace Jupiter
const Jupiter::ReadableString *type = nullptr; // Pointer to a constant (or otherwise managed) string const Jupiter::ReadableString *type = nullptr; // Pointer to a constant (or otherwise managed) string
const Jupiter::ReadableString *charset = nullptr; // Pointer to a constant (or otherwise managed) string const Jupiter::ReadableString *charset = nullptr; // Pointer to a constant (or otherwise managed) string
virtual Jupiter::ReadableString *execute(std::string_view query_string); virtual std::string* execute(std::string_view query_string);
Content(std::string in_name, Jupiter::HTTP::Server::HTTPFunction in_function); Content(std::string in_name, Jupiter::HTTP::Server::HTTPFunction in_function);
}; };
@ -76,7 +76,7 @@ namespace Jupiter
virtual bool remove(std::string_view path, std::string_view name); virtual bool remove(std::string_view path, std::string_view name);
virtual bool has(std::string_view name); virtual bool has(std::string_view name);
virtual Jupiter::HTTP::Server::Content* find(std::string_view name); virtual Jupiter::HTTP::Server::Content* find(std::string_view name);
virtual Jupiter::ReadableString* execute(std::string_view name, std::string_view query_string); virtual std::string* execute(std::string_view name, std::string_view query_string);
Directory(const Directory&) = delete; Directory(const Directory&) = delete;
Directory& operator=(const Directory&) = delete; Directory& operator=(const Directory&) = delete;
@ -97,8 +97,8 @@ namespace Jupiter
bool has(std::string_view host, std::string_view name); bool has(std::string_view host, std::string_view name);
Content *find(std::string_view name); Content *find(std::string_view name);
Content *find(std::string_view host, std::string_view name); Content *find(std::string_view host, std::string_view name);
Jupiter::ReadableString *execute(std::string_view name, std::string_view query_string); std::string* execute(std::string_view name, std::string_view query_string);
Jupiter::ReadableString *execute(std::string_view host, std::string_view name, std::string_view query_string); std::string* execute(std::string_view host, std::string_view name, std::string_view query_string);
bool bind(std::string_view hostname, uint16_t port = 80); bool bind(std::string_view hostname, uint16_t port = 80);
bool tls_bind(std::string_view hostname, uint16_t port = 443); bool tls_bind(std::string_view hostname, uint16_t port = 443);

2
src/include/Jupiter/IRC_Client.h

@ -312,7 +312,7 @@ namespace Jupiter
/** Private members */ /** Private members */
private: private:
std::shared_ptr<Jupiter::IRC::Client::User> m_user; std::shared_ptr<Jupiter::IRC::Client::User> m_user;
Jupiter::StringS m_prefixes; std::string m_prefixes;
}; };
using UserTableType = std::unordered_map<Jupiter::StringS, std::shared_ptr<Channel::User>, default_hash_function>; using UserTableType = std::unordered_map<Jupiter::StringS, std::shared_ptr<Channel::User>, default_hash_function>;

105
src/include/Jupiter/Readable_String.h

@ -33,102 +33,13 @@
#include "DataBuffer.h" #include "DataBuffer.h"
#include "Functions.h" #include "Functions.h"
namespace Jupiter namespace Jupiter {
{ /** DEPRECATED: Generic Readable String Type */
template<typename CharT>
/** using Readable_String = std::basic_string_view<CharT>;
* @brief Provides the basis for String classes by providing implementations for operators, comparative operations, and defining abstract functions. using ReadableString = std::string_view;
* Note: This is an abstract type.
* // these methods will be written in a similar fashion in jessilib, to retain behavior / ease of use
* @param T Element type which the String will store. Defaults to char.
*/
template<typename T = char> class Readable_String
{
public:
/**
* @brief Returns a pointer to the underlying string of elements.
*
* @return Pointer to the underlying string of elements.
*/
virtual const T *data() const = 0; // KEEP
/**
* @brief Returns the number of elements in the String.
*
* @return Number of elements in the string.
*/
virtual size_t size() const = 0; // KEEP
/**
* @brief Checks if the String is empty.
*
* @return True if the String is empty, false otherwise.
*/
bool empty() const { return size() == 0; }; // KEEP
/**
* @brief Returns the index of the first element in the string with the specified value.
*
* @param value Value of the element to search for.
* @param index Index of the match to return (i.e: 0 returns the first match).
* @return The index of an element if one is found, INVALID_INDEX otherwise.
*/
size_t find(const T &value, size_t index = 0) const; // KEEP
size_t find(const Readable_String<T> &in) const; // KEEP
/**
* @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; // REMOVE
bool equalsi(const std::basic_string<T> &in) const; // REMOVE
bool equalsi(const T *in, size_t len) const; // REMOVE
bool equalsi(const T &in) const; // REMOVE
/**
* @brief Destructor for the Readable_String class.
*/
virtual ~Readable_String() = default;
/** Access operator */
inline const T &operator[](size_t index) const { return this->data()[index]; };
/** Comparative operators */
inline bool operator==(const Readable_String<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 Readable_String<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 Readable_String<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 Readable_String<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 Readable_String<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 Readable_String<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); }
/** 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()); }
};
/** Generic Readable String Type */
typedef Readable_String<char> ReadableString;
// TEMP; create some equivalent in jessilib
template<typename CharT> template<typename CharT>
bool asBool(std::basic_string_view<CharT> in_string) { bool asBool(std::basic_string_view<CharT> in_string) {
using namespace std::literals; using namespace std::literals;
@ -248,6 +159,4 @@ namespace Jupiter
} }
} }
#include "Readable_String_Imp.h"
#endif // _READABLE_STRING_H_HEADER #endif // _READABLE_STRING_H_HEADER

137
src/include/Jupiter/Readable_String_Imp.h

@ -1,137 +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 _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"
/**
* IMPLEMENTATION:
* Readable_String
*/
// find
template<typename T> size_t Jupiter::Readable_String<T>::find(const T &value, size_t index) const
{
for (size_t i = 0; i != this->size(); i++)
{
if (operator[](i) == value)
{
if (index == 0) return i;
else index--;
}
}
return Jupiter::INVALID_INDEX;
}
template<typename T> size_t Jupiter::Readable_String<T>::find(const Jupiter::Readable_String<T> &in) const
{
if (in.size() > this->size())
return Jupiter::INVALID_INDEX;
if (in.size() == this->size())
return (*this == in) ? 0 : Jupiter::INVALID_INDEX;
if (in.empty())
return 0;
for (size_t i = 0, j; i != this->size() - in.size() + 1; i++)
{
j = 0;
while (operator[](i + j) == in[j])
if (++j == in.size()) return i;
}
return Jupiter::INVALID_INDEX;
}
// equalsi()
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const Jupiter::Readable_String<T> &in) const
{
return this->equalsi(in.data(), in.size());
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const std::basic_string<T> &in) const
{
return this->equalsi(in.data(), in.size());
}
template<> bool inline Jupiter::Readable_String<char>::equalsi(const char *in, size_t len) const
{
if (this->size() != len)
return false;
in += len;
while (len != 0)
if (toupper(operator[](--len)) != toupper(*(--in)))
return false;
return true;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::equalsi(const wchar_t *in, size_t len) const
{
if (this->size() != len)
return false;
while (len != 0)
if (towupper(operator[](--len)) != towupper(*(--in)))
return false;
return true;
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const T *in, size_t len) const
{
return *this == std::basic_string_view<T>(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(operator[](0)) == toupper(in);
}
template<> bool inline Jupiter::Readable_String<wchar_t>::equalsi(const wchar_t &in) const
{
return this->size() == 1 && towupper(operator[](0)) == towupper(in);
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const T &in) const
{
return *this == in; // Concept of "case" not supported for type.
}
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::Readable_String<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 // _READABLE_STRING_IMP_H_HEADER

82
src/include/Jupiter/Reference_String.h

@ -28,84 +28,12 @@
#include <string_view> #include <string_view>
#include "Readable_String.h" #include "Readable_String.h"
namespace Jupiter namespace Jupiter {
{ /** DEPRECATED: Generic Reference String Type */
using ReferenceString = std::string_view;
/**
* @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 Reference_String : public Jupiter::Readable_String<T>, public std::basic_string_view<T> {
/** DEPRECATED IN FAVOR OF std::string_view */
public:
/**
* @brief Returns the number of elements in the String.
*
* @return Number of elements in the string.
*/
size_t size() const override;
/**
* @brief Returns a pointer to the underlying string of elements.
*
* @return Pointer to the underlying string of elements.
*/
const T* data() const override;
/** Mutative operators */
inline Reference_String<T>& operator=(const Readable_String<T> &right) { std::basic_string_view<T>::operator=({
right.data(), right.size()}); return *this; };
inline Reference_String<T>& operator=(const Reference_String<T> &right) = default;
inline Reference_String<T>& operator=(const std::basic_string<T> &right) { std::basic_string_view<T>::operator=(right); return *this; };
inline Reference_String<T>& operator=(const std::basic_string_view<T> &right) { std::basic_string_view<T>::operator=(right); return *this; };
inline Reference_String<T>& operator=(const T *right) { std::basic_string_view<T>::operator=(right); return *this; };
/**
* @brief Default constructor for the Reference_String class.
*/
Reference_String() = default;
/**
* @brief Creates a reference to a C-Style string.
* Difference from basic_string_view: checks nullptr
*
* @param in String to get a reference of.
*/
Reference_String(const T *in);
/**
* @brief Move constructor for the Reference_String class.
*/
Reference_String(Jupiter::Reference_String<T> &&source) = default;
/**
* @brief Constructor for the Refererence_String class to create a reference to an existing string.
*/
Reference_String(const Jupiter::Readable_String<T> &in);
/**
* @brief Copy constructor for the Reference_String class.
*/
Reference_String(const Jupiter::Reference_String<T> &in) = default;
Reference_String(const std::basic_string_view<T>&in) : std::basic_string_view<T>(in){}
// Bring in constructors from basic_string_view
using std::basic_string_view<T>::basic_string_view;
/** Methods to force disambiguation between bases until this class is removed entirely */
using std::basic_string_view<T>::find;
using std::basic_string_view<T>::operator[];
using std::basic_string_view<T>::empty;
};
/** Generic Reference String Type */
typedef Reference_String<char> ReferenceString;
namespace literals { namespace literals {
/** Reference_String literals */ /** DEPRECATED: Reference_String literals */
inline Jupiter::ReferenceString operator"" _jrs(const char *str, size_t len) { return Jupiter::ReferenceString(str, len); } inline Jupiter::ReferenceString operator"" _jrs(const char *str, size_t len) { return Jupiter::ReferenceString(str, len); }
} }
} }
@ -114,6 +42,4 @@ namespace Jupiter
#define STRING_LITERAL_AS_REFERENCE(str) Jupiter::literals::operator"" _jrs(str, sizeof(str) - 1) #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) #define STRING_LITERAL_AS_NAMED_REFERENCE(name, str) Jupiter::ReferenceString name = STRING_LITERAL_AS_REFERENCE(str)
#include "Reference_String_Imp.h"
#endif // _REFERENCE_STRING_H_HEADER #endif // _REFERENCE_STRING_H_HEADER

78
src/include/Jupiter/Reference_String_Imp.h

@ -1,78 +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_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 <algorithm> // std::min according to standard
#include <cmath> // std::min on MSVC
#include "Functions.h"
// A hack due to some Windows.h inclusion somewhere, ugh
#ifdef min
#undef min
#endif
/**
* IMPLEMENTATION:
* Reference_String
*/
template<typename T> Jupiter::Reference_String<T>::Reference_String(const T *in)
: std::basic_string_view<T>{} {
if (in != nullptr) {
*this = in;
}
}
template<typename T> Jupiter::Reference_String<T>::Reference_String(const Jupiter::Readable_String<T>& in)
: Reference_String(in.data(), in.size()) {
}
template<typename T> size_t Jupiter::Reference_String<T>::size() const {
return std::basic_string_view<T>::size();
}
template<typename T> const T* Jupiter::Reference_String<T>::data() const {
return std::basic_string_view<T>::data();
}
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Reference_String> {
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::Reference_String<Y> *data) {
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
};
template<typename Y> static Jupiter::Reference_String<Y> interpret(uint8_t *&head) {
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::Reference_String<Y> r = Jupiter::Reference_String<Y>(reinterpret_cast<Y *>(head), size_);
head += size_;
return r;
}
};
#endif // _REFERENCE_STRING_IMP

8
src/include/Jupiter/Shift_String_Imp.h

@ -121,11 +121,9 @@ template<typename T> bool Jupiter::Shift_String_Type<T>::setBufferSizeNoCopy(siz
// Jupiter::DataBuffer specialization // Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Shift_String_Type> 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) {
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);
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
}; };
}; };

1
src/include/Jupiter/Socket.h

@ -437,7 +437,6 @@ namespace Jupiter
* @return Number of bytes sent on success, SOCKET_ERROR (-1) otherwise. * @return Number of bytes sent on success, SOCKET_ERROR (-1) otherwise.
* Note: Any returned value less than or equal to 0 should be treated as an error. * Note: Any returned value less than or equal to 0 should be treated as an error.
*/ */
int send(const Jupiter::ReadableString &str);
int send(std::string_view str); int send(std::string_view str);
/** /**

33
src/include/Jupiter/String.hpp

@ -133,7 +133,6 @@ namespace Jupiter
String_Strict(const String_Strict<T> &in); String_Strict(const String_Strict<T> &in);
String_Strict(const Readable_String<T> &in); String_Strict(const Readable_String<T> &in);
String_Strict(const std::basic_string<T> &in); String_Strict(const std::basic_string<T> &in);
explicit String_Strict(const std::basic_string_view<T> &in) : String_Strict<T>(in.data(), in.size()){};
String_Strict(const T *in, size_t len); String_Strict(const T *in, size_t len);
String_Strict(const T *in); String_Strict(const T *in);
String_Strict(const Jupiter::DataBuffer &in); String_Strict(const Jupiter::DataBuffer &in);
@ -161,11 +160,12 @@ namespace Jupiter
}; };
/** String_Strict<T> Addition Operators */ /** String_Strict<T> Addition Operators */
template<typename T> static inline Jupiter::String_Strict<T> operator+(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<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::Readable_String<T> &lhs, const 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::Readable_String<T> &lhs, const Jupiter::Readable_String<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::Readable_String<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<T> &rhs);
template<typename T> static inline Jupiter::String_Strict<T> operator+(const Jupiter::Readable_String<T> &lhs, const 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);
/** /**
* @brief Provides a "loose" String implementation that's more optimized for repeated concatenations. * @brief Provides a "loose" String implementation that's more optimized for repeated concatenations.
@ -324,26 +324,16 @@ namespace Jupiter
typedef String_Strict<char> StringS; typedef String_Strict<char> StringS;
/** Definition of a Loose String. */ /** Definition of a Loose String. */
typedef String_Loose<char> StringL; typedef String_Strict<char> StringL;
/** Definition of a String. */ /** Definition of a String. */
typedef StringL String; typedef StringS String;
namespace literals { namespace literals {
/** String_Strict literals */ /** String_Strict literals */
inline Jupiter::StringS operator""_jss(const char *str, size_t len) { return Jupiter::StringS(str, len); } inline Jupiter::StringS operator""_jss(const char *str, size_t len) { return Jupiter::StringS(str, len); }
} }
// Carried over from Hash_Table.h for compatibility
struct default_hash_function {
size_t operator()(const Jupiter::ReadableString& in) const {
if constexpr (sizeof(size_t) >= sizeof(uint64_t))
return static_cast<size_t>(Jupiter::fnv1a<char>(in));
return static_cast<size_t>(Jupiter::fnv1a_32<char>(in));
}
};
template<typename CharT> template<typename CharT>
struct str_hash { struct str_hash {
using is_transparent = std::true_type; using is_transparent = std::true_type;
@ -357,7 +347,14 @@ namespace Jupiter
auto operator()(const std::basic_string<CharT>& in_key) const noexcept { auto operator()(const std::basic_string<CharT>& in_key) const noexcept {
return std::hash<std::basic_string<CharT>>()(in_key); 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 */ /** Re-enable warning */

20
src/include/Jupiter/String_Imp.h

@ -313,22 +313,27 @@ template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>:
return Jupiter::operator+(*this, rhs); return Jupiter::operator+(*this, rhs);
} }
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const T &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); return Jupiter::String_Strict<T>(lhs, rhs);
} }
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &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); return Jupiter::String_Strict<T>(lhs, rhs);
} }
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const std::basic_string<T> &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); return Jupiter::String_Strict<T>(lhs, rhs);
} }
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const T *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); return Jupiter::String_Strict<T>(lhs, rhs);
} }
@ -337,9 +342,8 @@ template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Strict> 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) template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Strict<Y> *data) {
{ _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Strict>::push<Y>(buffer, data);
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
}; };
template<typename Y> static Jupiter::String_Strict<Y> interpret(uint8_t *&head) template<typename Y> static Jupiter::String_Strict<Y> interpret(uint8_t *&head)
@ -706,7 +710,7 @@ template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Strin
{ {
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Loose<Y> *data) template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Loose<Y> *data)
{ {
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data); _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Type>::push<Y>(buffer, data);
}; };
template<typename Y> static Jupiter::String_Loose<Y> interpret(uint8_t *&head) template<typename Y> static Jupiter::String_Loose<Y> interpret(uint8_t *&head)

66
src/include/Jupiter/String_Type.h

@ -43,7 +43,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 : public Jupiter::Readable_String<T> template<typename T = char> class String_Type
{ {
public: public:
@ -52,7 +52,7 @@ namespace Jupiter
* *
* @return Number of elements in the string. * @return Number of elements in the string.
*/ */
size_t size() const override; size_t size() const;
/** /**
* @brief Returns the maximum number of elements the String can contain, * @brief Returns the maximum number of elements the String can contain,
@ -68,7 +68,7 @@ namespace Jupiter
* *
* @return Pointer to the underlying string of elements. * @return Pointer to the underlying string of elements.
*/ */
const T *data() const override; const T *data() const;
/** /**
* @brief Sets the String's contents based on the format string and input variables. * @brief Sets the String's contents based on the format string and input variables.
@ -183,7 +183,6 @@ namespace Jupiter
*/ */
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);
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, const T *value, size_t valueSize);
virtual size_t replace(size_t index, size_t length, const Jupiter::Readable_String<T> &value);
virtual size_t replace(size_t index, size_t length, std::basic_string_view<T> value); virtual size_t replace(size_t index, size_t length, std::basic_string_view<T> value);
/** /**
@ -197,13 +196,9 @@ namespace Jupiter
virtual size_t replace(const T *target, size_t targetSize, 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 Jupiter::Readable_String<T> &target, const T &value);
//virtual size_t replace(const T &target, const T *value, size_t valueSize);
//virtual size_t replace(const T &target, const Jupiter::Readable_String<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 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 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(const Jupiter::Readable_String<T> &target, const T *value, size_t valueSize);
virtual size_t replace(const Jupiter::Readable_String<T> &target, const Jupiter::Readable_String<T> &value);
virtual size_t replace(std::basic_string_view<T> target, std::basic_string_view<T> value); virtual size_t replace(std::basic_string_view<T> target, std::basic_string_view<T> value);
/** /**
@ -262,21 +257,18 @@ namespace Jupiter
virtual bool setBufferSizeNoCopy(size_t len) = 0; virtual bool setBufferSizeNoCopy(size_t len) = 0;
/** Mutative operators */ /** Mutative operators */
inline String_Type<T> &operator+=(const Readable_String<T> &right) { this->concat(right); return *this; };
inline String_Type<T> &operator+=(const String_Type<T> &right) { this->concat(right); return *this; }; 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<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+=(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-=(size_t right) { this->truncate(right); return *this; };
inline String_Type<T> &operator=(const Readable_String<T> &right) { this->set(right); return *this; };
inline String_Type<T> &operator=(const String_Type<T> &right) { this->set(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<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 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; };
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; };
using Readable_String<T>::operator[];
/** /**
* @brief Default constructor for the String_Type class. * @brief Default constructor for the String_Type class.
*/ */
@ -303,11 +295,61 @@ namespace Jupiter
*/ */
virtual ~String_Type() = default; 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: protected:
T *str{}; /** Pointer for the underlying string of elements */ T *str{}; /** Pointer for the underlying string of elements */
size_t length{}; /** Number of representable elements in the string */ size_t length{}; /** Number of representable elements in the string */
}; };
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 */ /** Generic String Type */
typedef String_Type<char> StringType; typedef String_Type<char> StringType;
} }

19
src/include/Jupiter/String_Type_Imp.h

@ -548,10 +548,6 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_
return Jupiter::String_Type<T>::length; return Jupiter::String_Type<T>::length;
} }
template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, const Jupiter::Readable_String<T> &value) {
return this->replace(index, targetSize, value.data(), value.size());
}
template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, std::basic_string_view<T> value) { 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()); return this->replace(index, targetSize, value.data(), value.size());
} }
@ -716,11 +712,6 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Read
return this->replace(target.data(), target.size(), value, valueSize); return this->replace(target.data(), target.size(), value, valueSize);
} }
template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const Jupiter::Readable_String<T> &value)
{
return this->replace(target.data(), target.size(), value.data(), value.size());
}
template<typename T> size_t Jupiter::String_Type<T>::replace(std::basic_string_view<T> target, std::basic_string_view<T> value) 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()); return this->replace(target.data(), target.size(), value.data(), value.size());
@ -801,11 +792,11 @@ template<typename T> template<template<typename> class R> R<T> Jupiter::String_T
// Jupiter::DataBuffer specialization // Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Type> 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) {
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());
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data); buffer->push(reinterpret_cast<const uint8_t *>(data->data()), data->size() * sizeof(Y));
}; };
}; };

Loading…
Cancel
Save