-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verbatim chunks for Key Expressions (#655)
* implement key expression namespaces * implement verbatim chunks * fix bug in includes --------- Co-authored-by: Pierre Avital <[email protected]>
- Loading branch information
Showing
4 changed files
with
91 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
use super::{keyexpr, utils::Split, DELIMITER, DOUBLE_WILD, STAR_DSL}; | ||
use super::{intersect::MayHaveVerbatim, keyexpr, utils::Split, DELIMITER, DOUBLE_WILD, STAR_DSL}; | ||
|
||
pub const DEFAULT_INCLUDER: LTRIncluder = LTRIncluder; | ||
|
||
|
@@ -24,7 +24,7 @@ impl<T: for<'a> Includer<&'a [u8], &'a [u8]>> Includer<&keyexpr, &keyexpr> for T | |
fn includes(&self, left: &keyexpr, right: &keyexpr) -> bool { | ||
let left = left.as_bytes(); | ||
let right = right.as_bytes(); | ||
if left == right || left == b"**" { | ||
if left == right { | ||
return true; | ||
} | ||
self.includes(left, right) | ||
|
@@ -38,9 +38,12 @@ impl Includer<&[u8], &[u8]> for LTRIncluder { | |
let (lchunk, lrest) = left.split_once(&DELIMITER); | ||
let lempty = lrest.is_empty(); | ||
if lchunk == DOUBLE_WILD { | ||
if lempty || self.includes(lrest, right) { | ||
if (lempty && !right.has_verbatim()) || (!lempty && self.includes(lrest, right)) { | ||
return true; | ||
} | ||
if unsafe { right.has_direct_verbatim_non_empty() } { | ||
return false; | ||
} | ||
right = right.split_once(&DELIMITER).1; | ||
if right.is_empty() { | ||
return false; | ||
|
@@ -66,7 +69,13 @@ impl Includer<&[u8], &[u8]> for LTRIncluder { | |
|
||
impl LTRIncluder { | ||
fn non_double_wild_chunk_includes(&self, lchunk: &[u8], rchunk: &[u8]) -> bool { | ||
if lchunk == b"*" || lchunk == rchunk { | ||
if lchunk == rchunk { | ||
true | ||
} else if unsafe { | ||
lchunk.has_direct_verbatim_non_empty() || rchunk.has_direct_verbatim_non_empty() | ||
} { | ||
false | ||
} else if lchunk == b"*" { | ||
true | ||
} else if lchunk.contains(&b'$') { | ||
let mut spleft = lchunk.splitter(STAR_DSL); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use crate::DELIMITER; | ||
|
||
use super::keyexpr; | ||
|
||
mod classical; | ||
|
@@ -100,3 +102,24 @@ impl< | |
} | ||
} | ||
} | ||
|
||
pub(crate) trait MayHaveVerbatim { | ||
fn has_verbatim(&self) -> bool; | ||
fn has_direct_verbatim(&self) -> bool; | ||
unsafe fn has_direct_verbatim_non_empty(&self) -> bool { | ||
self.has_direct_verbatim() | ||
} | ||
} | ||
|
||
impl MayHaveVerbatim for [u8] { | ||
fn has_direct_verbatim(&self) -> bool { | ||
matches!(self, [b'@', ..]) | ||
} | ||
fn has_verbatim(&self) -> bool { | ||
self.split(|c| *c == DELIMITER) | ||
.any(MayHaveVerbatim::has_direct_verbatim) | ||
} | ||
unsafe fn has_direct_verbatim_non_empty(&self) -> bool { | ||
unsafe { *self.get_unchecked(0) == b'@' } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters