Skip to content

Commit

Permalink
Update Bitflags Version
Browse files Browse the repository at this point in the history
Switch to the 1.0 version of bitflags and fixup the breaking changes.
  • Loading branch information
iwillspeak committed Sep 16, 2017
1 parent 5fe35dc commit 947357e
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 140 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static-libonig = ["onig_sys/static_onig"]

[dependencies]
libc = "0.2"
bitflags = "0.7"
bitflags = "1.0"
lazy_static = "0.2"

[target.'cfg(not(target_env = "musl"))'.dependencies.onig_sys]
Expand Down
6 changes: 3 additions & 3 deletions examples/listcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use onig::*;
fn ex(hay: &str, pattern: &str, syntax: &Syntax) {

let reg = Regex::with_options(pattern,
REGEX_OPTION_NONE,
RegexOptions::REGEX_OPTION_NONE,
syntax).unwrap();

println!("number of captures: {}", reg.captures_len());
Expand All @@ -16,7 +16,7 @@ fn ex(hay: &str, pattern: &str, syntax: &Syntax) {
let r = reg.search_with_options(hay,
0,
hay.len(),
SEARCH_OPTION_NONE,
SearchOptions::SEARCH_OPTION_NONE,
Some(&mut region));
if let Some(pos) = r {
println!("match at {}", pos);
Expand All @@ -34,7 +34,7 @@ fn ex(hay: &str, pattern: &str, syntax: &Syntax) {

fn main() {
let mut syn = Syntax::default().clone();
syn.enable_operators(SYNTAX_OPERATOR_ATMARK_CAPTURE_HISTORY);
syn.enable_operators(SyntaxOperator::SYNTAX_OPERATOR_ATMARK_CAPTURE_HISTORY);

ex("((())())", "\\g<p>(?@<p>\\(\\g<s>\\)){0}(?@<s>(?:\\g<p>)*|){0}", &syn);
ex("x00x00x00", "(?@x(?@\\d+))+", &syn);
Expand Down
2 changes: 1 addition & 1 deletion examples/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
let mut region = Region::new();

if let Some(position) = r.search_with_options(string, 0, string.len(),
SEARCH_OPTION_NONE, Some(&mut region))
SearchOptions::SEARCH_OPTION_NONE, Some(&mut region))
{
println!("match at {} in {:?}", position, string);

Expand Down
4 changes: 2 additions & 2 deletions examples/simple_grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
println!("Compiling '{}'", arg);
let regex_compilation = Regex::with_options(
&arg,
onig::REGEX_OPTION_SINGLELINE,
onig::RegexOptions::REGEX_OPTION_SINGLELINE,
onig::Syntax::emacs());
match regex_compilation {
Ok(regex) => {regexes.insert(arg, regex);},
Expand All @@ -26,7 +26,7 @@ fn main() {
for (name, regex) in regexes.iter() {
let res = regex.search_with_options(&line,
0, line.len(),
onig::SEARCH_OPTION_NONE,
onig::SearchOptions::SEARCH_OPTION_NONE,
None);
match res {
Some(pos) => println!("{} => matched @ {}", name, pos),
Expand Down
18 changes: 9 additions & 9 deletions examples/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ fn main() {

let mut syntax = Syntax::default().clone();

syntax.set_operators(SYNTAX_OPERATOR_VARIABLE_META_CHARACTERS);
syntax.set_operators(SyntaxOperator::SYNTAX_OPERATOR_VARIABLE_META_CHARACTERS);
syntax.set_behavior(SyntaxBehavior::empty());
syntax.set_options(REGEX_OPTION_MULTILINE);
syntax.set_options(RegexOptions::REGEX_OPTION_MULTILINE);

syntax.set_meta_char(META_CHAR_ESCAPE, MetaChar::Character('\\'));
syntax.set_meta_char(META_CHAR_ANYCHAR, MetaChar::Character('_'));
syntax.set_meta_char(META_CHAR_ANYTIME, MetaChar::Ineffective);
syntax.set_meta_char(META_CHAR_ZERO_OR_ONE_TIME, MetaChar::Ineffective);
syntax.set_meta_char(META_CHAR_ONE_OR_MORE_TIME, MetaChar::Ineffective);
syntax.set_meta_char(META_CHAR_ANYCHAR_ANYTIME, MetaChar::Character('%'));
syntax.set_meta_char(MetaCharType::META_CHAR_ESCAPE, MetaChar::Character('\\'));
syntax.set_meta_char(MetaCharType::META_CHAR_ANYCHAR, MetaChar::Character('_'));
syntax.set_meta_char(MetaCharType::META_CHAR_ANYTIME, MetaChar::Ineffective);
syntax.set_meta_char(MetaCharType::META_CHAR_ZERO_OR_ONE_TIME, MetaChar::Ineffective);
syntax.set_meta_char(MetaCharType::META_CHAR_ONE_OR_MORE_TIME, MetaChar::Ineffective);
syntax.set_meta_char(MetaCharType::META_CHAR_ANYCHAR_ANYTIME, MetaChar::Character('%'));

let reg = Regex::with_options("\\_%\\\\__zz",
REGEX_OPTION_NONE,
RegexOptions::REGEX_OPTION_NONE,
&syntax).unwrap();

match reg.captures("a_abcabcabc\\ppzz") {
Expand Down
2 changes: 1 addition & 1 deletion examples/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use onig::*;

fn exec(syntax: &Syntax, pattern: &str, to_search: &str) {

let reg = Regex::with_options(pattern, REGEX_OPTION_NONE, syntax).unwrap();
let reg = Regex::with_options(pattern, RegexOptions::REGEX_OPTION_NONE, syntax).unwrap();

match reg.captures(to_search) {
Some(caps) => {
Expand Down
17 changes: 12 additions & 5 deletions src/find.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use std::iter::Iterator;
use super::{Region, Regex, SearchOptions, SEARCH_OPTION_NONE};
use super::{Region, Regex, SearchOptions};

impl Regex {
/// Returns the capture groups corresponding to the leftmost-first match
/// in text. Capture group `0` always corresponds to the entire match.
/// If no match is found, then `None` is returned.
pub fn captures<'t>(&self, text: &'t str) -> Option<Captures<'t>> {
let mut region = Region::new();
self.search_with_options(text, 0, text.len(), SEARCH_OPTION_NONE, Some(&mut region))
self.search_with_options(text,
0,
text.len(),
SearchOptions::SEARCH_OPTION_NONE,
Some(&mut region))
.map(|pos| {
Captures {
text: text,
Expand Down Expand Up @@ -181,7 +185,10 @@ impl Regex {
{

let mut region = Region::new();
self.scan_with_region(to_search, &mut region, SEARCH_OPTION_NONE, |n, s, region| {
self.scan_with_region(to_search,
&mut region,
SearchOptions::SEARCH_OPTION_NONE,
|n, s, region| {
let captures = Captures {
text: to_search,
region: region.clone(),
Expand Down Expand Up @@ -339,7 +346,7 @@ impl<'r, 't> Iterator for FindMatches<'r, 't> {
let r = self.regex.search_with_options(self.text,
self.last_end,
self.text.len(),
SEARCH_OPTION_NONE,
SearchOptions::SEARCH_OPTION_NONE,
Some(&mut self.region));
if r.is_none() {
return None;
Expand Down Expand Up @@ -393,7 +400,7 @@ impl<'r, 't> Iterator for FindCaptures<'r, 't> {
let r = self.regex.search_with_options(self.text,
self.last_end,
self.text.len(),
SEARCH_OPTION_NONE,
SearchOptions::SEARCH_OPTION_NONE,
Some(&mut region));
if r.is_none() {
return None;
Expand Down
Loading

0 comments on commit 947357e

Please sign in to comment.