aboutsummaryrefslogtreecommitdiff
path: root/crates/stdx
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-30 21:38:58 +0100
committerGitHub <[email protected]>2020-07-30 21:38:58 +0100
commit43d81422149cabf7e61c0db67e298103c86bfb0d (patch)
tree8e98a36d67b2aeb58cb571c53a555f40004135be /crates/stdx
parent08d18e0edda948215a9bb649d022a342d01e77a8 (diff)
parentcd9f863b017a6d568b5ef45f1ce200e3148cfd03 (diff)
Merge #5614
5614: Use split_once polyfill r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/stdx')
-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 {