aboutsummaryrefslogtreecommitdiff
path: root/crates/stdx/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-30 21:19:58 +0100
committerAleksey Kladov <[email protected]>2020-07-30 21:23:12 +0100
commitbe49547b446cba240f8f2a9592284e77d4a6896f (patch)
treede01434050b1fb9437dd519ca0d65229d52156a3 /crates/stdx/src
parent239dd506f68db0cbe4417b6e5c7f737d8ff8a159 (diff)
Use split_once polyfill
Diffstat (limited to 'crates/stdx/src')
-rw-r--r--crates/stdx/src/lib.rs15
1 files changed, 12 insertions, 3 deletions
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) {
109 *buf = buf.replace(from, to) 109 *buf = buf.replace(from, to)
110} 110}
111 111
112pub fn split_delim(haystack: &str, delim: char) -> Option<(&str, &str)> { 112// https://github.com/rust-lang/rust/issues/74773
113 let idx = haystack.find(delim)?; 113pub fn split_once(haystack: &str, delim: char) -> Option<(&str, &str)> {
114 Some((&haystack[..idx], &haystack[idx + delim.len_utf8()..])) 114 let mut split = haystack.splitn(2, delim);
115 let prefix = split.next()?;
116 let suffix = split.next()?;
117 Some((prefix, suffix))
118}
119pub fn rsplit_once(haystack: &str, delim: char) -> Option<(&str, &str)> {
120 let mut split = haystack.rsplitn(2, delim);
121 let suffix = split.next()?;
122 let prefix = split.next()?;
123 Some((prefix, suffix))
115} 124}
116 125
117pub fn trim_indent(mut text: &str) -> String { 126pub fn trim_indent(mut text: &str) -> String {