Repository navigation
cut: trim Unicode blanks with -w=trimmed - #15832
Open
sarankumar1325 wants to merge 1 commit into
Open
sarankumar1325 wants to merge 1 commit into
sarankumar1325 wants to merge 1 commit into
Conversation
In a UTF-8 locale the whitespace matcher splits fields on Unicode blanks such as U+3000, but -w=trimmed only stripped SPACE and TAB from the ends of a line. A leading Unicode blank then emptied field 1 and shifted every word, a trailing one added an empty last field, and -s kept one-word lines. Trim with the same matcher that splits the fields, and update the help text, which still said Space/Tab only. Fixes uutils#15819
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15819.
In a UTF-8 locale,
WhitespaceMatchersplits fields on Unicode blanks such as U+3000, butcut_fields_whitespace_trimmedtrimmed the ends of each line with a byte test that only knows SPACE and TAB. A leading Unicode blank therefore survived trimming and became a delimiter, which emptied field 1. A trailing one added an empty last field, and-sstopped dropping one-word lines:The ends are now trimmed with the same
WhitespaceMatcherthat splits the fields: a blank run at offset 0 is skipped, and a blank run that ends at the end of the line is dropped. In the C locale the matcher only sees SPACE/TAB through itsmemchr2fast path, so output there is unchanged.The
-whelp text inen-US.ftlstill said "Space/Tab", so it now mentions Unicode spaces in a UTF-8 locale.Tests
test_whitespace_delimited_trimmed_unicode_blanks: leading U+3000, mixed leading/trailing SPACE + U+3000/U+2003, and-swith a one-word line padded by U+3000. It fails onmainand passes with this change.cargo test --features cut --no-default-features test_cut: 81 passed;cargo test -p uu_cut: 22 passed.cargo fmt --check -p uu_cutandcargo clippy -p uu_cut --all-targets -- -D warningsare clean.I used an AI assistant while working on this; I reviewed the change and the tests myself.