- Wrote and Debugged Unit Tests for fennec::file
This commit is contained in:
@@ -330,7 +330,7 @@ public:
|
||||
/// \brief Copy Assignment Operator
|
||||
/// \param str the string to copy
|
||||
/// \returns a reference to `this`
|
||||
constexpr string& operator=(const cstring& str) {
|
||||
constexpr _string& operator=(const cstring& str) {
|
||||
resize(str.size());
|
||||
fennec::memcpy(_str.data(), str, str.size());
|
||||
_str[str.size()] = '\0';
|
||||
@@ -341,7 +341,7 @@ public:
|
||||
/// \brief Copy Assignment Operator
|
||||
/// \param str the string to copy
|
||||
/// \returns a reference to `this`
|
||||
constexpr string& operator=(const string& str) {
|
||||
constexpr _string& operator=(const string& str) {
|
||||
resize(str.size());
|
||||
fennec::memcpy(_str.data(), str, str.size());
|
||||
_str[str.size()] = '\0';
|
||||
@@ -352,64 +352,75 @@ public:
|
||||
/// \brief Move Assignment Operator
|
||||
/// \param str the string to move
|
||||
/// \returns a reference to `this`
|
||||
constexpr string& operator=(string&& str) noexcept {
|
||||
_str = fennec::move(str._str);
|
||||
constexpr _string& operator=(string&& str) noexcept {
|
||||
_str = move(str._str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Replace all instances of `x` with `y`
|
||||
/// \param x the character to search for
|
||||
/// \param y the character to replace with
|
||||
void replace(char x, char y) {
|
||||
size_t i = 0;
|
||||
while ((i = find(x, 0)) != size()) {
|
||||
_str[i] = y;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Retrieve a substring of a string
|
||||
/// \param i the start index
|
||||
/// \param n the number of characters
|
||||
/// \return
|
||||
constexpr string substring(size_t i, size_t n = npos) const {
|
||||
constexpr _string substring(size_t i, size_t n = npos) const {
|
||||
if (i >= size()) {
|
||||
return string("");
|
||||
return _string("");
|
||||
}
|
||||
n = min(n, size() - i);
|
||||
return string(_str.data() + i, n);
|
||||
return _string(_str.data() + i, n);
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Returns a string with `c` appended to it
|
||||
/// \param c
|
||||
/// \returns
|
||||
constexpr string operator+(char c) const {
|
||||
constexpr _string operator+(char c) const {
|
||||
// Copy contents with one additional byte.
|
||||
string res(_str, _str.size());
|
||||
_string res(_str.data(), _str.size());
|
||||
res[size()] = c; // Set the last character to c
|
||||
return res;
|
||||
}
|
||||
|
||||
constexpr string operator+(const cstring& str) const {
|
||||
string res(size() + str.size()); // Make a new string with the size of this + str
|
||||
constexpr _string operator+(const cstring& str) const {
|
||||
_string res(size() + str.size()); // Make a new string with the size of this + str
|
||||
fennec::memcpy(&res[0], _str.data(), size()); // Copy the contents of this
|
||||
fennec::memcpy(&res[size()], str, str.size()); // Append the contents of str
|
||||
return res;
|
||||
}
|
||||
|
||||
constexpr string operator+(const string& str) const {
|
||||
string res(size() + str.size()); // Make a new string with the size of this + str
|
||||
constexpr _string operator+(const _string& str) const {
|
||||
_string res(size() + str.size()); // Make a new string with the size of this + str
|
||||
fennec::memcpy(&res[0], _str.data(), size()); // Copy the contents of this
|
||||
fennec::memcpy(&res[size()], str, str.size()); // Append the contents of str
|
||||
return res;
|
||||
}
|
||||
|
||||
constexpr string& operator+=(char c) {
|
||||
constexpr _string& operator+=(char c) {
|
||||
size_t x = size();
|
||||
resize(x + 1);
|
||||
_str[x] = c;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr string& operator+=(const cstring& str) {
|
||||
constexpr _string& operator+=(const cstring& str) {
|
||||
size_t x = size();
|
||||
resize(x + str.size());
|
||||
fennec::memcpy(&_str[x], str, str.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr string& operator+=(const string& str) {
|
||||
constexpr _string& operator+=(const _string& str) {
|
||||
size_t x = size();
|
||||
resize(x + str.size());
|
||||
fennec::memcpy(&_str[x], str, str.size());
|
||||
|
||||
Reference in New Issue
Block a user