Skip to content
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
4 changes: 0 additions & 4 deletions docs/sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ Changed
- Enhanced error handling: ``timezone::from_string()`` returns ``std::optional<timezone>``
- Simplified API: removed redundant timezone methods (``is_local()``, ``has_offset()``)
- Updated documentation to reflect timestamp and timezone APIs
- **Breaking:** ``split()`` now takes its arguments as ``std::string_view``
instead of ``const std::string&``; callers passing a type that converts
implicitly to ``std::string`` but not to ``std::string_view`` will no
longer compile

v0.1.0 - 2024-01-20
-------------------
Expand Down
3 changes: 1 addition & 2 deletions include/dross/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
#include <dross/type/value.h>

#include <string>
#include <string_view>
#include <vector>

/**
Expand All @@ -93,7 +92,7 @@ namespace dross {
* // Result: {"a", "b", "c"}
* @endcode
*/
std::vector<std::string> split(std::string_view s, std::string_view delimiter);
std::vector<std::string> split(const std::string& s, const std::string& delimiter);

/**
* @brief Join string tokens into a single string using a delimiter.
Expand Down
11 changes: 9 additions & 2 deletions src/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

#include <numeric>
#include <ranges>
#include <string_view>

namespace dross {

std::vector<std::string> split(std::string_view s, std::string_view delimiter)
std::vector<std::string> split(const std::string& s, const std::string& delimiter)
{
std::vector<std::string> tokens;

auto range = s | std::views::split(delimiter) | std::views::transform([](auto&& p) {
// Pipe over views rather than over the arguments themselves. On some of
// the compiler and standard library pairings this project supports, a
// const std::string is not accepted as the left operand of the pipe.
const std::string_view sv{s};
const std::string_view dv{delimiter};

auto range = sv | std::views::split(dv) | std::views::transform([](auto&& p) {
return std::string(p.begin(), p.end());
});

Expand Down
Loading