rust/hg-core/src/utils.rs
changeset 42869 62eabdf91f85
parent 42851 ce6797ef6eab
child 42959 3fe40dd6355d
--- a/rust/hg-core/src/utils.rs	Sun Aug 25 22:52:36 2019 -0400
+++ b/rust/hg-core/src/utils.rs	Mon Aug 26 08:25:01 2019 -0400
@@ -40,6 +40,7 @@
     fn trim_end(&self) -> &Self;
     fn trim_start(&self) -> &Self;
     fn trim(&self) -> &Self;
+    fn drop_prefix(&self, needle: &Self) -> Option<&Self>;
 }
 
 fn is_not_whitespace(c: &u8) -> bool {
@@ -80,4 +81,12 @@
     fn trim(&self) -> &[u8] {
         self.trim_start().trim_end()
     }
+
+    fn drop_prefix(&self, needle: &Self) -> Option<&Self> {
+        if self.starts_with(needle) {
+            Some(&self[needle.len()..])
+        } else {
+            None
+        }
+    }
 }