@@ -65,20 +65,6 @@ pub fn replace(buf: &mut String, from: char, to: &str) {
6565 * buf = buf. replace ( from, to)
6666}
6767
68- // https://github.com/rust-lang/rust/issues/74773
69- pub fn split_once ( haystack : & str , delim : char ) -> Option < ( & str , & str ) > {
70- let mut split = haystack. splitn ( 2 , delim) ;
71- let prefix = split. next ( ) ?;
72- let suffix = split. next ( ) ?;
73- Some ( ( prefix, suffix) )
74- }
75- pub fn rsplit_once ( haystack : & str , delim : char ) -> Option < ( & str , & str ) > {
76- let mut split = haystack. rsplitn ( 2 , delim) ;
77- let suffix = split. next ( ) ?;
78- let prefix = split. next ( ) ?;
79- Some ( ( prefix, suffix) )
80- }
81-
8268pub fn trim_indent ( mut text : & str ) -> String {
8369 if text. starts_with ( '\n' ) {
8470 text = & text[ 1 ..] ;
@@ -89,7 +75,7 @@ pub fn trim_indent(mut text: &str) -> String {
8975 . map ( |it| it. len ( ) - it. trim_start ( ) . len ( ) )
9076 . min ( )
9177 . unwrap_or ( 0 ) ;
92- lines_with_ends ( text)
78+ text. split_inclusive ( '\n' )
9379 . map (
9480 |line| {
9581 if line. len ( ) <= indent {
@@ -102,70 +88,12 @@ pub fn trim_indent(mut text: &str) -> String {
10288 . collect ( )
10389}
10490
105- pub fn lines_with_ends ( text : & str ) -> LinesWithEnds {
106- LinesWithEnds { text }
107- }
108-
109- pub struct LinesWithEnds < ' a > {
110- text : & ' a str ,
111- }
112-
113- impl < ' a > Iterator for LinesWithEnds < ' a > {
114- type Item = & ' a str ;
115- fn next ( & mut self ) -> Option < & ' a str > {
116- if self . text . is_empty ( ) {
117- return None ;
118- }
119- let idx = self . text . find ( '\n' ) . map_or ( self . text . len ( ) , |it| it + 1 ) ;
120- let ( res, next) = self . text . split_at ( idx) ;
121- self . text = next;
122- Some ( res)
123- }
124- }
125-
126- /// Returns `idx` such that:
127- ///
128- /// ```text
129- /// ∀ x in slice[..idx]: pred(x)
130- /// && ∀ x in slice[idx..]: !pred(x)
131- /// ```
132- ///
133- /// https://github.com/rust-lang/rust/issues/73831
134- pub fn partition_point < T , P > ( slice : & [ T ] , mut pred : P ) -> usize
135- where
136- P : FnMut ( & T ) -> bool ,
137- {
138- let mut left = 0 ;
139- let mut right = slice. len ( ) ;
140-
141- while left != right {
142- let mid = left + ( right - left) / 2 ;
143- // SAFETY:
144- // When left < right, left <= mid < right.
145- // Therefore left always increases and right always decreases,
146- // and either of them is selected.
147- // In both cases left <= right is satisfied.
148- // Therefore if left < right in a step,
149- // left <= right is satisfied in the next step.
150- // Therefore as long as left != right, 0 <= left < right <= len is satisfied
151- // and if this case 0 <= mid < len is satisfied too.
152- let value = unsafe { slice. get_unchecked ( mid) } ;
153- if pred ( value) {
154- left = mid + 1 ;
155- } else {
156- right = mid;
157- }
158- }
159-
160- left
161- }
162-
16391pub fn equal_range_by < T , F > ( slice : & [ T ] , mut key : F ) -> ops:: Range < usize >
16492where
16593 F : FnMut ( & T ) -> Ordering ,
16694{
167- let start = partition_point ( slice , |it| key ( it) == Ordering :: Less ) ;
168- let len = partition_point ( & slice[ start..] , |it| key ( it) == Ordering :: Equal ) ;
95+ let start = slice . partition_point ( |it| key ( it) == Ordering :: Less ) ;
96+ let len = slice[ start..] . partition_point ( |it| key ( it) == Ordering :: Equal ) ;
16997 start..start + len
17098}
17199
0 commit comments