mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +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 {
|
pub struct LuaCaptures {
|
||||||
inner: LuaCapturesInner,
|
inner: LuaCapturesInner,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LuaCaptures {
|
impl LuaCaptures {
|
||||||
pub fn new(pattern: &Regex, text: String) -> Self {
|
/**
|
||||||
Self {
|
Create a new `LuaCaptures` instance from a `Regex` pattern and a `String` text.
|
||||||
inner: LuaCapturesInner::new(Arc::from(text), |owned| pattern.captures(owned.as_str())),
|
|
||||||
|
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 mlua::prelude::*;
|
||||||
use regex::Match;
|
use regex::Match;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A wrapper over the `regex::Match` struct that can be used from Lua.
|
||||||
|
*/
|
||||||
pub struct LuaMatch {
|
pub struct LuaMatch {
|
||||||
text: Arc<String>,
|
text: Arc<String>,
|
||||||
start: usize,
|
start: usize,
|
||||||
|
@ -10,6 +13,9 @@ pub struct LuaMatch {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
pub fn new(text: Arc<String>, matched: Match) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text,
|
text,
|
||||||
|
|
|
@ -5,11 +5,18 @@ use regex::Regex;
|
||||||
|
|
||||||
use super::{captures::LuaCaptures, matches::LuaMatch};
|
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 {
|
pub struct LuaRegex {
|
||||||
inner: Regex,
|
inner: Regex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LuaRegex {
|
impl LuaRegex {
|
||||||
|
/**
|
||||||
|
Create a new `LuaRegex` instance from a `String` pattern.
|
||||||
|
*/
|
||||||
pub fn new(pattern: String) -> LuaResult<Self> {
|
pub fn new(pattern: String) -> LuaResult<Self> {
|
||||||
Regex::new(&pattern)
|
Regex::new(&pattern)
|
||||||
.map(|inner| Self { inner })
|
.map(|inner| Self { inner })
|
||||||
|
|
Loading…
Reference in a new issue