fix range semantic in detect_columns, str substring, str index-of (#12894)

# Description
Fixes: https://github.com/nushell/nushell/issues/7761

It's still unsure if we want to change the `range semantic` itself, but
it's good to keep range semantic consistent between nushell commands.

# User-Facing Changes
### Before
```nushell
❯ "abc" | str substring 1..=2
b
```
### After
```nushell
❯ "abc" | str substring 1..=2
bc
```

# Tests + Formatting
Adjust tests to fit new behavior
This commit is contained in:
Wind
2024-05-23 01:00:58 +08:00
committed by GitHub
parent 7ede90cba5
commit ac4125f8ed
6 changed files with 12 additions and 12 deletions

View File

@ -405,7 +405,7 @@ mod tests {
let range = Range::new(
Value::int(0, Span::test_data()),
Value::int(1, Span::test_data()),
Value::int(3, Span::test_data()),
Value::int(2, Span::test_data()),
RangeInclusion::Inclusive,
Span::test_data(),
)

View File

@ -70,7 +70,7 @@ impl Command for SubCommand {
}
fn usage(&self) -> &str {
"Get part of a string. Note that the start is included but the end is excluded, and that the first character of a string is index 0."
"Get part of a string. Note that the first character of a string is index 0."
}
fn search_terms(&self) -> Vec<&str> {
@ -108,12 +108,12 @@ impl Command for SubCommand {
Example {
description:
"Get a substring \"nushell\" from the text \"good nushell\" using a range",
example: " 'good nushell' | str substring 5..12",
example: " 'good nushell' | str substring 5..11",
result: Some(Value::test_string("nushell")),
},
Example {
description: "Count indexes and split using grapheme clusters",
example: " '🇯🇵ほげ ふが ぴよ' | str substring --grapheme-clusters 4..6",
example: " '🇯🇵ほげ ふが ぴよ' | str substring --grapheme-clusters 4..5",
result: Some(Value::test_string("ふが")),
},
]