Skip to content

Improves commands that support range input#13113

Merged
fdncred merged 6 commits intonushell:mainfrom
WindSoilder:str_range
Jun 18, 2024
Merged

Improves commands that support range input#13113
fdncred merged 6 commits intonushell:mainfrom
WindSoilder:str_range

Conversation

@WindSoilder
Copy link
Copy Markdown
Contributor

Description

Fixes: #13105
Fixes: #13077

This pr makes str substring, bytes at work better with negative index.

And it also fixes the false range semantic on detect columns -c in some cases.

User-Facing Changes

For str substring, bytes at, it will no-longer return an error if start index is larger than end index. It makes sense to return an empty string of empty bytes directly.

Before

# str substring
 ("aaa" | str substring 2..-3) == ""
Error: nu::shell::type_mismatch

  × Type mismatch.
   ╭─[entry #23:1:10]
 1  ("aaa" | str substring 2..-3) == ""
   ·          ──────┬──────
   ·                ╰── End must be greater than or equal to Start
 2  true
   ╰────

# bytes at
 ("aaa" | encode utf-8 | bytes at 2..-3) == ("" | encode utf-8)
Error: nu::shell::type_mismatch

  × Type mismatch.
   ╭─[entry #27:1:25]
 1  ("aaa" | encode utf-8 | bytes at 2..-3) == ("" | encode utf-8)
   ·                         ────┬───
   ·                             ╰── End must be greater than or equal to Start
   ╰────

After

# str substring
 ("aaa" | str substring 2..-3) == ""
true

# bytes at
  ("aaa" | encode utf-8 | bytes at 2..-3) == ("" | encode utf-8)
true

Tests + Formatting

Added some tests, adjust existing tests

@WindSoilder WindSoilder added notes:fixes Include the release notes summary in the "Bug fixes" section deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way labels Jun 11, 2024
@fdncred fdncred merged commit 28ed0fe into nushell:main Jun 18, 2024
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Jun 18, 2024

Thanks

@hustcer hustcer added this to the v0.95.0 milestone Jun 18, 2024
@WindSoilder WindSoilder deleted the str_range branch July 15, 2024 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way notes:fixes Include the release notes summary in the "Bug fixes" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.94.x detect columns --combine-columns a..b range regression (off by 1) 0.94.x str substring regression with negative end-offset

3 participants