Skip to content

Commit fb680d9

Browse files
author
Ulrik Sverdrup
committed
---
yaml --- r: 217553 b: refs/heads/tmp c: a6dd203 h: refs/heads/master i: 217551: 23b011d v: v3
1 parent c509a48 commit fb680d9

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2626
refs/heads/beta: 2ad26e850ed5dfedda8c96d7315aee50145ceedd
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
28-
refs/heads/tmp: b890b7bbc732cd26f13c309573b5a3e45d0748de
28+
refs/heads/tmp: a6dd2031a363d0b46caea06ef77209f678327719
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: a5286998df566e736b32f6795bfc3803bdaf453d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828

branches/tmp/src/libcore/str/pattern.rs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,6 @@ unsafe impl<'a, C: CharEq> ReverseSearcher<'a> for CharEqSearcher<'a, C> {
343343

344344
impl<'a, C: CharEq> DoubleEndedSearcher<'a> for CharEqSearcher<'a, C> {}
345345

346-
/////////////////////////////////////////////////////////////////////////////
347-
// Impl for &str
348-
/////////////////////////////////////////////////////////////////////////////
349-
350-
/// Non-allocating substring search.
351-
///
352-
/// Will handle the pattern `""` as returning empty matches at each character
353-
/// boundary.
354-
impl<'a, 'b> Pattern<'a> for &'b str {
355-
type Searcher = StrSearcher<'a, 'b>;
356-
357-
#[inline]
358-
fn into_searcher(self, haystack: &'a str) -> StrSearcher<'a, 'b> {
359-
StrSearcher::new(haystack, self)
360-
}
361-
}
362-
363346
/////////////////////////////////////////////////////////////////////////////
364347

365348
macro_rules! pattern_methods {
@@ -511,6 +494,39 @@ impl<'a, 'b> Pattern<'a> for &'b &'b str {
511494
pattern_methods!(StrSearcher<'a, 'b>, |&s| s, |s| s);
512495
}
513496

497+
/////////////////////////////////////////////////////////////////////////////
498+
// Impl for &str
499+
/////////////////////////////////////////////////////////////////////////////
500+
501+
/// Non-allocating substring search.
502+
///
503+
/// Will handle the pattern `""` as returning empty matches at each character
504+
/// boundary.
505+
impl<'a, 'b> Pattern<'a> for &'b str {
506+
type Searcher = StrSearcher<'a, 'b>;
507+
508+
#[inline]
509+
fn into_searcher(self, haystack: &'a str) -> StrSearcher<'a, 'b> {
510+
StrSearcher::new(haystack, self)
511+
}
512+
513+
/// Checks whether the pattern matches at the front of the haystack
514+
#[inline]
515+
fn is_prefix_of(self, haystack: &'a str) -> bool {
516+
// Use `as_bytes` so that we can slice through a character in the haystack.
517+
// Since self is always valid UTF-8, this can't result in a false positive.
518+
self.len() <= haystack.len() &&
519+
self.as_bytes() == &haystack.as_bytes()[..self.len()]
520+
}
521+
522+
/// Checks whether the pattern matches at the back of the haystack
523+
#[inline]
524+
fn is_suffix_of(self, haystack: &'a str) -> bool {
525+
self.len() <= haystack.len() &&
526+
self.as_bytes() == &haystack.as_bytes()[haystack.len() - self.len()..]
527+
}
528+
}
529+
514530

515531
/////////////////////////////////////////////////////////////////////////////
516532
// Two Way substring searcher

0 commit comments

Comments
 (0)