- Adjusted how asserts work and types of asserts
This commit is contained in:
@@ -107,7 +107,7 @@ public:
|
||||
/// \param i the index to access
|
||||
/// \returns a reference to the character
|
||||
constexpr char& operator[](int i) {
|
||||
assert(i >= 0 && i < size(), "Array Out of Bounds");
|
||||
assertd(i >= 0 && i < size(), "Array Out of Bounds");
|
||||
return _str[i];
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ public:
|
||||
/// \brief Const-Array Access Operator
|
||||
/// \param i the index to access
|
||||
/// \returns a copy of the character
|
||||
constexpr char operator[](int i) const {
|
||||
assert(i >= 0 && i < size(), "Array Out of Bounds");
|
||||
constexpr char operator[](int i) const {
|
||||
assertd(i >= 0 && i < size(), "Array Out of Bounds");
|
||||
return _str[i];
|
||||
}
|
||||
|
||||
@@ -176,16 +176,51 @@ public:
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Finds the index of the last occurrence of `x` in the string.
|
||||
/// \param x the string to find
|
||||
/// \returns The index of `x` if it occurs in the string, otherwise returns `size()`
|
||||
constexpr size_t rfind(char x) const
|
||||
/// \brief Finds the index of the last occurrence of `c` in the string.
|
||||
/// \param c the string to find
|
||||
/// \param i the index to start at
|
||||
/// \returns The index of `c` if it occurs in the string, otherwise returns `size()`
|
||||
constexpr size_t rfind(char c, size_t i = 0) const
|
||||
{
|
||||
const char* loc = ::strrchr(_str, x);
|
||||
return loc ? loc - _str : size();
|
||||
if (size() == 0) return size();
|
||||
i = min(i, size() - 1); // clamp i to bounds
|
||||
do {
|
||||
if (_str[i] == c) return i; // loop backwards looking for c
|
||||
} while (i--);
|
||||
return size(); // base case
|
||||
}
|
||||
|
||||
// TODO: constexpr size_t rfind(const string& str) const;
|
||||
///
|
||||
/// \brief Finds the index of the last occurrence of `str` in the string.
|
||||
/// \param str the string to find
|
||||
/// \param i the index to start at
|
||||
/// \returns The index of `str` if it occurs in the string, otherwise returns `size()`
|
||||
constexpr size_t rfind(const cstring& str, size_t i = 0) const
|
||||
{
|
||||
const char first = str[0];
|
||||
i = min(i, size() - str.size());
|
||||
do {
|
||||
if(_str[i] == first)
|
||||
if (compare(str, i) == 0) return i; // loop backwards looking for str
|
||||
} while (i--);
|
||||
return size(); // base case
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Finds the index of the last occurrence of `str` in the string.
|
||||
/// \param str the string to find
|
||||
/// \param i the index to start at
|
||||
/// \returns The index of `str` if it occurs in the string, otherwise returns `size()`
|
||||
constexpr size_t rfind(const string& str, size_t i = 0) const
|
||||
{
|
||||
const char first = str[0];
|
||||
i = min(i, size() - str.size());
|
||||
do {
|
||||
if(_str[i] == first)
|
||||
if (compare(str, i) == 0) return i; // loop backwards looking for str
|
||||
} while (i--);
|
||||
return size(); // base case
|
||||
}
|
||||
|
||||
// Manipulation ========================================================================================================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user