diff --git a/src/common/Command.cpp b/src/common/Command.cpp index 904bf74..f35472e 100644 --- a/src/common/Command.cpp +++ b/src/common/Command.cpp @@ -19,42 +19,23 @@ #include #include "jessilib/unicode.hpp" #include "Command.h" -#include "String.hpp" - -struct Jupiter::Command::Data { // TODO: remove pimpl - std::vector triggers; -}; - -Jupiter::Command::Command() { - m_data = new Data(); -} - -Jupiter::Command::Command(const Command &command) { - m_data = new Data(); - //for (size_t i = 0; i != m_data->triggers.size(); i++) // triggers.size() would always be 0? this code does nothing? - // m_data->triggers.add(new Jupiter::StringS(*command.m_data->triggers.get(i))); -} - -Jupiter::Command::~Command() { - delete m_data; -} // Command Functions void Jupiter::Command::addTrigger(std::string_view trigger) { - m_data->triggers.emplace_back(trigger); + m_triggers.emplace_back(trigger); } std::string_view Jupiter::Command::getTrigger(size_t index) const { - return m_data->triggers[index]; + return m_triggers[index]; } size_t Jupiter::Command::getTriggerCount() const { - return m_data->triggers.size(); + return m_triggers.size(); } bool Jupiter::Command::matches(std::string_view in_trigger) const { - for (const auto& trigger : m_data->triggers) { + for (const auto& trigger : m_triggers) { if (jessilib::equalsi(trigger, in_trigger)) { return true; } diff --git a/src/common/Database.cpp b/src/common/Database.cpp index e7d9b38..a15e1ca 100644 --- a/src/common/Database.cpp +++ b/src/common/Database.cpp @@ -36,7 +36,7 @@ void Jupiter::Database::create_header(FILE *) { } -bool Jupiter::Database::process_file(const Jupiter::ReadableString &file) +bool Jupiter::Database::process_file(std::string_view file) { Jupiter::Database::data_->file_name = static_cast(file); return Jupiter::Database::Data::process_file(this); @@ -125,17 +125,11 @@ bool Jupiter::Database::append(Jupiter::DataBuffer &data) return Jupiter::Database::append(Jupiter::Database::data_->file_name, data); } -bool Jupiter::Database::append(Jupiter::ReadableString &file, Jupiter::DataBuffer &data) -{ - char *str = new char[file.size() + 1]; - memcpy(str, file.data(), file.size() * sizeof(char)); - str[file.size()] = '\0'; - bool r = Jupiter::Database::append(str, data); - delete[] str; - return r; +bool Jupiter::Database::append(std::string_view file, Jupiter::DataBuffer &data) { + return append(static_cast(file), data); } -bool Jupiter::Database::append(std::string &file, Jupiter::DataBuffer &data) +bool Jupiter::Database::append(const std::string& file, Jupiter::DataBuffer &data) { return Jupiter::Database::append(file.c_str(), data); } @@ -158,7 +152,7 @@ bool Jupiter::Database::append(FILE *file, Jupiter::DataBuffer &data) return true; } -bool Jupiter::Database::create_database(const Jupiter::ReadableString &file, const Jupiter::DataBuffer *header) +bool Jupiter::Database::create_database(std::string_view file, const Jupiter::DataBuffer *header) { char *str = new char[file.size() + 1]; memcpy(str, file.data(), file.size() * sizeof(char)); diff --git a/src/common/GenericCommand.cpp b/src/common/GenericCommand.cpp index 1f3c5f3..4e0b4c5 100644 --- a/src/common/GenericCommand.cpp +++ b/src/common/GenericCommand.cpp @@ -53,7 +53,7 @@ bool Jupiter::GenericCommand::isNamespace() const { return false; } -void Jupiter::GenericCommand::setNamespace(const Jupiter::ReadableString &in_namespace) { +void Jupiter::GenericCommand::setNamespace(std::string_view in_namespace) { if (Jupiter::GenericCommand::m_parent == nullptr) { return; // We have no parent to start from } @@ -80,7 +80,7 @@ Jupiter::GenericCommandNamespace *Jupiter::GenericCommand::getNamespace() const /** GenericCommand::ResponseLine */ -Jupiter::GenericCommand::ResponseLine::ResponseLine(const Jupiter::ReadableString &in_response, GenericCommand::DisplayType in_type) +Jupiter::GenericCommand::ResponseLine::ResponseLine(std::string_view in_response, GenericCommand::DisplayType in_type) : response{ in_response }, type{ in_type } { } @@ -90,7 +90,7 @@ Jupiter::GenericCommand::ResponseLine::ResponseLine(std::string in_response, Gen type{ in_type } { } -Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommand::ResponseLine::set(const Jupiter::ReadableString &in_response, GenericCommand::DisplayType in_type) { +Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommand::ResponseLine::set(std::string_view in_response, GenericCommand::DisplayType in_type) { response = in_response; type = in_type; return this; @@ -101,7 +101,7 @@ Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommand::ResponseLine::se Jupiter::GenericCommandNamespace::~GenericCommandNamespace() { } -Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommandNamespace::trigger(const Jupiter::ReadableString &in_input) { +Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommandNamespace::trigger(std::string_view in_input) { GenericCommand* command; Jupiter::ReferenceString input(in_input); auto split_input = jessilib::word_split_once_view(input, GENERIC_COMMAND_WORD_DELIMITER_SV); @@ -112,13 +112,13 @@ Jupiter::GenericCommand::ResponseLine* Jupiter::GenericCommandNamespace::trigger command = Jupiter::GenericCommandNamespace::getCommand(split_input.first); if (command != nullptr) { - return command->trigger(Jupiter::ReferenceString{split_input.second}); + return command->trigger(split_input.second); } return new Jupiter::GenericCommand::ResponseLine(""_jrs, Jupiter::GenericCommand::DisplayType::PrivateError); } -const Jupiter::ReadableString &Jupiter::GenericCommandNamespace::getHelp(const Jupiter::ReadableString ¶meters) { +std::string_view Jupiter::GenericCommandNamespace::getHelp(std::string_view parameters) { static Jupiter::ReferenceString not_found = "Error: Command not found"_jrs; Jupiter::ReferenceString input(parameters); @@ -136,7 +136,7 @@ const Jupiter::ReadableString &Jupiter::GenericCommandNamespace::getHelp(const J // Search for command command = Jupiter::GenericCommandNamespace::getCommand(input_split.first); if (command != nullptr) { - return command->getHelp(Jupiter::ReferenceString{input_split.second}); + return command->getHelp(input_split.second); } // Command not found diff --git a/src/common/HTTP_Server.cpp b/src/common/HTTP_Server.cpp index cb31f07..a49e1cd 100644 --- a/src/common/HTTP_Server.cpp +++ b/src/common/HTTP_Server.cpp @@ -452,7 +452,7 @@ int Jupiter::HTTP::Server::Data::process_request(HTTPSession &session) { { // 200 (success) // TODO: remove referencestring warpper - std::string* content_result = content->execute(Jupiter::ReferenceString{query_string}); + std::string* content_result = content->execute(query_string); switch (session.version) { @@ -481,21 +481,22 @@ int Jupiter::HTTP::Server::Data::process_request(HTTPSession &session) { result += "Connection: close"_jrs ENDL; result += "Content-Type: "_jrs; - if (content->type == nullptr) + if (content->type.empty()) { result += Jupiter::HTTP::Content::Type::Text::PLAIN; - else - result += *content->type; - if (content->charset != nullptr) - { + } + else { + result += content->type; + } + + if (!content->charset.empty()) { result += "; charset="_jrs; - result += *content->charset; + result += content->charset; } result += ENDL; - if (content->language != nullptr) - { + if (!content->language.empty()) { result += "Content-Language: "_jrs; - result += *content->language; + result += content->language; result += ENDL; } @@ -827,5 +828,5 @@ int Jupiter::HTTP::Server::think() { return 0; } -const Jupiter::ReadableString &Jupiter::HTTP::Server::global_namespace = ""_jrs; -const Jupiter::ReadableString &Jupiter::HTTP::Server::server_string = "Jupiter"_jrs; \ No newline at end of file +std::string_view Jupiter::HTTP::Server::global_namespace = ""_jrs; +std::string_view Jupiter::HTTP::Server::server_string = "Jupiter"_jrs; \ No newline at end of file diff --git a/src/common/IRC_Client.cpp b/src/common/IRC_Client.cpp index d36b0ce..bc7e7a0 100644 --- a/src/common/IRC_Client.cpp +++ b/src/common/IRC_Client.cpp @@ -215,7 +215,7 @@ std::string_view Jupiter::IRC::Client::getRealname() const { return m_realname; } -const Jupiter::ReadableString &Jupiter::IRC::Client::getServerName() const { +std::string_view Jupiter::IRC::Client::getServerName() const { return m_server_name; } @@ -270,7 +270,7 @@ int Jupiter::IRC::Client::getAccessLevel(const Channel &in_channel, std::string_ } int Jupiter::IRC::Client::getAccessLevel(std::string_view in_channel, std::string_view in_nickname) const { - auto channel = m_channels.find(Jupiter::ReferenceString{in_channel}); + auto channel = m_channels.find(in_channel); if (channel != m_channels.end()) return this->getAccessLevel(channel->second, in_nickname); @@ -278,7 +278,7 @@ int Jupiter::IRC::Client::getAccessLevel(std::string_view in_channel, std::strin return 0; } -void Jupiter::IRC::Client::send(const Jupiter::ReadableString &rawMessage) { +void Jupiter::IRC::Client::send(std::string_view rawMessage) { Jupiter::StringS out = rawMessage; out += ENDL; @@ -294,7 +294,7 @@ size_t Jupiter::IRC::Client::getUserCount() const { } std::shared_ptr Jupiter::IRC::Client::getUser(std::string_view in_nickname) const { - auto user = m_users.find(Jupiter::ReferenceString{in_nickname}); + auto user = m_users.find(in_nickname); if (user != m_users.end()) { return user->second; } @@ -368,7 +368,7 @@ size_t Jupiter::IRC::Client::messageChannels(int type, std::string_view message) return m_channels.size(); } -size_t Jupiter::IRC::Client::messageChannels(const Jupiter::ReadableString &message) +size_t Jupiter::IRC::Client::messageChannels(std::string_view message) { for (auto& channel : m_channels) { sendMessage(channel.second.getName(), message); @@ -926,7 +926,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) { } if (user->getChannelCount() == 0) { - m_users.erase(Jupiter::ReferenceString{kicked_nickname}); + m_users.erase(kicked_nickname); } } } @@ -1164,7 +1164,7 @@ void Jupiter::IRC::Client::disconnect(bool stayDead) } } -void Jupiter::IRC::Client::disconnect(const Jupiter::ReadableString &message, bool stayDead) +void Jupiter::IRC::Client::disconnect(std::string_view message, bool stayDead) { m_socket->send(Jupiter::StringS::Format("QUIT :%.*s" ENDL, message.size(), message.data())); Jupiter::IRC::Client::disconnect(stayDead); @@ -1253,7 +1253,7 @@ int Jupiter::IRC::Client::think() return handle_error(tmp); } -std::string_view Jupiter::IRC::Client::readConfigValue(const Jupiter::ReadableString &key, std::string_view defaultValue) const { +std::string_view Jupiter::IRC::Client::readConfigValue(std::string_view key, std::string_view defaultValue) const { if (m_primary_section != nullptr) { std::string_view val = m_primary_section->get(key); if (!val.empty()) { @@ -1268,7 +1268,7 @@ std::string_view Jupiter::IRC::Client::readConfigValue(const Jupiter::ReadableSt return defaultValue; } -bool Jupiter::IRC::Client::readConfigBool(const Jupiter::ReadableString &key, bool defaultValue) const { +bool Jupiter::IRC::Client::readConfigBool(std::string_view key, bool defaultValue) const { if (m_primary_section != nullptr) { std::string_view val = m_primary_section->get(key); @@ -1284,7 +1284,7 @@ bool Jupiter::IRC::Client::readConfigBool(const Jupiter::ReadableString &key, bo return defaultValue; } -int Jupiter::IRC::Client::readConfigInt(const Jupiter::ReadableString &key, int defaultValue) const { +int Jupiter::IRC::Client::readConfigInt(std::string_view key, int defaultValue) const { if (m_primary_section != nullptr) { std::string_view val = m_primary_section->get(key); @@ -1300,7 +1300,7 @@ int Jupiter::IRC::Client::readConfigInt(const Jupiter::ReadableString &key, int return defaultValue; } -long Jupiter::IRC::Client::readConfigLong(const Jupiter::ReadableString &key, long defaultValue) const { +long Jupiter::IRC::Client::readConfigLong(std::string_view key, long defaultValue) const { if (m_primary_section != nullptr) { std::string_view val = m_primary_section->get(key); @@ -1315,7 +1315,7 @@ long Jupiter::IRC::Client::readConfigLong(const Jupiter::ReadableString &key, lo return defaultValue; } -double Jupiter::IRC::Client::readConfigDouble(const Jupiter::ReadableString &key, double defaultValue) const { +double Jupiter::IRC::Client::readConfigDouble(std::string_view key, double defaultValue) const { if (m_primary_section != nullptr) { std::string_view val = m_primary_section->get(key); @@ -1331,7 +1331,7 @@ double Jupiter::IRC::Client::readConfigDouble(const Jupiter::ReadableString &key return defaultValue; } -void Jupiter::IRC::Client::writeToLogs(const Jupiter::ReadableString &message) { +void Jupiter::IRC::Client::writeToLogs(std::string_view message) { if (m_log_file != nullptr) { fwrite(message.data(), sizeof(char), message.size(), m_log_file); fputs("\r\n", m_log_file); @@ -1344,10 +1344,10 @@ void Jupiter::IRC::Client::writeToLogs(const Jupiter::ReadableString &message) { */ void Jupiter::IRC::Client::delChannel(std::string_view in_channel) { - m_channels.erase(Jupiter::ReferenceString{in_channel}); + m_channels.erase(in_channel); } -std::shared_ptr Jupiter::IRC::Client::findUser(const Jupiter::ReadableString &in_nickname) const { +std::shared_ptr Jupiter::IRC::Client::findUser(std::string_view in_nickname) const { return getUser(in_nickname); } @@ -1452,7 +1452,7 @@ size_t Jupiter::IRC::Client::User::getChannelCount() const { * Channel Implementation */ -Jupiter::IRC::Client::Channel::Channel(const Jupiter::ReadableString &in_name, Jupiter::IRC::Client *in_parent) { +Jupiter::IRC::Client::Channel::Channel(std::string_view in_name, Jupiter::IRC::Client *in_parent) { auto to_lower = [&in_name]() { Jupiter::String result(in_name.size()); const char *itr = in_name.data(); @@ -1490,7 +1490,7 @@ std::shared_ptr Jupiter::IRC::Client::Chann ++user->m_channel_count; - m_users[Jupiter::ReferenceString{channel_user->getNickname()}] = channel_user; + m_users[channel_user->getNickname()] = channel_user; return channel_user; } @@ -1501,12 +1501,12 @@ std::shared_ptr Jupiter::IRC::Client::Chann ++user->m_channel_count; - m_users[Jupiter::ReferenceString{channel_user->getNickname()}] = channel_user; + m_users[channel_user->getNickname()] = channel_user; return channel_user; } void Jupiter::IRC::Client::Channel::delUser(std::string_view in_nickname) { - m_users.erase(Jupiter::ReferenceString{in_nickname}); + m_users.erase(in_nickname); } void Jupiter::IRC::Client::Channel::addUserPrefix(std::string_view in_nickname, char prefix) { @@ -1527,12 +1527,12 @@ void Jupiter::IRC::Client::Channel::delUserPrefix(std::string_view in_nickname, } } -const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::getName() const { +std::string_view Jupiter::IRC::Client::Channel::getName() const { return m_name; } std::shared_ptr Jupiter::IRC::Client::Channel::getUser(std::string_view in_nickname) const { - auto user = m_users.find(Jupiter::ReferenceString{in_nickname}); + auto user = m_users.find(in_nickname); if (user != m_users.end()) { return user->second; } @@ -1591,7 +1591,7 @@ Jupiter::IRC::Client::User *Jupiter::IRC::Client::Channel::User::getUser() const return m_user.get(); } -const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::User::getPrefixes() const { +std::string_view Jupiter::IRC::Client::Channel::User::getPrefixes() const { return m_prefixes; } diff --git a/src/common/Plugin.cpp b/src/common/Plugin.cpp index 20e50ac..b8bee79 100644 --- a/src/common/Plugin.cpp +++ b/src/common/Plugin.cpp @@ -73,7 +73,7 @@ const char module_file_extension[]{ ".dll" }; const char module_file_extension[]{ ".so" }; #endif // _WIN32 -const Jupiter::ReferenceString config_file_extension = ".ini"_jrs; +constexpr std::string_view config_file_extension = ".ini"sv; std::string plugins_directory = "Plugins"s + directory_character; std::string plugin_configs_directory = "Configs"s + directory_character; @@ -102,7 +102,7 @@ bool Jupiter::Plugin::shouldRemove() const { return _shouldRemove; } -const Jupiter::ReadableString &Jupiter::Plugin::getName() const { +std::string_view Jupiter::Plugin::getName() const { return name; } @@ -119,7 +119,7 @@ void Jupiter::Plugin::OnPostInitialize() { // Static Functions -void Jupiter::Plugin::setDirectory(const Jupiter::ReadableString &dir) { +void Jupiter::Plugin::setDirectory(std::string_view dir) { plugins_directory = dir; if (!plugins_directory.empty() && plugins_directory.back() != directory_character) { plugins_directory += directory_character; @@ -130,7 +130,7 @@ const std::string& Jupiter::Plugin::getDirectory() { return plugins_directory; } -void Jupiter::Plugin::setConfigDirectory(const Jupiter::ReadableString &dir) { +void Jupiter::Plugin::setConfigDirectory(std::string_view dir) { plugin_configs_directory = dir; if (!plugin_configs_directory.empty() && plugin_configs_directory.back() != directory_character) { plugin_configs_directory += directory_character; @@ -180,7 +180,7 @@ Jupiter::Plugin *Jupiter::Plugin::load(const std::string_view& pluginName) { } // Initialize the plugin - weak_plugin->name = Jupiter::ReferenceString{pluginName}; + weak_plugin->name = pluginName; std::string config_path = plugin_configs_directory; config_path += pluginName; config_path += config_file_extension; diff --git a/src/common/Socket.cpp b/src/common/Socket.cpp index 217b009..6f9f0e2 100644 --- a/src/common/Socket.cpp +++ b/src/common/Socket.cpp @@ -476,12 +476,12 @@ size_t Jupiter::Socket::getBufferSize() const { return Jupiter::Socket::data_->buffer.capacity(); } -const Jupiter::ReadableString &Jupiter::Socket::setBufferSize(size_t size) { +std::string_view Jupiter::Socket::setBufferSize(size_t size) { Jupiter::Socket::data_->buffer.setBufferSize(size); return Jupiter::Socket::data_->buffer; } -const Jupiter::ReadableString &Jupiter::Socket::getData() { +std::string_view Jupiter::Socket::getData() { if (this->recv() <= 0) Jupiter::Socket::data_->buffer.erase(); return Jupiter::Socket::data_->buffer; diff --git a/src/include/Jupiter/Command.h b/src/include/Jupiter/Command.h index 97d29c9..687e29a 100644 --- a/src/include/Jupiter/Command.h +++ b/src/include/Jupiter/Command.h @@ -24,8 +24,16 @@ * @brief Provides an extendable command system. */ +#include +#include +#include #include "Jupiter.h" -#include "Reference_String.h" + +/** DLL Linkage Nagging */ +#if defined _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4251) +#endif namespace Jupiter { @@ -73,29 +81,33 @@ 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 ¶meters = Jupiter::ReferenceString{}) = 0; + virtual std::string_view getHelp(std::string_view parameters = {}) = 0; /** * @brief Default constructor for command class. */ - Command(); + Command() = default; /** * @brief Copy constructor for command class. */ - Command(const Command &command); + Command(const Command &command) = default; /** * @brief destructor for command class. */ - virtual ~Command(); + virtual ~Command() = default; /** Private members */ private: - struct Data; - Data *m_data; + std::vector m_triggers; }; } +/** Re-enable warnings */ +#if defined _MSC_VER +#pragma warning(pop) +#endif // _MSC_VER + #endif // _COMMAND_H_HEADER \ No newline at end of file diff --git a/src/include/Jupiter/Database.h b/src/include/Jupiter/Database.h index 82bfc3e..50f94f3 100644 --- a/src/include/Jupiter/Database.h +++ b/src/include/Jupiter/Database.h @@ -66,7 +66,7 @@ namespace Jupiter * @param file File being processed * @return True on success, false otherwise */ - bool process_file(const Jupiter::ReadableString &file); + bool process_file(std::string_view file); bool process_file(const std::string &file); bool process_file(const char *file); bool process_file(FILE *file); @@ -99,8 +99,8 @@ namespace Jupiter * @param data DataBuffer to append * @return True on success, false otherwise. */ - static bool append(Jupiter::ReadableString &file, Jupiter::DataBuffer &data); - static bool append(std::string &file, Jupiter::DataBuffer &data); + static bool append(std::string_view file, Jupiter::DataBuffer &data); + static bool append(const std::string& file, Jupiter::DataBuffer &data); static bool append(const char *file, Jupiter::DataBuffer &data); static bool append(FILE *file, Jupiter::DataBuffer &data); @@ -111,7 +111,7 @@ namespace Jupiter * @param flie Name of the Database to generate * @param header DataBuffer containing the header to write to the file */ - static bool create_database(const Jupiter::ReadableString &file, const Jupiter::DataBuffer *header = nullptr); + static bool create_database(std::string_view file, const Jupiter::DataBuffer *header = nullptr); static bool create_database(const std::string &file, const Jupiter::DataBuffer *header = nullptr); static bool create_database(const char *file, const Jupiter::DataBuffer *header = nullptr); diff --git a/src/include/Jupiter/GenericCommand.h b/src/include/Jupiter/GenericCommand.h index e65c729..216e86d 100644 --- a/src/include/Jupiter/GenericCommand.h +++ b/src/include/Jupiter/GenericCommand.h @@ -68,9 +68,9 @@ namespace Jupiter * @param in_type Value to set type to. * @return This. */ - ResponseLine *set(const Jupiter::ReadableString &response, GenericCommand::DisplayType type); + ResponseLine *set(std::string_view response, GenericCommand::DisplayType type); ResponseLine() = default; - ResponseLine(const Jupiter::ReadableString &response, GenericCommand::DisplayType type); + ResponseLine(std::string_view response, GenericCommand::DisplayType type); ResponseLine(std::string response, GenericCommand::DisplayType type); }; @@ -79,7 +79,7 @@ namespace Jupiter * * @param input Parameters passed to the command by the user. */ - virtual ResponseLine *trigger(const Jupiter::ReadableString &input) = 0; + virtual ResponseLine *trigger(std::string_view input) = 0; /** * @brief Checks if this command is a namespace @@ -94,7 +94,7 @@ namespace Jupiter * * @param in_namespace Name of the namespace to move the command into */ - void setNamespace(const Jupiter::ReadableString &in_namespace); + void setNamespace(std::string_view in_namespace); /** * @brief Places this command in a namespace @@ -130,8 +130,8 @@ namespace Jupiter class JUPITER_API GenericCommandNamespace : public Jupiter::GenericCommand { public: // Jupiter::Command - ResponseLine *trigger(const Jupiter::ReadableString &input) override; - const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString ¶meters) override; + ResponseLine *trigger(std::string_view input) override; + std::string_view getHelp(std::string_view parameters) override; public: // Jupiter::GenericCommand bool isNamespace() const override; @@ -170,8 +170,8 @@ namespace Jupiter #define BASE_GENERIC_COMMAND(CLASS) \ public: \ CLASS(); \ - Jupiter::GenericCommand::ResponseLine *trigger(const Jupiter::ReadableString ¶meters) override; \ - const Jupiter::ReadableString &getHelp(const Jupiter::ReadableString ¶meters) override; \ + Jupiter::GenericCommand::ResponseLine *trigger(std::string_view parameters) override; \ + std::string_view getHelp(std::string_view parameters) override; \ static CLASS &instance; /** Expands to become the entire declaration for a generic command. In most cases, this will be sufficient. */ diff --git a/src/include/Jupiter/HTTP_QueryString.h b/src/include/Jupiter/HTTP_QueryString.h index f068b11..a4b9fef 100644 --- a/src/include/Jupiter/HTTP_QueryString.h +++ b/src/include/Jupiter/HTTP_QueryString.h @@ -39,7 +39,7 @@ namespace Jupiter { public: QueryString() = delete; - inline QueryString(const Jupiter::ReadableString &query_string) : QueryString(query_string.data(), query_string.size()) {} + inline QueryString(std::string_view query_string) : QueryString(query_string.data(), query_string.size()) {} inline QueryString(const char *ptr, size_t str_size); }; @@ -212,7 +212,7 @@ inline Jupiter::HTTP::HTMLFormResponse::HTMLFormResponse(const char *ptr, size_t else if (*ptr == '&') // End of key/value, start of key { if (!key.empty()) { // A key was already set; end of value - Jupiter::HTTP::HTMLFormResponse::table[key] = Jupiter::ReferenceString(token_start, buf - token_start); + Jupiter::HTTP::HTMLFormResponse::table[key] = std::string_view(token_start, buf - token_start); } key = std::string_view{}; @@ -239,13 +239,13 @@ inline Jupiter::HTTP::HTMLFormResponse::HTMLFormResponse(const char *ptr, size_t { key = std::string_view(token_start, ++buf - token_start); *buf = *++ptr; - Jupiter::HTTP::HTMLFormResponse::table[key] = Jupiter::ReferenceString(ptr, 1); + Jupiter::HTTP::HTMLFormResponse::table[key] = std::string_view(ptr, 1); } else *++buf = *++ptr; if (!key.empty()) // A key was already set; end of value - Jupiter::HTTP::HTMLFormResponse::table[key] = Jupiter::ReferenceString(token_start, buf - token_start + 1); + Jupiter::HTTP::HTMLFormResponse::table[key] = std::string_view(token_start, buf - token_start + 1); Jupiter::StringType::length = buf + 1 - str; } diff --git a/src/include/Jupiter/HTTP_Server.h b/src/include/Jupiter/HTTP_Server.h index 8687fcd..cd68963 100644 --- a/src/include/Jupiter/HTTP_Server.h +++ b/src/include/Jupiter/HTTP_Server.h @@ -46,8 +46,8 @@ namespace Jupiter public: // Server typedef std::string* HTTPFunction(std::string_view query_string); - static const Jupiter::ReadableString &global_namespace; - static const Jupiter::ReadableString &server_string; + static std::string_view global_namespace; + static std::string_view server_string; struct JUPITER_API Content { @@ -55,9 +55,9 @@ namespace Jupiter Jupiter::HTTP::Server::HTTPFunction *function; // function to generate content data std::string name; // name of the content unsigned int name_checksum; // name.calcChecksum() - const Jupiter::ReadableString *language = nullptr; // Pointer to a constant (or otherwise managed) string - const Jupiter::ReadableString *type = nullptr; // Pointer to a constant (or otherwise managed) string - const Jupiter::ReadableString *charset = nullptr; // Pointer to a constant (or otherwise managed) string + std::string_view language; // Pointer to a constant (or otherwise managed) string + std::string_view type; // Pointer to a constant (or otherwise managed) string + std::string_view charset; // Pointer to a constant (or otherwise managed) string virtual std::string* execute(std::string_view query_string); diff --git a/src/include/Jupiter/IRC_Client.h b/src/include/Jupiter/IRC_Client.h index 42e0081..7549e4a 100644 --- a/src/include/Jupiter/IRC_Client.h +++ b/src/include/Jupiter/IRC_Client.h @@ -277,7 +277,7 @@ namespace Jupiter * * @return String containing the user's channel prefixes. */ - const Jupiter::ReadableString &getPrefixes() const; + std::string_view getPrefixes() const; /** * @brief Fetches the user's nickname. @@ -322,7 +322,7 @@ namespace Jupiter * * @return String containing the name of the channel. */ - const Jupiter::ReadableString &getName() const; + std::string_view getName() const; /** * @brief Searches for a user based on their nickname. @@ -417,7 +417,7 @@ namespace Jupiter * @param channelName String containing the name of a channel. * @param iFace Server in which this channel is located. */ - Channel(const Jupiter::ReadableString &in_name, Client *in_parent); + Channel(std::string_view in_name, Client *in_parent); /** Private members */ private: @@ -509,7 +509,7 @@ namespace Jupiter * * @return String containing the server's name. */ - const Jupiter::ReadableString &getServerName() const; + std::string_view getServerName() const; /** * @brief Returns the server's hostname. @@ -693,7 +693,7 @@ namespace Jupiter * @param message String containing the message to send. * @return Number of messages sent. */ - size_t messageChannels(const Jupiter::ReadableString &in_message); + size_t messageChannels(std::string_view in_message); /** * @brief Returns if the client will automatically reconnect upon failure. @@ -715,7 +715,7 @@ namespace Jupiter * * @param rawMessage String containing the data to send. */ - void send(const Jupiter::ReadableString &in_message); + void send(std::string_view in_message); /** * @brief Processes an input line of IRC protocol data. @@ -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, std::string_view in_default_value = std::string_view{}) const; + std::string_view readConfigValue(std::string_view key, std::string_view in_default_value = std::string_view{}) const; /** * @brief Returns a key's value as a boolean. @@ -741,7 +741,7 @@ namespace Jupiter * @param key String containing the key name. * @return Boolean value of the key value if it exists, in_default_value otherwise. */ - bool readConfigBool(const Jupiter::ReadableString &key, bool in_default_value = false) const; + bool readConfigBool(std::string_view key, bool in_default_value = false) const; /** * @brief Returns a key's value as an integer. @@ -750,7 +750,7 @@ namespace Jupiter * @param key String containing the key name. * @return Integer value of the key value if it exists, in_default_value otherwise. */ - int readConfigInt(const Jupiter::ReadableString &key, int in_default_value = 0) const; + int readConfigInt(std::string_view key, int in_default_value = 0) const; /** * @brief Returns a key's value as a long integer. @@ -759,7 +759,7 @@ namespace Jupiter * @param key String containing the key name. * @return Long integer value of the key value if it exists, in_default_value otherwise. */ - long readConfigLong(const Jupiter::ReadableString &key, long in_default_value = 0) const; + long readConfigLong(std::string_view key, long in_default_value = 0) const; /** * @brief Returns a key's value as a double. @@ -768,14 +768,14 @@ namespace Jupiter * @param key String containing the key name. * @return Double value of the key value if it exists, in_default_value otherwise. */ - double readConfigDouble(const Jupiter::ReadableString &key, double in_default_value = 0) const; + double readConfigDouble(std::string_view key, double in_default_value = 0) const; /** * @brief Writes to the server's log file. * * @param message String containing the text to write to the file. */ - void writeToLogs(const Jupiter::ReadableString &in_message); + void writeToLogs(std::string_view in_message); /** * @brief Connects the client to its server. @@ -797,7 +797,7 @@ namespace Jupiter * * @param message String containing the QUIT message to send prior to disconnecting. */ - void disconnect(const Jupiter::ReadableString &in_message, bool in_stay_dead = false); + void disconnect(std::string_view in_message, bool in_stay_dead = false); /** * @brief Calls disconnect() if the client has not already, then calls connect(). @@ -845,7 +845,7 @@ namespace Jupiter Jupiter::Config *m_secondary_section; std::string m_log_file_name; std::string m_last_line; - Jupiter::StringS m_server_name; + std::string m_server_name; std::string m_nickname; std::string m_realname; @@ -877,7 +877,7 @@ namespace Jupiter bool startCAP(); bool registerClient(); - std::shared_ptr findUser(const Jupiter::ReadableString &in_nickname) const; + std::shared_ptr findUser(std::string_view in_nickname) const; std::shared_ptr findUserOrAdd(std::string_view in_nickname); }; // Jupiter::IRC::Client class diff --git a/src/include/Jupiter/Plugin.h b/src/include/Jupiter/Plugin.h index bf15908..10a3857 100644 --- a/src/include/Jupiter/Plugin.h +++ b/src/include/Jupiter/Plugin.h @@ -88,7 +88,7 @@ namespace Jupiter * * @return String containing the name of the plugin. */ - const Jupiter::ReadableString &getName() const; + std::string_view getName() const; /** * @brief Returns the plugin's configuration file. @@ -296,7 +296,7 @@ namespace Jupiter * * @param dir Directory to look for plugins in. */ - static void setDirectory(const Jupiter::ReadableString &dir); + static void setDirectory(std::string_view dir); /** * @brief Returns the current plugin directory. @@ -310,7 +310,7 @@ namespace Jupiter * * @param dir Directory to look for configuration files in. */ - static void setConfigDirectory(const Jupiter::ReadableString &dir); + static void setConfigDirectory(std::string_view dir); /** * @brief Returns the current plugin configuration directory diff --git a/src/include/Jupiter/Reference_String.h b/src/include/Jupiter/Reference_String.h index a32f68f..77b0eae 100644 --- a/src/include/Jupiter/Reference_String.h +++ b/src/include/Jupiter/Reference_String.h @@ -34,7 +34,7 @@ namespace Jupiter { namespace literals { /** DEPRECATED: Reference_String literals */ - inline Jupiter::ReferenceString operator"" _jrs(const char *str, size_t len) { return Jupiter::ReferenceString(str, len); } + inline constexpr std::string_view operator"" _jrs(const char *str, size_t len) { return { str, len }; } } } diff --git a/src/include/Jupiter/Socket.h b/src/include/Jupiter/Socket.h index c3a2dc8..404a501 100644 --- a/src/include/Jupiter/Socket.h +++ b/src/include/Jupiter/Socket.h @@ -355,14 +355,14 @@ namespace Jupiter * @param size The size of the buffer to be made. * @return The newly created buffer. */ - const Jupiter::ReadableString &setBufferSize(size_t size); + std::string_view setBufferSize(size_t size); /** * @brief Copies any new socket data to the buffer and returns it. * * @return Socket buffer if new data is successfully received, an empty buffer otherwise. */ - const Jupiter::ReadableString &getData(); + std::string_view getData(); /** * @brief Returns the local hostname of the local machine. diff --git a/src/include/Jupiter/String.hpp b/src/include/Jupiter/String.hpp index f30734e..5d81cc7 100644 --- a/src/include/Jupiter/String.hpp +++ b/src/include/Jupiter/String.hpp @@ -167,159 +167,6 @@ namespace Jupiter template static inline Jupiter::String_Strict operator+(const Jupiter::String_Type &lhs, const std::basic_string_view &rhs); template static inline Jupiter::String_Strict operator+(const Jupiter::String_Type &lhs, const T *rhs); - /** - * @brief Provides a "loose" String implementation that's more optimized for repeated concatenations. - * Note: The underlying string will always have a size which is a power of 2, but no fewer than 8 elements. - * - * @param T Element type which the String will store. Defaults to char. - */ - template class String_Loose : public Shift_String_Type - { - public: - - /** - * @brief Returns the maximum number of elements the String can contain, - * without expanding the socket buffer. This is generally the size of the - * underlying memory buffer. - * - * @return Number of elements the string can contain without reallocation. - */ - virtual size_t capacity() const; - - /** - * @brief Sets the String's contents based on the format string and input variables. - * Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t. - * - * @param format Format that the string is compared against. - * @param args Inputs to match the format specifiers. - * @return Number of characters written. - */ - size_t vformat(const T *format, va_list args); - - /** - * @brief Appends to a String's contents based on the format string and input variables. - * Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t. - * - * @param format Format that the string is compared against. - * @param args Inputs to match the format specifiers. - * @return Number of characters written. - */ - size_t avformat(const T *format, va_list args); - - /** - * @brief Sets the String's contents based on the format string and input variables. - * Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t. - * - * @param format Format that the string is compared against. - * @param ... Inputs to match the format specifiers. - * @return String containing the new format. - */ - static String_Loose Format(const T *format, ...); - - /** - * @brief Creates a partial copy of the string. - * - * @param pos Position in the string to start copying from. - * @return String containing a partial copy of the original string. - */ - typename Jupiter::template String_Loose substring(size_t pos) const; - - /** - * @brief Creates a partial copy of the string. - * - * @param pos Position in the string to start copying from. - * @param length Number of characters to copy. - * @return String containing a partial copy of the original string. - */ - typename Jupiter::template String_Loose substring(size_t pos, size_t length) const; - - /** - * @brief Creates a partial copy of the string. - * - * @param in String to get a partial copy of. - * @param pos Position in the string to start copying from. - * @return String containing a partial copy of the original string. - */ - static typename Jupiter::template String_Loose substring(const Jupiter::Readable_String &in, size_t pos); - static typename Jupiter::template String_Loose substring(const T *in, size_t pos); - - /** - * @brief Creates a partial copy of the string. - * - * @param in String to get a partial copy of. - * @param pos Position in the string to start copying from. - * @param length Number of characters to copy. - * @return String containing a partial copy of the original string. - */ - static typename Jupiter::template String_Loose substring(const Jupiter::Readable_String &in, size_t pos, size_t length); - static typename Jupiter::template String_Loose substring(const T *in, size_t pos, size_t length); - - /** - * @brief Sets the internal buffer to be at least large enough to old a specified number of elements. - * Note: This does nothing if len is less than the string's current length. - * - * @param len Minimum number of elements the string buffer must be able to hold. - * @return True if a new buffer was allocated, false otherwise. - */ - virtual bool setBufferSize(size_t len) override; - - /** - * @brief Empties the string, and sets the internal buffer to be at least large enough to old a specified number of elements. - * Note: This does nothing if len is less than the string's current length. - * - * @param len Minimum number of elements the string buffer must be able to hold. - * @return True if a new buffer was allocated, false otherwise. - */ - virtual bool setBufferSizeNoCopy(size_t len) override; - - /** Default constructor */ - String_Loose(); - - /** - * @brief Size hint constructor. - * - * @param size Minimum number of elements the string must be able to hold. - */ - String_Loose(size_t size); - - /** Move Constructor */ - String_Loose(String_Loose &&source); - - /** Copy Constructors */ - String_Loose(const String_Loose &in); - String_Loose(const Readable_String &in); - String_Loose(const std::basic_string &in); - String_Loose(const T *in, size_t len); - String_Loose(const T *in); - String_Loose(const Jupiter::DataBuffer &in); - - /** Concatenation Constructors */ - String_Loose(const Readable_String &lhs, const T &rhs); - String_Loose(const Readable_String &lhs, const Readable_String &rhs); - String_Loose(const Readable_String &lhs, const std::basic_string &rhs); - String_Loose(const Readable_String &lhs, const T *rhs); - String_Loose(const Readable_String &lhs, const T *rhs, size_t rhs_size); - - /** Addition Operators */ - inline String_Loose operator+(const T &rhs) const; - inline String_Loose operator+(const String_Loose &rhs) const; - inline String_Loose operator+(const Readable_String &rhs) const; - inline String_Loose operator+(const std::basic_string &rhs) const; - inline String_Loose operator+(const T *rhs) const; - - /** Assignment Operators */ - inline String_Loose &operator=(const String_Loose &right) { this->set(right); return *this; }; - inline String_Loose &operator=(const Readable_String &right) { this->set(right); return *this; }; - inline String_Loose &operator=(const std::basic_string &right) { this->set(right); return *this; }; - inline String_Loose &operator=(const T *right) { this->set(right); return *this; }; - inline String_Loose &operator=(const T right) { this->set(right); return *this; }; - - static const size_t start_size = 8; /** Starting size for loose Strings. */ - - protected: - size_t strSize; /** Size of underlying string buffer */ - }; - /** Definition of a Strict String. */ typedef String_Strict StringS; diff --git a/src/include/Jupiter/String_Imp.h b/src/include/Jupiter/String_Imp.h index 461ae4d..79fad34 100644 --- a/src/include/Jupiter/String_Imp.h +++ b/src/include/Jupiter/String_Imp.h @@ -343,7 +343,7 @@ template static inline Jupiter::String_Strict Jupiter::operator+( template<> struct _Jupiter_DataBuffer_partial_specialization_impl { template static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Strict *data) { - _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); }; template static Jupiter::String_Strict interpret(uint8_t *&head) @@ -356,371 +356,4 @@ template<> struct _Jupiter_DataBuffer_partial_specialization_impl Jupiter::String_Loose::String_Loose() : Jupiter::String_Loose::String_Loose(Jupiter::String_Loose::start_size) -{ -} - -template Jupiter::String_Loose::String_Loose(Jupiter::String_Loose &&source) : Jupiter::Shift_String_Type(std::move(source)) -{ - Jupiter::String_Loose::strSize = source.strSize; - source.strSize = 0; -} - -template Jupiter::String_Loose::String_Loose(size_t len) -{ - if (len > Jupiter::String_Loose::start_size) Jupiter::String_Loose::strSize = len; - else Jupiter::String_Loose::strSize = Jupiter::String_Loose::start_size; - - Jupiter::Shift_String_Type::base = new T[Jupiter::String_Loose::strSize]; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; - Jupiter::String_Type::length = 0; -} - -template Jupiter::String_Loose::String_Loose(const Jupiter::String_Loose &in) -{ - Jupiter::String_Loose::strSize = in.strSize; - Jupiter::Shift_String_Type::base = new T[Jupiter::String_Loose::strSize]; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; - for (Jupiter::String_Type::length = 0; Jupiter::String_Type::length != in.length; Jupiter::String_Type::length++) - Jupiter::String_Type::str[Jupiter::String_Type::length] = in.get(Jupiter::String_Type::length); -} - -template Jupiter::String_Loose::String_Loose(const Jupiter::Readable_String &in) : Jupiter::String_Loose::String_Loose( - in.data(), in.size()) -{ -} - -template Jupiter::String_Loose::String_Loose(const std::basic_string &in) : Jupiter::String_Loose::String_Loose(in.data(), in.size()) -{ -} - -template Jupiter::String_Loose::String_Loose(const T *in, size_t len) : Jupiter::String_Loose::String_Loose(len) -{ - while (Jupiter::String_Type::length != len) - { - Jupiter::String_Type::str[Jupiter::String_Type::length] = *in; - ++in, ++Jupiter::String_Type::length; - } -} - -template Jupiter::String_Loose::String_Loose(const T *in) -{ - if (in == nullptr) - { - Jupiter::String_Loose::strSize = Jupiter::String_Loose::start_size; - Jupiter::Shift_String_Type::base = new T[Jupiter::String_Loose::strSize]; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; - Jupiter::String_Type::length = 0; - } - else - { - Jupiter::String_Type::length = Jupiter::strlen(in); - - Jupiter::String_Loose::strSize = getPowerTwo(Jupiter::String_Type::length); - if (Jupiter::String_Loose::strSize < Jupiter::String_Loose::start_size) Jupiter::String_Loose::strSize = Jupiter::String_Loose::start_size; - - Jupiter::Shift_String_Type::base = new T[Jupiter::String_Loose::strSize]; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; - for (Jupiter::String_Type::length = 0; *in != 0; Jupiter::String_Type::length++, in++) Jupiter::String_Type::str[Jupiter::String_Type::length] = *in; - } -} - -template Jupiter::String_Loose::String_Loose(const Jupiter::DataBuffer &in) : String_Loose(reinterpret_cast(in.getHead()), in.size() / sizeof(T)) -{ -} - -template Jupiter::String_Loose::String_Loose(const Jupiter::Readable_String &lhs, const T &rhs) : String_Loose(lhs.size() + 1) -{ - const T *itr; - const T *end; - - if (!lhs.empty()) - { - itr = lhs.data(); - end = itr + lhs.size(); - *Jupiter::String_Type::str = *itr; - while (++itr != end) - *++Jupiter::String_Type::str = *itr; - ++Jupiter::String_Type::str; - } - - *Jupiter::String_Type::str = rhs; - - Jupiter::String_Type::length = Jupiter::String_Type::str - Jupiter::Shift_String_Type::base + 1; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; -} - -template Jupiter::String_Loose::String_Loose(const Jupiter::Readable_String &lhs, const Jupiter::Readable_String &rhs) : String_Loose(lhs, - rhs.data(), rhs.size()) -{ -} - -template Jupiter::String_Loose::String_Loose(const Jupiter::Readable_String &lhs, const std::basic_string &rhs) : String_Loose(lhs, rhs.data(), rhs.size()) -{ -} - -template Jupiter::String_Loose::String_Loose(const Jupiter::Readable_String &lhs, const T *rhs) : String_Loose(lhs, rhs, Jupiter::strlen(rhs)) -{ -} - -template Jupiter::String_Loose::String_Loose(const Jupiter::Readable_String &lhs, const T *rhs, size_t rhs_size) : String_Loose(lhs.size() + rhs_size) -{ - const T *itr; - const T *end; - - if (!lhs.empty()) - { - itr = lhs.data(); - end = itr + lhs.size(); - *Jupiter::String_Type::str = *itr; - while (++itr != end) - *++Jupiter::String_Type::str = *itr; - ++Jupiter::String_Type::str; - } - - if (rhs_size != 0) - { - itr = rhs; - end = itr + rhs_size; - *Jupiter::String_Type::str = *itr; - while (++itr != end) - *++Jupiter::String_Type::str = *itr; - ++Jupiter::String_Type::str; - } - - Jupiter::String_Type::length = Jupiter::String_Type::str - Jupiter::Shift_String_Type::base; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; -} - -template bool Jupiter::String_Loose::setBufferSize(size_t len) -{ - size_t offset = Jupiter::String_Type::str - Jupiter::Shift_String_Type::base; - - if (len + offset > Jupiter::String_Loose::strSize) - { - if (len > Jupiter::String_Loose::strSize) - { - // Buffer is not large enough; reallocate - Jupiter::String_Loose::strSize = getPowerTwo(len); - - T *ptr = new T[Jupiter::String_Loose::strSize]; - for (size_t i = 0; i < Jupiter::String_Type::length; i++) - ptr[i] = Jupiter::String_Type::str[i]; - - delete[] Jupiter::Shift_String_Type::base; - Jupiter::Shift_String_Type::base = ptr; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; - - return true; - } - - // Buffer has enough space to accomodate; shift data to the left - T *read_itr = Jupiter::String_Type::str; - T *read_end = read_itr + Jupiter::String_Type::length; - T *write_itr = Jupiter::Shift_String_Type::base; - - while (read_itr != read_end) - { - *write_itr = *read_itr; - - ++read_itr; - ++write_itr; - } - - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; - } - - return false; -} - -template bool Jupiter::String_Loose::setBufferSizeNoCopy(size_t len) -{ - len = getPowerTwo(len); - if (len > Jupiter::String_Loose::strSize) - { - Jupiter::String_Type::length = 0; - delete[] Jupiter::Shift_String_Type::base; - Jupiter::Shift_String_Type::base = new T[len]; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; - return true; - } - - Jupiter::String_Type::length = 0; - Jupiter::String_Type::str = Jupiter::Shift_String_Type::base; - - return false; -} - -// vformat() - -template<> size_t inline Jupiter::String_Loose::vformat(const char *format, va_list args) -{ - int minLen; - va_list sargs; - va_copy(sargs, args); - minLen = JUPITER_VSCPRINTF(format, sargs); - va_end(sargs); - if (minLen < 0) return 0; // We simply can not work with this. - - this->setBufferSizeNoCopy(minLen + 1); // vsnprintf REQUIRES space for an additional null character. - minLen = vsnprintf(Jupiter::String_Type::str, minLen + 1, format, args); - if (minLen < 0) return 0; - return Jupiter::String_Type::length = minLen; -} - -template<> size_t inline Jupiter::String_Loose::vformat(const wchar_t *format, va_list args) -{ - int minLen; - va_list sargs; - va_copy(sargs, args); - minLen = JUPITER_VSCWPRINTF(format, sargs); - va_end(sargs); - if (minLen < 0) return 0; // We simply can not work with this. - - this->setBufferSizeNoCopy(minLen + 1); // vsnprintf REQUIRES space for an additional null character. - minLen = vswprintf(Jupiter::String_Type::str, minLen + 1, format, args); - if (minLen < 0) return 0; - return Jupiter::String_Type::length = minLen; -} - -template size_t Jupiter::String_Loose::capacity() const -{ - return Jupiter::String_Loose::strSize; -} - -template size_t Jupiter::String_Loose::vformat(const T *format, va_list args) -{ - return 0; -} - -// avformat() - -template<> size_t inline Jupiter::String_Loose::avformat(const char *format, va_list args) -{ - int minLen; - va_list sargs; - va_copy(sargs, args); - minLen = JUPITER_VSCPRINTF(format, sargs); - va_end(sargs); - if (minLen < 0) return 0; // We simply can not work with this. - - this->setBufferSize(Jupiter::String_Type::length + minLen + 1); // vsnprintf REQUIRES space for an additional null character. - minLen = vsnprintf(Jupiter::String_Type::str + Jupiter::String_Type::length, minLen + 1, format, args); - if (minLen <= 0) return 0; - Jupiter::String_Type::length += minLen; - return minLen; -} - -template<> size_t inline Jupiter::String_Loose::avformat(const wchar_t *format, va_list args) -{ - int minLen; - va_list sargs; - va_copy(sargs, args); - minLen = JUPITER_VSCWPRINTF(format, sargs); - va_end(sargs); - if (minLen < 0) return 0; // We simply can not work with this. - this->setBufferSize(minLen + Jupiter::String_Type::length + 1); // vsnprintf REQUIRES space for an additional null character. - - minLen = vswprintf(Jupiter::String_Type::str + Jupiter::String_Type::length, minLen + 1, format, args); - if (minLen <= 0) return 0; - Jupiter::String_Type::length += minLen; - return minLen; -} - -template size_t Jupiter::String_Loose::avformat(const T *format, va_list args) -{ - return 0; -} - -template Jupiter::String_Loose Jupiter::String_Loose::Format(const T *format, ...) -{ - String_Loose r; - va_list args; - va_start(args, format); - r.vformat(format, args); - va_end(args); - return r; -} - -template typename Jupiter::template String_Loose Jupiter::String_Loose::substring(size_t pos) const -{ - return Jupiter::String_Loose::substring(*this, pos); -} - -template typename Jupiter::template String_Loose Jupiter::String_Loose::substring(size_t pos, size_t length) const -{ - return Jupiter::String_Loose::substring(*this, pos, length); -} - -template typename Jupiter::template String_Loose Jupiter::String_Loose::substring(const Jupiter::Readable_String &in, size_t pos) -{ - return Jupiter::String_Type::template substring(in, pos); -} - -template typename Jupiter::template String_Loose Jupiter::String_Loose::substring(const T *in, size_t pos) -{ - return Jupiter::String_Type::template substring(in, pos); -} - -template typename Jupiter::template String_Loose Jupiter::String_Loose::substring(const Jupiter::Readable_String &in, size_t pos, size_t len) -{ - return Jupiter::String_Type::template substring(in, pos, len); -} - -template typename Jupiter::template String_Loose Jupiter::String_Loose::substring(const T *in, size_t pos, size_t len) -{ - return Jupiter::String_Type::template substring(in, pos, len); -} - -// Operators - -template inline Jupiter::String_Loose Jupiter::String_Loose::operator+(const T &rhs) const -{ - return Jupiter::operator+(*this, rhs); -} - -template inline Jupiter::String_Loose Jupiter::String_Loose::operator+(const Jupiter::String_Loose &rhs) const -{ - return Jupiter::String_Loose::operator+(reinterpret_cast &>(rhs)); -} - -template inline Jupiter::String_Loose Jupiter::String_Loose::operator+(const Jupiter::Readable_String &rhs) const -{ - return Jupiter::operator+(*this, rhs); -} - -template inline Jupiter::String_Loose Jupiter::String_Loose::operator+(const std::basic_string &rhs) const -{ - return Jupiter::operator+(*this, rhs); -} - -template inline Jupiter::String_Loose Jupiter::String_Loose::operator+(const T *rhs) const -{ - return Jupiter::operator+(*this, rhs); -} - -// Jupiter::DataBuffer specialization - -template<> struct _Jupiter_DataBuffer_partial_specialization_impl -{ - template static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Loose *data) - { - _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); - }; - - template static Jupiter::String_Loose interpret(uint8_t *&head) - { - size_t size_ = *reinterpret_cast(head); - head += sizeof(size_t); - Jupiter::String_Loose r = Jupiter::String_Loose(reinterpret_cast(head), size_); - head += size_; - return r; - } -}; - #endif // _STRING_IMP_H_HEADER \ No newline at end of file