Skip to content

Commit

Permalink
butano: more overloads added to string::assign and string::append
Browse files Browse the repository at this point in the history
  • Loading branch information
GValiente committed Aug 29, 2024
1 parent dde8dee commit 8bb580f
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 23 deletions.
62 changes: 62 additions & 0 deletions butano/include/bn_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,37 @@ class istring : public istring_base
return *this;
}

/**
* @brief Replaces the contents of the istring.
* @param view string_view replacement.
* @param position Starting character index.
* @return Reference to this.
*/
constexpr istring& assign(const string_view& view, size_type position)
{
size_type view_size = view.size();
BN_ASSERT(position >= 0 && position <= view_size, "Invalid position: ", position, " - ", view_size);

_assign(view.data() + position, view_size - position);
return *this;
}

/**
* @brief Replaces the contents of the istring.
* @param view string_view replacement.
* @param position Starting character index.
* @param count Number of characters to assign.
* @return Reference to this.
*/
constexpr istring& assign(const string_view& view, size_type position, size_type count)
{
BN_ASSERT(position >= 0 && position <= view.size(), "Invalid position: ", position, " - ", view.size());
BN_ASSERT(count >= 0 && count <= view.size() - position, "Invalid count: ", count, " - ", view.size());

_assign(view.data() + position, count);
return *this;
}

/**
* @brief Replaces the contents of the istring.
* @param char_array_ptr Pointer to null-terminated characters array replacement.
Expand Down Expand Up @@ -640,6 +671,37 @@ class istring : public istring_base
return *this;
}

/**
* @brief Appends additional characters to the istring.
* @param view string_view to append.
* @param position Starting character index.
* @return Reference to this.
*/
constexpr istring& append(const string_view& view, size_type position)
{
size_type view_size = view.size();
BN_ASSERT(position >= 0 && position <= view_size, "Invalid position: ", position, " - ", view_size);

_append(view.data() + position, view_size - position);
return *this;
}

/**
* @brief Appends additional characters to the istring.
* @param view string_view to append.
* @param position Starting character index.
* @param count Number of characters to append.
* @return Reference to this.
*/
constexpr istring& append(const string_view& view, size_type position, size_type count)
{
BN_ASSERT(position >= 0 && position <= view.size(), "Invalid position: ", position, " - ", view.size());
BN_ASSERT(count >= 0 && count <= view.size() - position, "Invalid count: ", count, " - ", view.size());

_append(view.data() + position, count);
return *this;
}

/**
* @brief Appends additional characters to the istring.
* @param char_array_ptr Pointer to null-terminated characters array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* a `nullptr` char array is disallowed.
* * bn::unique_ptr is now `constexpr`.
* * bn::bitset and bn::string aren't `constexpr` anymore (it didn't work before).
* * More overloads added to bn::string construction, assignment and bn::string::append.
* * More overloads added to bn::string construction, assignment, bn::string::assign and bn::string::append.
* * bn::string::find and bn::string_view::find added.
* * bn::string::contains and bn::string_view::contains added.
* * bn::string::substr added.
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.html

Large diffs are not rendered by default.

Loading

0 comments on commit 8bb580f

Please sign in to comment.