From be49547b446cba240f8f2a9592284e77d4a6896f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 22:19:58 +0200 Subject: Use split_once polyfill --- crates/stdx/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'crates/stdx/src') diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index ea0e6b949..b65875c96 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -109,9 +109,18 @@ pub fn replace(buf: &mut String, from: char, to: &str) { *buf = buf.replace(from, to) } -pub fn split_delim(haystack: &str, delim: char) -> Option<(&str, &str)> { - let idx = haystack.find(delim)?; - Some((&haystack[..idx], &haystack[idx + delim.len_utf8()..])) +// https://github.com/rust-lang/rust/issues/74773 +pub fn split_once(haystack: &str, delim: char) -> Option<(&str, &str)> { + let mut split = haystack.splitn(2, delim); + let prefix = split.next()?; + let suffix = split.next()?; + Some((prefix, suffix)) +} +pub fn rsplit_once(haystack: &str, delim: char) -> Option<(&str, &str)> { + let mut split = haystack.rsplitn(2, delim); + let suffix = split.next()?; + let prefix = split.next()?; + Some((prefix, suffix)) } pub fn trim_indent(mut text: &str) -> String { -- cgit v1.2.3