#pattern-matching #pattern #matching #regex #search-pattern #text-search #fsa

rosie

用于Rosie模式语言的接口,用于高效且可维护的文本模式匹配和搜索

2个版本

0.1.1 2022年6月8日
0.1.0 2022年6月5日

#743 in 文本处理

MIT/Apache

82KB
961

Rosie Rust接口概述

本crate实现了对Rosie匹配引擎的Rosie模式语言(rpl)的高级别接口。

rpl的完整参考文档在这里更多示例可以在这里找到。

In Cargo.toml

要将Rosie作为您项目的一部分进行构建,请将以下行添加到您的Cargo.toml [dependencies]部分

rosie= {features= ["build_static_librosie"] }

要构建Rosie以链接到已安装在系统上的共享librosie,请添加以下行代替

rosie= {features= ["link_shared_librosie"] }

部署

Rosie依赖于一个rosie_home目录,其中包含包括标准模式库在内的支持文件。有关部署说明,请参阅[rosie_sys] crate的README中的安装 & 部署部分。

用法

您可以在三个级别上访问Rosie。

高级:使用Rosie::match_str()

只需一行代码即可检查匹配

use rosie::*;

if Rosie::match_str("{ [H][^]* }", "Hello, Rosie!") {
    println!("It Matches!");
}

或获取匹配的子字符串

use rosie::*;

let result : MatchResult = Rosie::match_str("date.any", "Nov 5, 1955! That was the day");
println!("Matched Substring = {}", result.matched_str());
assert_eq!(result.matched_str(), "Nov 5, 1955");

中级:使用编译后的模式

显式编译可以减少开销,因为您可以自己管理编译后的模式,删除不需要的模式并避免不必要的重新编译。

use rosie::*;

let date_pat = Rosie::compile("date.us_long").unwrap();
let result : MatchResult = date_pat.match_str("Saturday, Nov 5, 1955").unwrap();
println!("did_match = {}", result.did_match());
println!("matched_str = {}", result.matched_str());

低级:使用RosieEngine

请参阅[engine]以获取详细信息。

依赖项

~0.6–2MB
~33K SLoC