Browse Source

Remove most extraneous functions from ReadableString

task/remove_strings
Jessica James 3 years ago
parent
commit
9db2fd92b8
  1. 44
      src/common/File.cpp
  2. 42
      src/common/GenericCommand.cpp
  3. 56
      src/common/HTTP_Server.cpp
  4. 1150
      src/common/IRC_Client.cpp
  5. 30
      src/common/Plugin.cpp
  6. 16
      src/common/Socket.cpp
  7. 2
      src/include/Jupiter/Command.h
  8. 9
      src/include/Jupiter/Config.h
  9. 14
      src/include/Jupiter/File.h
  10. 7
      src/include/Jupiter/GenericCommand.h
  11. 90
      src/include/Jupiter/IRC_Client.h
  12. 1
      src/include/Jupiter/IRC_Numerics.h
  13. 30
      src/include/Jupiter/Plugin.h
  14. 287
      src/include/Jupiter/Readable_String.h
  15. 787
      src/include/Jupiter/Readable_String_Imp.h
  16. 69
      src/include/Jupiter/Reference_String.h
  17. 30
      src/include/Jupiter/Reference_String_Imp.h
  18. 1
      src/include/Jupiter/Socket.h
  19. 115
      src/include/Jupiter/String.hpp
  20. 80
      src/include/Jupiter/String_Imp.h
  21. 12
      src/include/Jupiter/String_Type_Imp.h

44
src/common/File.cpp

