diff --git a/src/Fable.Transforms/Rust/Replacements.fs b/src/Fable.Transforms/Rust/Replacements.fs index da8c1cb87..d1f0f8815 100644 --- a/src/Fable.Transforms/Rust/Replacements.fs +++ b/src/Fable.Transforms/Rust/Replacements.fs @@ -893,16 +893,21 @@ let fsFormat (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op | ("PrintFormatThen" | "PrintFormatToStringThen"), None, [ cont; MaybeCasted(template) ] -> Helper.Application(cont, t, [ template ], ?loc = r) |> Some | "PrintFormatToError", None, [ StringConst fmt ] -> "eprintf!" |> makeRustFormatExpr com r t fmt [] |> Some - | "PrintFormatToError", None, [ StringTempl _ ] -> "eprintf!" |> emitFormat com r t args |> Some + | "PrintFormatToError", None, _ -> "eprintf!" |> emitFormat com r t args |> Some | "PrintFormatLineToError", None, [ StringConst fmt ] -> "eprintfn!" |> makeRustFormatExpr com r t fmt [] |> Some | "PrintFormatLineToError", None, _ -> "eprintfn!" |> emitFormat com r t args |> Some | "PrintFormat", None, [ StringConst fmt ] -> "printf!" |> makeRustFormatExpr com r t fmt [] |> Some - | "PrintFormat", None, [ StringTempl _ ] -> "printf!" |> emitFormat com r t args |> Some + | "PrintFormat", None, _ -> "printf!" |> emitFormat com r t args |> Some | "PrintFormatLine", None, [ StringConst fmt ] -> "printfn!" |> makeRustFormatExpr com r t fmt [] |> Some - | "PrintFormatLine", None, [ StringTempl _ ] -> "printfn!" |> emitFormat com r t args |> Some + | "PrintFormatLine", None, _ -> "printfn!" |> emitFormat com r t args |> Some + | "PrintFormatToTextWriter", None, [ StringConst fmt ] -> "printf!" |> makeRustFormatExpr com r t fmt [] |> Some + | "PrintFormatToTextWriter", None, _ -> "printf!" |> emitFormat com r t args |> Some + | "PrintFormatLineToTextWriter", None, [ StringConst fmt ] -> + "printfn!" |> makeRustFormatExpr com r t fmt [] |> Some + | "PrintFormatLineToTextWriter", None, _ -> "printfn!" |> emitFormat com r t args |> Some | "PrintFormatToStringThenFail", None, [ StringConst fmt ] -> "failwithf!" |> makeRustFormatExpr com r t fmt [] |> Some - | "PrintFormatToStringThenFail", None, [ StringTempl _ ] -> "failwithf!" |> emitFormat com r t args |> Some + | "PrintFormatToStringThenFail", None, _ -> "failwithf!" |> emitFormat com r t args |> Some | "PrintFormatToStringBuilder", None, [ sb; StringConst fmt ] -> let cont = Helper.LibCall(com, "Util", "bprintf", t, [ sb ]) "kprintf!" |> makeRustFormatExpr com r t fmt [ cont ] |> Some @@ -1430,6 +1435,9 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | [ Value(NewArray(ArrayValues [ arg1 ], String, _), _); ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg2) ] -> Helper.LibCall(com, "String", "split", t, [ c; arg1; makeIntConst -1; arg2 ], ?loc = r) |> Some + | [ ExprTypeAs(Array(String, _), arg1); ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg2) ] -> + Helper.LibCall(com, "String", "splitStrings", t, [ c; arg1; arg2 ], ?loc = r) + |> Some | [ Value(NewArray(ArrayValues [ arg1 ], String, _), _) ExprTypeAs(Number(Int32, _), arg2) ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg3) ] -> diff --git a/src/fable-library-rust/src/String.rs b/src/fable-library-rust/src/String.rs index fa72cf91f..9d8a4fe07 100644 --- a/src/fable-library-rust/src/String.rs +++ b/src/fable-library-rust/src/String.rs @@ -693,6 +693,14 @@ pub mod String_ { withSplitOptions(a, count, options) } + pub fn splitStrings(s: string, ps: Array, options: i32) -> Array { + let mut a: Vec<&str> = vec![s.as_str()]; + for p in ps.iter() { + a = a.iter().flat_map(|&s| s.split(p.as_str())).collect(); + } + withSplitOptions(a, -1, options) + } + pub fn toCharArray(s: string) -> Array { array_from(s.chars().collect()) } diff --git a/tests/Rust/tests/src/StringTests.fs b/tests/Rust/tests/src/StringTests.fs index 92dfc2f1a..fa3feb33a 100644 --- a/tests/Rust/tests/src/StringTests.fs +++ b/tests/Rust/tests/src/StringTests.fs @@ -895,10 +895,10 @@ let ``String.Split with single separator works`` () = let ``String.Split with multiple char args works`` () = "a;b,c".Split(',', ';') |> equal [|"a"; "b"; "c"|] -// [] -// let ``String.Split with string array works`` () = -// "a;b,c".Split([|","; ";"|], StringSplitOptions.None) -// |> equal [|"a"; "b"; "c"|] +[] +let ``String.Split with string array works`` () = + "a;b,c".Split([|","; ";"|], StringSplitOptions.None) + |> equal [|"a"; "b"; "c"|] [] let ``String.Split with RemoveEmptyEntries works`` () =