Skip to content

Fix str.split bytes.split #1861

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

Merged
merged 3 commits into from
Apr 16, 2020
Merged

Conversation

youknowone
Copy link
Member

@youknowone youknowone commented Apr 11, 2020

Failing test depends on #1855

@youknowone youknowone changed the title Fix str.split Fix str.split bytes.split Apr 11, 2020
@youknowone youknowone force-pushed the str-split branch 2 times, most recently from 4c749a2 to c04c088 Compare April 12, 2020 12:56
@@ -311,6 +309,8 @@ impl ByteInnerSplitlinesOptions {

#[allow(clippy::len_without_is_empty)]
impl PyByteInner {
const ASCII_WHITESPACES: [u8; 6] = [0x20, 0x09, 0x0a, 0x0c, 0x0d, 0x0b];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use is_ascii_whitespace?

Copy link
Member Author

@youknowone youknowone Apr 14, 2020

Choose a reason for hiding this comment

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

find_byteset takes array, slice or vector instead of function. do you have any idea not to define this const?

Ok(elements)
}

fn rsplit_whitespace(&self, maxsplit: isize) -> Vec<Vec<u8>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like there is a lot of code duplication of split_whitespace. Maybe we can create some sort of macro?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unlike split and rsplit, I don't see a good solution for _whitespaces to achieve enough readability. They have similar structure but lots of signs and variables are different.

splited
}

pub fn rsplit(
Copy link
Contributor

Choose a reason for hiding this comment

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

Again maybe we can share code with split?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is possible to share but split_whitespace looks to require too much effort

Copy link
Member Author

Choose a reason for hiding this comment

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

@palaviv how do you think about this new revision?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks great

@youknowone youknowone merged commit 1c93a36 into RustPython:master Apr 16, 2020
@youknowone youknowone deleted the str-split branch April 16, 2020 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants