mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 04:50:36 +00:00
Add docs on public functions, fix captures being returned even if not found
This commit is contained in:
parent
12f5824da9
commit
54081c1b0f
3 changed files with 28 additions and 3 deletions
|
@ -16,14 +16,26 @@ self_cell! {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
A wrapper over the `regex::Captures` struct that can be used from Lua.
|
||||
*/
|
||||
pub struct LuaCaptures {
|
||||
inner: LuaCapturesInner,
|
||||
}
|
||||
|
||||
impl LuaCaptures {
|
||||
pub fn new(pattern: &Regex, text: String) -> Self {
|
||||
Self {
|
||||
inner: LuaCapturesInner::new(Arc::from(text), |owned| pattern.captures(owned.as_str())),
|
||||
/**
|
||||
Create a new `LuaCaptures` instance from a `Regex` pattern and a `String` text.
|
||||
|
||||
Returns `Some(_)` if captures were found, `None` if no captures were found.
|
||||
*/
|
||||
pub fn new(pattern: &Regex, text: String) -> Option<Self> {
|
||||
let inner =
|
||||
LuaCapturesInner::new(Arc::from(text), |owned| pattern.captures(owned.as_str()));
|
||||
if inner.borrow_dependent().is_some() {
|
||||
Some(Self { inner })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ use std::{ops::Range, sync::Arc};
|
|||
use mlua::prelude::*;
|
||||
use regex::Match;
|
||||
|
||||
/**
|
||||
A wrapper over the `regex::Match` struct that can be used from Lua.
|
||||
*/
|
||||
pub struct LuaMatch {
|
||||
text: Arc<String>,
|
||||
start: usize,
|
||||
|
@ -10,6 +13,9 @@ pub struct LuaMatch {
|
|||
}
|
||||
|
||||
impl LuaMatch {
|
||||
/**
|
||||
Create a new `LuaMatch` instance from a `String` text and a `regex::Match`.
|
||||
*/
|
||||
pub fn new(text: Arc<String>, matched: Match) -> Self {
|
||||
Self {
|
||||
text,
|
||||
|
|
|
@ -5,11 +5,18 @@ use regex::Regex;
|
|||
|
||||
use super::{captures::LuaCaptures, matches::LuaMatch};
|
||||
|
||||
/**
|
||||
A wrapper over the `regex::Regex` struct that can be used from Lua.
|
||||
*/
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LuaRegex {
|
||||
inner: Regex,
|
||||
}
|
||||
|
||||
impl LuaRegex {
|
||||
/**
|
||||
Create a new `LuaRegex` instance from a `String` pattern.
|
||||
*/
|
||||
pub fn new(pattern: String) -> LuaResult<Self> {
|
||||
Regex::new(&pattern)
|
||||
.map(|inner| Self { inner })
|
||||
|
|
Loading…
Reference in a new issue