- Removed a bug with attempt to include pure c headers
- Added some more information about the license - fennec::file implementation
This commit is contained in:
@@ -75,7 +75,33 @@ public:
|
||||
/// \details adds additional character for null termination.
|
||||
constexpr _string(char c, size_t n)
|
||||
: _str(n + 1) {
|
||||
fennec::memset(_str, c, n); _str[n] = '\0';
|
||||
fennec::memset(_str.data(), c, n); _str[n] = '\0';
|
||||
}
|
||||
///
|
||||
/// \brief Buffer Copy Constructor
|
||||
/// \param str the buffer to copy
|
||||
/// \param len number of characters in the buffer
|
||||
///
|
||||
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
|
||||
/// This constructor makes the assumption that `len` is the intended number of characters.
|
||||
template<size_t n>
|
||||
constexpr _string(const char str[n])
|
||||
: _str(str, n + 1) {
|
||||
::strncpy(_str.data(), str, n);
|
||||
_str[n] = '\0';
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Buffer Copy Constructor
|
||||
/// \param str the buffer to copy
|
||||
/// \param len number of characters in the buffer
|
||||
///
|
||||
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
|
||||
/// This constructor makes the assumption that `len` is the intended number of characters.
|
||||
constexpr _string(const char* str, size_t n)
|
||||
: _str(str, n + 1) {
|
||||
::strncpy(_str.data(), str, n);
|
||||
_str[n] = '\0';
|
||||
}
|
||||
|
||||
///
|
||||
@@ -94,7 +120,7 @@ public:
|
||||
/// \brief String Copy Constructor
|
||||
/// \param str the string to copy
|
||||
constexpr _string(const string& str)
|
||||
: _string(str, str.size() - 1) {
|
||||
: _string(str, str.size()) {
|
||||
}
|
||||
|
||||
constexpr _string(_string&& str) noexcept
|
||||
@@ -112,6 +138,10 @@ public:
|
||||
return _str.capacity() - 1;
|
||||
}
|
||||
|
||||
constexpr bool empty() const {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
|
||||
// Access ==============================================================================================================
|
||||
|
||||
@@ -187,16 +217,16 @@ public:
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Finds the index of the first occurrence of `x` in the string
|
||||
/// \param x the character to find
|
||||
/// \returns The index of `x` if it occurs in the string, otherwise returns `size()`
|
||||
/// \brief Finds the index of the first occurrence of `c` in the string
|
||||
/// \param c the character to find
|
||||
/// \returns The index of `c` if it occurs in the string, otherwise returns `size()`
|
||||
constexpr size_t find(char c, size_t i = 0) const {
|
||||
if (i >= size()) { // bounds check
|
||||
return size();
|
||||
}
|
||||
|
||||
const char* loc = ::strchr(_str + i, c); // get location using strchr
|
||||
return loc ? loc - _str : size(); // return size if not found
|
||||
const char* loc = ::strchr(_str.data() + i, c); // get location using strchr
|
||||
return loc ? loc - _str.data() : size(); // return size if not found
|
||||
}
|
||||
|
||||
///
|
||||
@@ -293,7 +323,18 @@ public:
|
||||
constexpr void resize(size_t n) {
|
||||
size_t i = size();
|
||||
_str.reallocate(n + 1);
|
||||
if (n > i) fennec::memset(*_str + i, '\0', n - i);
|
||||
if (n > i) fennec::memset(_str.data() + i, '\0', n - i);
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Copy Assignment Operator
|
||||
/// \param str the string to copy
|
||||
/// \returns a reference to `this`
|
||||
constexpr string& operator=(const cstring& str) {
|
||||
resize(str.size());
|
||||
fennec::memcpy(_str.data(), str, str.size());
|
||||
_str[str.size()] = '\0';
|
||||
return *this;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -301,8 +342,8 @@ public:
|
||||
/// \param str the string to copy
|
||||
/// \returns a reference to `this`
|
||||
constexpr string& operator=(const string& str) {
|
||||
if (str.size() > size()) resize(str.size());
|
||||
fennec::memcpy(_str, str, str.size());
|
||||
resize(str.size());
|
||||
fennec::memcpy(_str.data(), str, str.size());
|
||||
_str[str.size()] = '\0';
|
||||
return *this;
|
||||
}
|
||||
@@ -321,10 +362,12 @@ public:
|
||||
/// \param i the start index
|
||||
/// \param n the number of characters
|
||||
/// \return
|
||||
constexpr string substring(size_t i, size_t n = size()) const {
|
||||
assert(i < size(), "Array Out of Bounds");
|
||||
constexpr string substring(size_t i, size_t n = npos) const {
|
||||
if (i >= size()) {
|
||||
return string("");
|
||||
}
|
||||
n = min(n, size() - i);
|
||||
return string(&_str[i], n);
|
||||
return string(_str.data() + i, n);
|
||||
}
|
||||
|
||||
///
|
||||
@@ -340,14 +383,14 @@ public:
|
||||
|
||||
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, _str, size()); // Copy the contents of this
|
||||
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
|
||||
fennec::memcpy(res, _str, size()); // Copy the contents of this
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user