Skip to content

Commit d303438

Browse files
author
Ulrik Sverdrup
committed
---
yaml --- r: 227935 b: refs/heads/try c: a6dd203 h: refs/heads/master i: 227933: 003c82e 227931: 100369d 227927: 5526790 227919: 43c2681 227903: f0bf1d3 v: v3
1 parent 314fcc9 commit d303438

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: b890b7bbc732cd26f13c309573b5a3e45d0748de
4+
refs/heads/try: a6dd2031a363d0b46caea06ef77209f678327719
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/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)