Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(String) Fix partition returning wrong middle value #87

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Unit tests
on:
workflow_dispatch:
push:
branches: ["develop"]
pull_request:
Expand Down
10 changes: 5 additions & 5 deletions core/include/vc/core/util/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@ static inline auto partition(std::string_view s, std::string_view sep)
}

// Split into parts
const auto endPos = startPos + sep.size();
auto pre = std::string(s.substr(0, startPos));
auto mid = std::string(s.substr(startPos, endPos));
auto post = std::string(s.substr(endPos));
auto mid = std::string(s.substr(startPos, sep.size()));
auto post = std::string(s.substr(startPos + sep.size()));

// Return the parts
return {pre, mid, post};
Expand All @@ -244,8 +243,9 @@ static inline auto partition(std::string_view s, std::string_view sep)
/** @brief Convert an Integer to a padded string */
template <
typename Integer,
std::enable_if_t<std::is_integral<Integer>::value, bool> = true>
auto to_padded_string(Integer val, int padding, char fill = '0') -> std::string
std::enable_if_t<std::is_integral_v<Integer>, bool> = true>
auto to_padded_string(Integer val, const int padding, const char fill = '0')
-> std::string
{
std::stringstream stream;
stream << std::setw(padding) << std::setfill(fill) << val;
Expand Down