| 139 | /* span: codepoint start and end of the first match as a two element list. */ |
| 140 | #[plugin_fn] |
| 141 | fn span(pattern: String, string: String) -> Result<Option<Handle>> { |
| 142 | let Some(f) = rx(main::find(&pattern, &string, Mode::Search))? else { return Ok(None); }; |
| 143 | let list = Handle::new_list()?; |
| 144 | let a = encode(Value::Int(f.start as i128))?; |
| 145 | let b = encode(Value::Int(f.end as i128))?; |
| 146 | list.call("append", &[a.raw()])?; |
| 147 | list.call("append", &[b.raw()])?; |
| 148 | Ok(Some(list)) |
| 149 | } |
| 150 | |
| 151 | /* sub: replace every match, expanding backreferences in the template. */ |
| 152 | #[plugin_fn] |