Skip to content

Commit fd55842

Browse files
author
Ulrik Sverdrup
committed
---
yaml --- r: 223423 b: refs/heads/beta c: a6dd203 h: refs/heads/master i: 223421: 63170ff 223419: ccd8faa 223415: 3b99f4e 223407: e2e2764 223391: 4f764ea 223359: 2c5a508 v: v3
1 parent c846ce0 commit fd55842

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
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: b890b7bbc732cd26f13c309573b5a3e45d0748de
26+
refs/heads/beta: a6dd2031a363d0b46caea06ef77209f678327719
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 938f5d7af401e2d8238522fed4a612943b6e77fd
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

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