@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <string>
#include "jessilib/word_split.hpp"
#include "File.h"
#include "String.hpp"
@ -41,7 +42,7 @@ const size_t defaultBufferSize = 8192;
struct JUPITER_API Jupiter::File::Data { // TODO: remove pimpl
std::string fileName;
std::vector<Jupiter::StringS> lines;
std::vector<std::string> lines;
Data();
Data(const Data &data);
@ -53,6 +54,8 @@ struct JUPITER_API Jupiter::File::Data { // TODO: remove pimpl
#pragma warning(pop)
#endif
using namespace std::literals;
Jupiter::File::Data::Data() {
}
@ -88,7 +91,7 @@ size_t Jupiter::File::getLineCount() const {
return m_data->lines.size();
}
const Jupiter::ReadableString &Jupiter::File::getLine(size_t line) const {
const std::string& Jupiter::File::getLine(size_t line) const {
return m_data->lines[line];
}
@ -96,12 +99,14 @@ const std::string &Jupiter::File::getFileName() const {
return m_data->fileName;
}
bool Jupiter::File::addData(const Jupiter::ReadableString &data) {
unsigned int word_count = data.wordCount(ENDL);
if (word_count == 0) return false;
bool Jupiter::File::addData(std::string_view data) {
auto lines = jessilib::word_split_view(data, "\r\n"sv);
if (lines.empty()) {
return false;
}
for (unsigned int i = 0; i < word_count; i++) {
m_data->lines.emplace_back(std::move(Jupiter::StringS::getWord(data, i, ENDL)));
for (const auto& line : lines) {
m_data->lines.emplace_back(line);
}
return true;
}
@ -121,15 +126,14 @@ bool Jupiter::File::load(const char *file) {
return result;
}
bool Jupiter::File::load(const Jupiter::ReadableString &file) {
std::string fileName = static_cast<std::string>(file);
FILE *filePtr = fopen(fileName.c_str(), "rb");
bool Jupiter::File::load(std::string file) {
FILE *filePtr = fopen(file.c_str(), "rb");
if (filePtr == nullptr) {
return false;
}
if (m_data->fileName.empty()) {
m_data->fileName = fileName;
m_data->fileName = std::move(file);
}
bool r = load(filePtr);
@ -225,7 +229,7 @@ bool Jupiter::File::reload() {
std::string fileName(std::move(m_data->fileName));
unload();
return load(fileName.c_str());
return load(fileName);
}
bool Jupiter::File::reload(const char *file) {
@ -233,9 +237,9 @@ bool Jupiter::File::reload(const char *file) {
return load(file);
}
bool Jupiter::File::reload(const Jupiter::ReadableString &file) {
bool Jupiter::File::reload(std::string file) {
unload();
return load(file);
return load(std::move(file));
}
bool Jupiter::File::reload(FILE *file) {
@ -253,19 +257,23 @@ bool Jupiter::File::sync() {
bool Jupiter::File::sync(const char *file) {
FILE *filePtr = fopen(file, "wb");
if (filePtr == nullptr) return false;
if (filePtr == nullptr) {
return false;
}
sync(filePtr); // Always returns true.
fclose(filePtr);
return true;
}
bool Jupiter::File::sync(const Jupiter::ReadableString &file) {
return sync(static_cast<std::string>(file).c_str());
bool Jupiter::File::sync(const std::string& file) {
return sync(file.c_str());
}
bool Jupiter::File::sync(FILE *file) {
for (const auto& line : m_data->lines) {
line.println(file);
fwrite(line.data(), sizeof(char), line.size(), file);
fputs("\r\n", file);
}
return true;

42
src/common/GenericCommand.cpp

@ -17,12 +17,14 @@
*/
#include "GenericCommand.h"
#include "jessilib/word_split.hpp"
#include "Plugin.h"
using namespace Jupiter::literals;
using namespace std::literals;
constexpr const char GENERIC_COMMAND_WORD_DELIMITER = ' ';
constexpr const char *GENERIC_COMMAND_WORD_DELIMITER_CS = " ";
// Is there a reason we're not using WHITESPACE_SV?
constexpr std::string_view GENERIC_COMMAND_WORD_DELIMITER_SV = " "sv;
Jupiter::GenericCommandNamespace o_generic_commands;
Jupiter::GenericCommandNamespace &Jupiter::g_generic_commands = o_generic_commands;
@ -52,17 +54,14 @@ bool Jupiter::GenericCommand::isNamespace() const {
}
void Jupiter::GenericCommand::setNamespace(const Jupiter::ReadableString &in_namespace) {
if (in_namespace.wordCount(GENERIC_COMMAND_WORD_DELIMITER_CS) == 0) {
return; // We're already here
}
if (Jupiter::GenericCommand::m_parent == nullptr) {
return; // We have no parent to start from
}
Jupiter::GenericCommand *command = Jupiter::GenericCommand::m_parent->getCommand(in_namespace);
if (command != nullptr && command->isNamespace())
Jupiter::GenericCommand::setNamespace(*static_cast<Jupiter::GenericCommandNamespace *>(command));
if (command != nullptr && command != this && command->isNamespace()) {
Jupiter::GenericCommand::setNamespace(*static_cast<Jupiter::GenericCommandNamespace*>(command));
}
}
void Jupiter::GenericCommand::setNamespace(Jupiter::GenericCommandNamespace &in_namespace) {
@ -86,6 +85,11 @@ Jupiter::GenericCommand::ResponseLine::ResponseLine(const Jupiter::ReadableStrin
type{ in_type } {
}
Jupiter::GenericCommand::ResponseLine::ResponseLine(std::string in_response, GenericCommand::DisplayType in_type)
: response{ std::move(in_response) },
type{ in_type } {
}
Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommand::ResponseLine::set(const Jupiter::ReadableString &in_response, GenericCommand::DisplayType in_type) {
response = in_response;
type = in_type;
@ -100,23 +104,26 @@ Jupiter::GenericCommandNamespace::~GenericCommandNamespace() {
Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommandNamespace::trigger(const Jupiter::ReadableString &in_input) {
GenericCommand* command;
Jupiter::ReferenceString input(in_input);
auto split_input = jessilib::word_split_once_view(input, GENERIC_COMMAND_WORD_DELIMITER_SV);
if (input.wordCount(GENERIC_COMMAND_WORD_DELIMITER_CS) == 0) { // No parameters; list commands
if (split_input.second.empty()) { // No parameters; list commands
return new Jupiter::GenericCommand::ResponseLine(m_help,Jupiter::GenericCommand::DisplayType::PrivateSuccess);
}
command = Jupiter::GenericCommandNamespace::getCommand(input.getWord(0, GENERIC_COMMAND_WORD_DELIMITER_CS));
command = Jupiter::GenericCommandNamespace::getCommand(split_input.first);
if (command != nullptr) {
return command->trigger(input.gotoWord(1, GENERIC_COMMAND_WORD_DELIMITER_CS));
return command->trigger(Jupiter::ReferenceString{split_input.second});
}
return new Jupiter::GenericCommand::ResponseLine(Jupiter::ReferenceString::empty, Jupiter::GenericCommand::DisplayType::PrivateError);
return new Jupiter::GenericCommand::ResponseLine(""_jrs, Jupiter::GenericCommand::DisplayType::PrivateError);
}
const Jupiter::ReadableString &Jupiter::GenericCommandNamespace::getHelp(const Jupiter::ReadableString &parameters) {
static Jupiter::ReferenceString not_found = "Error: Command not found"_jrs;
Jupiter::ReferenceString input(parameters);
if (parameters.wordCount(GENERIC_COMMAND_WORD_DELIMITER_CS) == 0) // No parameters; list commands
auto input_split = jessilib::word_split_once_view(input, GENERIC_COMMAND_WORD_DELIMITER_SV);
if (input_split.second.empty()) // No parameters; list commands
{
if (Jupiter::GenericCommandNamespace::m_should_update_help)
Jupiter::GenericCommandNamespace::updateHelp();
@ -124,13 +131,12 @@ const Jupiter::ReadableString &Jupiter::GenericCommandNamespace::getHelp(const J
return Jupiter::GenericCommandNamespace::m_help;
}
Jupiter::ReferenceString input(parameters);
GenericCommand *command;
// Search for command
command = Jupiter::GenericCommandNamespace::getCommand(input.getWord(0, GENERIC_COMMAND_WORD_DELIMITER_CS));
command = Jupiter::GenericCommandNamespace::getCommand(input_split.first);
if (command != nullptr) {
return command->getHelp(input.gotoWord(1, GENERIC_COMMAND_WORD_DELIMITER_CS));
return command->getHelp(Jupiter::ReferenceString{input_split.second});
}
// Command not found
@ -169,7 +175,7 @@ std::vector<Jupiter::GenericCommand*> Jupiter::GenericCommandNamespace::getComma
return result;
}
Jupiter::GenericCommand *Jupiter::GenericCommandNamespace::getCommand(const Jupiter::ReadableString &in_command) const {
Jupiter::GenericCommand *Jupiter::GenericCommandNamespace::getCommand(std::string_view in_command) const {
/** This is broken into 2 loops in order to insure that exact matches are ALWAYS prioritized over inexact matches */
// Search commands
@ -212,7 +218,7 @@ void Jupiter::GenericCommandNamespace::removeCommand(Jupiter::GenericCommand &in
}
}
void Jupiter::GenericCommandNamespace::removeCommand(const Jupiter::ReadableString &in_command)
void Jupiter::GenericCommandNamespace::removeCommand(std::string_view in_command)
{
for (auto itr = m_commands.begin(); itr != m_commands.end(); ++itr) {
if ((*itr)->matches(in_command)) {

56
src/common/HTTP_Server.cpp

@ -93,26 +93,26 @@ Jupiter::HTTP::Server::Directory::~Directory() {
// .hook("dir/subdir/", content)
void Jupiter::HTTP::Server::Directory::hook(std::string_view in_name, std::unique_ptr<Content> in_content) {
Jupiter::ReferenceString in_name_ref = in_name;
in_name_ref.shiftRight(in_name_ref.span('/'));
std::string_view in_name_ref = in_name;
size_t in_name_start = in_name_ref.find_first_not_of('/');
if (in_name_ref.isEmpty()) { // Hook content
if (in_name_start == std::string_view::npos) { // Hook content
content.push_back(std::move(in_content));
return;
}
in_name_ref.remove_prefix(in_name_start);
size_t index = in_name_ref.find('/');
size_t in_name_end = in_name_ref.find('/');
std::string_view dir_name;
if (index == Jupiter::INVALID_INDEX) {
if (in_name_end == std::string_view::npos) {
dir_name = in_name_ref;
}
else {
dir_name = in_name_ref.substring(size_t{ 0 }, index);
dir_name = in_name_ref.substr(size_t{ 0 }, in_name_end);
}
in_name_ref.shiftRight(dir_name.size());
in_name_ref.remove_prefix(dir_name.size());
unsigned int dir_name_checksum = calc_checksum(dir_name);
index = directories.size();
for (auto& directory : directories) {
if (directory->name_checksum == dir_name_checksum && directory->name == dir_name) {
directory->hook(in_name_ref, std::move(in_content));
@ -124,14 +124,16 @@ void Jupiter::HTTP::Server::Directory::hook(std::string_view in_name, std::uniqu
Directory* directory = directories.emplace_back(std::make_unique<Directory>(static_cast<std::string>(dir_name))).get();
directory_add_loop: // TODO: for the love of god, why why why
in_name_ref.shiftRight(in_name_ref.span('/'));
if (in_name_ref.isNotEmpty()) {
in_name_start = in_name_ref.find_first_not_of('/');
if (in_name_start != std::string_view::npos) {
in_name_ref.remove_prefix(in_name_start);
// add directory
index = in_name_ref.find('/');
size_t index = in_name_ref.find('/');
if (index != Jupiter::INVALID_INDEX) {
directory->directories.push_back(std::make_unique<Directory>(static_cast<std::string>(in_name_ref.substring(size_t{ 0 }, index))));
directory->directories.push_back(std::make_unique<Directory>(static_cast<std::string>(in_name_ref.substr(size_t{ 0 }, index))));
directory = directory->directories[directories.size() - 1].get();
in_name_ref.shiftRight(index + 1);
in_name_ref.remove_prefix(index + 1);
goto directory_add_loop;
}
directory->directories.push_back(std::make_unique<Directory>(static_cast<std::string>(in_name_ref)));
@ -143,12 +145,11 @@ directory_add_loop: // TODO: for the love of god, why why why
}
bool Jupiter::HTTP::Server::Directory::remove(std::string_view path, std::string_view content_name) {
Jupiter::ReferenceString in_name_ref = path;
in_name_ref.shiftRight(in_name_ref.span('/'));
unsigned int checksum;
std::string_view in_name_ref = path;
size_t in_name_start = in_name_ref.find_first_not_of('/');
if (in_name_ref.isEmpty()) { // Remove content
checksum = calc_checksum(content_name);
if (in_name_start == std::string_view::npos) { // Remove content
unsigned int checksum = calc_checksum(content_name);
for (auto itr = content.begin(); itr != content.end(); ++itr) {
auto& content_node = *itr;
if (content_node->name_checksum == checksum && content_node->name == content_name) {
@ -159,17 +160,18 @@ bool Jupiter::HTTP::Server::Directory::remove(std::string_view path, std::string
return false;
}
in_name_ref.remove_prefix(in_name_start);
// Call remove() on next directory in path
size_t index = in_name_ref.find('/');
std::string_view dir_name;
if (index == Jupiter::INVALID_INDEX)
if (index == std::string_view::npos)
dir_name = in_name_ref;
else
dir_name = in_name_ref.substring(size_t{ 0 }, index);
dir_name = in_name_ref.substr(size_t{ 0 }, index);
in_name_ref.shiftRight(dir_name.size());
checksum = calc_checksum(dir_name);
in_name_ref.remove_prefix(dir_name.size());
unsigned int checksum = calc_checksum(dir_name);
for (auto& directory : directories) {
if (directory->name_checksum == checksum && directory->name == dir_name) {
return directory->remove(in_name_ref, content_name);
@ -300,7 +302,6 @@ Jupiter::HTTP::Server::Data::~Data() {
// Data functions
void Jupiter::HTTP::Server::Data::hook(std::string_view hostname, std::string_view in_path, std::unique_ptr<Content> in_content) {
Jupiter::ReferenceString path = in_path;
Jupiter::ReferenceString dir_name;
Jupiter::HTTP::Server::Host* host = find_host(hostname);
@ -310,12 +311,13 @@ void Jupiter::HTTP::Server::Data::hook(std::string_view hostname, std::string_vi
// OPTIMIZE: create directory tree and return.
}
path.shiftRight(path.span('/'));
if (path.isEmpty()) {
size_t in_path_start = in_path.find_first_not_of('/');
if (in_path_start == std::string_view::npos) {
host->content.push_back(std::move(in_content));
}
else {
host->hook(path, std::move(in_content));
in_path.remove_prefix(in_path_start);
host->hook(in_path, std::move(in_content));
}
}
@ -824,5 +826,5 @@ int Jupiter::HTTP::Server::think() {
return 0;
}
const Jupiter::ReadableString &Jupiter::HTTP::Server::global_namespace = Jupiter::ReferenceString::empty;
const Jupiter::ReadableString &Jupiter::HTTP::Server::global_namespace = ""_jrs;
const Jupiter::ReadableString &Jupiter::HTTP::Server::server_string = "Jupiter"_jrs;

1150
src/common/IRC_Client.cpp

File diff suppressed because it is too large

30
src/common/Plugin.cpp

@ -281,63 +281,63 @@ void Jupiter::Plugin::OnReconnectAttempt(Jupiter::IRC::Client *, bool) {
return;
}
void Jupiter::Plugin::OnRaw(Jupiter::IRC::Client *, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnRaw(Jupiter::IRC::Client *, std::string_view) {
return;
}
void Jupiter::Plugin::OnNumeric(Jupiter::IRC::Client *, long int, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnNumeric(Jupiter::IRC::Client *, long int, std::string_view) {
return;
}
void Jupiter::Plugin::OnError(Jupiter::IRC::Client *, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnError(Jupiter::IRC::Client *, std::string_view) {
return;
}
void Jupiter::Plugin::OnChat(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnChat(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnNotice(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnNotice(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnServerNotice(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnServerNotice(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnCTCP(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnCTCP(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnAction(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnAction(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnInvite(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnInvite(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnJoin(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnJoin(Jupiter::IRC::Client *, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnPart(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnPart(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnNick(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnNick(Jupiter::IRC::Client *, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnKick(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnKick(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnQuit(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnQuit(Jupiter::IRC::Client *, std::string_view, std::string_view) {
return;
}
void Jupiter::Plugin::OnMode(Jupiter::IRC::Client *, const Jupiter::ReadableString &, const Jupiter::ReadableString &, const Jupiter::ReadableString &) {
void Jupiter::Plugin::OnMode(Jupiter::IRC::Client *, std::string_view, std::string_view, std::string_view) {
return;
}

16
src/common/Socket.cpp

@ -346,15 +346,17 @@ in_addr6 Jupiter::Socket::pton6(const char *str) {
Jupiter::StringS Jupiter::Socket::ntop4(uint32_t ip) {
static char buf[16];
if (inet_ntop(AF_INET, &ip, buf, sizeof(buf)) == nullptr)
return Jupiter::StringS::empty;
if (inet_ntop(AF_INET, &ip, buf, sizeof(buf)) == nullptr) {
return {};
}
return Jupiter::String(buf);
}
Jupiter::StringS Jupiter::Socket::ntop6(in_addr6 ip) {
static char buf[46];
if (inet_ntop(AF_INET6, &ip, buf, sizeof(buf)) == nullptr)
return Jupiter::StringS::empty;
if (inet_ntop(AF_INET6, &ip, buf, sizeof(buf)) == nullptr) {
return {};
}
return Jupiter::String(buf);
}
@ -365,7 +367,7 @@ Jupiter::StringS Jupiter::Socket::ntop(void *ip, size_t size) {
case 16:
return ntop6(*reinterpret_cast<in_addr6 *>(ip));
default:
return Jupiter::StringS::empty;
return {};
}
}
@ -503,6 +505,10 @@ int Jupiter::Socket::send(const Jupiter::ReadableString &str) {
return this->send(str.ptr(), str.size());
}
int Jupiter::Socket::send(std::string_view str) {
return this->send(str.data(), str.size());
}
int Jupiter::Socket::send(const char *msg) {
return this->send(msg, strlen(msg));
}

2
src/include/Jupiter/Command.h

@ -73,7 +73,7 @@ namespace Jupiter
* @param parameters Optional string containing any data to be passed to the help command.
* @return Brief description of command and syntax.
*/
virtual const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString &parameters = Jupiter::ReferenceString::empty) = 0;
virtual const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString &parameters = Jupiter::ReferenceString{}) = 0;
/**
* @brief Default constructor for command class.

9
src/include/Jupiter/Config.h

@ -253,14 +253,15 @@ namespace Jupiter
/** Template function implementations */
template<typename T> inline T Jupiter::Config::get(std::string_view in_key, T in_default_value) const
{
template<typename T>
inline T Jupiter::Config::get(std::string_view in_key, T in_default_value) const {
auto result = m_table.find(JUPITER_WRAP_CONFIG_KEY(in_key));
if (result == m_table.end())
if (result == m_table.end()) {
return in_default_value;
}
return static_cast<T>(Jupiter::ReferenceString{result->second});
return from_string<T>(result->second);
}
/** Re-enable warnings */

14
src/include/Jupiter/File.h

@ -48,14 +48,14 @@ namespace Jupiter
* @param line Index of the line to fetch.
* @return Line of text at the specified index.
*/
const Jupiter::ReadableString &getLine(size_t line) const;
const std::string& getLine(size_t line) const;
/**
* @brief Returns the name of the first raw file originally loaded.
*
* @return String containing the name of the first file loaded into this file.
*/
const std::string &getFileName() const;
const std::string& getFileName() const;
/**
* @brief Adds data to a file, which may consist of one or more lines.
@ -63,7 +63,7 @@ namespace Jupiter
* @param data Data to add to the file.
* @param True if data was added to the file, false otherwise.
*/
bool addData(const Jupiter::ReadableString &data);
bool addData(std::string_view data);
/**
* @brief Loads a file from the drive into this file.
@ -72,7 +72,7 @@ namespace Jupiter
* @return True if a file was successfully loaded from the drive, false otherwise.
*/
bool load(const char *file);
bool load(const Jupiter::ReadableString &file);
bool load(std::string file);
/**
* @brief Loads a file from the drive into this file.
@ -101,7 +101,7 @@ namespace Jupiter
* @return True if a file was successfully loaded from the drive, false otherwise.
*/
bool reload(const char *file);
bool reload(const Jupiter::ReadableString &file);
bool reload(std::string file);
/**
* @brief Unloads all of a file's contents, and attempts to load from a specified file stream.
@ -125,7 +125,7 @@ namespace Jupiter
* @return True if the file was successfully written to the drive, false otherwise.
*/
bool sync(const char *file);
bool sync(const Jupiter::ReadableString &file);
bool sync(const std::string& file);
/**
* @brief Syncs data from the file to the drive.
@ -133,7 +133,7 @@ namespace Jupiter
* @param file C FILE stream to output to.
* @return True if the file was successfully written to the drive, false otherwise.
*/
bool sync(FILE *file);
bool sync(FILE *file); // Why are we working with FILE instead of istream?
/**
* @brief Default constructor for File class.

7
src/include/Jupiter/GenericCommand.h

@ -57,7 +57,7 @@ namespace Jupiter
/** Data entry returned by trigger() */
struct JUPITER_API ResponseLine
{
Jupiter::StringS response;
std::string response;
GenericCommand::DisplayType type;
ResponseLine *next = nullptr;
@ -71,6 +71,7 @@ namespace Jupiter
ResponseLine *set(const Jupiter::ReadableString &response, GenericCommand::DisplayType type);
ResponseLine() = default;
ResponseLine(const Jupiter::ReadableString &response, GenericCommand::DisplayType type);
ResponseLine(std::string response, GenericCommand::DisplayType type);
};
/**
@ -140,11 +141,11 @@ namespace Jupiter
void setUsing(bool in_value);
std::vector<GenericCommand*> getCommands() const; // differs from m_commands in that it checks if it's using a namespace
GenericCommand *getCommand(const Jupiter::ReadableString &in_command) const;
GenericCommand *getCommand(std::string_view in_command) const;
void addCommand(GenericCommand &in_command);
void removeCommand(GenericCommand &in_command);
void removeCommand(const Jupiter::ReadableString &in_command);
void removeCommand(std::string_view in_command);
void updateHelp();

90
src/include/Jupiter/IRC_Client.h

@ -77,7 +77,7 @@ namespace Jupiter
*
* @param in_message The raw message.
*/
virtual void OnRaw(const Jupiter::ReadableString &in_message);
virtual void OnRaw(std::string_view in_message);
/**
* @brief This is called after an IRC numeric has been processed.
@ -85,7 +85,7 @@ namespace Jupiter
* @param in_numerouic The numeroic of the message
* @param in_message The raw message.
*/
virtual void OnNumeric(long int in_numeric, const Jupiter::ReadableString &in_message);
virtual void OnNumeric(long int in_numeric, std::string_view in_message);
/**
* @brief This is called when an ERROR is received.
@ -93,7 +93,7 @@ namespace Jupiter
*
* @param message Message sent by the server.
*/
virtual void OnError(const Jupiter::ReadableString &in_message);
virtual void OnError(std::string_view in_message);
/**
* @brief This is called when a chat message is received.
@ -102,7 +102,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnChat(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nickname, const Jupiter::ReadableString &in_message);
virtual void OnChat(std::string_view in_channel, std::string_view in_nickname, std::string_view in_message);
/**
* @brief This is called when a notice is received.
@ -111,7 +111,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnNotice(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_sender, const Jupiter::ReadableString &in_message);
virtual void OnNotice(std::string_view in_channel, std::string_view in_sender, std::string_view in_message);
/**
* @brief This is called when a server notice is received.
@ -120,7 +120,7 @@ namespace Jupiter
* @param nick String containing the sender.
* @param message String containing the message sent.
*/
virtual void OnServerNotice(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_sender, const Jupiter::ReadableString &in_message);
virtual void OnServerNotice(std::string_view in_channel, std::string_view in_sender, std::string_view in_message);
/**
* @brief This is called when a CTCP message is received.
@ -129,7 +129,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnCTCP(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nickname, const Jupiter::ReadableString &in_command, const Jupiter::ReadableString &in_message);
virtual void OnCTCP(std::string_view in_channel, std::string_view in_nickname, std::string_view in_command, std::string_view in_message);
/**
* @brief This is called when an action message is received.
@ -138,7 +138,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnAction(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nickname, const Jupiter::ReadableString &in_message);
virtual void OnAction(std::string_view in_channel, std::string_view in_nickname, std::string_view in_message);
/**
* @brief This is called when an invite is received.
@ -147,7 +147,7 @@ namespace Jupiter
* @param inviter String containing the nickname of the inviter.
* @param invited String containing the nickname of the user invited.
*/
virtual void OnInvite(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_inviter, const Jupiter::ReadableString &in_invited);
virtual void OnInvite(std::string_view in_channel, std::string_view in_inviter, std::string_view in_invited);
/**
* @brief This is called when a chat message is received.
@ -156,7 +156,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnJoin(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nickname);
virtual void OnJoin(std::string_view in_channel, std::string_view in_nickname);
/**
* @brief This is called when a user parts a channel.
@ -165,7 +165,7 @@ namespace Jupiter
* @param nick String containing the nickname of the user.
* @param reason String containing the reason for parting, or nullptr if none is specified.
*/
virtual void OnPart(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nickname, const Jupiter::ReadableString &in_reason);
virtual void OnPart(std::string_view in_channel, std::string_view in_nickname, std::string_view in_reason);
/**
* @brief This is called when a user changes their nickname.
@ -173,7 +173,7 @@ namespace Jupiter
* @param oldnick String containing the old nickname of the user.
* @param newnick String containing the new nickname of the user.
*/
virtual void OnNick(const Jupiter::ReadableString &in_old_nick, const Jupiter::ReadableString &in_new_nick);
virtual void OnNick(std::string_view in_old_nick, std::string_view in_new_nick);
/**
* @brief This is called when a user is kicked from a channel.
@ -183,7 +183,7 @@ namespace Jupiter
* @param kicked String containing the nickname of the user kicked.
* @param reason String containing the reason for the kick, or nullptr if none is specified.
*/
virtual void OnKick(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_kicker, const Jupiter::ReadableString &in_kicked, const Jupiter::ReadableString &in_reason);
virtual void OnKick(std::string_view in_channel, std::string_view in_kicker, std::string_view in_kicked, std::string_view in_reason);
/**
* @brief This is called when a user quits the server.
@ -191,7 +191,7 @@ namespace Jupiter
* @param nick String containing the nickname of the user.
* @param message String containing the reason for quiting.
*/
virtual void OnQuit(const Jupiter::ReadableString &in_nickname, const Jupiter::ReadableString &in_message);
virtual void OnQuit(std::string_view in_nickname, std::string_view in_message);
/**
* @brief This is called when a channel mode is changed.
@ -200,7 +200,7 @@ namespace Jupiter
* @param nick String containing the nickname of the user.
* @param modeString String containing the modes changed.
*/
virtual void OnMode(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nickname, const Jupiter::ReadableString &in_mode_string);
virtual void OnMode(std::string_view in_channel, std::string_view in_nickname, std::string_view in_mode_string);
public:
class Channel;
@ -330,7 +330,7 @@ namespace Jupiter
* @param nickname String containing the nickname of the user to find.
* @return A user if a match is found, nullptr otherwise.
*/
std::shared_ptr<Channel::User> getUser(const Jupiter::ReadableString &in_nickname) const;
std::shared_ptr<Channel::User> getUser(std::string_view in_nickname) const;
/**
* @brief Adds a user to the channel
@ -354,7 +354,7 @@ namespace Jupiter
*
* @param nickname String containing the nickname of the user.
*/
void delUser(const Jupiter::ReadableString &in_nickname);
void delUser(std::string_view in_nickname);
/**
* @brief Adds a prefix to a user.
@ -362,7 +362,7 @@ namespace Jupiter
* @param user String containing the nickname of the user.
* @param prefix Prefix to add to the user.
*/
void addUserPrefix(const Jupiter::ReadableString &in_nickname, char in_prefix);
void addUserPrefix(std::string_view in_nickname, char in_prefix);
/**
* @brief Removes a prefix from a user.
@ -370,7 +370,7 @@ namespace Jupiter
* @param user String containing the nickname of a user.
* @param prefix Prefix to remove from the user.
*/
void delUserPrefix(const Jupiter::ReadableString &in_nickname, char in_prefix);
void delUserPrefix(std::string_view in_nickname, char in_prefix);
/**
* @brief Returns a user's most significant prefix.
@ -379,7 +379,7 @@ namespace Jupiter
* @return User's most significant prefix.
*/
char getUserPrefix(const Channel::User &in_user) const;
char getUserPrefix(const Jupiter::ReadableString &in_nickname) const;
char getUserPrefix(std::string_view in_nickname) const;
/**
* @brief Fetches the channel's user table
@ -437,7 +437,7 @@ namespace Jupiter
*
* @return String containing a config section's name.
*/
const Jupiter::ReadableString &getConfigSection() const;
std::string_view getConfigSection() const;
/**
* @brief Fetches the primary config section
@ -481,14 +481,14 @@ namespace Jupiter
*
* @return String containing nickname prefixes.
*/
const Jupiter::ReadableString &getPrefixes() const;
std::string_view getPrefixes() const;
/**
* @brief Returns mode symbols for nickname prefixes supported by the connected server.
*
* @return String containing mode symbols for nickname prefixes.
*/
const Jupiter::ReadableString &getPrefixModes() const;
std::string_view getPrefixModes() const;
/**
* @brief Returns the client's current nickname.
@ -598,7 +598,7 @@ namespace Jupiter
* @param nickname String containing the nickname of the user to fetch.
* @return A User if a match is found, nullptr otherwise.
*/
std::shared_ptr<User> getUser(const Jupiter::ReadableString &in_nickname) const;
std::shared_ptr<User> getUser(std::string_view in_nickname) const;
/**
* @brief Fetches the channel table
@ -620,7 +620,7 @@ namespace Jupiter
* @param chanName String containing the name of a channel.
* @return A channel with the specified name if it exists, nullptr otherwise.
*/
Channel *getChannel(const Jupiter::ReadableString &in_channel) const;
Channel *getChannel(std::string_view in_channel) const;
/**
* @brief Sends a join request.
@ -635,14 +635,14 @@ namespace Jupiter
* @param channel Channel to join.
* @param password Password to use.
*/
void joinChannel(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_password);
void joinChannel(std::string_view in_channel, std::string_view in_password);
/**
* @brief Parts a channel.
*
* @param channel Channel to part.
*/
void partChannel(const Jupiter::ReadableString &in_channel);
void partChannel(std::string_view in_channel);
/**
* @brief Parts a channel.
@ -650,7 +650,7 @@ namespace Jupiter
* @param channel Channel to part.
* @param message Reason for parting.
*/
void partChannel(const Jupiter::ReadableString &in_channel, std::string_view in_message);
void partChannel(std::string_view in_channel, std::string_view in_message);
/**
* @brief Gets the access level of a user.
@ -659,8 +659,8 @@ namespace Jupiter
* @param nick String containing the nickname of the user.
* @return Access level of the user.
*/
int getAccessLevel(const Channel &in_channel, const Jupiter::ReadableString &in_nickname) const;
int getAccessLevel(const Jupiter::ReadableString &in_channel, const Jupiter::ReadableString &in_nickname) const;
int getAccessLevel(const Channel &in_channel, std::string_view in_nickname) const;
int getAccessLevel(std::string_view in_channel, std::string_view in_nickname) const;
/**
* @brief Sends a message.
@ -668,7 +668,7 @@ namespace Jupiter
* @param dest String containing the destination of the message (nickname or channel).
* @param message String containing the message to send.
*/
void sendMessage(const Jupiter::ReadableString &in_destination, const Jupiter::ReadableString &in_message);
void sendMessage(std::string_view in_destination, std::string_view in_message);
/**
* @brief Sends a notice.
@ -676,7 +676,7 @@ namespace Jupiter
* @param dest String containing the destination of the message (nickname or channel).
* @param message String containing the message to send.
*/
void sendNotice(const Jupiter::ReadableString &in_destination, const Jupiter::ReadableString &in_message);
void sendNotice(std::string_view in_destination, std::string_view in_message);
/**
* @brief Sends a message to all channels of a given type.
@ -685,7 +685,7 @@ namespace Jupiter
* @param message String containing the message to send.
* @return Number of messages sent.
*/
size_t messageChannels(int type, const Jupiter::ReadableString &in_message);
size_t messageChannels(int type, std::string_view in_message);
/**
* @brief Sends a message to all channels with a type of at least 0.
@ -732,7 +732,7 @@ namespace Jupiter
* @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.
*/
std::string_view readConfigValue(const Jupiter::ReadableString &key, const Jupiter::ReadableString &in_default_value = Jupiter::ReferenceString::empty) const;
std::string_view readConfigValue(const Jupiter::ReadableString &key, std::string_view in_default_value = std::string_view{}) const;
/**
* @brief Returns a key's value as a boolean.
@ -849,13 +849,13 @@ namespace Jupiter
std::string m_nickname;
std::string m_realname;
Jupiter::StringS m_prefix_modes = "ov";
Jupiter::StringS m_prefixes = "@+";
Jupiter::StringS m_chan_types = "#";
Jupiter::StringS m_modeA = "b";
Jupiter::StringS m_modeB = "k";
Jupiter::StringS m_modeC = "l";
Jupiter::StringS m_modeD = "psitnm";
std::string m_prefix_modes = "ov";
std::string m_prefixes = "@+";
std::string m_chan_types = "#";
std::string m_modeA = "b";
std::string m_modeB = "k";
std::string m_modeC = "l";
std::string m_modeD = "psitnm";
UserTableType m_users;
ChannelTableType m_channels;
@ -871,14 +871,14 @@ namespace Jupiter
int m_default_chan_type;
bool m_dead = false;
void delChannel(const Jupiter::ReadableString &in_channel);
void addNamesToChannel(Channel &in_channel, Jupiter::ReadableString &in_names);
void addChannel(const Jupiter::ReadableString &in_channel);
void delChannel(std::string_view in_channel);
void addNamesToChannel(Channel &in_channel, std::string_view in_names);
void addChannel(std::string_view in_channel);
bool startCAP();
bool registerClient();
std::shared_ptr<User> findUser(const Jupiter::ReadableString &in_nickname) const;
std::shared_ptr<User> findUserOrAdd(const Jupiter::ReadableString &in_nickname);
std::shared_ptr<User> findUserOrAdd(std::string_view in_nickname);
}; // Jupiter::IRC::Client class
} // Jupiter::IRC namespace

1
src/include/Jupiter/IRC_Numerics.h

@ -38,7 +38,6 @@ namespace Jupiter
constexpr NumericType YOURHOST = 2; /** RFC2812: Post-registration. Your host is this server and I am running some daemon */
constexpr NumericType CREATED = 3; /** RFC2812: Post-registration. This was was created at some point in time */
constexpr NumericType MYINFO = 4; /** RFC2812: Post-registration. <server_name> <version> <user_modes> <chan_modes> */
constexpr NumericType BOUNCEOLD = 5; /** RFC2812/DEPRECATED: 005 is rarely used as a bounce indicator, but was defined in RFC2812. */
constexpr NumericType ISUPPORT = 5; /** Used to indicate what a server supports. Does not appear in any RFC, but was drafted in 2004. */
constexpr NumericType SNOMASK = 8; /** Server notice mask */
constexpr NumericType STATMEMTOT = 9; /** I have no idea what this does. */

30
src/include/Jupiter/Plugin.h

@ -139,14 +139,14 @@ namespace Jupiter
*
* @param raw The raw message.
*/
virtual void OnRaw(Jupiter::IRC::Client *server, const Jupiter::ReadableString &raw);
virtual void OnRaw(Jupiter::IRC::Client *server, std::string_view raw);
/**
* @brief This is called after an IRC numeric has been processed.
*
* @param raw The raw message.
*/
virtual void OnNumeric(Jupiter::IRC::Client *server, long int numeric, const Jupiter::ReadableString &raw);
virtual void OnNumeric(Jupiter::IRC::Client *server, long int numeric, std::string_view raw);
/**
* @brief This is called when an ERROR is received.
@ -154,7 +154,7 @@ namespace Jupiter
*
* @param message Message sent by the server.
*/
virtual void OnError(Jupiter::IRC::Client *server, const Jupiter::ReadableString &message);
virtual void OnError(Jupiter::IRC::Client *server, std::string_view message);
/**
* @brief This is called when a chat message is received.
@ -163,7 +163,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnChat(Jupiter::IRC::Client *server, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message);
virtual void OnChat(Jupiter::IRC::Client *server, std::string_view channel, std::string_view nick, std::string_view message);
/**
* @brief This is called when a notice is received.
@ -172,7 +172,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnNotice(Jupiter::IRC::Client *server, const Jupiter::ReadableString &chan, const Jupiter::ReadableString &sender, const Jupiter::ReadableString &message);
virtual void OnNotice(Jupiter::IRC::Client *server, std::string_view chan, std::string_view sender, std::string_view message);
/**
* @brief This is called when a server notice is received.
@ -181,7 +181,7 @@ namespace Jupiter
* @param nick String containing the sender.
* @param message String containing the message sent.
*/
virtual void OnServerNotice(Jupiter::IRC::Client *server, const Jupiter::ReadableString &chan, const Jupiter::ReadableString &sender, const Jupiter::ReadableString &message);
virtual void OnServerNotice(Jupiter::IRC::Client *server, std::string_view chan, std::string_view sender, std::string_view message);
/**
* @brief This is called when a CTCP message is received.
@ -190,7 +190,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnCTCP(Jupiter::IRC::Client *server, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message);
virtual void OnCTCP(Jupiter::IRC::Client *server, std::string_view channel, std::string_view nick, std::string_view message);
/**
* @brief This is called when an action message is received.
@ -199,7 +199,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnAction(Jupiter::IRC::Client *server, const Jupiter::ReadableString &chan, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message);
virtual void OnAction(Jupiter::IRC::Client *server, std::string_view chan, std::string_view nick, std::string_view message);
/**
* @brief This is called when an invite is received.
@ -208,7 +208,7 @@ namespace Jupiter
* @param inviter String containing the nickname of the inviter.
* @param invited String containing the nickname of the user invited.
*/
virtual void OnInvite(Jupiter::IRC::Client *server, const Jupiter::ReadableString &chan, const Jupiter::ReadableString &inviter, const Jupiter::ReadableString &invited);
virtual void OnInvite(Jupiter::IRC::Client *server, std::string_view chan, std::string_view inviter, std::string_view invited);
/**
* @brief This is called when a chat message is received.
@ -217,7 +217,7 @@ namespace Jupiter
* @param nick String containing the nickname of the sender.
* @param message String containing the message sent.
*/
virtual void OnJoin(Jupiter::IRC::Client *server, const Jupiter::ReadableString &chan, const Jupiter::ReadableString &nick);
virtual void OnJoin(Jupiter::IRC::Client *server, std::string_view chan, std::string_view nick);
/**
* @brief This is called when a user parts a channel.
@ -226,7 +226,7 @@ namespace Jupiter
* @param nick String containing the nickname of the user.
* @param reason String containing the reason for parting, or nullptr if none is specified.
*/
virtual void OnPart(Jupiter::IRC::Client *server, const Jupiter::ReadableString &chan, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &reason);
virtual void OnPart(Jupiter::IRC::Client *server, std::string_view chan, std::string_view nick, std::string_view reason);
/**
* @brief This is called when a user changes their nickname.
@ -234,7 +234,7 @@ namespace Jupiter
* @param oldnick String containing the old nickname of the user.
* @param newnick String containing the new nickname of the user.
*/
virtual void OnNick(Jupiter::IRC::Client *server, const Jupiter::ReadableString &oldnick, const Jupiter::ReadableString &newnick);
virtual void OnNick(Jupiter::IRC::Client *server, std::string_view oldnick, std::string_view newnick);
/**
* @brief This is called when a user is kicked from a channel.
@ -244,7 +244,7 @@ namespace Jupiter
* @param kicked String containing the nickname of the user kicked.
* @param reason String containing the reason for the kick, or nullptr if none is specified.
*/
virtual void OnKick(Jupiter::IRC::Client *server, const Jupiter::ReadableString &chan, const Jupiter::ReadableString &kicker, const Jupiter::ReadableString &kicked, const Jupiter::ReadableString &reason);
virtual void OnKick(Jupiter::IRC::Client *server, std::string_view chan, std::string_view kicker, std::string_view kicked, std::string_view reason);
/**
* @brief This is called when a user quits the server.
@ -252,7 +252,7 @@ namespace Jupiter
* @param nick String containing the nickname of the user.
* @param message String containing the reason for quiting.
*/
virtual void OnQuit(Jupiter::IRC::Client *server, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message);
virtual void OnQuit(Jupiter::IRC::Client *server, std::string_view nick, std::string_view message);
/**
* @brief This is called when a channel mode is changed.
@ -261,7 +261,7 @@ namespace Jupiter
* @param nick String containing the nickname of the user.
* @param modeString String containing the modes changed.
*/
virtual void OnMode(Jupiter::IRC::Client *server, const Jupiter::ReadableString &chan, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &modeString);
virtual void OnMode(Jupiter::IRC::Client *server, std::string_view chan, std::string_view nick, std::string_view modeString);
/**
* @brief This is called when a server "thinks".

287
src/include/Jupiter/Readable_String.h

@ -31,6 +31,7 @@
#include <iostream> // std::endl
#include "InvalidIndex.h"
#include "DataBuffer.h"
#include "Functions.h"
namespace Jupiter
{
@ -45,50 +46,33 @@ namespace Jupiter
{
public:
/**
* @brief Fetches an element from the string.
*
* @param index Index of the element to return.
* @return The element located at the specified index.
*/
virtual const T &get(size_t index) const = 0;
/**
* @brief Returns a pointer to the underlying string of elements.
*
* @return Pointer to the underlying string of elements.
*/
virtual const T *ptr() const = 0;
virtual const T *ptr() const = 0; // RENAME; 'data'
/**
* @brief Returns the number of elements in the String.
*
* @return Number of elements in the string.
*/
virtual size_t size() const = 0;
virtual size_t size() const = 0; // KEEP
/**
* @brief Checks if the String is empty.
*
* @return True if the String is empty, false otherwise.
*/
bool isEmpty() const { return size() == 0; };
bool empty() const { return size() == 0; };
bool empty() const { return size() == 0; }; // KEEP
/**
* @brief Checks if the String is not empty.
*
* @return True if the String is not empty, false otherwise.
*/
virtual bool isNotEmpty() const { return !empty(); };
/**
* @brief Checks if the string contains an element with the specified value.
*
* @param value Value of the element to search for.
* @return True if a match is found, false otherwise.
*/
bool contains(const T &value) const;
virtual bool isNotEmpty() const { return !empty(); }; // REMOVE
/**
* @brief Returns the index of the first element in the string with the specified value.
@ -97,18 +81,8 @@ namespace Jupiter
* @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;
size_t find(const Readable_String<T> &in) const;
/**
* @brief Returns the number of elements of the string which match the input string.
*
* @param in Character set to match against.
* @return Number of elements at the start of the string that match the character set.
*/
size_t span(const Readable_String<T> &in) const;
size_t span(const T *str) const;
size_t span(const T &in) const;
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.
@ -117,114 +91,10 @@ namespace Jupiter
* @param in String to compare against.
* @return True if the contents of the strings are equal, false otherwise.
*/
bool equalsi(const Readable_String<T> &in) const;
bool equalsi(const std::basic_string<T> &in) const;
bool equalsi(const T *in, size_t len) const;
bool equalsi(const T &in) const;
/**
* @brief Checks if the String matches a wildcard format.
* Note: Case sensitive.
*
* @param format Format that the string is compared against.
* @return True if the String matches the wildcard format, false otherwise.
*/
bool match(const Readable_String<T> &format) const;
bool match(const std::basic_string<T> &format) const;
bool match(const T *format, size_t formatSize) const;
bool match(const T *format) const;
/**
* @brief Checks if the CString matches a wildcard format.
* Note: Case insensitive. Returns false for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @return True if the CString matches the wildcard format, false otherwise.
*/
bool matchi(const Readable_String<T> &format) const;
bool matchi(const std::basic_string<T> &format) const;
bool matchi(const T *format, size_t formatSize) const;
bool matchi(const T *format) const;
/**
* @brief Counts the number of token deliminated words.
*
* @param whitespace A string of tokens used to deliminate words.
* @return Number of words found.
*/
unsigned int wordCount(const T *whitespace) const;
/**
* @brief Interprets the string as a bool.
*
* @return Bool interpretation of the string.
*/
bool asBool() const;
/**
* @brief Interprets the string as an integer.
* Note: This returns 0 on any value string type other than char.
*
* @param base Base of the string representation.
* @return Integer representation of the string.
*/
int asInt(int base = 0) const;
long long asLongLong(int base = 0) const;
unsigned int asUnsignedInt(int base = 0) const;
unsigned long long asUnsignedLongLong(int base = 0) const;
/**
* @brief Interprets the string as a floating-point decimal number.
* Note: This returns 0 on any value string type other than char.
*
* @param base Base of the string representation.
* @return Integer representation of the string.
*/
double asDouble() const;
/**
* @brief Outputs the string to a FILE stream.
*
* @param out Stream to output to.
* @return Number of elements written successfully.
*/
size_t print(FILE *out) const;
size_t print(std::basic_ostream<T> &out) const;
/**
* @brief Outputs the string and a newline to a FILE stream
*
* @param out Stream to output to.
* @param Number of elements written successfully.
*/
size_t println(FILE *out) const;
size_t println(std::basic_ostream<T> &out) const;
/**
* @brief Copies a "word" from an input string and returns it in an output type.
*
* @param R Type to return. Must be a subclass of String_Type.
*
* @param in String to get a partial copy of.
* @param pos Index of the word to copy.
* @param whitespace String of characters that are to be considered whitespace.
* @return Copy of the word at the specified index on success, an empty string otherwise.
*/
template<template<typename> class R> static R<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
template<template<typename> class R> static R<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Copies a part of an input string starting at a specified "word" and returns it in an output type.
*
* @param R Type to return. Must be a subclass of String_Type.
*
* @param in String to get a partial copy of.
* @param pos Index of the word to start copying from.
* @param whitespace String of characters that are to be considered whitespace.
* @return Copy of the string starting at the specified word on success, an empty string otherwise.
*/
template<template<typename> class R> static R<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
template<template<typename> class R> static R<T> gotoWord(const T *in, size_t pos, const T *whitespace);
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.
@ -232,7 +102,7 @@ namespace Jupiter
virtual ~Readable_String() = default;
/** Access operator */
inline const T &operator[](size_t index) const { return this->get(index); };
inline const T &operator[](size_t index) const { return this->ptr()[index]; };
/** Comparative operators */
inline bool operator==(const Readable_String<T>& right)const{ return operator==(std::basic_string_view<T>{right}); }
@ -258,26 +128,131 @@ namespace Jupiter
inline bool operator>=(const T right)const{ return !operator<(right); }
/** Conversion operators */
explicit inline operator bool() const { return this->asBool(); }
explicit inline operator signed char() const { return static_cast<signed char>(this->asInt()); }
explicit inline operator unsigned char() const { return static_cast<unsigned char>(this->asUnsignedInt()); }
explicit inline operator short() const { return static_cast<short>(this->asInt()); }
explicit inline operator unsigned short() const { return static_cast<unsigned short>(this->asUnsignedInt()); }
explicit inline operator int() const { return this->asInt(); }
explicit inline operator unsigned int() const { return this->asUnsignedInt(); }
explicit inline operator long() const { return static_cast<long>(this->asLongLong()); }
explicit inline operator unsigned long() const { return static_cast<unsigned long>(this->asLongLong()); }
explicit inline operator long long() const { return this->asLongLong(); }
explicit inline operator unsigned long long() const { return this->asUnsignedLongLong(); }
explicit inline operator float() const { return static_cast<float>(this->asDouble()); }
explicit inline operator double() const { return this->asDouble(); }
explicit inline operator long double() const { return this->asDouble(); } // NEEDS TO NOT CAST FROM DOUBLE
explicit inline operator std::basic_string<T>() const { return std::basic_string<T>(this->ptr(), this->size()); }
inline operator std::basic_string_view<T>() const { return std::basic_string_view<T>(this->ptr(), this->size()); }
};
/** Generic Readable String Type */
typedef Readable_String<char> ReadableString;
// TEMP; create some equivalent in jessilib
template<typename CharT>
bool asBool(std::basic_string_view<CharT> in_string) {
using namespace std::literals;
// Invert the logic here, so that we return true for numerics and "true"/"on"/"+", false otherwise
// Note: temporarily removed case insensitivity, solely to avoid including unicode.hpp here
if (in_string == "FALSE"sv
|| in_string == "false"sv
|| in_string == "0"sv
|| in_string == "OFF"sv
|| in_string == "off"sv
|| in_string == "-"sv) {
return false;
}
return true;
}
template<typename CharT>
int asInt(std::basic_string_view<CharT> in_string, int base = 0) {
return Jupiter_strtoi_s(in_string.data(), in_string.size(), base);
}
template<typename CharT>
long long asLongLong(std::basic_string_view<CharT> in_string, int base = 0) {
return Jupiter_strtoll_s(in_string.data(), in_string.size(), base);
}
template<typename CharT>
unsigned int asUnsignedInt(std::basic_string_view<CharT> in_string, int base = 0) {
return Jupiter_strtoui_s(in_string.data(), in_string.size(), base);
}
template<typename CharT>
unsigned long long asUnsignedLongLong(std::basic_string_view<CharT> in_string, int base = 0) {
return Jupiter_strtoull_s(in_string.data(), in_string.size(), base);
}
template<typename CharT>
double asDouble(std::basic_string_view<CharT> in_string) {
return Jupiter_strtod_s(in_string.data(), in_string.size());
}
template<typename OutT>
OutT from_string(std::string_view in_string) {
return static_cast<OutT>(in_string);
}
template<>
inline bool from_string<bool>(std::string_view in_string) {
return asBool(in_string);
}
template<>
inline signed char from_string<signed char>(std::string_view in_string) {
return static_cast<signed char>(asInt(in_string));
}
template<>
inline unsigned char from_string<unsigned char>(std::string_view in_string) {
return static_cast<unsigned char>(asUnsignedInt(in_string));
}
template<>
inline short from_string<short>(std::string_view in_string) {
return static_cast<short>(asInt(in_string));
}
template<>
inline unsigned short from_string<unsigned short>(std::string_view in_string) {
return static_cast<unsigned short>(asUnsignedInt(in_string));
}
template<>
inline int from_string<int>(std::string_view in_string) {
return asInt(in_string);
}
template<>
inline unsigned int from_string<unsigned int>(std::string_view in_string) {
return asUnsignedInt(in_string);
}
template<>
inline long from_string<long>(std::string_view in_string) {
return asInt(in_string);
}
template<>
inline unsigned long from_string<unsigned long>(std::string_view in_string) {
return asUnsignedInt(in_string);
}
template<>
inline long long from_string<long long>(std::string_view in_string) {
return asLongLong(in_string);
}
template<>
inline unsigned long long from_string<unsigned long long>(std::string_view in_string) {
return asUnsignedLongLong(in_string);
}
template<>
inline float from_string<float>(std::string_view in_string) {
return static_cast<float>(asDouble(in_string));
}
template<>
inline double from_string<double>(std::string_view in_string) {
return asDouble(in_string);
}
template<>
inline long double from_string<long double>(std::string_view in_string) {
return asDouble(in_string);
}
}
#include "Readable_String_Imp.h"

787
src/include/Jupiter/Readable_String_Imp.h

@ -26,28 +26,19 @@
*/
#include "Readable_String.h"
#include "Functions.h"
/**
* IMPLEMENTATION:
* Readable_String
*/
// contains
template<typename T> bool Jupiter::Readable_String<T>::contains(const T &value) const
{
for (size_t i = 0; i != this->size(); i++) if (this->get(i) == value) return true;
return false;
}
// 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 (this->get(i) == value)
if (operator[](i) == value)
{
if (index == 0) return i;
else index--;
@ -62,44 +53,18 @@ template<typename T> size_t Jupiter::Readable_String<T>::find(const Jupiter::Rea
return Jupiter::INVALID_INDEX;
if (in.size() == this->size())
return (*this == in) ? 0 : Jupiter::INVALID_INDEX;
if (in.isEmpty())
if (in.empty())
return 0;
for (size_t i = 0, j; i != this->size() - in.size() + 1; i++)
{
j = 0;
while (this->get(i + j) == in.get(j))
while (operator[](i + j) == in[j])
if (++j == in.size()) return i;
}
return Jupiter::INVALID_INDEX;
}
// span()
template<typename T> size_t Jupiter::Readable_String<T>::span(const Jupiter::Readable_String<T> &in) const
{
size_t index = 0;
while (index != this->size() && in.contains(this->get(index)))
++index;
return index;
}
template<typename T> size_t Jupiter::Readable_String<T>::span(const T *in) const
{
size_t index = 0;
while (index != this->size() && containsSymbol(in, this->get(index)))
++index;
return index;
}
template<typename T> size_t Jupiter::Readable_String<T>::span(const T &in) const
{
size_t index = 0;
while (index != this->size() && this->get(index) == in)
++index;
return index;
}
// equalsi()
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const Jupiter::Readable_String<T> &in) const
@ -119,7 +84,7 @@ template<> bool inline Jupiter::Readable_String<char>::equalsi(const char *in, s
in += len;
while (len != 0)
if (toupper(this->get(--len)) != toupper(*(--in)))
if (toupper(operator[](--len)) != toupper(*(--in)))
return false;
return true;
@ -131,7 +96,7 @@ template<> bool inline Jupiter::Readable_String<wchar_t>::equalsi(const wchar_t
return false;
while (len != 0)
if (towupper(this->get(--len)) != towupper(*(--in)))
if (towupper(operator[](--len)) != towupper(*(--in)))
return false;
return true;
@ -144,12 +109,12 @@ template<typename T> bool Jupiter::Readable_String<T>::equalsi(const T *in, size
template<> bool inline Jupiter::Readable_String<char>::equalsi(const char &in) const
{
return this->size() == 1 && toupper(this->get(0)) == toupper(in);
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(this->get(0)) == towupper(in);
return this->size() == 1 && towupper(operator[](0)) == towupper(in);
}
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const T &in) const
@ -157,744 +122,6 @@ template<typename T> bool Jupiter::Readable_String<T>::equalsi(const T &in) cons
return *this == in; // Concept of "case" not supported for type.
}
// match()
template<typename T> bool Jupiter::Readable_String<T>::match(const Jupiter::Readable_String<T> &format) const
{
return this->match(format.ptr(), format.size());
}
template<typename T> bool Jupiter::Readable_String<T>::match(const std::basic_string<T> &format) const
{
return this->match(format.data(), format.size());
}
template<> bool inline Jupiter::Readable_String<char>::match(const char *format, size_t formatSize) const
{
if (this->size() == 0)
{
if (formatSize == 0)
return true;
while (format[--formatSize] == '*')
if (formatSize == 0)
return *format == '*';
return false;
}
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != formatSize)
{
if (format[formatIndex] == '*')
{
if (++formatIndex == formatSize)
return true;
while (format[formatIndex] == '?')
{
if (++formatIndex == formatSize)
return true;
if (++index == this->size())
{
while (format[formatIndex++] == '*')
if (formatIndex == formatSize)
return true;
return false;
}
}
if (format[formatIndex] == '*') continue;
while (format[formatIndex] != this->get(index))
{
if (++index == this->size())
{
while (format[formatIndex] == '*')
if (++formatIndex == formatSize)
return true;
return false;
}
}
}
else if (format[formatIndex] != '?' && format[formatIndex] != this->get(index)) return false;
formatIndex++;
if (++index == this->size())
{
if (formatIndex == formatSize)
return true;
while (format[formatIndex] == '*')
if (++formatIndex == formatSize)
return true;
return false;
}
}
return false;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::match(const wchar_t *format, size_t formatSize) const
{
if (this->size() == 0)
{
if (formatSize == 0)
return true;
while (format[--formatSize] == L'*')
if (formatSize == 0)
return *format == L'*';
return false;
}
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != formatSize)
{
if (format[formatIndex] == L'*')
{
if (++formatIndex == formatSize)
return true;
while (format[formatIndex] == L'?')
{
if (++formatIndex == formatSize)
return index + 1 == this->size();
if (++index == this->size())
{
while (format[formatIndex++] == L'*')
if (formatIndex == formatSize)
return true;
return false;
}
}
if (format[formatIndex] == L'*') continue;
while (format[formatIndex] != this->get(index))
{
if (++index == this->size())
{
while (format[formatIndex] == L'*')
if (++formatIndex == formatSize)
return true;
return false;
}
}
}
else if (format[formatIndex] != L'?' && format[formatIndex] != this->get(index)) return false;
formatIndex++;
if (++index == this->size())
{
while (format[formatIndex] == L'*')
if (++formatIndex == formatSize)
return true;
return false;
}
}
return false;
}
template<typename T> bool Jupiter::Readable_String<T>::match(const T *, size_t) const
{
return false; // Wildcard matching not supported for type.
}
template<> bool inline Jupiter::Readable_String<char>::match(const char *format) const
{
if (this->size() == 0)
{
while (*format == '*')
format++;
return *format == 0;
}
size_t index = 0;
while (*format != 0)
{
if (*format == '*')
{
format++;
while (*format == '?')
{
format++;
if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
}
if (*format == 0) return true;
if (*format == '*') continue;
while (*format != this->get(index))
{
if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
}
}
else if (*format != '?' && *format != this->get(index)) return false;
format++;
if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
}
return false;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::match(const wchar_t *format) const
{
if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
size_t index = 0;
while (*format != 0)
{
if (*format == L'*')
{
format++;
while (*format == L'?')
{
format++;
if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
}
if (*format == 0) return true;
if (*format == '*') continue;
while (*format != this->get(index))
{
if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
}
}
else if (*format != L'?' && *format != this->get(index)) return false;
format++;
if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
}
return false;
}
template<typename T> bool Jupiter::Readable_String<T>::match(const T *format) const
{
return false; // Wildcard matching not supported for type.
}
// matchi()
template<typename T> bool Jupiter::Readable_String<T>::matchi(const Jupiter::Readable_String<T> &format) const
{
return this->matchi(format.ptr(), format.size());
}
template<typename T> bool Jupiter::Readable_String<T>::matchi(const std::basic_string<T> &format) const
{
return this->matchi(format.data(), format.size());
}
template<> bool inline Jupiter::Readable_String<char>::matchi(const char *format, size_t formatSize) const
{
if (this->size() == 0)
{
if (formatSize == 0)
return true;
while (format[--formatSize] == '*')
if (formatSize == 0)
return *format == '*';
return false;
}
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != formatSize)
{
if (format[formatIndex] == '*')
{
if (++formatIndex == formatSize)
return true;
while (format[formatIndex] == '?')
{
if (++formatIndex == formatSize)
return true;
if (++index == this->size())
{
while (format[formatIndex++] == '*')
if (formatIndex == formatSize)
return true;
return false;
}
}
if (format[formatIndex] == '*') continue;
while (toupper(format[formatIndex]) != toupper(this->get(index)))
{
if (++index == this->size())
{
while (format[formatIndex] == '*')
if (++formatIndex == formatSize)
return true;
return false;
}
}
}
else if (format[formatIndex] != '?' && toupper(format[formatIndex]) != toupper(this->get(index))) return false;
formatIndex++;
if (++index == this->size())
{
if (formatIndex == formatSize)
return true;
while (format[formatIndex] == '*')
if (++formatIndex == formatSize)
return true;
return false;
}
}
return false;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const wchar_t *format, size_t formatSize) const
{
if (this->size() == 0)
{
if (formatSize == 0)
return true;
while (format[--formatSize] == L'*')
if (formatSize == 0)
return *format == L'*';
return false;
}
size_t index = 0;
size_t formatIndex = 0;
while (formatIndex != formatSize)
{
if (format[formatIndex] == L'*')
{
if (++formatIndex == formatSize)
return true;
while (format[formatIndex] == L'?')
{
if (++formatIndex == formatSize)
return index + 1 == this->size();
if (++index == this->size())
{
while (format[formatIndex++] == L'*')
if (formatIndex == formatSize)
return true;
return false;
}
}
if (format[formatIndex] == L'*') continue;
while (towupper(format[formatIndex]) != towupper(this->get(index)))
{
if (++index == this->size())
{
while (format[formatIndex] == L'*')
if (++formatIndex == formatSize)
return true;
return false;
}
}
}
else if (format[formatIndex] != L'?' && towupper(format[formatIndex]) != towupper(this->get(index))) return false;
formatIndex++;
if (++index == this->size())
{
while (format[formatIndex] == L'*')
if (++formatIndex == formatSize)
return true;
return false;
}
}
return false;
}
template<typename T> bool Jupiter::Readable_String<T>::matchi(const T *, size_t) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
}
template<> bool inline Jupiter::Readable_String<char>::matchi(const char *format) const
{
if (this->size() == 0)
{
while (*format == '*')
format++;
return *format == 0;
}
size_t index = 0;
while (*format != 0)
{
if (*format == '*')
{
format++;
while (*format == '?')
{
format++;
if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
}
if (*format == 0) return true;
if (*format == '*') continue;
while (toupper(*format) != toupper(this->get(index)))
{
if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
}
}
else if (*format != '?' && toupper(*format) != toupper(this->get(index))) return false;
format++;
if (++index == this->size())
{
while (*format == '*')
format++;
return *format == 0;
}
}
return false;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::matchi(const wchar_t *format) const
{
if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
size_t index = 0;
while (*format != 0)
{
if (*format == L'*')
{
format++;
while (*format == L'?')
{
format++;
if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
}
if (*format == 0) return true;
if (*format == '*') continue;
while (towupper(*format) != towupper(this->get(index)))
{
if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
}
}
else if (*format != L'?' && towupper(*format) != towupper(this->get(index))) return false;
format++;
if (this->size() == 0)
{
while (*format == L'*')
format++;
return *format == 0;
}
}
return false;
}
template<typename T> bool Jupiter::Readable_String<T>::matchi(const T *format) const
{
return false; // Wildcard matching not supported for type. Concept of "case" not supported for type.
}
// wordCount()
template<typename T> unsigned int Jupiter::Readable_String<T>::wordCount(const T *whitespace) const
{
unsigned int result = 0;
size_t i = 0;
bool prev = true;
while (i != this->size())
{
if (Jupiter::strpbrk<T>(whitespace, this->get(i)) == nullptr) // This isn't whitespace!
{
if (prev == true) // We just left whitespace!
{
prev = false;
result++;
}
}
else prev = true; // This is whitespace!
i++;
}
return result;
}
// as<type>
template<> bool inline Jupiter::Readable_String<char>::asBool() const
{
if (this->equalsi("FALSE")) return false;
if (this->equalsi('0')) return false;
if (this->equalsi("OFF")) return false;
if (this->equalsi('-')) return false;
return true;
}
template<> bool inline Jupiter::Readable_String<wchar_t>::asBool() const
{
if (this->equalsi(L"FALSE")) return false;
if (this->equalsi(L'0')) return false;
if (this->equalsi(L"OFF")) return false;
if (this->equalsi(L'-')) return false;
return true;
}
template<typename T> bool Jupiter::Readable_String<T>::asBool() const
{
return false;
}
template<> int inline Jupiter::Readable_String<char>::asInt(int base) const
{
return Jupiter_strtoi_s(this->ptr(), this->size(), base);
}
template<typename T> int Jupiter::Readable_String<T>::asInt(int base) const
{
return 0;
}
template<> long long inline Jupiter::Readable_String<char>::asLongLong(int base) const
{
return Jupiter_strtoll_s(this->ptr(), this->size(), base);
}
template<typename T> long long Jupiter::Readable_String<T>::asLongLong(int base) const
{
return 0;
}
template<> unsigned int inline Jupiter::Readable_String<char>::asUnsignedInt(int base) const
{
return Jupiter_strtoui_s(this->ptr(), this->size(), base);
}
template<typename T> unsigned int Jupiter::Readable_String<T>::asUnsignedInt(int base) const
{
return 0;
}
template<> unsigned long long inline Jupiter::Readable_String<char>::asUnsignedLongLong(int base) const
{
return Jupiter_strtoull_s(this->ptr(), this->size(), base);
}
template<typename T> unsigned long long Jupiter::Readable_String<T>::asUnsignedLongLong(int base) const
{
return 0;
}
template<> double inline Jupiter::Readable_String<char>::asDouble() const
{
return Jupiter_strtod_s(this->ptr(), this->size());
}
template<typename T> double Jupiter::Readable_String<T>::asDouble() const
{
return 0;
}
// Stream output
template<typename T> size_t Jupiter::Readable_String<T>::print(FILE *out) const
{
return fwrite(this->ptr(), sizeof(T), this->size(), out);
}
template<> size_t inline Jupiter::Readable_String<wchar_t>::print(FILE *out) const
{
size_t index = 0;
while (index != this->size() && fputwc(this->get(index), out) != WEOF) index++;
return index;
}
template<typename T> size_t Jupiter::Readable_String<T>::print(std::basic_ostream<T> &out) const
{
size_t index = 0;
while (index != this->size())
{
out << this->get(index);
index++;
}
return index;
}
template<typename T> size_t Jupiter::Readable_String<T>::println(FILE *out) const
{
size_t r = this->print(out);
if (r != this->size()) return r;
if (fputs("\r\n", out) != EOF) r += 2;
return r;
}
template<typename T> size_t Jupiter::Readable_String<T>::println(std::basic_ostream<T> &out) const
{
size_t r = this->print(out);
if (r != this->size()) return r;
out << std::endl;
return r;
}
// getWord
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
unsigned int y = 1;
for (unsigned int i = 0; i < pos || y == 1; x++)
{
if (x == in.size()) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in.get(x)) != nullptr)
{
if (y != 1)
{
y = 1;
i++;
}
}
else
{
if (i >= pos) break;
y = 0;
}
}
for (y = x; y != in.size() && Jupiter::strpbrk<T>(whitespace, in.get(y)) == nullptr; y++);
return R<T>::substring(in, x, y - x);
}
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::getWord(const T *in, size_t pos, const T *whitespace)
{
if (*in == 0)
return R<T>();
while (Jupiter::strpbrk<T>(whitespace, *in) != nullptr)
if (*++in == 0)
return R<T>();
if (pos == 0)
{
do
++in, ++pos;
while (*in != 0 && Jupiter::strpbrk<T>(whitespace, *in) == nullptr);
in -= pos;
return R<T>::substring(in, 0, pos);
}
loop_start:
{
if (Jupiter::strpbrk<T>(whitespace, *in) != nullptr)
{
do
if (*++in == 0)
return R<T>();
while (Jupiter::strpbrk<T>(whitespace, *in) != nullptr);
if (--pos == 0)
goto loop_end;
}
if (*++in == 0)
return R<T>();
goto loop_start;
}
loop_end:
do
++in, ++pos;
while (*in != 0 && Jupiter::strpbrk<T>(whitespace, *in) == nullptr);
in -= pos;
return R<T>::substring(in, 0, pos);
}
// gotoWord
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
bool y = true;
for (unsigned int i = 0; i < pos || y == true; x++)
{
if (x == in.size()) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in.get(x)) != nullptr)
{
if (y != true)
{
y = true;
i++;
}
}
else
{
if (i >= pos) break;
y = false;
}
}
return R<T>::substring(in, x);
}
template<typename T> template<template<typename> class R> R<T> Jupiter::Readable_String<T>::gotoWord(const T *in, size_t pos, const T *whitespace)
{
unsigned int x = 0;
bool y = true;
for (unsigned int i = 0; i < pos || y == true; x++)
{
if (in[x] == 0) return R<T>();
if (Jupiter::strpbrk<T>(whitespace, in[x]) != nullptr)
{
if (y != true)
{
y = true;
i++;
}
}
else
{
if (i >= pos) break;
y = false;
}
}
return R<T>::substring(in, x);
}
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>

69
src/include/Jupiter/Reference_String.h

@ -41,14 +41,6 @@ namespace Jupiter
/** DEPRECATED IN FAVOR OF std::string_view */
public:
/**
* @brief Fetches an element from the string.
*
* @param index Index of the element to return.
* @return The element located at the specified index.
*/
const T &get(size_t index) const override;
/**
* @brief Returns the number of elements in the String.
*
@ -141,64 +133,6 @@ namespace Jupiter
static Reference_String<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length);
static Reference_String<T> substring(const T *in, size_t pos, size_t length);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> getWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
*
* @param in C-Style string to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> gotoWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param in C-Style string to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> gotoWord(const T *in, size_t pos, const T *whitespace);
/** Mutative operators */
inline Reference_String<T>& operator-=(size_t right) { this->truncate(right); return *this; };
inline Reference_String<T>& operator=(const Readable_String<T> &right) { std::basic_string_view<T>::operator=({right.ptr(), right.size()}); return *this; };
@ -239,11 +173,10 @@ namespace Jupiter
// Bring in constructors from basic_string_view
using std::basic_string_view<T>::basic_string_view;
static const Jupiter::Reference_String<T> empty; /** Empty instantiation of Reference_String */
/** 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 */

30
src/include/Jupiter/Reference_String_Imp.h

@ -51,10 +51,6 @@ template<typename T> Jupiter::Reference_String<T>::Reference_String(const Jupite
: Reference_String(in.ptr(), in.size()) {
}
template<typename T> const T &Jupiter::Reference_String<T>::get(size_t index) const {
return operator[](index);
}
template<typename T> size_t Jupiter::Reference_String<T>::size() const {
return std::basic_string_view<T>::size();
}
@ -142,32 +138,6 @@ template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::
return Jupiter::Reference_String<T>(in + pos, len);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getWord(size_t pos, const T *whitespace) const {
return Jupiter::Reference_String<T>::getWord(*this, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace) {
return Jupiter::Readable_String<T>::template getWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getWord(const T *in, size_t pos, const T *whitespace) {
return Jupiter::Readable_String<T>::template getWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoWord(size_t pos, const T *whitespace) const {
return Jupiter::Reference_String<T>::gotoWord(*this, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace) {
return Jupiter::Readable_String<T>::template gotoWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoWord(const T *in, size_t pos, const T *whitespace) {
return Jupiter::Readable_String<T>::template gotoWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> const Jupiter::Reference_String<T> Jupiter::Reference_String<T>::empty = Jupiter::Reference_String<T>();
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Reference_String> {

1
src/include/Jupiter/Socket.h

@ -438,6 +438,7 @@ namespace Jupiter
* 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);
/**
* @brief Sends a null-terminated string of data across the socket.

115
src/include/Jupiter/String.hpp

@ -115,54 +115,6 @@ namespace Jupiter
static typename Jupiter::template String_Strict<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length);
static typename Jupiter::template String_Strict<T> substring(const T *in, size_t pos, size_t length);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
String_Strict<T> getWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static String_Strict<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
*
* @param in C-Style string to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static String_Strict<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
String_Strict<T> gotoWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static String_Strict<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/** Default Constructor */
String_Strict();
@ -181,7 +133,7 @@ namespace Jupiter
String_Strict(const String_Strict<T> &in);
String_Strict(const Readable_String<T> &in);
String_Strict(const std::basic_string<T> &in);
//String_Strict(const std::basic_string_view<T> &in) : String_Strict<T>(in.data(), in.size()){};
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);
String_Strict(const Jupiter::DataBuffer &in);
@ -206,18 +158,14 @@ namespace Jupiter
inline String_Strict<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline String_Strict<T> &operator=(const T *right) { this->set(right); return *this; };
inline String_Strict<T> &operator=(const T right) { this->set(right); return *this; };
static const Jupiter::String_Strict<T> empty; /** Empty instantiation of String_Strict */
};
#if defined JUPITER_STRING_STRICT_OPERATOR_PLUS
/** 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::Readable_String<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::Readable_String<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);
#endif // JUPITER_STRING_STRICT_OPERATOR_PLUS
/**
* @brief Provides a "loose" String implementation that's more optimized for repeated concatenations.
@ -306,56 +254,6 @@ namespace Jupiter
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 Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
String_Loose<T> getWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
* Useful when the input string's type isn't known.
*
* @param in String to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static String_Loose<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
* Useful when the input string's type isn't known.
*
* @param in C-Style string to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static String_Loose<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
String_Loose<T> gotoWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static String_Loose<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @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.
@ -416,23 +314,12 @@ namespace Jupiter
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 Jupiter::String_Loose<T> empty; /** Empty instantiation of String_Loose */
static const size_t start_size = 8; /** Starting size for loose Strings. */
protected:
size_t strSize; /** Size of underlying string buffer */
};
#if !defined JUPITER_STRING_STRICT_OPERATOR_PLUS
#if !defined DISABLE_DEFAULT_JUPITER_STRING_OPERATOR_PLUS
/** String_Loose<T> Addition Operator */
template<typename T> static inline Jupiter::String_Loose<T> operator+(const Jupiter::Readable_String<T> &lhs, const T &rhs);
template<typename T> static inline Jupiter::String_Loose<T> operator+(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &rhs);
template<typename T> static inline Jupiter::String_Loose<T> operator+(const Jupiter::Readable_String<T> &lhs, const std::basic_string<T> &rhs);
template<typename T> static inline Jupiter::String_Loose<T> operator+(const Jupiter::Readable_String<T> &lhs, const T *rhs);
#endif // DISABLE_DEFAULT_JUPITER_STRING_OPERATOR_PLUS
#endif // JUPITER_STRING_STRICT_OPERATOR_PLUS
/** Definition of a Strict String. */
typedef String_Strict<char> StringS;

80
src/include/Jupiter/String_Imp.h

@ -283,31 +283,6 @@ template<typename T> typename Jupiter::String_Strict<T> Jupiter::String_Strict<T
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Strict>(in, pos, len);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWord(size_t pos, const T *whitespace) const
{
return Jupiter::String_Strict<T>::getWord(*this, pos, whitespace);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::template getWord<Jupiter::template String_Strict>(in, pos, whitespace);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::getWord(const T *in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::template getWord<Jupiter::template String_Strict>(in, pos, whitespace);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWord(size_t pos, const T *whitespace) const
{
return Jupiter::String_Strict<T>::gotoWord(*this, pos, whitespace);
}
template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::template gotoWord<Jupiter::template String_Strict>(in, pos, whitespace);
}
// Operators
template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>::operator+(const T &rhs) const
@ -335,7 +310,6 @@ template<typename T> inline Jupiter::String_Strict<T> Jupiter::String_Strict<T>:
return Jupiter::operator+(*this, rhs);
}
#if defined JUPITER_STRING_STRICT_OPERATOR_PLUS
template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const T &rhs)
{
return Jupiter::String_Strict<T>(lhs, rhs);
@ -355,9 +329,6 @@ template<typename T> static inline Jupiter::String_Strict<T> Jupiter::operator+(
{
return Jupiter::String_Strict<T>(lhs, rhs);
}
#endif // JUPITER_STRING_STRICT_OPERATOR_PLUS
template<typename T> const Jupiter::String_Strict<T> Jupiter::String_Strict<T>::empty = Jupiter::String_Strict<T>();
// Jupiter::DataBuffer specialization
@ -697,31 +668,6 @@ template<typename T> typename Jupiter::template String_Loose<T> Jupiter::String_
return Jupiter::String_Type<T>::template substring<Jupiter::template String_Loose>(in, pos, len);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(size_t pos, const T *whitespace) const
{
return Jupiter::String_Loose<T>::getWord(*this, pos, whitespace);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::template getWord<Jupiter::template String_Loose>(in, pos, whitespace);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::getWord(const T *in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::template getWord<Jupiter::template String_Loose>(in, pos, whitespace);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord(size_t pos, const T *whitespace) const
{
return Jupiter::String_Loose<T>::gotoWord(*this, pos, whitespace);
}
template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::template gotoWord<Jupiter::template String_Loose>(in, pos, whitespace);
}
// Operators
template<typename T> inline Jupiter::String_Loose<T> Jupiter::String_Loose<T>::operator+(const T &rhs) const
@ -749,32 +695,6 @@ template<typename T> inline Jupiter::String_Loose<T> Jupiter::String_Loose<T>::o
return Jupiter::operator+(*this, rhs);
}
#if !defined JUPITER_STRING_STRICT_OPERATOR_PLUS
#if !defined DISABLE_DEFAULT_JUPITER_STRING_OPERATOR_PLUS
template<typename T> static inline Jupiter::String_Loose<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const T &rhs)
{
return Jupiter::String_Loose<T>(lhs, rhs);
}
template<typename T> static inline Jupiter::String_Loose<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &rhs)
{
return Jupiter::String_Loose<T>(lhs, rhs);
}
template<typename T> static inline Jupiter::String_Loose<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const std::basic_string<T> &rhs)
{
return Jupiter::String_Loose<T>(lhs, rhs);
}
template<typename T> static inline Jupiter::String_Loose<T> Jupiter::operator+(const Jupiter::Readable_String<T> &lhs, const T *rhs)
{
return Jupiter::String_Loose<T>(lhs, rhs);
}
#endif // DISABLE_DEFAULT_JUPITER_STRING_OPERATOR_PLUS
#endif // JUPITER_STRING_STRICT_OPERATOR_PLUS
template<typename T> const Jupiter::String_Loose<T> Jupiter::String_Loose<T>::empty = Jupiter::String_Loose<T>();
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Loose>

12
src/include/Jupiter/String_Type_Imp.h

@ -442,11 +442,11 @@ template<typename T> size_t Jupiter::String_Type<T>::insert(size_t index, const
if (index >= Jupiter::String_Type<T>::length)
return this->concat(value);
if (value.isEmpty())
if (value.empty())
return Jupiter::String_Type<T>::length;
if (value.size() == 1)
return this->insert(index, value.get(0));
return this->insert(index, value[0]);
this->setBufferSize(Jupiter::String_Type<T>::length + value.size());
size_t i;
@ -455,10 +455,10 @@ template<typename T> size_t Jupiter::String_Type<T>::insert(size_t index, const
while (i != index)
{
Jupiter::String_Type<T>::str[i] = value.get(i - index);
Jupiter::String_Type<T>::str[i] = value[i - index];
i--;
}
Jupiter::String_Type<T>::str[index] = value.get(0);
Jupiter::String_Type<T>::str[index] = value[0];
return Jupiter::String_Type<T>::length += value.size();
}
@ -774,7 +774,7 @@ template<typename T> template<template<typename> class R> R<T> Jupiter::String_T
{
if (pos >= in.size()) return R<T>();
R<T> r = R<T>(in.size() - pos);
for (r.length = 0; pos + r.length != in.size(); r.length++) r.str[r.length] = in.get(pos + r.length);
for (r.length = 0; pos + r.length != in.size(); r.length++) r.str[r.length] = in[pos + r.length];
return r;
}
@ -782,7 +782,7 @@ template<typename T> template<template<typename> class R> R<T> Jupiter::String_T
{
if (pos + len >= in.size()) return R<T>::substring(in, pos);
R<T> r = R<T>(len);
for (r.length = 0; r.length != len; r.length++) r.str[r.length] = in.get(pos + r.length);
for (r.length = 0; r.length != len; r.length++) r.str[r.length] = in[pos + r.length];
return r;
}

Loading…
Cancel
Save