{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/24933221","id":24933221,"diff_hunk":"@@ -0,0 +1,370 @@\n+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT\n+// file at the top-level directory of this distribution and at\n+// http://rust-lang.org/COPYRIGHT.\n+//\n+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or\n+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your\n+// option. This file may not be copied, modified, or distributed\n+// except according to those terms.\n+\n+#![allow(missing_docs)]\n+\n+use prelude::*;\n+use super::CharEq;\n+\n+// Pattern\n+\n+pub trait Pattern<'a>: Sized {\n+    type Searcher: Searcher<'a>;\n+    fn into_searcher(self, haystack: &'a str) -> Self::Searcher;\n+\n+    #[inline]\n+    fn is_contained_in(self, haystack: &'a str) -> bool {\n+        self.into_searcher(haystack).next_match().is_some()\n+    }\n+\n+    #[inline]\n+    fn match_starts_at(self, haystack: &'a str, idx: usize) -> bool {\n+        let mut matcher = self.into_searcher(haystack);\n+        loop {\n+            match matcher.next() {\n+                SearchStep::Match(i, _) if i == idx => return true,\n+                SearchStep::Match(i, _)\n+                | SearchStep::Reject(i, _) if i >= idx => break,\n+                SearchStep::Done => break,\n+                _ => continue,\n+            }\n+        }\n+        false\n+    }\n+\n+    #[inline]\n+    fn match_ends_at(self, haystack: &'a str, idx: usize) -> bool\n+    where Self::Searcher: ReverseSearcher<'a> {\n+        let mut matcher = self.into_searcher(haystack);\n+        loop {\n+            match matcher.next_back() {\n+                SearchStep::Match(_, j) if idx == j => return true,\n+                SearchStep::Match(_, j)\n+                | SearchStep::Reject(_, j) if idx >= j => break,\n+                SearchStep::Done => break,\n+                _ => continue,\n+            }\n+        }\n+        false\n+    }\n+}\n+\n+// Searcher\n+\n+#[derive(Copy, Clone, Eq, PartialEq, Debug)]\n+pub enum SearchStep {\n+    Match(usize, usize),\n+    Reject(usize, usize),\n+    Done\n+}\n+\n+pub unsafe trait Searcher<'a> {\n+    fn haystack(&self) -> &'a str;\n+    fn next(&mut self) -> SearchStep;\n+    #[inline]\n+    fn next_match(&mut self) -> Option<(usize, usize)> {\n+        loop {\n+            match self.next() {\n+                SearchStep::Match(a, b) => return Some((a, b)),\n+                SearchStep::Done => return None,\n+                _ => continue,\n+            }\n+        }\n+    }\n+    #[inline]\n+    fn next_reject(&mut self) -> Option<(usize, usize)>{\n+        loop {\n+            match self.next() {\n+                SearchStep::Reject(a, b) => return Some((a, b)),\n+                SearchStep::Done => return None,\n+                _ => continue,\n+            }\n+        }\n+    }\n+}\n+\n+pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {\n+    fn next_back(&mut self) -> SearchStep;\n+    #[inline]\n+    fn next_match_back(&mut self) -> Option<(usize, usize)>{\n+        loop {\n+            match self.next_back() {\n+                SearchStep::Match(a, b) => return Some((a, b)),\n+                SearchStep::Done => return None,\n+                _ => continue,\n+            }\n+        }\n+    }\n+    #[inline]\n+    fn next_reject_back(&mut self) -> Option<(usize, usize)>{\n+        loop {\n+            match self.next_back() {\n+                SearchStep::Reject(a, b) => return Some((a, b)),\n+                SearchStep::Done => return None,\n+                _ => continue,\n+            }\n+        }\n+    }\n+}\n+\n+pub trait DoubleEndedSearcher<'a>: ReverseSearcher<'a> {}\n+\n+// Impl for a CharEq wrapper\n+\n+struct CharEqPattern<C: CharEq>(C);","path":"src/libcore/str/pattern.rs","position":121,"original_position":121,"commit_id":"763e4894473cf3ddf92bd205634645f2d21dd74a","original_commit_id":"763e4894473cf3ddf92bd205634645f2d21dd74a","user":{"login":"Kimundi","id":2903206,"avatar_url":"https://avatars.githubusercontent.com/u/2903206?v=3","gravatar_id":"","url":"https://api.github.com/users/Kimundi","html_url":"https://github.com/Kimundi","followers_url":"https://api.github.com/users/Kimundi/followers","following_url":"https://api.github.com/users/Kimundi/following{/other_user}","gists_url":"https://api.github.com/users/Kimundi/gists{/gist_id}","starred_url":"https://api.github.com/users/Kimundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kimundi/subscriptions","organizations_url":"https://api.github.com/users/Kimundi/orgs","repos_url":"https://api.github.com/users/Kimundi/repos","events_url":"https://api.github.com/users/Kimundi/events{/privacy}","received_events_url":"https://api.github.com/users/Kimundi/received_events","type":"User","site_admin":false},"body":"Sure, its just used as an implementation detail for code reuse now. It can be made private and disappear over time.","created_at":"2015-02-18T19:38:53Z","updated_at":"2015-02-18T19:38:53Z","html_url":"https://github.com/rust-lang/rust/pull/22466#discussion_r24933221","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/22466","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/24933221"},"html":{"href":"https://github.com/rust-lang/rust/pull/22466#discussion_r24933221"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/22466"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/22466","id":29483462,"html_url":"https://github.com/rust-lang/rust/pull/22466","diff_url":"https://github.com/rust-lang/rust/pull/22466.diff","patch_url":"https://github.com/rust-lang/rust/pull/22466.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/22466","number":22466,"state":"open","locked":false,"title":"WIP Implement the string pattern API","user":{"login":"Kimundi","id":2903206,"avatar_url":"https://avatars.githubusercontent.com/u/2903206?v=3","gravatar_id":"","url":"https://api.github.com/users/Kimundi","html_url":"https://github.com/Kimundi","followers_url":"https://api.github.com/users/Kimundi/followers","following_url":"https://api.github.com/users/Kimundi/following{/other_user}","gists_url":"https://api.github.com/users/Kimundi/gists{/gist_id}","starred_url":"https://api.github.com/users/Kimundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kimundi/subscriptions","organizations_url":"https://api.github.com/users/Kimundi/orgs","repos_url":"https://api.github.com/users/Kimundi/repos","events_url":"https://api.github.com/users/Kimundi/events{/privacy}","received_events_url":"https://api.github.com/users/Kimundi/received_events","type":"User","site_admin":false},"body":"This is not a complete implementation of the RFC:\r\n\r\n- only existing methods got updated, no new ones added\r\n- doc comments are missing\r\n- commit history needs to be cleaned up\r\n- optimizations got lost and need to be reimplemented\r\n\r\nNB: The last few commits revert and reimplement a lot of the prior ones.\r\n\r\nSee https://github.com/rust-lang/rfcs/pull/528","created_at":"2015-02-17T22:22:51Z","updated_at":"2015-02-18T19:38:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7f04b781a563a5d2ac94a407f4e1681fdbb7a1ab","assignee":{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/22466/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/22466/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/22466/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/763e4894473cf3ddf92bd205634645f2d21dd74a","head":{"label":"Kimundi:str_pattern_ai_safe","ref":"str_pattern_ai_safe","sha":"763e4894473cf3ddf92bd205634645f2d21dd74a","user":{"login":"Kimundi","id":2903206,"avatar_url":"https://avatars.githubusercontent.com/u/2903206?v=3","gravatar_id":"","url":"https://api.github.com/users/Kimundi","html_url":"https://github.com/Kimundi","followers_url":"https://api.github.com/users/Kimundi/followers","following_url":"https://api.github.com/users/Kimundi/following{/other_user}","gists_url":"https://api.github.com/users/Kimundi/gists{/gist_id}","starred_url":"https://api.github.com/users/Kimundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kimundi/subscriptions","organizations_url":"https://api.github.com/users/Kimundi/orgs","repos_url":"https://api.github.com/users/Kimundi/repos","events_url":"https://api.github.com/users/Kimundi/events{/privacy}","received_events_url":"https://api.github.com/users/Kimundi/received_events","type":"User","site_admin":false},"repo":{"id":7525322,"name":"rust","full_name":"Kimundi/rust","owner":{"login":"Kimundi","id":2903206,"avatar_url":"https://avatars.githubusercontent.com/u/2903206?v=3","gravatar_id":"","url":"https://api.github.com/users/Kimundi","html_url":"https://github.com/Kimundi","followers_url":"https://api.github.com/users/Kimundi/followers","following_url":"https://api.github.com/users/Kimundi/following{/other_user}","gists_url":"https://api.github.com/users/Kimundi/gists{/gist_id}","starred_url":"https://api.github.com/users/Kimundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kimundi/subscriptions","organizations_url":"https://api.github.com/users/Kimundi/orgs","repos_url":"https://api.github.com/users/Kimundi/repos","events_url":"https://api.github.com/users/Kimundi/events{/privacy}","received_events_url":"https://api.github.com/users/Kimundi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Kimundi/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/Kimundi/rust","forks_url":"https://api.github.com/repos/Kimundi/rust/forks","keys_url":"https://api.github.com/repos/Kimundi/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kimundi/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kimundi/rust/teams","hooks_url":"https://api.github.com/repos/Kimundi/rust/hooks","issue_events_url":"https://api.github.com/repos/Kimundi/rust/issues/events{/number}","events_url":"https://api.github.com/repos/Kimundi/rust/events","assignees_url":"https://api.github.com/repos/Kimundi/rust/assignees{/user}","branches_url":"https://api.github.com/repos/Kimundi/rust/branches{/branch}","tags_url":"https://api.github.com/repos/Kimundi/rust/tags","blobs_url":"https://api.github.com/repos/Kimundi/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kimundi/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kimundi/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kimundi/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kimundi/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/Kimundi/rust/languages","stargazers_url":"https://api.github.com/repos/Kimundi/rust/stargazers","contributors_url":"https://api.github.com/repos/Kimundi/rust/contributors","subscribers_url":"https://api.github.com/repos/Kimundi/rust/subscribers","subscription_url":"https://api.github.com/repos/Kimundi/rust/subscription","commits_url":"https://api.github.com/repos/Kimundi/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kimundi/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kimundi/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kimundi/rust/issues/comments/{number}","contents_url":"https://api.github.com/repos/Kimundi/rust/contents/{+path}","compare_url":"https://api.github.com/repos/Kimundi/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kimundi/rust/merges","archive_url":"https://api.github.com/repos/Kimundi/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kimundi/rust/downloads","issues_url":"https://api.github.com/repos/Kimundi/rust/issues{/number}","pulls_url":"https://api.github.com/repos/Kimundi/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/Kimundi/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/Kimundi/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kimundi/rust/labels{/name}","releases_url":"https://api.github.com/repos/Kimundi/rust/releases{/id}","created_at":"2013-01-09T17:13:13Z","updated_at":"2015-02-10T13:42:29Z","pushed_at":"2015-02-18T15:04:27Z","git_url":"git://github.com/Kimundi/rust.git","ssh_url":"git@github.com:Kimundi/rust.git","clone_url":"https://github.com/Kimundi/rust.git","svn_url":"https://github.com/Kimundi/rust","homepage":"http://www.rust-lang.org","size":236974,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"6c065fc8cb036785f61ff03e05c1563cbb2dd081","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":724712,"name":"rust","full_name":"rust-lang/rust","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rust","description":"a safe, concurrent, practical language","fork":false,"url":"https://api.github.com/repos/rust-lang/rust","forks_url":"https://api.github.com/repos/rust-lang/rust/forks","keys_url":"https://api.github.com/repos/rust-lang/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rust/teams","hooks_url":"https://api.github.com/repos/rust-lang/rust/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rust/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rust/events","assignees_url":"https://api.github.com/repos/rust-lang/rust/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rust/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rust/tags","blobs_url":"https://api.github.com/repos/rust-lang/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rust/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rust/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rust/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rust/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rust/subscription","commits_url":"https://api.github.com/repos/rust-lang/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rust/issues/comments/{number}","contents_url":"https://api.github.com/repos/rust-lang/rust/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rust/merges","archive_url":"https://api.github.com/repos/rust-lang/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rust/downloads","issues_url":"https://api.github.com/repos/rust-lang/rust/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rust/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rust/releases{/id}","created_at":"2010-06-16T20:39:03Z","updated_at":"2015-02-18T15:37:41Z","pushed_at":"2015-02-18T19:17:09Z","git_url":"git://github.com/rust-lang/rust.git","ssh_url":"git@github.com:rust-lang/rust.git","clone_url":"https://github.com/rust-lang/rust.git","svn_url":"https://github.com/rust-lang/rust","homepage":"http://www.rust-lang.org","size":480495,"stargazers_count":9437,"watchers_count":9437,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1807,"mirror_url":null,"open_issues_count":1904,"forks":1807,"open_issues":1904,"watchers":9437,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/22466"},"html":{"href":"https://github.com/rust-lang/rust/pull/22466"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/22466"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/22466/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/22466/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/22466/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/763e4894473cf3ddf92bd205634645f2d21dd74a"}}}}