Browse Source

Replace all ReferenceString& with std::string_view, various cleanup

task/remove_strings
Jessica James 3 years ago
parent
commit
6b693b96a9
  1. 27
      src/common/Command.cpp
  2. 16
      src/common/Database.cpp
  3. 14
      src/common/GenericCommand.cpp
  4. 25
      src/common/HTTP_Server.cpp
  5. 44
      src/common/IRC_Client.cpp
  6. 10
      src/common/Plugin.cpp
  7. 4
      src/common/Socket.cpp
  8. 26
      src/include/Jupiter/Command.h
  9. 8
      src/include/Jupiter/Database.h
  10. 16
      src/include/Jupiter/GenericCommand.h
  11. 8
      src/include/Jupiter/HTTP_QueryString.h
  12. 10
      src/include/Jupiter/HTTP_Server.h
  13. 30
      src/include/Jupiter/IRC_Client.h
  14. 6
      src/include/Jupiter/Plugin.h
  15. 2
      src/include/Jupiter/Reference_String.h
  16. 4
      src/include/Jupiter/Socket.h
  17. 153
      src/include/Jupiter/String.hpp
  18. 369
      src/include/Jupiter/String_Imp.h

27
src/common/Command.cpp

@ -19,42 +19,23 @@
#include <cstring> #include <cstring>
#include "jessilib/unicode.hpp" #include "jessilib/unicode.hpp"
#include "Command.h" #include "Command.h"
#include "String.hpp"
struct Jupiter::Command::Data { // TODO: remove pimpl
std::vector<std::string> triggers;
};
Jupiter::Command::Command() {
m_data = new Data();
}
Jupiter::Command::Command(const Command &command) {
m_data = new Data();
//for (size_t i = 0; i != m_data->triggers.size(); i++) // triggers.size() would always be 0? this code does nothing?
// m_data->triggers.add(new Jupiter::StringS(*command.m_data->triggers.get(i)));
}
Jupiter::Command::~Command() {
delete m_data;
}
// Command Functions // Command Functions
void Jupiter::Command::addTrigger(std::string_view trigger) { void Jupiter::Command::addTrigger(std::string_view trigger) {
m_data->triggers.emplace_back(trigger); m_triggers.emplace_back(trigger);
} }
std::string_view Jupiter::Command::getTrigger(size_t index) const { std::string_view Jupiter::Command::getTrigger(size_t index) const {
return m_data->triggers[index]; return m_triggers[index];
} }
size_t Jupiter::Command::getTriggerCount() const { size_t Jupiter::Command::getTriggerCount() const {
return m_data->triggers.size(); return m_triggers.size();
} }
bool Jupiter::Command::matches(std::string_view in_trigger) const { bool Jupiter::Command::matches(std::string_view in_trigger) const {
for (const auto& trigger : m_data->triggers) { for (const auto& trigger : m_triggers) {
if (jessilib::equalsi(trigger, in_trigger)) { if (jessilib::equalsi(trigger, in_trigger)) {
return true; return true;
} }

16
src/common/Database.cpp

@ -36,7 +36,7 @@ void Jupiter::Database::create_header(FILE *)
{ {
} }
bool Jupiter::Database::process_file(const Jupiter::ReadableString &file) bool Jupiter::Database::process_file(std::string_view file)
{ {
Jupiter::Database::data_->file_name = static_cast<std::string>(file); Jupiter::Database::data_->file_name = static_cast<std::string>(file);
return Jupiter::Database::Data::process_file(this); return Jupiter::Database::Data::process_file(this);
@ -125,17 +125,11 @@ bool Jupiter::Database::append(Jupiter::DataBuffer &data)
return Jupiter::Database::append(Jupiter::Database::data_->file_name, data); return Jupiter::Database::append(Jupiter::Database::data_->file_name, data);
} }
bool Jupiter::Database::append(Jupiter::ReadableString &file, Jupiter::DataBuffer &data) bool Jupiter::Database::append(std::string_view file, Jupiter::DataBuffer &data) {
{ return append(static_cast<std::string>(file), data);
char *str = new char[file.size() + 1];
memcpy(str, file.data(), file.size() * sizeof(char));
str[file.size()] = '\0';
bool r = Jupiter::Database::append(str, data);
delete[] str;
return r;
} }
bool Jupiter::Database::append(std::string &file, Jupiter::DataBuffer &data) bool Jupiter::Database::append(const std::string& file, Jupiter::DataBuffer &data)
{ {
return Jupiter::Database::append(file.c_str(), data); return Jupiter::Database::append(file.c_str(), data);
} }
@ -158,7 +152,7 @@ bool Jupiter::Database::append(FILE *file, Jupiter::DataBuffer &data)
return true; return true;
} }
bool Jupiter::Database::create_database(const Jupiter::ReadableString &file, const Jupiter::DataBuffer *header) bool Jupiter::Database::create_database(std::string_view file, const Jupiter::DataBuffer *header)
{ {
char *str = new char[file.size() + 1]; char *str = new char[file.size() + 1];
memcpy(str, file.data(), file.size() * sizeof(char)); memcpy(str, file.data(), file.size() * sizeof(char));

14
src/common/GenericCommand.cpp

@ -53,7 +53,7 @@ bool Jupiter::GenericCommand::isNamespace() const {
return false; return false;
} }
void Jupiter::GenericCommand::setNamespace(const Jupiter::ReadableString &in_namespace) { void Jupiter::GenericCommand::setNamespace(std::string_view in_namespace) {
if (Jupiter::GenericCommand::m_parent == nullptr) { if (Jupiter::GenericCommand::m_parent == nullptr) {
return; // We have no parent to start from return; // We have no parent to start from
} }
@ -80,7 +80,7 @@ Jupiter::GenericCommandNamespace *Jupiter::GenericCommand::getNamespace() const
/** GenericCommand::ResponseLine */ /** GenericCommand::ResponseLine */
Jupiter::GenericCommand::ResponseLine::ResponseLine(const Jupiter::ReadableString &in_response, GenericCommand::DisplayType in_type) Jupiter::GenericCommand::ResponseLine::ResponseLine(std::string_view in_response, GenericCommand::DisplayType in_type)
: response{ in_response }, : response{ in_response },
type{ in_type } { type{ in_type } {
} }
@ -90,7 +90,7 @@ Jupiter::GenericCommand::ResponseLine::ResponseLine(std::string in_response, Gen
type{ in_type } { type{ in_type } {
} }
Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommand::ResponseLine::set(const Jupiter::ReadableString &in_response, GenericCommand::DisplayType in_type) { Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommand::ResponseLine::set(std::string_view in_response, GenericCommand::DisplayType in_type) {
response = in_response; response = in_response;
type = in_type; type = in_type;
return this; return this;
@ -101,7 +101,7 @@ Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommand::ResponseLine::se
Jupiter::GenericCommandNamespace::~GenericCommandNamespace() { Jupiter::GenericCommandNamespace::~GenericCommandNamespace() {
} }
Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommandNamespace::trigger(const Jupiter::ReadableString &in_input) { Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommandNamespace::trigger(std::string_view in_input) {
GenericCommand* command; GenericCommand* command;
Jupiter::ReferenceString input(in_input); Jupiter::ReferenceString input(in_input);
auto split_input = jessilib::word_split_once_view(input, GENERIC_COMMAND_WORD_DELIMITER_SV); auto split_input = jessilib::word_split_once_view(input, GENERIC_COMMAND_WORD_DELIMITER_SV);
@ -112,13 +112,13 @@ Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommandNamespace::trigger
command = Jupiter::GenericCommandNamespace::getCommand(split_input.first); command = Jupiter::GenericCommandNamespace::getCommand(split_input.first);
if (command != nullptr) { if (command != nullptr) {
return command->trigger(Jupiter::ReferenceString{split_input.second}); return command->trigger(split_input.second);
} }
return new Jupiter::GenericCommand::ResponseLine(""_jrs, Jupiter::GenericCommand::DisplayType::PrivateError); return new Jupiter::GenericCommand::ResponseLine(""_jrs, Jupiter::GenericCommand::DisplayType::PrivateError);
} }
const Jupiter::ReadableString &Jupiter::GenericCommandNamespace::getHelp(const Jupiter::ReadableString &parameters) { std::string_view Jupiter::GenericCommandNamespace::getHelp(std::string_view parameters) {
static Jupiter::ReferenceString not_found = "Error: Command not found"_jrs; static Jupiter::ReferenceString not_found = "Error: Command not found"_jrs;
Jupiter::ReferenceString input(parameters); Jupiter::ReferenceString input(parameters);
@ -136,7 +136,7 @@ const Jupiter::ReadableString &Jupiter::GenericCommandNamespace::getHelp(const J
// Search for command // Search for command
command = Jupiter::GenericCommandNamespace::getCommand(input_split.first); command = Jupiter::GenericCommandNamespace::getCommand(input_split.first);
if (command != nullptr) { if (command != nullptr) {
return command->getHelp(Jupiter::ReferenceString{input_split.second}); return command->getHelp(input_split.second);
} }
// Command not found // Command not found

25
src/common/HTTP_Server.cpp

@ -452,7 +452,7 @@ int Jupiter::HTTP::Server::Data::process_request(HTTPSession &session) {
{ {
// 200 (success) // 200 (success)
// TODO: remove referencestring warpper // TODO: remove referencestring warpper
std::string* content_result = content->execute(Jupiter::ReferenceString{query_string}); std::string* content_result = content->execute(query_string);
switch (session.version) switch (session.version)
{ {
@ -481,21 +481,22 @@ int Jupiter::HTTP::Server::Data::process_request(HTTPSession &session) {
result += "Connection: close"_jrs ENDL; result += "Connection: close"_jrs ENDL;
result += "Content-Type: "_jrs; result += "Content-Type: "_jrs;
if (content->type == nullptr) if (content->type.empty()) {
result += Jupiter::HTTP::Content::Type::Text::PLAIN; result += Jupiter::HTTP::Content::Type::Text::PLAIN;
else }
result += *content->type; else {
if (content->charset != nullptr) result += content->type;
{ }
if (!content->charset.empty()) {
result += "; charset="_jrs; result += "; charset="_jrs;
result += *content->charset; result += content->charset;
} }
result += ENDL; result += ENDL;
if (content->language != nullptr) if (!content->language.empty()) {
{
result += "Content-Language: "_jrs; result += "Content-Language: "_jrs;
result += *content->language; result += content->language;
result += ENDL; result += ENDL;
} }
@ -827,5 +828,5 @@ int Jupiter::HTTP::Server::think() {
return 0; return 0;
} }
const Jupiter::ReadableString &Jupiter::HTTP::Server::global_namespace = ""_jrs; std::string_view Jupiter::HTTP::Server::global_namespace = ""_jrs;
const Jupiter::ReadableString &Jupiter::HTTP::Server::server_string = "Jupiter"_jrs; std::string_view Jupiter::HTTP::Server::server_string = "Jupiter"_jrs;

44
src/common/IRC_Client.cpp

@ -215,7 +215,7 @@ std::string_view Jupiter::IRC::Client::getRealname() const {
return m_realname; return m_realname;
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::getServerName() const { std::string_view Jupiter::IRC::Client::getServerName() const {
return m_server_name; return m_server_name;
} }
@ -270,7 +270,7 @@ int Jupiter::IRC::Client::getAccessLevel(const Channel &in_channel, std::string_
} }
int Jupiter::IRC::Client::getAccessLevel(std::string_view in_channel, std::string_view in_nickname) const { int Jupiter::IRC::Client::getAccessLevel(std::string_view in_channel, std::string_view in_nickname) const {
auto channel = m_channels.find(Jupiter::ReferenceString{in_channel}); auto channel = m_channels.find(in_channel);
if (channel != m_channels.end()) if (channel != m_channels.end())
return this->getAccessLevel(channel->second, in_nickname); return this->getAccessLevel(channel->second, in_nickname);
@ -278,7 +278,7 @@ int Jupiter::IRC::Client::getAccessLevel(std::string_view in_channel, std::strin
return 0; return 0;
} }
void Jupiter::IRC::Client::send(const Jupiter::ReadableString &rawMessage) { void Jupiter::IRC::Client::send(std::string_view rawMessage) {
Jupiter::StringS out = rawMessage; Jupiter::StringS out = rawMessage;
out += ENDL; out += ENDL;
@ -294,7 +294,7 @@ size_t Jupiter::IRC::Client::getUserCount() const {
} }
std::shared_ptr<Jupiter::IRC::Client::User> Jupiter::IRC::Client::getUser(std::string_view in_nickname) const { std::shared_ptr<Jupiter::IRC::Client::User> Jupiter::IRC::Client::getUser(std::string_view in_nickname) const {
auto user = m_users.find(Jupiter::ReferenceString{in_nickname}); auto user = m_users.find(in_nickname);
if (user != m_users.end()) { if (user != m_users.end()) {
return user->second; return user->second;
} }
@ -368,7 +368,7 @@ size_t Jupiter::IRC::Client::messageChannels(int type, std::string_view message)
return m_channels.size(); return m_channels.size();
} }
size_t Jupiter::IRC::Client::messageChannels(const Jupiter::ReadableString &message) size_t Jupiter::IRC::Client::messageChannels(std::string_view message)
{ {
for (auto& channel : m_channels) { for (auto& channel : m_channels) {
sendMessage(channel.second.getName(), message); sendMessage(channel.second.getName(), message);
@ -926,7 +926,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
} }
if (user->getChannelCount() == 0) { if (user->getChannelCount() == 0) {
m_users.erase(Jupiter::ReferenceString{kicked_nickname}); m_users.erase(kicked_nickname);
} }
} }
} }
@ -1164,7 +1164,7 @@ void Jupiter::IRC::Client::disconnect(bool stayDead)
} }
} }
void Jupiter::IRC::Client::disconnect(const Jupiter::ReadableString &message, bool stayDead) void Jupiter::IRC::Client::disconnect(std::string_view message, bool stayDead)
{ {
m_socket->send(Jupiter::StringS::Format("QUIT :%.*s" ENDL, message.size(), message.data())); m_socket->send(Jupiter::StringS::Format("QUIT :%.*s" ENDL, message.size(), message.data()));
Jupiter::IRC::Client::disconnect(stayDead); Jupiter::IRC::Client::disconnect(stayDead);
@ -1253,7 +1253,7 @@ int Jupiter::IRC::Client::think()
return handle_error(tmp); return handle_error(tmp);
} }
std::string_view Jupiter::IRC::Client::readConfigValue(const Jupiter::ReadableString &key, std::string_view defaultValue) const { std::string_view Jupiter::IRC::Client::readConfigValue(std::string_view key, std::string_view defaultValue) const {
if (m_primary_section != nullptr) { if (m_primary_section != nullptr) {
std::string_view val = m_primary_section->get(key); std::string_view val = m_primary_section->get(key);
if (!val.empty()) { if (!val.empty()) {
@ -1268,7 +1268,7 @@ std::string_view Jupiter::IRC::Client::readConfigValue(const Jupiter::ReadableSt
return defaultValue; return defaultValue;
} }
bool Jupiter::IRC::Client::readConfigBool(const Jupiter::ReadableString &key, bool defaultValue) const { bool Jupiter::IRC::Client::readConfigBool(std::string_view key, bool defaultValue) const {
if (m_primary_section != nullptr) { if (m_primary_section != nullptr) {
std::string_view val = m_primary_section->get(key); std::string_view val = m_primary_section->get(key);
@ -1284,7 +1284,7 @@ bool Jupiter::IRC::Client::readConfigBool(const Jupiter::ReadableString &key, bo
return defaultValue; return defaultValue;
} }
int Jupiter::IRC::Client::readConfigInt(const Jupiter::ReadableString &key, int defaultValue) const { int Jupiter::IRC::Client::readConfigInt(std::string_view key, int defaultValue) const {
if (m_primary_section != nullptr) { if (m_primary_section != nullptr) {
std::string_view val = m_primary_section->get(key); std::string_view val = m_primary_section->get(key);
@ -1300,7 +1300,7 @@ int Jupiter::IRC::Client::readConfigInt(const Jupiter::ReadableString &key, int
return defaultValue; return defaultValue;
} }
long Jupiter::IRC::Client::readConfigLong(const Jupiter::ReadableString &key, long defaultValue) const { long Jupiter::IRC::Client::readConfigLong(std::string_view key, long defaultValue) const {
if (m_primary_section != nullptr) { if (m_primary_section != nullptr) {
std::string_view val = m_primary_section->get(key); std::string_view val = m_primary_section->get(key);
@ -1315,7 +1315,7 @@ long Jupiter::IRC::Client::readConfigLong(const Jupiter::ReadableString &key, lo
return defaultValue; return defaultValue;
} }
double Jupiter::IRC::Client::readConfigDouble(const Jupiter::ReadableString &key, double defaultValue) const { double Jupiter::IRC::Client::readConfigDouble(std::string_view key, double defaultValue) const {
if (m_primary_section != nullptr) { if (m_primary_section != nullptr) {
std::string_view val = m_primary_section->get(key); std::string_view val = m_primary_section->get(key);
@ -1331,7 +1331,7 @@ double Jupiter::IRC::Client::readConfigDouble(const Jupiter::ReadableString &key
return defaultValue; return defaultValue;
} }
void Jupiter::IRC::Client::writeToLogs(const Jupiter::ReadableString &message) { void Jupiter::IRC::Client::writeToLogs(std::string_view message) {
if (m_log_file != nullptr) { if (m_log_file != nullptr) {
fwrite(message.data(), sizeof(char), message.size(), m_log_file); fwrite(message.data(), sizeof(char), message.size(), m_log_file);
fputs("\r\n", m_log_file); fputs("\r\n", m_log_file);
@ -1344,10 +1344,10 @@ void Jupiter::IRC::Client::writeToLogs(const Jupiter::ReadableString &message) {
*/ */
void Jupiter::IRC::Client::delChannel(std::string_view in_channel) { void Jupiter::IRC::Client::delChannel(std::string_view in_channel) {
m_channels.erase(Jupiter::ReferenceString{in_channel}); m_channels.erase(in_channel);
} }
std::shared_ptr<Jupiter::IRC::Client::User> Jupiter::IRC::Client::findUser(const Jupiter::ReadableString &in_nickname) const { std::shared_ptr<Jupiter::IRC::Client::User> Jupiter::IRC::Client::findUser(std::string_view in_nickname) const {
return getUser(in_nickname); return getUser(in_nickname);
} }
@ -1452,7 +1452,7 @@ size_t Jupiter::IRC::Client::User::getChannelCount() const {
* Channel Implementation * Channel Implementation
*/ */
Jupiter::IRC::Client::Channel::Channel(const Jupiter::ReadableString &in_name, Jupiter::IRC::Client *in_parent) { Jupiter::IRC::Client::Channel::Channel(std::string_view in_name, Jupiter::IRC::Client *in_parent) {
auto to_lower = [&in_name]() { auto to_lower = [&in_name]() {
Jupiter::String result(in_name.size()); Jupiter::String result(in_name.size());
const char *itr = in_name.data(); const char *itr = in_name.data();
@ -1490,7 +1490,7 @@ std::shared_ptr<Jupiter::IRC::Client::Channel::User> Jupiter::IRC::Client::Chann
++user->m_channel_count; ++user->m_channel_count;
m_users[Jupiter::ReferenceString{channel_user->getNickname()}] = channel_user; m_users[channel_user->getNickname()] = channel_user;
return channel_user; return channel_user;
} }
@ -1501,12 +1501,12 @@ std::shared_ptr<Jupiter::IRC::Client::Channel::User> Jupiter::IRC::Client::Chann
++user->m_channel_count; ++user->m_channel_count;
m_users[Jupiter::ReferenceString{channel_user->getNickname()}] = channel_user; m_users[channel_user->getNickname()] = channel_user;
return channel_user; return channel_user;
} }
void Jupiter::IRC::Client::Channel::delUser(std::string_view in_nickname) { void Jupiter::IRC::Client::Channel::delUser(std::string_view in_nickname) {
m_users.erase(Jupiter::ReferenceString{in_nickname}); m_users.erase(in_nickname);
} }
void Jupiter::IRC::Client::Channel::addUserPrefix(std::string_view in_nickname, char prefix) { void Jupiter::IRC::Client::Channel::addUserPrefix(std::string_view in_nickname, char prefix) {
@ -1527,12 +1527,12 @@ void Jupiter::IRC::Client::Channel::delUserPrefix(std::string_view in_nickname,
} }
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::getName() const { std::string_view Jupiter::IRC::Client::Channel::getName() const {
return m_name; return m_name;
} }
std::shared_ptr<Jupiter::IRC::Client::Channel::User> Jupiter::IRC::Client::Channel::getUser(std::string_view in_nickname) const { std::shared_ptr<Jupiter::IRC::Client::Channel::User> Jupiter::IRC::Client::Channel::getUser(std::string_view in_nickname) const {
auto user = m_users.find(Jupiter::ReferenceString{in_nickname}); auto user = m_users.find(in_nickname);
if (user != m_users.end()) { if (user != m_users.end()) {
return user->second; return user->second;
} }
@ -1591,7 +1591,7 @@ Jupiter::IRC::Client::User *Jupiter::IRC::Client::Channel::User::getUser() const
return m_user.get(); return m_user.get();
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::User::getPrefixes() const { std::string_view Jupiter::IRC::Client::Channel::User::getPrefixes() const {
return m_prefixes; return m_prefixes;
} }

10
src/common/Plugin.cpp

@ -73,7 +73,7 @@ const char module_file_extension[]{ ".dll" };
const char module_file_extension[]{ ".so" }; const char module_file_extension[]{ ".so" };
#endif // _WIN32 #endif // _WIN32
const Jupiter::ReferenceString config_file_extension = ".ini"_jrs; constexpr std::string_view config_file_extension = ".ini"sv;
std::string plugins_directory = "Plugins"s + directory_character; std::string plugins_directory = "Plugins"s + directory_character;
std::string plugin_configs_directory = "Configs"s + directory_character; std::string plugin_configs_directory = "Configs"s + directory_character;
@ -102,7 +102,7 @@ bool Jupiter::Plugin::shouldRemove() const {
return _shouldRemove; return _shouldRemove;
} }
const Jupiter::ReadableString &Jupiter::Plugin::getName() const { std::string_view Jupiter::Plugin::getName() const {
return name; return name;
} }
@ -119,7 +119,7 @@ void Jupiter::Plugin::OnPostInitialize() {
// Static Functions // Static Functions
void Jupiter::Plugin::setDirectory(const Jupiter::ReadableString &dir) { void Jupiter::Plugin::setDirectory(std::string_view dir) {
plugins_directory = dir; plugins_directory = dir;
if (!plugins_directory.empty() && plugins_directory.back() != directory_character) { if (!plugins_directory.empty() && plugins_directory.back() != directory_character) {
plugins_directory += directory_character; plugins_directory += directory_character;
@ -130,7 +130,7 @@ const std::string& Jupiter::Plugin::getDirectory() {
return plugins_directory; return plugins_directory;
} }
void Jupiter::Plugin::setConfigDirectory(const Jupiter::ReadableString &dir) { void Jupiter::Plugin::setConfigDirectory(std::string_view dir) {
plugin_configs_directory = dir; plugin_configs_directory = dir;
if (!plugin_configs_directory.empty() && plugin_configs_directory.back() != directory_character) { if (!plugin_configs_directory.empty() && plugin_configs_directory.back() != directory_character) {
plugin_configs_directory += directory_character; plugin_configs_directory += directory_character;
@ -180,7 +180,7 @@ Jupiter::Plugin *Jupiter::Plugin::load(const std::string_view& pluginName) {
} }
// Initialize the plugin // Initialize the plugin
weak_plugin->name = Jupiter::ReferenceString{pluginName}; weak_plugin->name = pluginName;
std::string config_path = plugin_configs_directory; std::string config_path = plugin_configs_directory;
config_path += pluginName; config_path += pluginName;
config_path += config_file_extension; config_path += config_file_extension;

4
src/common/Socket.cpp

@ -476,12 +476,12 @@ size_t Jupiter::Socket::getBufferSize() const {
return Jupiter::Socket::data_->buffer.capacity(); return Jupiter::Socket::data_->buffer.capacity();
} }
const Jupiter::ReadableString &Jupiter::Socket::setBufferSize(size_t size) { std::string_view Jupiter::Socket::setBufferSize(size_t size) {
Jupiter::Socket::data_->buffer.setBufferSize(size); Jupiter::Socket::data_->buffer.setBufferSize(size);
return Jupiter::Socket::data_->buffer; return Jupiter::Socket::data_->buffer;
} }
const Jupiter::ReadableString &Jupiter::Socket::getData() { std::string_view Jupiter::Socket::getData() {
if (this->recv() <= 0) if (this->recv() <= 0)
Jupiter::Socket::data_->buffer.erase(); Jupiter::Socket::data_->buffer.erase();
return Jupiter::Socket::data_->buffer; return Jupiter::Socket::data_->buffer;

26
src/include/Jupiter/Command.h

@ -24,8 +24,16 @@
* @brief Provides an extendable command system. * @brief Provides an extendable command system.
*/ */
#include <vector>
#include <string>
#include <string_view>
#include "Jupiter.h" #include "Jupiter.h"
#include "Reference_String.h"
/** DLL Linkage Nagging */
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
namespace Jupiter namespace Jupiter
{ {
@ -73,29 +81,33 @@ namespace Jupiter
* @param parameters Optional string containing any data to be passed to the help command. * @param parameters Optional string containing any data to be passed to the help command.
* @return Brief description of command and syntax. * @return Brief description of command and syntax.
*/ */
virtual const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString &parameters = Jupiter::ReferenceString{}) = 0; virtual std::string_view getHelp(std::string_view parameters = {}) = 0;
/** /**
* @brief Default constructor for command class. * @brief Default constructor for command class.
*/ */
Command(); Command() = default;
/** /**
* @brief Copy constructor for command class. * @brief Copy constructor for command class.
*/ */
Command(const Command &command); Command(const Command &command) = default;
/** /**
* @brief destructor for command class. * @brief destructor for command class.
*/ */
virtual ~Command(); virtual ~Command() = default;
/** Private members */ /** Private members */
private: private:
struct Data; std::vector<std::string> m_triggers;
Data *m_data;
}; };
} }
/** Re-enable warnings */
#if defined _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
#endif // _COMMAND_H_HEADER #endif // _COMMAND_H_HEADER

8
src/include/Jupiter/Database.h

@ -66,7 +66,7 @@ namespace Jupiter
* @param file File being processed * @param file File being processed
* @return True on success, false otherwise * @return True on success, false otherwise
*/ */
bool process_file(const Jupiter::ReadableString &file); bool process_file(std::string_view file);
bool process_file(const std::string &file); bool process_file(const std::string &file);
bool process_file(const char *file); bool process_file(const char *file);
bool process_file(FILE *file); bool process_file(FILE *file);
@ -99,8 +99,8 @@ namespace Jupiter
* @param data DataBuffer to append * @param data DataBuffer to append
* @return True on success, false otherwise. * @return True on success, false otherwise.
*/ */
static bool append(Jupiter::ReadableString &file, Jupiter::DataBuffer &data); static bool append(std::string_view file, Jupiter::DataBuffer &data);
static bool append(std::string &file, Jupiter::DataBuffer &data); static bool append(const std::string& file, Jupiter::DataBuffer &data);
static bool append(const char *file, Jupiter::DataBuffer &data); static bool append(const char *file, Jupiter::DataBuffer &data);
static bool append(FILE *file, Jupiter::DataBuffer &data); static bool append(FILE *file, Jupiter::DataBuffer &data);
@ -111,7 +111,7 @@ namespace Jupiter
* @param flie Name of the Database to generate * @param flie Name of the Database to generate
* @param header DataBuffer containing the header to write to the file * @param header DataBuffer containing the header to write to the file
*/ */
static bool create_database(const Jupiter::ReadableString &file, const Jupiter::DataBuffer *header = nullptr); static bool create_database(std::string_view file, const Jupiter::DataBuffer *header = nullptr);
static bool create_database(const std::string &file, const Jupiter::DataBuffer *header = nullptr); static bool create_database(const std::string &file, const Jupiter::DataBuffer *header = nullptr);
static bool create_database(const char *file, const Jupiter::DataBuffer *header = nullptr); static bool create_database(const char *file, const Jupiter::DataBuffer *header = nullptr);

16
src/include/Jupiter/GenericCommand.h

@ -68,9 +68,9 @@ namespace Jupiter
* @param in_type Value to set type to. * @param in_type Value to set type to.
* @return This. * @return This.
*/ */
ResponseLine *set(const Jupiter::ReadableString &response, GenericCommand::DisplayType type); ResponseLine *set(std::string_view response, GenericCommand::DisplayType type);
ResponseLine() = default; ResponseLine() = default;
ResponseLine(const Jupiter::ReadableString &response, GenericCommand::DisplayType type); ResponseLine(std::string_view response, GenericCommand::DisplayType type);
ResponseLine(std::string response, GenericCommand::DisplayType type); ResponseLine(std::string response, GenericCommand::DisplayType type);
}; };
@ -79,7 +79,7 @@ namespace Jupiter
* *
* @param input Parameters passed to the command by the user. * @param input Parameters passed to the command by the user.
*/ */
virtual ResponseLine *trigger(const Jupiter::ReadableString &input) = 0; virtual ResponseLine *trigger(std::string_view input) = 0;
/** /**
* @brief Checks if this command is a namespace * @brief Checks if this command is a namespace
@ -94,7 +94,7 @@ namespace Jupiter
* *
* @param in_namespace Name of the namespace to move the command into * @param in_namespace Name of the namespace to move the command into
*/ */
void setNamespace(const Jupiter::ReadableString &in_namespace); void setNamespace(std::string_view in_namespace);
/** /**
* @brief Places this command in a namespace * @brief Places this command in a namespace
@ -130,8 +130,8 @@ namespace Jupiter
class JUPITER_API GenericCommandNamespace : public Jupiter::GenericCommand class JUPITER_API GenericCommandNamespace : public Jupiter::GenericCommand
{ {
public: // Jupiter::Command public: // Jupiter::Command
ResponseLine *trigger(const Jupiter::ReadableString &input) override; ResponseLine *trigger(std::string_view input) override;
const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString &parameters) override; std::string_view getHelp(std::string_view parameters) override;
public: // Jupiter::GenericCommand public: // Jupiter::GenericCommand
bool isNamespace() const override; bool isNamespace() const override;
@ -170,8 +170,8 @@ namespace Jupiter
#define BASE_GENERIC_COMMAND(CLASS) \ #define BASE_GENERIC_COMMAND(CLASS) \
public: \ public: \
CLASS(); \ CLASS(); \
Jupiter::GenericCommand::ResponseLine *trigger(const Jupiter::ReadableString &parameters) override; \ Jupiter::GenericCommand::ResponseLine *trigger(std::string_view parameters) override; \
const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString &parameters) override; \ std::string_view getHelp(std::string_view parameters) override; \
static CLASS &instance; static CLASS &instance;
/** Expands to become the entire declaration for a generic command. In most cases, this will be sufficient. */ /** Expands to become the entire declaration for a generic command. In most cases, this will be sufficient. */

8
src/include/Jupiter/HTTP_QueryString.h

@ -39,7 +39,7 @@ namespace Jupiter
{ {
public: public:
QueryString() = delete; QueryString() = delete;
inline QueryString(const Jupiter::ReadableString &query_string) : QueryString(query_string.data(), query_string.size()) {} inline QueryString(std::string_view query_string) : QueryString(query_string.data(), query_string.size()) {}
inline QueryString(const char *ptr, size_t str_size); inline QueryString(const char *ptr, size_t str_size);
}; };
@ -212,7 +212,7 @@ inline Jupiter::HTTP::HTMLFormResponse::HTMLFormResponse(const char *ptr, size_t
else if (*ptr == '&') // End of key/value, start of key else if (*ptr == '&') // End of key/value, start of key
{ {
if (!key.empty()) { // A key was already set; end of value if (!key.empty()) { // A key was already set; end of value
Jupiter::HTTP::HTMLFormResponse::table[key] = Jupiter::ReferenceString(token_start, buf - token_start); Jupiter::HTTP::HTMLFormResponse::table[key] = std::string_view(token_start, buf - token_start);
} }
key = std::string_view{}; key = std::string_view{};
@ -239,13 +239,13 @@ inline Jupiter::HTTP::HTMLFormResponse::HTMLFormResponse(const char *ptr, size_t
{ {
key = std::string_view(token_start, ++buf - token_start); key = std::string_view(token_start, ++buf - token_start);
*buf = *++ptr; *buf = *++ptr;
Jupiter::HTTP::HTMLFormResponse::table[key] = Jupiter::ReferenceString(ptr, 1); Jupiter::HTTP::HTMLFormResponse::table[key] = std::string_view(ptr, 1);
} }
else else
*++buf = *++ptr; *++buf = *++ptr;
if (!key.empty()) // A key was already set; end of value if (!key.empty()) // A key was already set; end of value
Jupiter::HTTP::HTMLFormResponse::table[key] = Jupiter::ReferenceString(token_start, buf - token_start + 1); Jupiter::HTTP::HTMLFormResponse::table[key] = std::string_view(token_start, buf - token_start + 1);
Jupiter::StringType::length = buf + 1 - str; Jupiter::StringType::length = buf + 1 - str;
} }

10
src/include/Jupiter/HTTP_Server.h

@ -46,8 +46,8 @@ namespace Jupiter
public: // Server public: // Server
typedef std::string* HTTPFunction(std::string_view query_string); typedef std::string* HTTPFunction(std::string_view query_string);
static const Jupiter::ReadableString &global_namespace; static std::string_view global_namespace;
static const Jupiter::ReadableString &server_string; static std::string_view server_string;
struct JUPITER_API Content struct JUPITER_API Content
{ {
@ -55,9 +55,9 @@ namespace Jupiter
Jupiter::HTTP::Server::HTTPFunction *function; // function to generate content data Jupiter::HTTP::Server::HTTPFunction *function; // function to generate content data
std::string name; // name of the content std::string name; // name of the content
unsigned int name_checksum; // name.calcChecksum() unsigned int name_checksum; // name.calcChecksum()
const Jupiter::ReadableString *language = nullptr; // Pointer to a constant (or otherwise managed) string std::string_view language; // Pointer to a constant (or otherwise managed) string
const Jupiter::ReadableString *type = nullptr; // Pointer to a constant (or otherwise managed) string std::string_view type; // Pointer to a constant (or otherwise managed) string
const Jupiter::ReadableString *charset = nullptr; // Pointer to a constant (or otherwise managed) string std::string_view charset; // Pointer to a constant (or otherwise managed) string
virtual std::string* execute(std::string_view query_string); virtual std::string* execute(std::string_view query_string);

30
src/include/Jupiter/IRC_Client.h

@ -277,7 +277,7 @@ namespace Jupiter
* *
* @return String containing the user's channel prefixes. * @return String containing the user's channel prefixes.
*/ */
const Jupiter::ReadableString &getPrefixes() const; std::string_view getPrefixes() const;
/** /**
* @brief Fetches the user's nickname. * @brief Fetches the user's nickname.
@ -322,7 +322,7 @@ namespace Jupiter
* *
* @return String containing the name of the channel. * @return String containing the name of the channel.
*/ */
const Jupiter::ReadableString &getName() const; std::string_view getName() const;
/** /**
* @brief Searches for a user based on their nickname. * @brief Searches for a user based on their nickname.
@ -417,7 +417,7 @@ namespace Jupiter
* @param channelName String containing the name of a channel. * @param channelName String containing the name of a channel.
* @param iFace Server in which this channel is located. * @param iFace Server in which this channel is located.
*/ */
Channel(const Jupiter::ReadableString &in_name, Client *in_parent); Channel(std::string_view in_name, Client *in_parent);
/** Private members */ /** Private members */
private: private:
@ -509,7 +509,7 @@ namespace Jupiter
* *
* @return String containing the server's name. * @return String containing the server's name.
*/ */
const Jupiter::ReadableString &getServerName() const; std::string_view getServerName() const;
/** /**
* @brief Returns the server's hostname. * @brief Returns the server's hostname.
@ -693,7 +693,7 @@ namespace Jupiter
* @param message String containing the message to send. * @param message String containing the message to send.
* @return Number of messages sent. * @return Number of messages sent.
*/ */
size_t messageChannels(const Jupiter::ReadableString &in_message); size_t messageChannels(std::string_view in_message);
/** /**
* @brief Returns if the client will automatically reconnect upon failure. * @brief Returns if the client will automatically reconnect upon failure.
@ -715,7 +715,7 @@ namespace Jupiter
* *
* @param rawMessage String containing the data to send. * @param rawMessage String containing the data to send.
*/ */
void send(const Jupiter::ReadableString &in_message); void send(std::string_view in_message);
/** /**
* @brief Processes an input line of IRC protocol data. * @brief Processes an input line of IRC protocol data.
@ -732,7 +732,7 @@ namespace Jupiter
* @param in_default_value Optional parameter specifying the default value to return if none is found. * @param in_default_value Optional parameter specifying the default value to return if none is found.
* @return String containing the key value if it exists, in_default_value otherwise. * @return String containing the key value if it exists, in_default_value otherwise.
*/ */
std::string_view readConfigValue(const Jupiter::ReadableString &key, std::string_view in_default_value = std::string_view{}) const; std::string_view readConfigValue(std::string_view key, std::string_view in_default_value = std::string_view{}) const;
/** /**
* @brief Returns a key's value as a boolean. * @brief Returns a key's value as a boolean.
@ -741,7 +741,7 @@ namespace Jupiter
* @param key String containing the key name. * @param key String containing the key name.
* @return Boolean value of the key value if it exists, in_default_value otherwise. * @return Boolean value of the key value if it exists, in_default_value otherwise.
*/ */
bool readConfigBool(const Jupiter::ReadableString &key, bool in_default_value = false) const; bool readConfigBool(std::string_view key, bool in_default_value = false) const;
/** /**
* @brief Returns a key's value as an integer. * @brief Returns a key's value as an integer.
@ -750,7 +750,7 @@ namespace Jupiter
* @param key String containing the key name. * @param key String containing the key name.
* @return Integer value of the key value if it exists, in_default_value otherwise. * @return Integer value of the key value if it exists, in_default_value otherwise.
*/ */
int readConfigInt(const Jupiter::ReadableString &key, int in_default_value = 0) const; int readConfigInt(std::string_view key, int in_default_value = 0) const;
/** /**
* @brief Returns a key's value as a long integer. * @brief Returns a key's value as a long integer.
@ -759,7 +759,7 @@ namespace Jupiter
* @param key String containing the key name. * @param key String containing the key name.
* @return Long integer value of the key value if it exists, in_default_value otherwise. * @return Long integer value of the key value if it exists, in_default_value otherwise.
*/ */
long readConfigLong(const Jupiter::ReadableString &key, long in_default_value = 0) const; long readConfigLong(std::string_view key, long in_default_value = 0) const;
/** /**
* @brief Returns a key's value as a double. * @brief Returns a key's value as a double.
@ -768,14 +768,14 @@ namespace Jupiter
* @param key String containing the key name. * @param key String containing the key name.
* @return Double value of the key value if it exists, in_default_value otherwise. * @return Double value of the key value if it exists, in_default_value otherwise.
*/ */
double readConfigDouble(const Jupiter::ReadableString &key, double in_default_value = 0) const; double readConfigDouble(std::string_view key, double in_default_value = 0) const;
/** /**
* @brief Writes to the server's log file. * @brief Writes to the server's log file.
* *
* @param message String containing the text to write to the file. * @param message String containing the text to write to the file.
*/ */
void writeToLogs(const Jupiter::ReadableString &in_message); void writeToLogs(std::string_view in_message);
/** /**
* @brief Connects the client to its server. * @brief Connects the client to its server.
@ -797,7 +797,7 @@ namespace Jupiter
* *
* @param message String containing the QUIT message to send prior to disconnecting. * @param message String containing the QUIT message to send prior to disconnecting.
*/ */
void disconnect(const Jupiter::ReadableString &in_message, bool in_stay_dead = false); void disconnect(std::string_view in_message, bool in_stay_dead = false);
/** /**
* @brief Calls disconnect() if the client has not already, then calls connect(). * @brief Calls disconnect() if the client has not already, then calls connect().
@ -845,7 +845,7 @@ namespace Jupiter
Jupiter::Config *m_secondary_section; Jupiter::Config *m_secondary_section;
std::string m_log_file_name; std::string m_log_file_name;
std::string m_last_line; std::string m_last_line;
Jupiter::StringS m_server_name; std::string m_server_name;
std::string m_nickname; std::string m_nickname;
std::string m_realname; std::string m_realname;
@ -877,7 +877,7 @@ namespace Jupiter
bool startCAP(); bool startCAP();
bool registerClient(); bool registerClient();
std::shared_ptr<User> findUser(const Jupiter::ReadableString &in_nickname) const; std::shared_ptr<User> findUser(std::string_view in_nickname) const;
std::shared_ptr<User> findUserOrAdd(std::string_view in_nickname); std::shared_ptr<User> findUserOrAdd(std::string_view in_nickname);
}; // Jupiter::IRC::Client class }; // Jupiter::IRC::Client class

6
src/include/Jupiter/Plugin.h

@ -88,7 +88,7 @@ namespace Jupiter
* *
* @return String containing the name of the plugin. * @return String containing the name of the plugin.
*/ */
const Jupiter::ReadableString &getName() const; std::string_view getName() const;
/** /**
* @brief Returns the plugin's configuration file. * @brief Returns the plugin's configuration file.
@ -296,7 +296,7 @@ namespace Jupiter
* *
* @param dir Directory to look for plugins in. * @param dir Directory to look for plugins in.
*/ */
static void setDirectory(const Jupiter::ReadableString &dir); static void setDirectory(std::string_view dir);
/** /**
* @brief Returns the current plugin directory. * @brief Returns the current plugin directory.
@ -310,7 +310,7 @@ namespace Jupiter
* *
* @param dir Directory to look for configuration files in. * @param dir Directory to look for configuration files in.
*/ */
static void setConfigDirectory(const Jupiter::ReadableString &dir); static void setConfigDirectory(std::string_view dir);
/** /**
* @brief Returns the current plugin configuration directory * @brief Returns the current plugin configuration directory

2
src/include/Jupiter/Reference_String.h

@ -34,7 +34,7 @@ namespace Jupiter {
namespace literals { namespace literals {
/** DEPRECATED: Reference_String literals */ /** DEPRECATED: Reference_String literals */
inline Jupiter::ReferenceString operator"" _jrs(const char *str, size_t len) { return Jupiter::ReferenceString(str, len); } inline constexpr std::string_view operator"" _jrs(const char *str, size_t len) { return { str, len }; }
} }
} }

4
src/include/Jupiter/Socket.h

@ -355,14 +355,14 @@ namespace Jupiter
* @param size The size of the buffer to be made. * @param size The size of the buffer to be made.
* @return The newly created buffer. * @return The newly created buffer.
*/ */
const Jupiter::ReadableString &setBufferSize(size_t size); std::string_view setBufferSize(size_t size);
/** /**
* @brief Copies any new socket data to the buffer and returns it. * @brief Copies any new socket data to the buffer and returns it.
* *
* @return Socket buffer if new data is successfully received, an empty buffer otherwise. * @return Socket buffer if new data is successfully received, an empty buffer otherwise.
*/ */
const Jupiter::ReadableString &getData(); std::string_view getData();
/** /**
* @brief Returns the local hostname of the local machine. * @brief Returns the local hostname of the local machine.

153
src/include/Jupiter/String.hpp

@ -167,159 +167,6 @@ namespace Jupiter
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 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); 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.
* Note: The underlying string will always have a size which is a power of 2, but no fewer than 8 elements.
*
* @param T Element type which the String will store. Defaults to char.
*/
template<typename T = char> class String_Loose : public Shift_String_Type<T>
{
public:
/**
* @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 Sets the String's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param args Inputs to match the format specifiers.
* @return Number of characters written.
*/
size_t vformat(const T *format, va_list args);
/**
* @brief Appends to a String's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param args Inputs to match the format specifiers.
* @return Number of characters written.
*/
size_t avformat(const T *format, va_list args);
/**
* @brief Sets the String's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param ... Inputs to match the format specifiers.
* @return String containing the new format.
*/
static String_Loose<T> Format(const T *format, ...);
/**
* @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_Loose<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_Loose<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_Loose<T> substring(const Jupiter::Readable_String<T> &in, size_t pos);
static typename Jupiter::template String_Loose<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_Loose<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length);
static typename Jupiter::template String_Loose<T> substring(const T *in, size_t pos, size_t length);
/**
* @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 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) override;
/** Default constructor */
String_Loose();
/**
* @brief Size hint constructor.
*
* @param size Minimum number of elements the string must be able to hold.
*/
String_Loose(size_t size);
/** Move Constructor */
String_Loose(String_Loose<T> &&source);
/** Copy Constructors */
String_Loose(const String_Loose<T> &in);
String_Loose(const Readable_String<T> &in);
String_Loose(const std::basic_string<T> &in);
String_Loose(const T *in, size_t len);
String_Loose(const T *in);
String_Loose(const Jupiter::DataBuffer &in);
/** Concatenation Constructors */
String_Loose(const Readable_String<T> &lhs, const T &rhs);
String_Loose(const Readable_String<T> &lhs, const Readable_String<T> &rhs);
String_Loose(const Readable_String<T> &lhs, const std::basic_string<T> &rhs);
String_Loose(const Readable_String<T> &lhs, const T *rhs);
String_Loose(const Readable_String<T> &lhs, const T *rhs, size_t rhs_size);
/** Addition Operators */
inline String_Loose<T> operator+(const T &rhs) const;
inline String_Loose<T> operator+(const String_Loose<T> &rhs) const;
inline String_Loose<T> operator+(const Readable_String<T> &rhs) const;
inline String_Loose<T> operator+(const std::basic_string<T> &rhs) const;
inline String_Loose<T> operator+(const T *rhs) const;
/** Assignment Operators */
inline String_Loose<T> &operator=(const String_Loose<T> &right) { this->set(right); return *this; };
inline String_Loose<T> &operator=(const Readable_String<T> &right) { this->set(right); return *this; };
inline String_Loose<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline String_Loose<T> &operator=(const T *right) { this->set(right); return *this; };
inline String_Loose<T> &operator=(const T right) { this->set(right); return *this; };
static const size_t start_size = 8; /** Starting size for loose Strings. */
protected:
size_t strSize; /** Size of underlying string buffer */
};
/** Definition of a Strict String. */ /** Definition of a Strict String. */
typedef String_Strict<char> StringS; typedef String_Strict<char> StringS;

369
src/include/Jupiter/String_Imp.h

@ -343,7 +343,7 @@ 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::String_Type>::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)
@ -356,371 +356,4 @@ template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Strin
} }
}; };
/**
* IMPLEMENTATION:
* String_Loose
*/
template<typename T> Jupiter::String_Loose<T>::String_Loose() : Jupiter::String_Loose<T>::String_Loose(Jupiter::String_Loose<T>::start_size)
{
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(Jupiter::String_Loose<T> &&source) : Jupiter::Shift_String_Type<T>(std::move(source))
{
Jupiter::String_Loose<T>::strSize = source.strSize;
source.strSize = 0;
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(size_t len)
{
if (len > Jupiter::String_Loose<T>::start_size) Jupiter::String_Loose<T>::strSize = len;
else Jupiter::String_Loose<T>::strSize = Jupiter::String_Loose<T>::start_size;
Jupiter::Shift_String_Type<T>::base = new T[Jupiter::String_Loose<T>::strSize];
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base;
Jupiter::String_Type<T>::length = 0;
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::String_Loose<T> &in)
{
Jupiter::String_Loose<T>::strSize = in.strSize;
Jupiter::Shift_String_Type<T>::base = new T[Jupiter::String_Loose<T>::strSize];
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base;
for (Jupiter::String_Type<T>::length = 0; Jupiter::String_Type<T>::length != in.length; Jupiter::String_Type<T>::length++)
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = in.get(Jupiter::String_Type<T>::length);
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &in) : Jupiter::String_Loose<T>::String_Loose(
in.data(), in.size())
{
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const std::basic_string<T> &in) : Jupiter::String_Loose<T>::String_Loose(in.data(), in.size())
{
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const T *in, size_t len) : Jupiter::String_Loose<T>::String_Loose(len)
{
while (Jupiter::String_Type<T>::length != len)
{
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = *in;
++in, ++Jupiter::String_Type<T>::length;
}
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const T *in)
{
if (in == nullptr)
{
Jupiter::String_Loose<T>::strSize = Jupiter::String_Loose<T>::start_size;
Jupiter::Shift_String_Type<T>::base = new T[Jupiter::String_Loose<T>::strSize];
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base;
Jupiter::String_Type<T>::length = 0;
}
else
{
Jupiter::String_Type<T>::length = Jupiter::strlen<T>(in);
Jupiter::String_Loose<T>::strSize = getPowerTwo(Jupiter::String_Type<T>::length);
if (Jupiter::String_Loose<T>::strSize < Jupiter::String_Loose<T>::start_size) Jupiter::String_Loose<T>::strSize = Jupiter::String_Loose<T>::start_size;
Jupiter::Shift_String_Type<T>::base = new T[Jupiter::String_Loose<T>::strSize];
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base;
for (Jupiter::String_Type<T>::length = 0; *in != 0; Jupiter::String_Type<T>::length++, in++) Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = *in;
}
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::DataBuffer &in) : String_Loose(reinterpret_cast<T *>(in.getHead()), in.size() / sizeof(T))
{
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &lhs, const T &rhs) : String_Loose<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_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &rhs) : String_Loose<T>(lhs,
rhs.data(), rhs.size())
{
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &lhs, const std::basic_string<T> &rhs) : String_Loose<T>(lhs, rhs.data(), rhs.size())
{
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &lhs, const T *rhs) : String_Loose<T>(lhs, rhs, Jupiter::strlen<T>(rhs))
{
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &lhs, const T *rhs, size_t rhs_size) : String_Loose<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> bool Jupiter::String_Loose<T>::setBufferSize(size_t len)
{
size_t offset = Jupiter::String_Type<T>::str - Jupiter::Shift_String_Type<T>::base;
if (len + offset > Jupiter::String_Loose<T>::strSize)
{
if (len > Jupiter::String_Loose<T>::strSize)
{
// Buffer is not large enough; reallocate
Jupiter::String_Loose<T>::strSize = getPowerTwo(len);
T *ptr = new T[Jupiter::String_Loose<T>::strSize];
for (size_t 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;
}
// Buffer has enough space to accomodate; shift data to the left
T *read_itr = Jupiter::String_Type<T>::str;
T *read_end = read_itr + Jupiter::String_Type<T>::length;
T *write_itr = Jupiter::Shift_String_Type<T>::base;
while (read_itr != read_end)
{
*write_itr = *read_itr;
++read_itr;
++write_itr;
}
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base;
}
return false;
}
template<typename T> bool Jupiter::String_Loose<T>::setBufferSizeNoCopy(size_t len)
{
len = getPowerTwo(len);
if (len > Jupiter::String_Loose<T>::strSize)
{
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;
}
// vformat()
template<> size_t inline Jupiter::String_Loose<char>::vformat(const char *format, va_list args)
{
int minLen;
va_list sargs;
va_copy(sargs, args);
minLen = JUPITER_VSCPRINTF(format, sargs);
va_end(sargs);
if (minLen < 0) return 0; // We simply can not work with this.
this->setBufferSizeNoCopy(minLen + 1); // vsnprintf REQUIRES space for an additional null character.
minLen = vsnprintf(Jupiter::String_Type<char>::str, minLen + 1, format, args);
if (minLen < 0) return 0;
return Jupiter::String_Type<char>::length = minLen;
}
template<> size_t inline Jupiter::String_Loose<wchar_t>::vformat(const wchar_t *format, va_list args)
{
int minLen;
va_list sargs;
va_copy(sargs, args);
minLen = JUPITER_VSCWPRINTF(format, sargs);
va_end(sargs);
if (minLen < 0) return 0; // We simply can not work with this.
this->setBufferSizeNoCopy(minLen + 1); // vsnprintf REQUIRES space for an additional null character.
minLen = vswprintf(Jupiter::String_Type<wchar_t>::str, minLen + 1, format, args);
if (minLen < 0) return 0;
return Jupiter::String_Type<wchar_t>::length = minLen;
}
template<typename T> size_t Jupiter::String_Loose<T>::capacity() const
{
return Jupiter::String_Loose<T>::strSize;
}
template<typename T> size_t Jupiter::String_Loose<T>::vformat(const T *format, va_list args)
{
return 0;
}
// avformat()
template<> size_t inline Jupiter::String_Loose<char>::avformat(const char *format, va_list args)
{
int minLen;
va_list sargs;
va_copy(sargs, args);
minLen = JUPITER_VSCPRINTF(format, sargs);
va_end(sargs);
if (minLen < 0) return 0; // We simply can not work with this.
this->setBufferSize(Jupiter::String_Type<char>::length + minLen + 1); // vsnprintf REQUIRES space for an additional null character.
minLen = vsnprintf(Jupiter::String_Type<char>::str + Jupiter::String_Type<char>::length, minLen + 1, format, args);
if (minLen <= 0) return 0;
Jupiter::String_Type<char>::length += minLen;
return minLen;
}
template<> size_t inline Jupiter::String_Loose<wchar_t>::avformat(const wchar_t *format, va_list args)
{
int minLen;
va_list sargs;
va_copy(sargs, args);
minLen = JUPITER_VSCWPRINTF(format, sargs);
va_end(sargs);
if (minLen < 0) return 0; // We simply can not work with this.
this->setBufferSize(minLen + Jupiter::String_Type<wchar_t>::length + 1); // vsnprintf REQUIRES space for an additional null character.
minLen = vswprintf(Jupiter::String_Type<wchar_t>::str + Jupiter::String_Type<wchar_t>::length, minLen + 1, format, args);
if (minLen <= 0) return 0;
Jupiter::String_Type<wchar_t>::length += minLen;
return minLen;
}
template<typename T> size_t Jupiter::String_Loose<T>::avformat(const T *format, va_list args)
{
return 0;
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::Format(const T *format, ...)
{
String_Loose<T> r;
va_list args;
va_start(args, format);
r.vformat(format, args);
va_end(args);
return r;
}
template<typename T> typename Jupiter::template String_Loose<T> Jupiter::String_Loose<T>::substring(size_t pos) const
{
return Jupiter::String_Loose<T>::substring(*this, pos);
}
template<typename T> typename Jupiter::template String_Loose<T> Jupiter::String_Loose<T>::substring(size_t pos, size_t length) const
{
return Jupiter::String_Loose<T>::substring(*this, pos, length);
}
template<typename T> typename Jupiter::template String_Loose<T> Jupiter::String_Loose<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos)
{
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Loose>(in, pos);
}
template<typename T> typename Jupiter::template String_Loose<T> Jupiter::String_Loose<T>::substring(const T *in, size_t pos)
{
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Loose>(in, pos);
}
template<typename T> typename Jupiter::template String_Loose<T> Jupiter::String_Loose<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len)
{
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Loose>(in, pos, len);
}
template<typename T> typename Jupiter::template String_Loose<T> Jupiter::String_Loose<T>::substring(const T *in, size_t pos, size_t len)
{
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Loose>(in, pos, len);
}
// Operators
template<typename T> inline Jupiter::String_Loose<T> Jupiter::String_Loose<T>::operator+(const T &rhs) const
{
return Jupiter::operator+(*this, rhs);
}
template<typename T> inline Jupiter::String_Loose<T> Jupiter::String_Loose<T>::operator+(const Jupiter::String_Loose<T> &rhs) const
{
return Jupiter::String_Loose<T>::operator+(reinterpret_cast<const Jupiter::Readable_String<T> &>(rhs));
}
template<typename T> inline Jupiter::String_Loose<T> Jupiter::String_Loose<T>::operator+(const Jupiter::Readable_String<T> &rhs) const
{
return Jupiter::operator+(*this, rhs);
}
template<typename T> inline Jupiter::String_Loose<T> Jupiter::String_Loose<T>::operator+(const std::basic_string<T> &rhs) const
{
return Jupiter::operator+(*this, rhs);
}
template<typename T> inline Jupiter::String_Loose<T> Jupiter::String_Loose<T>::operator+(const T *rhs) const
{
return Jupiter::operator+(*this, rhs);
}
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Loose>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Loose<Y> *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)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::String_Loose<Y> r = Jupiter::String_Loose<Y>(reinterpret_cast<Y *>(head), size_);
head += size_;
return r;
}
};
#endif // _STRING_IMP_H_HEADER #endif // _STRING_IMP_H_HEADER
Loading…
Cancel
Save