Comments (4)
Corollary: Are you open to a pull request adding this feature? I'm thinking something like:
std::vector<std::string> multi_split(const std::string& str, const std::string& delims, bool collapse = true);
from strutil.
Sure, go ahead! If you write a working algorithm and test(s) for it, I'll merge your code into the code base :) Otherwise, I'll probably write my own implementation of this, but this could happen in ~3 weeks (best case scenario).
from strutil.
While implementing this, I'm noticing as few inconsistencies in the semantics of split
for char and str inputs:
Empty string handling
Splitting on an empty string results in different output depending on delimiter type:
split("", ';').size() == 0; // split return []
split("", ">=").size() == 1; // split returns [""]
I'm inclined to the second approach, as in python:
"".split(";') == [""] // True
Trailing Delimiter Handling
Splitting strings with trailing delimiters returns different results:
split("abc;", ';').size() == 1; // split returns ["abc"]
split("abc>=", ">=").size == 2; // split returns ["abc", ""]
Again, python favors the latter:
"abc;".split(";") == ["abc", ""] // True
Thoughts? I'm thinking I'll adjust the char-splitting version to match python semantics.
from strutil.
Sure, match char versions to string equivalents - these functions should have the same output (as their names are the same) not to mislead the end user. You can also add additional tests to tests/test_cases.cpp. I appreciate your contribution! :)
from strutil.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strutil.