/// ```rust
/// #![feature(phase)]
/// extern crate regex;
-/// #[phase(syntax)] extern crate regex_macros;
+/// #[phase(plugin)] extern crate regex_macros;
///
/// fn main() {
/// let re = regex!(r"\d+");
// See the comments for the `program` module in `lib.rs` for a more
// detailed explanation for what `regex!` requires.
#[doc(hidden)]
- Dynamic(Dynamic),
+ Dynamic(ExDynamic),
#[doc(hidden)]
- Native(Native),
+ Native(ExNative),
}
#[deriving(Clone)]
#[doc(hidden)]
-pub struct Dynamic {
+pub struct ExDynamic {
original: String,
names: Vec<Option<String>>,
#[doc(hidden)]
}
#[doc(hidden)]
-pub struct Native {
+pub struct ExNative {
#[doc(hidden)]
pub original: &'static str,
#[doc(hidden)]
pub prog: fn(MatchKind, &str, uint, uint) -> Vec<Option<uint>>
}
-impl Clone for Native {
- fn clone(&self) -> Native { *self }
+impl Clone for ExNative {
+ fn clone(&self) -> ExNative { *self }
}
impl fmt::Show for Regex {
pub fn new(re: &str) -> Result<Regex, parse::Error> {
let ast = try!(parse::parse(re));
let (prog, names) = Program::new(ast);
- Ok(Dynamic(Dynamic {
+ Ok(Dynamic(ExDynamic {
original: re.to_string(),
names: names,
prog: prog,
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let text = "I categorically deny having triskaidekaphobia.";
/// let matched = regex!(r"\b\w{13}\b").is_match(text);
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let text = "I categorically deny having triskaidekaphobia.";
/// let pos = regex!(r"\b\w{13}\b").find(text);
pub fn find(&self, text: &str) -> Option<(uint, uint)> {
let caps = exec(self, Location, text);
if has_match(&caps) {
- Some((caps.get(0).unwrap(), caps.get(1).unwrap()))
+ Some((caps[0].unwrap(), caps[1].unwrap()))
} else {
None
}
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let text = "Retroactively relinquishing remunerations is reprehensible.";
/// for pos in regex!(r"\b\w{13}\b").find_iter(text) {
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let re = regex!(r"'([^']+)'\s+\((\d{4})\)");
/// let text = "Not my favorite movie: 'Citizen Kane' (1941).";
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let re = regex!(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)");
/// let text = "Not my favorite movie: 'Citizen Kane' (1941).";
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let re = regex!(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)");
/// let text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931).";
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let re = regex!(r"[ \t]+");
/// let fields: Vec<&str> = re.split("a b \t c\td e").collect();
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let re = regex!(r"\W+");
/// let fields: Vec<&str> = re.splitn("Hey! How are you?", 3).collect();
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let re = regex!("[^01]+");
/// assert_eq!(re.replace("1078910", "").as_slice(), "1010");
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # use regex::Captures; fn main() {
/// let re = regex!(r"([^,\s]+),\s+(\S+)");
/// let result = re.replace("Springsteen, Bruce", |caps: &Captures| {
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// let re = regex!(r"(?P<last>[^,\s]+),\s+(?P<first>\S+)");
/// let result = re.replace("Springsteen, Bruce", "$first $last");
///
/// ```rust
/// # #![feature(phase)]
- /// # extern crate regex; #[phase(syntax)] extern crate regex_macros;
+ /// # extern crate regex; #[phase(plugin)] extern crate regex_macros;
/// # fn main() {
/// use regex::NoExpand;
///
/// Returns the original string of this regex.
pub fn as_str<'a>(&'a self) -> &'a str {
match *self {
- Dynamic(Dynamic { ref original, .. }) => original.as_slice(),
- Native(Native { ref original, .. }) => original.as_slice(),
+ Dynamic(ExDynamic { ref original, .. }) => original.as_slice(),
+ Native(ExNative { ref original, .. }) => original.as_slice(),
}
}
/// original string matched.
pub fn pos(&self, i: uint) -> Option<(uint, uint)> {
let (s, e) = (i * 2, i * 2 + 1);
- if e >= self.locs.len() || self.locs.get(s).is_none() {
+ if e >= self.locs.len() || self.locs[s].is_none() {
// VM guarantees that each pair of locations are both Some or None.
return None
}
- Some((self.locs.get(s).unwrap(), self.locs.get(e).unwrap()))
+ Some((self.locs[s].unwrap(), self.locs[e].unwrap()))
}
/// Returns the matched string for the capture group `i`.
}
}
-impl<'t> Container for Captures<'t> {
+impl<'t> Collection for Captures<'t> {
/// Returns the number of captured groups.
#[inline]
fn len(&self) -> uint {
if !has_match(&caps) {
return None
} else {
- (caps.get(0).unwrap(), caps.get(1).unwrap())
+ (caps[0].unwrap(), caps[1].unwrap())
};
// Don't accept empty matches immediately following a match.
if !has_match(&caps) {
return None
} else {
- (caps.get(0).unwrap(), caps.get(1).unwrap())
+ (caps[0].unwrap(), caps[1].unwrap())
};
// Don't accept empty matches immediately following a match.
fn exec_slice(re: &Regex, which: MatchKind,
input: &str, s: uint, e: uint) -> CaptureLocs {
match *re {
- Dynamic(Dynamic { ref prog, .. }) => vm::run(which, prog, input, s, e),
- Native(Native { prog, .. }) => prog(which, input, s, e),
+ Dynamic(ExDynamic { ref prog, .. }) => vm::run(which, prog, input, s, e),
+ Native(ExNative { prog, .. }) => prog(which, input, s, e),
}
}
#[inline]
fn has_match(caps: &CaptureLocs) -> bool {
- caps.len() >= 2 && caps.get(0).is_some() && caps.get(1).is_some()
+ caps.len() >= 2 && caps[0].is_some() && caps[1].is_some()
}