nushell/crates/nu-command/src/bytes
Wind 28ed0fe700
Improves commands that support range input (#13113)
# 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
```nushell
# str substring
❯ ("aaa" | str substring 2..-3) == ""
Error: nu:🐚: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:🐚: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
```nushell
# 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
2024-06-18 07:19:13 -05:00
..
add.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
at.rs Improves commands that support range input (#13113) 2024-06-18 07:19:13 -05:00
build_.rs Make bytes build accept integer values as individual bytes (#12685) 2024-05-01 17:29:33 -05:00
bytes_.rs Make get_full_help take &dyn Command (#12903) 2024-05-19 19:56:33 +02:00
collect.rs Add string/binary type color to ByteStream (#12897) 2024-05-20 00:35:32 +00:00
ends_with.rs Support ByteStreams in bytes starts-with and bytes ends-with (#12887) 2024-05-17 07:59:08 +08:00
index_of.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
length.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
mod.rs move 'bytes' back to commands (#10051) 2023-08-19 22:43:53 +02:00
remove.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
replace.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
reverse.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
starts_with.rs Support ByteStreams in bytes starts-with and bytes ends-with (#12887) 2024-05-17 07:59:08 +08:00