[ox/std] Addressing CLion suggestions

This commit is contained in:
Gary Talent 2021-03-11 21:18:50 -06:00
parent 01c0397680
commit 2f95c0aecc
5 changed files with 44 additions and 34 deletions

View File

@ -47,7 +47,7 @@ String::String(String &&other) noexcept {
m_buff = ox::move(other.m_buff);
}
const String &String::operator=(const char *str) noexcept {
String &String::operator=(const char *str) noexcept {
std::size_t strLen = ox_strlen(str) + 1;
m_buff.resize(strLen + 1);
memcpy(m_buff.data(), str, strLen);
@ -56,26 +56,26 @@ const String &String::operator=(const char *str) noexcept {
return *this;
}
const String &String::operator=(char *str) noexcept {
String &String::operator=(char *str) noexcept {
return *this = static_cast<const char*>(str);
}
const String &String::operator=(int64_t i) noexcept {
String &String::operator=(int64_t i) noexcept {
char str[65] = {};
ox_itoa(i, str);
return this->operator=(str);
}
const String &String::operator=(const String &src) noexcept {
String &String::operator=(const String &src) noexcept {
return *this = src.c_str();
}
const String &String::operator=(const String &&src) noexcept {
String &String::operator=(String &&src) noexcept {
m_buff = ox::move(src.m_buff);
return *this;
}
const String &String::operator+=(const char *str) noexcept {
String &String::operator+=(const char *str) noexcept {
std::size_t strLen = ox_strlen(str);
auto currentLen = len();
m_buff.resize(m_buff.size() + strLen);
@ -85,21 +85,21 @@ const String &String::operator+=(const char *str) noexcept {
return *this;
}
const String &String::operator+=(char *str) noexcept {
String &String::operator+=(char *str) noexcept {
return *this += static_cast<const char*>(str);
}
const String &String::operator+=(int64_t i) noexcept {
String &String::operator+=(int64_t i) noexcept {
char str[65] = {};
ox_itoa(i, str);
return this->operator+=(str);
}
const String &String::operator+=(const String &src) noexcept {
String &String::operator+=(const String &src) noexcept {
return *this += src.c_str();
}
const String String::operator+(const char *str) const noexcept {
String String::operator+(const char *str) const noexcept {
std::size_t strLen = ox_strlen(str);
auto currentLen = len();
String cpy(currentLen + strLen);
@ -111,17 +111,17 @@ const String String::operator+(const char *str) const noexcept {
return cpy;
}
const String String::operator+(char *str) const noexcept {
String String::operator+(char *str) const noexcept {
return *this + static_cast<const char*>(str);
}
const String String::operator+(int64_t i) const noexcept {
String String::operator+(int64_t i) const noexcept {
char str[65] = {};
ox_itoa(i, str);
return *this + str;
}
const String String::operator+(const String &src) const noexcept {
String String::operator+(const String &src) const noexcept {
return *this + src.c_str();
}

View File

@ -8,6 +8,10 @@
#pragma once
#if defined(OX_USE_STDLIB)
#include <string>
#endif
#include "memops.hpp"
#include "strops.hpp"
#include "typetraits.hpp"
@ -22,7 +26,7 @@ class String {
public:
String() noexcept;
String(std::size_t cap) noexcept;
explicit String(std::size_t cap) noexcept;
String(const char *str) noexcept;
@ -32,31 +36,31 @@ class String {
String(String&&) noexcept;
const String &operator=(const char *str) noexcept;
String &operator=(const char *str) noexcept;
const String &operator=(char *str) noexcept;
String &operator=(char *str) noexcept;
const String &operator=(int64_t i) noexcept;
String &operator=(int64_t i) noexcept;
const String &operator=(const String &src) noexcept;
String &operator=(const String &src) noexcept;
const String &operator=(const String &&src) noexcept;
String &operator=(String &&src) noexcept;
const String &operator+=(const char *str) noexcept;
String &operator+=(const char *str) noexcept;
const String &operator+=(char *str) noexcept;
String &operator+=(char *str) noexcept;
const String &operator+=(int64_t i) noexcept;
String &operator+=(int64_t i) noexcept;
const String &operator+=(const String &src) noexcept;
String &operator+=(const String &src) noexcept;
const String operator+(const char *str) const noexcept;
String operator+(const char *str) const noexcept;
const String operator+(char *str) const noexcept;
String operator+(char *str) const noexcept;
const String operator+(int64_t i) const noexcept;
String operator+(int64_t i) const noexcept;
const String operator+(const String &src) const noexcept;
String operator+(const String &src) const noexcept;
bool operator==(const String &other) const noexcept;
@ -66,19 +70,25 @@ class String {
char &operator[](std::size_t i) noexcept;
char *data() noexcept;
[[nodiscard]] char *data() noexcept;
const char *c_str() const noexcept;
[[nodiscard]] const char *c_str() const noexcept;
#ifdef OX_USE_STDLIB
[[nodiscard]] inline std::string toStdString() const {
return c_str();
}
#endif
/**
* Returns the number of characters in this string.
*/
std::size_t len() const noexcept;
[[nodiscard]] std::size_t len() const noexcept;
/**
* Returns the number of bytes used for this string.
*/
std::size_t bytes() const noexcept;
[[nodiscard]] std::size_t bytes() const noexcept;
};

View File

@ -126,7 +126,7 @@ template<typename T1, typename T2>
return retval;
}
[[nodiscard]] constexpr ox::Result<int> ox_atoi(const char *str) noexcept {
constexpr ox::Result<int> ox_atoi(const char *str) noexcept {
int total = 0;
int multiplier = 1;
for (auto i = static_cast<int64_t>(ox_strlen(str)) - 1; i != -1; i--) {

View File

@ -10,7 +10,7 @@
namespace ox::trace {
void logError(const char *file, int line, Error err) {
void logError(const char *file, int line, const Error &err) {
if (err) {
TraceStream trc(file, line, "ox::error");
trc << "Error:" << err;

View File

@ -158,7 +158,7 @@ using TraceStream = OutStream;
using TraceStream = NullStream;
#endif
void logError(const char *file, int line, Error err);
void logError(const char *file, int line, const Error &err);
void init();