Git Product home page Git Product logo

Comments (4)

flying-tiger avatar flying-tiger commented on June 26, 2024

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.

tgalaj avatar tgalaj commented on June 26, 2024

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.

flying-tiger avatar flying-tiger commented on June 26, 2024

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.

tgalaj avatar tgalaj commented on June 26, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.