mirror of
https://github.com/nushell/nushell
synced 2024-12-27 13:33:16 +00:00
switch substring to bytes (#538)
* switch substring to bytes * Add a test
This commit is contained in:
parent
1609101e62
commit
fc7ed1bfe4
2 changed files with 19 additions and 5 deletions
|
@ -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,
|
||||
|
|
|
@ -1316,3 +1316,11 @@ fn flatten_should_flatten_inner_table() -> TestResult {
|
|||
"123",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cjk_in_substrings() -> TestResult {
|
||||
run_test(
|
||||
r#"let s = '[Rust 程序设计语言](title-page.md)'; let start = ($s | str index-of '('); let end = ($s | str index-of ')'); echo ($s | str substring $"($start + 1),($end)")"#,
|
||||
"title-page.md",
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue