Skip to content

Commit

Permalink
Add binding to get unit string at index (#319)
Browse files Browse the repository at this point in the history
Signed-off-by: Yage Hu <me@huyage.dev>
  • Loading branch information
yagehu authored Oct 27, 2024
1 parent da43f0c commit 1a1e734
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions z3/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,34 @@ impl<'ctx> String<'ctx> {
}
}

/// Retrieve the substring of length 1 positioned at `index`.
///
/// # Examples
/// ```
/// # use z3::{Config, Context, Solver};
/// # use z3::ast::{Ast as _, Int};
/// #
/// # let cfg = Config::new();
/// # let ctx = Context::new(&cfg);
/// # let solver = Solver::new(&ctx);
/// #
/// let s = z3::ast::String::fresh_const(&ctx, "");
///
/// solver.assert(
/// &s.at(&Int::from_u64(&ctx, 0))
/// ._eq(&z3::ast::String::from_str(&ctx, "a").unwrap())
/// );
/// assert_eq!(solver.check(), z3::SatResult::Sat);
/// ```
pub fn at(&self, index: &Int<'ctx>) -> Self {
unsafe {
Self::wrap(
self.ctx,
Z3_mk_seq_at(self.ctx.z3_ctx, self.z3_ast, index.z3_ast),
)
}
}

/// Checks if this string matches a `z3::ast::Regexp`
pub fn regex_matches(&self, regex: &Regexp) -> Bool<'ctx> {
assert!(self.ctx == regex.ctx);
Expand Down

0 comments on commit 1a1e734

Please sign in to comment.