Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/utils.rs @ 47961:4d2a5ca060e3
rust: Add a Filelog struct that wraps Revlog
Some filelog-specific logic is moved from code `rhg cat` into this struct
where it can better be reused.
Additionally, a missing end delimiter for metadata causes an error
to be returned instead of being silently ignored.
Differential Revision: https://phab.mercurial-scm.org/D11408
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 13 Sep 2021 15:42:39 +0200 |
parents | 696abab107b4 |
children | 5734b03ecf3e |
line wrap: on
line diff
--- a/rust/hg-core/src/utils.rs Mon Sep 13 13:45:10 2021 +0200 +++ b/rust/hg-core/src/utils.rs Mon Sep 13 15:42:39 2021 +0200 @@ -74,6 +74,7 @@ fn trim(&self) -> &Self; fn drop_prefix(&self, needle: &Self) -> Option<&Self>; fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])>; + fn split_2_by_slice(&self, separator: &[u8]) -> Option<(&[u8], &[u8])>; } impl SliceExt for [u8] { @@ -134,6 +135,14 @@ let b = iter.next()?; Some((a, b)) } + + fn split_2_by_slice(&self, separator: &[u8]) -> Option<(&[u8], &[u8])> { + if let Some(pos) = find_slice_in_slice(self, separator) { + Some((&self[..pos], &self[pos + separator.len()..])) + } else { + None + } + } } pub trait Escaped {