Skip to content

[core] Add new ROOT/StringUtils.hxx file with ROOT::Split function#8821

Merged
guitargeek merged 3 commits intoroot-project:masterfrom
guitargeek:StringUtils_Split_1
Aug 11, 2021
Merged

[core] Add new ROOT/StringUtils.hxx file with ROOT::Split function#8821
guitargeek merged 3 commits intoroot-project:masterfrom
guitargeek:StringUtils_Split_1

Conversation

@guitargeek
Copy link
Copy Markdown
Contributor

The ROOT::Split function splits a string in the same way as the
str.split function from Python.

Closes #8807.

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-10T10:22:36.042Z] stderr: error: could not read '.git/rebase-apply/head-name': No such file or directory

@root-project root-project deleted a comment from phsft-bot Aug 10, 2021
@root-project root-project deleted a comment from phsft-bot Aug 10, 2021
@root-project root-project deleted a comment from phsft-bot Aug 10, 2021
@root-project root-project deleted a comment from phsft-bot Aug 10, 2021
@root-project root-project deleted a comment from phsft-bot Aug 10, 2021
@root-project root-project deleted a comment from phsft-bot Aug 10, 2021
@root-project root-project deleted a comment from phsft-bot Aug 10, 2021
Copy link
Copy Markdown
Member

@hageboeck hageboeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I have 2 more suggestions.

Comment on lines +9 to +20
auto test = [](std::string_view in, std::vector<std::string> const &ref) {
auto out = ROOT::Split(in, ",");
EXPECT_EQ(out, ref) << "ROOT::Split(\"" << in << "\") gave wrong result.";
};

test("a,b,c", {"a", "b", "c"});
test("a,,c", {"a", "", "c"});
test("a,,,", {"a", "", "", ""});
test(",,a,,,", {"", "", "a", "", "", ""});
test(",,,", {"", "", "", ""});
test(",,a", {"", "", "a"});
test("", {""});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto test = [](std::string_view in, std::vector<std::string> const &ref) {
auto out = ROOT::Split(in, ",");
EXPECT_EQ(out, ref) << "ROOT::Split(\"" << in << "\") gave wrong result.";
};
test("a,b,c", {"a", "b", "c"});
test("a,,c", {"a", "", "c"});
test("a,,,", {"a", "", "", ""});
test(",,a,,,", {"", "", "a", "", "", ""});
test(",,,", {"", "", "", ""});
test(",,a", {"", "", "a"});
test("", {""});
auto test = [](std::string_view in, std::vector<std::string> const &ref, bool skipEmpty) {
auto out = ROOT::Split(in, ",", skipEmpty);
EXPECT_EQ(out, ref) << "ROOT::Split(\"" << in << "\") gave wrong result.";
};
test("a,b,c", {"a", "b", "c"}, false);
test("a,b,c", {"a", "b", "c"}, true);
test("a,,c", {"a", "", "c"}, false);
test("a,,c", {"a", "c"}, true);
test("a,,,", {"a", "", "", ""}, false);
test(",,a,,,", {"", "", "a", "", "", ""}, false);
test(",,,", {"", "", "", ""}, false);
test(",,,", {}, true);
test(",,a", {"", "", "a"}, false);
test("", {""}, false);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I have changed that.

#include "RooHelpers.h"
#include "RooBatchCompute.h"
#include "RooFormulaVar.h"
#include "RooDerivative.h"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's here intentionally? (One could argue that this better goes into an extra commit, but maybe too much work).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to reorder the includes such that the RooFit includes appear before the remaining ROOT includes. Since I was touching the incudes, I thought why not do that

Copy link
Copy Markdown
Member

@hageboeck hageboeck Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's a good idea, but there was no such include before if I'm not mistaken?
Edit: Ah, never mind. 🙂

@guitargeek guitargeek force-pushed the StringUtils_Split_1 branch from b1438e0 to e1efcd3 Compare August 11, 2021 14:10
@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-08-11T14:40:33.757Z] stderr: error: could not read '.git/rebase-apply/head-name': No such file or directory

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Failing tests:

@guitargeek guitargeek merged commit ed916d2 into root-project:master Aug 11, 2021
@guitargeek guitargeek deleted the StringUtils_Split_1 branch August 11, 2021 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move and rename the tokenise() function for splitting strings to core/foundation

3 participants