Browse Source

Rename 'ptr' to 'data', remove various methods from ReadableString and ReferenceString

task/remove_strings
Jessica James 3 years ago
parent
commit
cee0c7ef7d
  1. 4
      src/common/Database.cpp
  2. 8
      src/common/INIConfig.cpp
  3. 62
      src/common/IRC_Client.cpp
  4. 2
      src/common/Socket.cpp
  5. 4
      src/include/Jupiter/HTTP_QueryString.h
  6. 10
      src/include/Jupiter/Hash.h
  7. 14
      src/include/Jupiter/IRC_Client.h
  8. 10
      src/include/Jupiter/Readable_String.h
  9. 4
      src/include/Jupiter/Readable_String_Imp.h
  10. 84
      src/include/Jupiter/Reference_String.h
  11. 83
      src/include/Jupiter/Reference_String_Imp.h
  12. 23
      src/include/Jupiter/String_Imp.h
  13. 14
      src/include/Jupiter/String_Type.h
  14. 75
      src/include/Jupiter/String_Type_Imp.h

4
src/common/Database.cpp

@ -128,7 +128,7 @@ bool Jupiter::Database::append(Jupiter::DataBuffer &data)
bool Jupiter::Database::append(Jupiter::ReadableString &file, Jupiter::DataBuffer &data) bool Jupiter::Database::append(Jupiter::ReadableString &file, Jupiter::DataBuffer &data)
{ {
char *str = new char[file.size() + 1]; char *str = new char[file.size() + 1];
memcpy(str, file.ptr(), file.size() * sizeof(char)); memcpy(str, file.data(), file.size() * sizeof(char));
str[file.size()] = '\0'; str[file.size()] = '\0';
bool r = Jupiter::Database::append(str, data); bool r = Jupiter::Database::append(str, data);
delete[] str; delete[] str;
@ -161,7 +161,7 @@ bool Jupiter::Database::append(FILE *file, Jupiter::DataBuffer &data)
bool Jupiter::Database::create_database(const Jupiter::ReadableString &file, const Jupiter::DataBuffer *header) bool Jupiter::Database::create_database(const Jupiter::ReadableString &file, const Jupiter::DataBuffer *header)
{ {
char *str = new char[file.size() + 1]; char *str = new char[file.size() + 1];
memcpy(str, file.ptr(), file.size() * sizeof(char)); memcpy(str, file.data(), file.size() * sizeof(char));
str[file.size()] = '\0'; str[file.size()] = '\0';
bool r = Jupiter::Database::create_database(str, header); bool r = Jupiter::Database::create_database(str, header);
delete[] str; delete[] str;

8
src/common/INIConfig.cpp

@ -214,7 +214,7 @@ bool Jupiter::INIConfig::read_internal(const char *in_filename) {
end = itr + buffer.size(); end = itr + buffer.size();
// Reset line // Reset line
line = std::string_view(buffer.ptr(), 0); line = std::string_view(buffer.data(), 0);
// Parse buffer for lines // Parse buffer for lines
while (itr != end) while (itr != end)
@ -223,7 +223,7 @@ bool Jupiter::INIConfig::read_internal(const char *in_filename) {
if (*itr == '\n' || *itr == '\r') if (*itr == '\n' || *itr == '\r')
{ {
// Process line // Process line
line = std::string_view(buffer.ptr(), itr - buffer.ptr()); line = std::string_view(buffer.data(), itr - buffer.data());
if (!line.empty()) if (!line.empty())
process_line(); process_line();
@ -242,7 +242,7 @@ bool Jupiter::INIConfig::read_internal(const char *in_filename) {
if (*itr != '\n' && *itr != '\r') if (*itr != '\n' && *itr != '\r')
{ {
// Shift buffer and break // Shift buffer and break
buffer.shiftRight(itr - buffer.ptr()); buffer.shiftRight(itr - buffer.data());
break; break;
} }
} }
@ -253,7 +253,7 @@ bool Jupiter::INIConfig::read_internal(const char *in_filename) {
} }
// Process data remaining in buffer as a line // Process data remaining in buffer as a line
line = std::string_view(buffer.ptr(), buffer.size()); line = std::string_view(buffer.data(), buffer.size());
if (!line.empty()) if (!line.empty())
process_line(); process_line();

62
src/common/IRC_Client.cpp

@ -666,7 +666,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
// Parse supported channel types // Parse supported channel types
pos = line.find("CHANTYPES="_jrs); pos = line.find("CHANTYPES="_jrs);
if (pos != Jupiter::INVALID_INDEX) { if (pos != Jupiter::INVALID_INDEX) {
m_chan_types = line.substring(pos + 10, line.find(' ')); m_chan_types = line.substr(pos + 10, line.find(' '));
} }
} }
break; break;
@ -792,10 +792,9 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
std::string_view channel_name = getLineToken(2); std::string_view channel_name = getLineToken(2);
if (!channel_name.empty()) { if (!channel_name.empty()) {
size_t pos = line.find('!', 0); size_t pos = line.find('!', 0);
auto message = Jupiter::ReferenceString::substring(line, line.find(':', 1) + 1, auto message = jessilib::split_once_view(line, ':').second;
line.size());
if (pos < line.find(' ')) { if (pos < line.find(' ')) {
auto nick = Jupiter::ReferenceString::substring(line, 1, pos); auto nick = line.substr(1, pos);
this->OnNotice(channel_name, nick, message); this->OnNotice(channel_name, nick, message);
for (auto& plugin: Jupiter::plugins) { for (auto& plugin: Jupiter::plugins) {
plugin->OnNotice(this, channel_name, nick, message); plugin->OnNotice(this, channel_name, nick, message);
@ -814,10 +813,10 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
} }
else if (jessilib::equalsi(command_token, "NICK"sv)) { else if (jessilib::equalsi(command_token, "NICK"sv)) {
auto nick = getSender(line); auto nick = getSender(line);
Jupiter::ReferenceString newnick = Jupiter::ReferenceString::substring(line, std::string_view newnick = jessilib::split_once_view(line, ' ').second;
line.find(' ', 1) + 1); if (!newnick.empty() && newnick[0] == ':') {
if (newnick.isNotEmpty() && newnick[0] == ':') newnick.remove_prefix(1);
newnick.shiftRight(1); }
if (nick.equalsi(m_nickname)) { if (nick.equalsi(m_nickname)) {
m_nickname = newnick; m_nickname = newnick;
} }
@ -876,8 +875,8 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
Jupiter::ReferenceString reason; Jupiter::ReferenceString reason;
size_t pos = line.find(':', 1); size_t pos = line.find(':', 1);
if (pos != Jupiter::INVALID_INDEX) if (pos != std::string_view::npos)
reason = Jupiter::ReferenceString::substring(line, pos + 1); reason = line.substr(pos + 1);
this->OnPart(channel_name, nick, reason); this->OnPart(channel_name, nick, reason);
@ -910,8 +909,8 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
size_t pos = line.find(':', 1); size_t pos = line.find(':', 1);
Jupiter::ReferenceString reason; Jupiter::ReferenceString reason;
if (pos != Jupiter::INVALID_INDEX) if (pos != std::string_view::npos)
reason = Jupiter::ReferenceString::substring(line, pos + 1); reason = line.substr(pos + 1);
this->OnKick(channel_name, kicker, kicked_nickname, reason); this->OnKick(channel_name, kicker, kicked_nickname, reason);
@ -937,8 +936,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
} }
else if (jessilib::equalsi(command_token, "QUIT"sv)) { else if (jessilib::equalsi(command_token, "QUIT"sv)) {
Jupiter::ReferenceString nick = getSender(line); Jupiter::ReferenceString nick = getSender(line);
Jupiter::ReferenceString message = Jupiter::ReferenceString::substring(line, std::string_view message = jessilib::split_once_view(line.substr(1), ':').second;
line.find(':', 1) + 1);
auto user = getUser(nick); auto user = getUser(nick);
if (user != nullptr) { if (user != nullptr) {
for (auto& channel: m_channels) { for (auto& channel: m_channels) {
@ -957,11 +955,10 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
else if (jessilib::equalsi(command_token, "INVITE"sv)) { else if (jessilib::equalsi(command_token, "INVITE"sv)) {
Jupiter::ReferenceString inviter = getSender(line); Jupiter::ReferenceString inviter = getSender(line);
std::string_view invited_nickname = getLineToken(2); std::string_view invited_nickname = getLineToken(2);
Jupiter::ReferenceString chan = Jupiter::ReferenceString::substring(line, std::string_view channel_name = jessilib::split_once_view(line.substr(1), ':').second;
line.find(':', 1) + 1); this->OnInvite(channel_name, inviter, invited_nickname);
this->OnInvite(chan, inviter, invited_nickname);
for (auto& plugin: Jupiter::plugins) { for (auto& plugin: Jupiter::plugins) {
plugin->OnInvite(this, chan, inviter, invited_nickname); plugin->OnInvite(this, channel_name, inviter, invited_nickname);
} }
} }
else if (jessilib::equalsi(command_token, "MODE"sv)) { else if (jessilib::equalsi(command_token, "MODE"sv)) {
@ -1040,8 +1037,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
// else if CHGHOST // else if CHGHOST
else if (numeric == Reply::NAMREPLY) { // Some names. else if (numeric == Reply::NAMREPLY) { // Some names.
std::string_view channel_name = getLineToken(4); std::string_view channel_name = getLineToken(4);
Jupiter::ReferenceString names = Jupiter::ReferenceString::substring(line, std::string_view names = jessilib::split_once_view(line.substr(1), ':').second;
line.find(':', 1) + 1);
Channel* channel = getChannel(channel_name); Channel* channel = getChannel(channel_name);
if (channel != nullptr) { if (channel != nullptr) {
@ -1082,7 +1078,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
} }
else if (w1 == "ERROR"sv) else if (w1 == "ERROR"sv)
{ {
Jupiter::ReferenceString reason = Jupiter::ReferenceString::substring(line, line.find(':') + 1); std::string_view reason = jessilib::split_once_view(line, ':').second;
this->OnError(reason); this->OnError(reason);
for (auto& plugin : Jupiter::plugins) { for (auto& plugin : Jupiter::plugins) {
plugin->OnError(this, reason); plugin->OnError(this, reason);
@ -1095,7 +1091,7 @@ int Jupiter::IRC::Client::process_line(std::string_view in_line) {
{ {
Jupiter::StringS auth_str = m_nickname + '\0' + m_sasl_account + '\0' + m_sasl_password; Jupiter::StringS auth_str = m_nickname + '\0' + m_sasl_account + '\0' + m_sasl_password;
char *enc = Jupiter::base64encode(auth_str.ptr(), auth_str.size()); char *enc = Jupiter::base64encode(auth_str.data(), auth_str.size());
m_socket->send("AUTHENTICATE "_jrs + enc + ENDL); m_socket->send("AUTHENTICATE "_jrs + enc + ENDL);
delete[] enc; delete[] enc;
} }
@ -1170,7 +1166,7 @@ void Jupiter::IRC::Client::disconnect(bool stayDead)
void Jupiter::IRC::Client::disconnect(const Jupiter::ReadableString &message, bool stayDead) void Jupiter::IRC::Client::disconnect(const Jupiter::ReadableString &message, bool stayDead)
{ {
m_socket->send(Jupiter::StringS::Format("QUIT :%.*s" ENDL, message.size(), message.ptr())); m_socket->send(Jupiter::StringS::Format("QUIT :%.*s" ENDL, message.size(), message.data()));
Jupiter::IRC::Client::disconnect(stayDead); Jupiter::IRC::Client::disconnect(stayDead);
} }
@ -1337,7 +1333,7 @@ double Jupiter::IRC::Client::readConfigDouble(const Jupiter::ReadableString &key
void Jupiter::IRC::Client::writeToLogs(const Jupiter::ReadableString &message) { void Jupiter::IRC::Client::writeToLogs(const Jupiter::ReadableString &message) {
if (m_log_file != nullptr) { if (m_log_file != nullptr) {
fwrite(message.ptr(), sizeof(char), message.size(), m_log_file); fwrite(message.data(), sizeof(char), message.size(), m_log_file);
fputs("\r\n", m_log_file); fputs("\r\n", m_log_file);
fflush(m_log_file); fflush(m_log_file);
} }
@ -1436,15 +1432,15 @@ bool Jupiter::IRC::Client::registerClient() {
* User Implementation * User Implementation
*/ */
const Jupiter::ReadableString &Jupiter::IRC::Client::User::getNickname() const { std::string_view Jupiter::IRC::Client::User::getNickname() const {
return m_nickname; return m_nickname;
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::User::getUsername() const { std::string_view Jupiter::IRC::Client::User::getUsername() const {
return m_username; return m_username;
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::User::getHostname() const { std::string_view Jupiter::IRC::Client::User::getHostname() const {
return m_hostname; return m_hostname;
} }
@ -1459,7 +1455,7 @@ size_t Jupiter::IRC::Client::User::getChannelCount() const {
Jupiter::IRC::Client::Channel::Channel(const Jupiter::ReadableString &in_name, Jupiter::IRC::Client *in_parent) { Jupiter::IRC::Client::Channel::Channel(const Jupiter::ReadableString &in_name, Jupiter::IRC::Client *in_parent) {
auto to_lower = [&in_name]() { auto to_lower = [&in_name]() {
Jupiter::String result(in_name.size()); Jupiter::String result(in_name.size());
const char *itr = in_name.ptr(); const char *itr = in_name.data();
const char *end = itr + in_name.size(); const char *end = itr + in_name.size();
while (itr != end) while (itr != end)
@ -1494,7 +1490,7 @@ std::shared_ptr<Jupiter::IRC::Client::Channel::User> Jupiter::IRC::Client::Chann
++user->m_channel_count; ++user->m_channel_count;
m_users[channel_user->getNickname()] = channel_user; m_users[Jupiter::ReferenceString{channel_user->getNickname()}] = channel_user;
return channel_user; return channel_user;
} }
@ -1505,7 +1501,7 @@ std::shared_ptr<Jupiter::IRC::Client::Channel::User> Jupiter::IRC::Client::Chann
++user->m_channel_count; ++user->m_channel_count;
m_users[channel_user->getNickname()] = channel_user; m_users[Jupiter::ReferenceString{channel_user->getNickname()}] = channel_user;
return channel_user; return channel_user;
} }
@ -1595,15 +1591,15 @@ const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::User::getPrefixes(
return m_prefixes; return m_prefixes;
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::User::getNickname() const { std::string_view Jupiter::IRC::Client::Channel::User::getNickname() const {
return m_user->getNickname(); return m_user->getNickname();
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::User::getUsername() const { std::string_view Jupiter::IRC::Client::Channel::User::getUsername() const {
return m_user->getUsername(); return m_user->getUsername();
} }
const Jupiter::ReadableString &Jupiter::IRC::Client::Channel::User::getHostname() const { std::string_view Jupiter::IRC::Client::Channel::User::getHostname() const {
return m_user->getHostname(); return m_user->getHostname();
} }

2
src/common/Socket.cpp

@ -502,7 +502,7 @@ int Jupiter::Socket::send(const char *data, size_t datalen) {
} }
int Jupiter::Socket::send(const Jupiter::ReadableString &str) { int Jupiter::Socket::send(const Jupiter::ReadableString &str) {
return this->send(str.ptr(), str.size()); return this->send(str.data(), str.size());
} }
int Jupiter::Socket::send(std::string_view str) { int Jupiter::Socket::send(std::string_view str) {

4
src/include/Jupiter/HTTP_QueryString.h

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

10
src/include/Jupiter/Hash.h

@ -77,7 +77,7 @@ template<typename T, typename R> inline R Jupiter::calcsum(const T *in_data, siz
template<typename T, typename R> inline R Jupiter::calcsum(const Jupiter::Readable_String<T> &str) template<typename T, typename R> inline R Jupiter::calcsum(const Jupiter::Readable_String<T> &str)
{ {
return Jupiter::calcsum<T, R>(str.ptr(), str.size()); return Jupiter::calcsum<T, R>(str.data(), str.size());
} }
/** fnv1 implementation */ /** fnv1 implementation */
@ -93,7 +93,7 @@ template<typename T> inline uint64_t Jupiter::fnv1(const T *data, size_t length)
template<typename T> inline uint64_t Jupiter::fnv1(const Jupiter::Readable_String<T> &data) template<typename T> inline uint64_t Jupiter::fnv1(const Jupiter::Readable_String<T> &data)
{ {
return Jupiter::fnv1(reinterpret_cast<const uint8_t *>(data.ptr()), reinterpret_cast<const uint8_t *>(data.ptr() + data.size())); return Jupiter::fnv1(reinterpret_cast<const uint8_t *>(data.data()), reinterpret_cast<const uint8_t *>(data.data() + data.size()));
} }
template<typename T> inline uint32_t Jupiter::fnv1_32(const T &data) template<typename T> inline uint32_t Jupiter::fnv1_32(const T &data)
@ -108,7 +108,7 @@ template<typename T> inline uint32_t Jupiter::fnv1_32(const T *data, size_t leng
template<typename T> inline uint32_t Jupiter::fnv1_32(const Jupiter::Readable_String<T> &data) template<typename T> inline uint32_t Jupiter::fnv1_32(const Jupiter::Readable_String<T> &data)
{ {
return Jupiter::fnv1_32(reinterpret_cast<const uint8_t *>(data.ptr()), reinterpret_cast<const uint8_t *>(data.ptr() + data.size())); return Jupiter::fnv1_32(reinterpret_cast<const uint8_t *>(data.data()), reinterpret_cast<const uint8_t *>(data.data() + data.size()));
} }
template<typename T> inline uint64_t Jupiter::fnv1a(const T &data) template<typename T> inline uint64_t Jupiter::fnv1a(const T &data)
@ -123,7 +123,7 @@ template<typename T> inline uint64_t Jupiter::fnv1a(const T *data, size_t length
template<typename T> inline uint64_t Jupiter::fnv1a(const Jupiter::Readable_String<T> &data) template<typename T> inline uint64_t Jupiter::fnv1a(const Jupiter::Readable_String<T> &data)
{ {
return Jupiter::fnv1a(data.ptr(), data.size()); return Jupiter::fnv1a(data.data(), data.size());
} }
template<typename T> inline uint32_t Jupiter::fnv1a_32(const T &data) template<typename T> inline uint32_t Jupiter::fnv1a_32(const T &data)
@ -138,7 +138,7 @@ template<typename T> inline uint32_t Jupiter::fnv1a_32(const T *data, size_t len
template<typename T> inline uint32_t Jupiter::fnv1a_32(const Jupiter::Readable_String<T> &data) template<typename T> inline uint32_t Jupiter::fnv1a_32(const Jupiter::Readable_String<T> &data)
{ {
return Jupiter::fnv1a_32(data.ptr(), data.size()); return Jupiter::fnv1a_32(data.data(), data.size());
} }
#endif // _HASH_H_HEADER #endif // _HASH_H_HEADER

14
src/include/Jupiter/IRC_Client.h

@ -218,21 +218,21 @@ namespace Jupiter
* *
* @return String containing the user's nickname. * @return String containing the user's nickname.
*/ */
const Jupiter::ReadableString &getNickname() const; std::string_view getNickname() const;
/** /**
* @brief Fetches the user's username. * @brief Fetches the user's username.
* *
* @return String containing the user's username. * @return String containing the user's username.
*/ */
const Jupiter::ReadableString &getUsername() const; std::string_view getUsername() const;
/** /**
* @brief Fetches the user's hostname. * @brief Fetches the user's hostname.
* *
* @return String containing the user's hostname. * @return String containing the user's hostname.
*/ */
const Jupiter::ReadableString &getHostname() const; std::string_view getHostname() const;
/** /**
* @brief Returns the number of channels the user shares with the local client. * @brief Returns the number of channels the user shares with the local client.
@ -244,7 +244,7 @@ namespace Jupiter
/** Private members */ /** Private members */
private: private:
unsigned int m_channel_count = 0; unsigned int m_channel_count = 0;
Jupiter::StringS m_nickname; std::string m_nickname;
Jupiter::StringS m_username; Jupiter::StringS m_username;
Jupiter::StringS m_hostname; Jupiter::StringS m_hostname;
}; };
@ -284,21 +284,21 @@ namespace Jupiter
* *
* @return String containing the user's nickname. * @return String containing the user's nickname.
*/ */
const Jupiter::ReadableString &getNickname() const; std::string_view getNickname() const;
/** /**
* @brief Fetches the user's username. * @brief Fetches the user's username.
* *
* @return String containing the user's username. * @return String containing the user's username.
*/ */
const Jupiter::ReadableString &getUsername() const; std::string_view getUsername() const;
/** /**
* @brief Fetches the user's hostname. * @brief Fetches the user's hostname.
* *
* @return String containing the user's hostname. * @return String containing the user's hostname.
*/ */
const Jupiter::ReadableString &getHostname() const; std::string_view getHostname() const;
/** /**
* @brief Returns the number of channels the user shares with the local client. * @brief Returns the number of channels the user shares with the local client.

10
src/include/Jupiter/Readable_String.h

@ -51,7 +51,7 @@ namespace Jupiter
* *
* @return Pointer to the underlying string of elements. * @return Pointer to the underlying string of elements.
*/ */
virtual const T *ptr() const = 0; // RENAME; 'data' virtual const T *data() const = 0; // KEEP
/** /**
* @brief Returns the number of elements in the String. * @brief Returns the number of elements in the String.
@ -102,12 +102,12 @@ namespace Jupiter
virtual ~Readable_String() = default; virtual ~Readable_String() = default;
/** Access operator */ /** Access operator */
inline const T &operator[](size_t index) const { return this->ptr()[index]; }; inline const T &operator[](size_t index) const { return this->data()[index]; };
/** Comparative operators */ /** Comparative operators */
inline bool operator==(const Readable_String<T>& right)const{ return operator==(std::basic_string_view<T>{right}); } inline bool operator==(const Readable_String<T>& right)const{ return operator==(std::basic_string_view<T>{right}); }
inline bool operator==(const std::basic_string<T>& right)const{ return operator==(std::basic_string_view<T>{right}); } inline bool operator==(const std::basic_string<T>& right)const{ return operator==(std::basic_string_view<T>{right}); }
inline bool operator==(const std::basic_string_view<T>& right)const{ return std::basic_string_view<T>(ptr(), size()) == right; } inline bool operator==(const std::basic_string_view<T>& right)const{ return std::basic_string_view<T>(data(), size()) == right; }
inline bool operator==(const T right)const{ return this->size() == 1 && this->get(0) == right; } inline bool operator==(const T right)const{ return this->size() == 1 && this->get(0) == right; }
inline bool operator==(std::nullptr_t) = delete; inline bool operator==(std::nullptr_t) = delete;
inline bool operator!=(const Readable_String<T> &right)const{ return !operator==(right); } inline bool operator!=(const Readable_String<T> &right)const{ return !operator==(right); }
@ -128,8 +128,8 @@ namespace Jupiter
inline bool operator>=(const T right)const{ return !operator<(right); } inline bool operator>=(const T right)const{ return !operator<(right); }
/** Conversion operators */ /** Conversion operators */
explicit inline operator std::basic_string<T>() const { return std::basic_string<T>(this->ptr(), this->size()); } explicit inline operator std::basic_string<T>() const { return std::basic_string<T>(this->data(), this->size()); }
inline operator std::basic_string_view<T>() const { return std::basic_string_view<T>(this->ptr(), this->size()); } inline operator std::basic_string_view<T>() const { return std::basic_string_view<T>(this->data(), this->size()); }
}; };
/** Generic Readable String Type */ /** Generic Readable String Type */

4
src/include/Jupiter/Readable_String_Imp.h

@ -69,7 +69,7 @@ template<typename T> size_t Jupiter::Readable_String<T>::find(const Jupiter::Rea
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const Jupiter::Readable_String<T> &in) const template<typename T> bool Jupiter::Readable_String<T>::equalsi(const Jupiter::Readable_String<T> &in) const
{ {
return this->equalsi(in.ptr(), in.size()); return this->equalsi(in.data(), in.size());
} }
template<typename T> bool Jupiter::Readable_String<T>::equalsi(const std::basic_string<T> &in) const template<typename T> bool Jupiter::Readable_String<T>::equalsi(const std::basic_string<T> &in) const
@ -130,7 +130,7 @@ template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Reada
{ {
buffer->secure(sizeof(size_t) + data->size() * sizeof(Y)); buffer->secure(sizeof(size_t) + data->size() * sizeof(Y));
buffer->push<size_t>(data->size()); buffer->push<size_t>(data->size());
buffer->push(reinterpret_cast<const uint8_t *>(data->ptr()), data->size() * sizeof(Y)); buffer->push(reinterpret_cast<const uint8_t *>(data->data()), data->size() * sizeof(Y));
}; };
}; };

84
src/include/Jupiter/Reference_String.h

@ -53,89 +53,11 @@ namespace Jupiter
* *
* @return Pointer to the underlying string of elements. * @return Pointer to the underlying string of elements.
*/ */
const T *ptr() const override; const T* data() const override;
/**
* @brief Truncates the string by a specified number of elements.
*
* @param n Number of elements to remove from the tail.
* @return New size of the String.
*/
virtual size_t truncate(size_t n);
/**
* @brief Erases the string (sets the string's length to 0)
*/
void erase();
/**
* @brief Shifts the string pointer to the left.
*
* @param length Number of elements to shift
* @return Number of elements shifted to the left.
*/
size_t shiftLeft(size_t length);
/**
* @brief Shifts the string pointer to the right.
*
* @param length Number of elements to shift
* @return Number of elements shifted.
*/
size_t shiftRight(size_t length);
/**
* @brief Sets the reference to point to an input string.
*
* @param in String containing the data to be referenced.
* @return New size of the String.
*/
size_t set(const Jupiter::Readable_String<T> &in);
size_t set(const std::basic_string<T> &in);
size_t set(const T *in, size_t len);
size_t set(const T *in);
/**
* @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.
*/
Reference_String<T> substring(size_t pos) const;
/**
* @brief Creates a partial copy of the string.
*
* @param pos Position in the string to start copying from.
* @param length Number of characters to copy.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> substring(size_t pos, size_t length) const;
/**
* @brief Creates a partial copy of the string.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> substring(const Jupiter::Readable_String<T> &in, size_t pos);
static Reference_String<T> substring(const T *in, size_t pos);
/**
* @brief Creates a partial copy of the string.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param length Number of characters to copy.
* @return String containing a partial copy of the original string.
*/
static 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);
/** Mutative operators */ /** 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=({
inline Reference_String<T>& operator=(const Readable_String<T> &right) { std::basic_string_view<T>::operator=({right.ptr(), right.size()}); return *this; }; right.data(), right.size()}); return *this; };
inline Reference_String<T>& operator=(const Reference_String<T> &right) = default; inline Reference_String<T>& operator=(const Reference_String<T> &right) = default;
inline Reference_String<T>& operator=(const std::basic_string<T> &right) { std::basic_string_view<T>::operator=(right); return *this; }; inline Reference_String<T>& operator=(const std::basic_string<T> &right) { std::basic_string_view<T>::operator=(right); return *this; };
inline Reference_String<T>& operator=(const std::basic_string_view<T> &right) { std::basic_string_view<T>::operator=(right); return *this; }; inline Reference_String<T>& operator=(const std::basic_string_view<T> &right) { std::basic_string_view<T>::operator=(right); return *this; };

83
src/include/Jupiter/Reference_String_Imp.h

@ -48,96 +48,17 @@ template<typename T> Jupiter::Reference_String<T>::Reference_String(const T *in)
} }
template<typename T> Jupiter::Reference_String<T>::Reference_String(const Jupiter::Readable_String<T>& in) template<typename T> Jupiter::Reference_String<T>::Reference_String(const Jupiter::Readable_String<T>& in)
: Reference_String(in.ptr(), in.size()) { : Reference_String(in.data(), in.size()) {
} }
template<typename T> size_t Jupiter::Reference_String<T>::size() const { template<typename T> size_t Jupiter::Reference_String<T>::size() const {
return std::basic_string_view<T>::size(); return std::basic_string_view<T>::size();
} }
template<typename T> const T* Jupiter::Reference_String<T>::ptr() const { template<typename T> const T* Jupiter::Reference_String<T>::data() const {
return std::basic_string_view<T>::data(); return std::basic_string_view<T>::data();
} }
// truncate
template<typename T> size_t Jupiter::Reference_String<T>::truncate(size_t n) {
std::basic_string_view<T>::remove_suffix(std::min(n, size()));
return size();
}
// erase
template<typename T> void Jupiter::Reference_String<T>::erase() {
std::basic_string_view<T>::remove_suffix(size());
}
// shift
template<typename T> size_t Jupiter::Reference_String<T>::shiftLeft(size_t len) {
*this = std::basic_string_view<T>{ this->data() - len, size() };
return len;
}
template<typename T> size_t Jupiter::Reference_String<T>::shiftRight(size_t len) {
len = std::min(len, size());
this->remove_prefix(len);
return len;
}
// set
template<typename T> size_t Jupiter::Reference_String<T>::set(const Jupiter::Readable_String<T> &in) {
return this->set(in.ptr(), in.size());
}
template<typename T> size_t Jupiter::Reference_String<T>::set(const std::basic_string<T> &in) {
*this = in;
return size();
}
template<typename T> size_t Jupiter::Reference_String<T>::set(const T *in, size_t len) {
*this = std::basic_string_view<T>{ in, len };
return size();
}
template<typename T> size_t Jupiter::Reference_String<T>::set(const T *in) {
if (in == nullptr) {
*this = std::basic_string_view<T>{};
}
*this = std::basic_string_view<T>{ in };
return size();
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(size_t pos) const {
return Jupiter::Reference_String<T>::substring(*this, pos);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(size_t pos, size_t len) const {
return Jupiter::Reference_String<T>::substring(*this, pos, len);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos) {
pos = std::min(pos, in.size());
return Jupiter::Reference_String<T>(in.ptr() + pos, in.size() - pos);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(const T *in, size_t pos) {
return Jupiter::Reference_String<T>(in + pos);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len) {
if (pos + len > in.size()) {
return Jupiter::Reference_String<T>::substring(in, pos);
}
return Jupiter::Reference_String<T>(in.ptr() + pos, len);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(const T *in, size_t pos, size_t len) {
return Jupiter::Reference_String<T>(in + pos, len);
}
// Jupiter::DataBuffer specialization // Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Reference_String> { template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Reference_String> {

23
src/include/Jupiter/String_Imp.h

@ -69,11 +69,13 @@ template<typename T> Jupiter::String_Strict<T>::String_Strict(Jupiter::String_St
{ {
} }
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::String_Strict<T> &in) : Jupiter::String_Strict<T>::String_Strict(in.ptr(), in.size()) template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::String_Strict<T> &in) : Jupiter::String_Strict<T>::String_Strict(
in.data(), in.size())
{ {
} }
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &in) : Jupiter::String_Strict<T>::String_Strict(in.ptr(), in.size()) template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &in) : Jupiter::String_Strict<T>::String_Strict(
in.data(), in.size())
{ {
} }
@ -112,7 +114,7 @@ template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Rea
if (lhs.isNotEmpty()) if (lhs.isNotEmpty())
{ {
itr = lhs.ptr(); itr = lhs.data();
end = itr + lhs.size(); end = itr + lhs.size();
*Jupiter::String_Type<T>::str = *itr; *Jupiter::String_Type<T>::str = *itr;
while (++itr != end) while (++itr != end)
@ -126,7 +128,8 @@ template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Rea
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base;
} }
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &rhs) : String_Strict<T>(lhs, rhs.ptr(), rhs.size()) template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &rhs) : String_Strict<T>(lhs,
rhs.data(), rhs.size())
{ {
} }
@ -145,7 +148,7 @@ template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Rea
if (lhs.isNotEmpty()) if (lhs.isNotEmpty())
{ {
itr = lhs.ptr(); itr = lhs.data();
end = itr + lhs.size(); end = itr + lhs.size();
*Jupiter::String_Type<T>::str = *itr; *Jupiter::String_Type<T>::str = *itr;
while (++itr != end) while (++itr != end)
@ -383,7 +386,8 @@ template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Strin
Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = in.get(Jupiter::String_Type<T>::length); Jupiter::String_Type<T>::str[Jupiter::String_Type<T>::length] = in.get(Jupiter::String_Type<T>::length);
} }
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &in) : Jupiter::String_Loose<T>::String_Loose(in.ptr(), in.size()) template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &in) : Jupiter::String_Loose<T>::String_Loose(
in.data(), in.size())
{ {
} }
@ -433,7 +437,7 @@ template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Reada
if (lhs.isNotEmpty()) if (lhs.isNotEmpty())
{ {
itr = lhs.ptr(); itr = lhs.data();
end = itr + lhs.size(); end = itr + lhs.size();
*Jupiter::String_Type<T>::str = *itr; *Jupiter::String_Type<T>::str = *itr;
while (++itr != end) while (++itr != end)
@ -447,7 +451,8 @@ template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Reada
Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base; Jupiter::String_Type<T>::str = Jupiter::Shift_String_Type<T>::base;
} }
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &rhs) : String_Loose<T>(lhs, rhs.ptr(), rhs.size()) template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Readable_String<T> &lhs, const Jupiter::Readable_String<T> &rhs) : String_Loose<T>(lhs,
rhs.data(), rhs.size())
{ {
} }
@ -466,7 +471,7 @@ template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::Reada
if (lhs.isNotEmpty()) if (lhs.isNotEmpty())
{ {
itr = lhs.ptr(); itr = lhs.data();
end = itr + lhs.size(); end = itr + lhs.size();
*Jupiter::String_Type<T>::str = *itr; *Jupiter::String_Type<T>::str = *itr;
while (++itr != end) while (++itr != end)

14
src/include/Jupiter/String_Type.h

@ -47,20 +47,12 @@ namespace Jupiter
{ {
public: 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;
/** /**
* @brief Returns the number of elements in the String. * @brief Returns the number of elements in the String.
* *
* @return Number of elements in the string. * @return Number of elements in the string.
*/ */
size_t size() const; size_t size() const override;
/** /**
* @brief Returns the maximum number of elements the String can contain, * @brief Returns the maximum number of elements the String can contain,
@ -76,7 +68,7 @@ namespace Jupiter
* *
* @return Pointer to the underlying string of elements. * @return Pointer to the underlying string of elements.
*/ */
const T *ptr() const; const T *data() const override;
/** /**
* @brief Sets the String's contents based on the format string and input variables. * @brief Sets the String's contents based on the format string and input variables.
@ -283,6 +275,8 @@ namespace Jupiter
inline String_Type<T> &operator=(const T *right) { this->set(right); return *this; }; inline String_Type<T> &operator=(const T *right) { this->set(right); return *this; };
inline String_Type<T> &operator=(const T right) { this->set(right); return *this; }; inline String_Type<T> &operator=(const T right) { this->set(right); return *this; };
using Readable_String<T>::operator[];
/** /**
* @brief Default constructor for the String_Type class. * @brief Default constructor for the String_Type class.
*/ */

75
src/include/Jupiter/String_Type_Imp.h

@ -41,11 +41,6 @@ template<typename T> Jupiter::String_Type<T>::String_Type(Jupiter::String_Type<T
source.str = nullptr; source.str = nullptr;
} }
template<typename T> const T &Jupiter::String_Type<T>::get(size_t index) const
{
return Jupiter::String_Type<T>::str[index];
}
template<typename T> size_t Jupiter::String_Type<T>::size() const template<typename T> size_t Jupiter::String_Type<T>::size() const
{ {
return Jupiter::String_Type<T>::length; return Jupiter::String_Type<T>::length;
@ -56,7 +51,7 @@ template<typename T> size_t Jupiter::String_Type<T>::capacity() const
return this->size(); return this->size();
} }
template<typename T> const T *Jupiter::String_Type<T>::ptr() const template<typename T> const T *Jupiter::String_Type<T>::data() const
{ {
return Jupiter::String_Type<T>::str; return Jupiter::String_Type<T>::str;
} }
@ -179,32 +174,32 @@ template<> inline void Jupiter::String_Type<char>::processEscapeSequences()
size_t index = 0; size_t index = 0;
while (index + 1 != Jupiter::String_Type<char>::length) while (index + 1 != Jupiter::String_Type<char>::length)
{ {
if (this->get(index) == '\\') if (operator[](index) == '\\')
{ {
switch (this->get(++index)) switch (operator[](++index))
{ {
case '0': case '0':
case '1': case '1':
case '2': case '2':
case '3': case '3':
if (index + 1 != Jupiter::String_Type<char>::length && Jupiter_isOctal(this->get(index + 1))) if (index + 1 != Jupiter::String_Type<char>::length && Jupiter_isOctal(operator[](index + 1)))
{ {
if (index + 2 != Jupiter::String_Type<char>::length && Jupiter_isOctal(this->get(index + 2))) if (index + 2 != Jupiter::String_Type<char>::length && Jupiter_isOctal(operator[](index + 2)))
this->replace(index - 1, 4, static_cast<uint8_t>(Jupiter_getOctal(this->get(index))) << 6 | static_cast<uint8_t>(Jupiter_getOctal(this->get(index + 1))) << 3 | static_cast<uint8_t>(Jupiter_getOctal(this->get(index + 2)))); this->replace(index - 1, 4, static_cast<uint8_t>(Jupiter_getOctal(operator[](index))) << 6 | static_cast<uint8_t>(Jupiter_getOctal(operator[](index + 1))) << 3 | static_cast<uint8_t>(Jupiter_getOctal(operator[](index + 2))));
else else
this->replace(index - 1, 3, static_cast<uint8_t>(Jupiter_getOctal(this->get(index))) << 3 | static_cast<uint8_t>(Jupiter_getOctal(this->get(index + 1)))); this->replace(index - 1, 3, static_cast<uint8_t>(Jupiter_getOctal(operator[](index))) << 3 | static_cast<uint8_t>(Jupiter_getOctal(operator[](index + 1))));
} }
else else
this->replace(index - 1, 2, static_cast<uint8_t>(Jupiter_getOctal(this->get(index)))); this->replace(index - 1, 2, static_cast<uint8_t>(Jupiter_getOctal(operator[](index))));
break; break;
case '4': case '4':
case '5': case '5':
case '6': case '6':
case '7': case '7':
if (index + 1 != Jupiter::String_Type<char>::length && Jupiter_isOctal(this->get(index + 1))) if (index + 1 != Jupiter::String_Type<char>::length && Jupiter_isOctal(operator[](index + 1)))
this->replace(index - 1, 3, static_cast<uint8_t>(Jupiter_getOctal(this->get(index))) << 3 | static_cast<uint8_t>(Jupiter_getOctal(this->get(index + 1)))); this->replace(index - 1, 3, static_cast<uint8_t>(Jupiter_getOctal(operator[](index))) << 3 | static_cast<uint8_t>(Jupiter_getOctal(operator[](index + 1))));
else else
this->replace(index - 1, 2, static_cast<uint8_t>(Jupiter_getOctal(this->get(index)))); this->replace(index - 1, 2, static_cast<uint8_t>(Jupiter_getOctal(operator[](index))));
break; break;
case 'a': case 'a':
this->replace(index - 1, 2, '\a'); this->replace(index - 1, 2, '\a');
@ -241,20 +236,20 @@ template<> inline void Jupiter::String_Type<char>::processEscapeSequences()
break; break;
case 'x': case 'x':
if (Jupiter::String_Type<char>::length >= index + 2 if (Jupiter::String_Type<char>::length >= index + 2
&& Jupiter_isHex(this->get(index + 1)) && Jupiter_isHex(this->get(index + 2))) && Jupiter_isHex(operator[](index + 1)) && Jupiter_isHex(operator[](index + 2)))
this->replace(index - 1, 4, static_cast<uint8_t>(Jupiter_getHex(this->get(index + 1))) << 4 | static_cast<uint8_t>(Jupiter_getHex(this->get(index + 2)))); this->replace(index - 1, 4, static_cast<uint8_t>(Jupiter_getHex(operator[](index + 1))) << 4 | static_cast<uint8_t>(Jupiter_getHex(operator[](index + 2))));
break; break;
case 'U': case 'U':
if (Jupiter::String_Type<char>::length >= index + 8 if (Jupiter::String_Type<char>::length >= index + 8
&& Jupiter_isHex(this->get(index + 1)) && Jupiter_isHex(this->get(index + 2)) && Jupiter_isHex(this->get(index + 3)) && Jupiter_isHex(this->get(index + 4)) && Jupiter_isHex(this->get(index + 5)) && Jupiter_isHex(this->get(index + 6)) && Jupiter_isHex(this->get(index + 7)) && Jupiter_isHex(this->get(index + 8))) && Jupiter_isHex(operator[](index + 1)) && Jupiter_isHex(operator[](index + 2)) && Jupiter_isHex(operator[](index + 3)) && Jupiter_isHex(operator[](index + 4)) && Jupiter_isHex(operator[](index + 5)) && Jupiter_isHex(operator[](index + 6)) && Jupiter_isHex(operator[](index + 7)) && Jupiter_isHex(operator[](index + 8)))
{ {
uint32_t codepoint = static_cast<uint8_t>(Jupiter_getHex(this->get(index + 1))) << 4 | static_cast<uint8_t>(Jupiter_getHex(this->get(index + 2))); uint32_t codepoint = static_cast<uint8_t>(Jupiter_getHex(operator[](index + 1))) << 4 | static_cast<uint8_t>(Jupiter_getHex(operator[](index + 2)));
codepoint <<= 8; codepoint <<= 8;
codepoint |= static_cast<uint8_t>(Jupiter_getHex(this->get(index + 3))) << 4 | static_cast<uint8_t>(Jupiter_getHex(this->get(index + 4))); codepoint |= static_cast<uint8_t>(Jupiter_getHex(operator[](index + 3))) << 4 | static_cast<uint8_t>(Jupiter_getHex(operator[](index + 4)));
codepoint <<= 8; codepoint <<= 8;
codepoint |= static_cast<uint8_t>(Jupiter_getHex(this->get(index + 5))) << 4 | static_cast<uint8_t>(Jupiter_getHex(this->get(index + 6))); codepoint |= static_cast<uint8_t>(Jupiter_getHex(operator[](index + 5))) << 4 | static_cast<uint8_t>(Jupiter_getHex(operator[](index + 6)));
codepoint <<= 8; codepoint <<= 8;
codepoint |= static_cast<uint8_t>(Jupiter_getHex(this->get(index + 7))) << 4 | static_cast<uint8_t>(Jupiter_getHex(this->get(index + 8))); codepoint |= static_cast<uint8_t>(Jupiter_getHex(operator[](index + 7))) << 4 | static_cast<uint8_t>(Jupiter_getHex(operator[](index + 8)));
if (codepoint <= 0x007F) if (codepoint <= 0x007F)
this->replace(index - 1, 10, static_cast<uint8_t>(codepoint)); this->replace(index - 1, 10, static_cast<uint8_t>(codepoint));
else if (codepoint <= 0x07FF) else if (codepoint <= 0x07FF)
@ -288,11 +283,11 @@ template<> inline void Jupiter::String_Type<char>::processEscapeSequences()
break; break;
case 'u': case 'u':
if (Jupiter::String_Type<char>::length >= index + 4 if (Jupiter::String_Type<char>::length >= index + 4
&& Jupiter_isHex(this->get(index + 1)) && Jupiter_isHex(this->get(index + 2)) && Jupiter_isHex(this->get(index + 3)) && Jupiter_isHex(this->get(index + 4))) && Jupiter_isHex(operator[](index + 1)) && Jupiter_isHex(operator[](index + 2)) && Jupiter_isHex(operator[](index + 3)) && Jupiter_isHex(operator[](index + 4)))
{ {
uint16_t codepoint = static_cast<uint8_t>(Jupiter_getHex(this->get(index + 1))) << 4 | static_cast<uint8_t>(Jupiter_getHex(this->get(index + 2))); uint16_t codepoint = static_cast<uint8_t>(Jupiter_getHex(operator[](index + 1))) << 4 | static_cast<uint8_t>(Jupiter_getHex(operator[](index + 2)));
codepoint <<= 8; codepoint <<= 8;
codepoint |= static_cast<uint8_t>(Jupiter_getHex(this->get(index + 3))) << 4 | static_cast<uint8_t>(Jupiter_getHex(this->get(index + 4))); codepoint |= static_cast<uint8_t>(Jupiter_getHex(operator[](index + 3))) << 4 | static_cast<uint8_t>(Jupiter_getHex(operator[](index + 4)));
if (codepoint <= 0x007F) if (codepoint <= 0x007F)
this->replace(index - 1, 6, static_cast<uint8_t>(codepoint)); this->replace(index - 1, 6, static_cast<uint8_t>(codepoint));
else if (codepoint <= 0x07FF) else if (codepoint <= 0x07FF)
@ -377,7 +372,7 @@ template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const T *
template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const Jupiter::Readable_String<T> &in) template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const Jupiter::Readable_String<T> &in)
{ {
return this->set(index, in.ptr(), in.size()); return this->set(index, in.data(), in.size());
} }
template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const std::basic_string<T> &in) template<typename T> size_t Jupiter::String_Type<T>::set(size_t index, const std::basic_string<T> &in)
@ -402,7 +397,7 @@ template<typename T> size_t Jupiter::String_Type<T>::set(const T *in, size_t inS
template<typename T> size_t Jupiter::String_Type<T>::set(const Jupiter::Readable_String<T> &in) template<typename T> size_t Jupiter::String_Type<T>::set(const Jupiter::Readable_String<T> &in)
{ {
return this->set(in.ptr(), in.size()); return this->set(in.data(), in.size());
} }
template<typename T> size_t Jupiter::String_Type<T>::set(const std::basic_string<T> &in) template<typename T> size_t Jupiter::String_Type<T>::set(const std::basic_string<T> &in)
@ -431,7 +426,7 @@ template<typename T> size_t Jupiter::String_Type<T>::insert(size_t index, const
this->setBufferSize(Jupiter::String_Type<T>::length + 1); this->setBufferSize(Jupiter::String_Type<T>::length + 1);
for (size_t i = Jupiter::String_Type<T>::length; i != index; i--) for (size_t i = Jupiter::String_Type<T>::length; i != index; i--)
Jupiter::String_Type<T>::str[i] = this->get(i-1); Jupiter::String_Type<T>::str[i] = operator[](i-1);
Jupiter::String_Type<T>::str[index] = value; Jupiter::String_Type<T>::str[index] = value;
return ++Jupiter::String_Type<T>::length; return ++Jupiter::String_Type<T>::length;
@ -451,7 +446,7 @@ template<typename T> size_t Jupiter::String_Type<T>::insert(size_t index, const
this->setBufferSize(Jupiter::String_Type<T>::length + value.size()); this->setBufferSize(Jupiter::String_Type<T>::length + value.size());
size_t i; size_t i;
for (i = Jupiter::String_Type<T>::length + value.size() - 1; i != index + value.size() - 1; i--) for (i = Jupiter::String_Type<T>::length + value.size() - 1; i != index + value.size() - 1; i--)
Jupiter::String_Type<T>::str[i] = this->get(i - value.size()); Jupiter::String_Type<T>::str[i] = operator[](i - value.size());
while (i != index) while (i != index)
{ {
@ -554,7 +549,7 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_
} }
template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, const Jupiter::Readable_String<T> &value) { template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, const Jupiter::Readable_String<T> &value) {
return this->replace(index, targetSize, value.ptr(), value.size()); return this->replace(index, targetSize, value.data(), value.size());
} }
template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, std::basic_string_view<T> value) { template<typename T> size_t Jupiter::String_Type<T>::replace(size_t index, size_t targetSize, std::basic_string_view<T> value) {
@ -565,7 +560,7 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(const T &target, co
{ {
for (size_t i = 0; i != Jupiter::String_Type<T>::length; i++) for (size_t i = 0; i != Jupiter::String_Type<T>::length; i++)
{ {
if (this->get(i) == target) if (operator[](i) == target)
Jupiter::String_Type<T>::str[i] = value; Jupiter::String_Type<T>::str[i] = value;
} }
return Jupiter::String_Type<T>::length; return Jupiter::String_Type<T>::length;
@ -584,7 +579,7 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, si
while (j <= Jupiter::String_Type<T>::length - targetSize) while (j <= Jupiter::String_Type<T>::length - targetSize)
{ {
k = 0; k = 0;
while (this->get(j + k) == target[k]) while (operator[](j + k) == target[k])
{ {
if (++k == targetSize) // match found if (++k == targetSize) // match found
{ {
@ -610,7 +605,7 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, si
template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const T &value) template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const T &value)
{ {
return this->replace(target.ptr(), target.size(), value); return this->replace(target.data(), target.size(), value);
} }
template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const T *value, size_t valueSize) template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const T *value, size_t valueSize)
@ -634,7 +629,7 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, si
while (i <= Jupiter::String_Type<T>::length - targetSize) while (i <= Jupiter::String_Type<T>::length - targetSize)
{ {
j = 0; j = 0;
while (this->get(i + j) == target[j]) while (operator[](i + j) == target[j])
{ {
if (++j == targetSize) if (++j == targetSize)
{ {
@ -685,7 +680,7 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, si
while (j <= Jupiter::String_Type<T>::length - targetSize) while (j <= Jupiter::String_Type<T>::length - targetSize)
{ {
k = 0; k = 0;
while (this->get(j + k) == target[k]) while (operator[](j + k) == target[k])
{ {
if (++k == targetSize) // match found if (++k == targetSize) // match found
{ {
@ -713,17 +708,17 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, si
template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const Jupiter::Readable_String<T> &value) template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const Jupiter::Readable_String<T> &value)
{ {
return this->replace(target, targetSize, value.ptr(), value.size()); return this->replace(target, targetSize, value.data(), value.size());
} }
template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const T *value, size_t valueSize) template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const T *value, size_t valueSize)
{ {
return this->replace(target.ptr(), target.size(), value, valueSize); return this->replace(target.data(), target.size(), value, valueSize);
} }
template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const Jupiter::Readable_String<T> &value) template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const Jupiter::Readable_String<T> &value)
{ {
return this->replace(target.ptr(), target.size(), value.ptr(), value.size()); return this->replace(target.data(), target.size(), value.data(), value.size());
} }
template<typename T> size_t Jupiter::String_Type<T>::replace(std::basic_string_view<T> target, std::basic_string_view<T> value) template<typename T> size_t Jupiter::String_Type<T>::replace(std::basic_string_view<T> target, std::basic_string_view<T> value)
@ -743,7 +738,7 @@ template<typename T> size_t Jupiter::String_Type<T>::concat(const T *in, size_t
template<typename T> size_t Jupiter::String_Type<T>::concat(const Jupiter::Readable_String<T> &in) template<typename T> size_t Jupiter::String_Type<T>::concat(const Jupiter::Readable_String<T> &in)
{ {
return this->concat(in.ptr(), in.size()); return this->concat(in.data(), in.size());
} }
template<typename T> size_t Jupiter::String_Type<T>::concat(const std::basic_string<T> &in) template<typename T> size_t Jupiter::String_Type<T>::concat(const std::basic_string<T> &in)

Loading…
Cancel
Save