switch substring to bytes (#538)

* switch substring to bytes

* Add a test
This commit is contained in:
JT
2021-12-21 11:49:02 +11:00
committed by GitHub
parent 1609101e62
commit fc7ed1bfe4
2 changed files with 19 additions and 5 deletions

View File

@ -157,12 +157,18 @@ fn action(input: &Value, options: &Substring, head: Span) -> Value {
Ordering::Less => Value::String {
val: {
if end == isize::max_value() {
s.chars().skip(start as usize).collect::<String>()
String::from_utf8_lossy(
&s.bytes().skip(start as usize).collect::<Vec<_>>(),
)
.to_string()
} else {
s.chars()
.skip(start as usize)
.take((end - start) as usize)
.collect::<String>()
String::from_utf8_lossy(
&s.bytes()
.skip(start as usize)
.take((end - start) as usize)
.collect::<Vec<_>>(),
)
.to_string()
}
},
span: head,