mirror of
https://github.com/nushell/nushell.git
synced 2025-01-23 06:39:17 +01:00
remove panic from lpad
and rpad
, change truncation behaviour for lpad
(#6495)
* condense `lpad` and `rpad` into `pad` * change description * back to original names, add change
This commit is contained in:
parent
b398448cd9
commit
d1e1d0ac3e
@ -74,10 +74,10 @@ impl Command for SubCommand {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Use lpad to truncate a string",
|
description: "Use lpad to truncate a string to its last three characters",
|
||||||
example: "'123456789' | str lpad -l 3 -c '0'",
|
example: "'123456789' | str lpad -l 3 -c '0'",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "123".to_string(),
|
val: "789".to_string(),
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@ -105,6 +105,13 @@ fn operate(
|
|||||||
column_paths: call.rest(engine_state, stack, 0)?,
|
column_paths: call.rest(engine_state, stack, 0)?,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if options.length.expect("this exists") < 0 {
|
||||||
|
return Err(ShellError::UnsupportedInput(
|
||||||
|
String::from("The length of the string cannot be negative"),
|
||||||
|
call.head,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
input.map(
|
input.map(
|
||||||
move |v| {
|
move |v| {
|
||||||
@ -142,7 +149,14 @@ fn action(
|
|||||||
let s = *x as usize;
|
let s = *x as usize;
|
||||||
if s < val.len() {
|
if s < val.len() {
|
||||||
Value::String {
|
Value::String {
|
||||||
val: val.chars().take(s).collect::<String>(),
|
val: val
|
||||||
|
.chars()
|
||||||
|
.rev()
|
||||||
|
.take(s)
|
||||||
|
.collect::<String>()
|
||||||
|
.chars()
|
||||||
|
.rev()
|
||||||
|
.collect::<String>(),
|
||||||
span: head,
|
span: head,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,7 +74,7 @@ impl Command for SubCommand {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Use rpad to truncate a string",
|
description: "Use rpad to truncate a string to its first three characters",
|
||||||
example: "'123456789' | str rpad -l 3 -c '0'",
|
example: "'123456789' | str rpad -l 3 -c '0'",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "123".to_string(),
|
val: "123".to_string(),
|
||||||
@ -105,6 +105,13 @@ fn operate(
|
|||||||
column_paths: call.rest(engine_state, stack, 0)?,
|
column_paths: call.rest(engine_state, stack, 0)?,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if options.length.expect("this exists") < 0 {
|
||||||
|
return Err(ShellError::UnsupportedInput(
|
||||||
|
String::from("The length of the string cannot be negative"),
|
||||||
|
call.head,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
input.map(
|
input.map(
|
||||||
move |v| {
|
move |v| {
|
||||||
|
Loading…
Reference in New Issue
Block a user