Skip to content

Commit cfacfcb

Browse files
committed
---
yaml --- r: 120315 b: refs/heads/dist-snap c: ec5911b h: refs/heads/master i: 120313: 2485535 120311: 8898a59 v: v3
1 parent 3b5f106 commit cfacfcb

File tree

6 files changed

+51
-46
lines changed

6 files changed

+51
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 1813e5aa1a03b0596b8de7abd1af31edf5d6098f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 62cf95f67482c0ee7c70a984ce4edb6f6cd9f716
9+
refs/heads/dist-snap: ec5911b2a62b0d603da7deb18c34c8e853c91d2c
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libregex/compile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ pub struct Program {
8383
/// If the regular expression requires a literal prefix in order to have a
8484
/// match, that prefix is stored here. (It's used in the VM to implement
8585
/// an optimization.)
86-
pub prefix: ~str,
86+
pub prefix: StrBuf,
8787
}
8888

8989
impl Program {
9090
/// Compiles a Regex given its AST.
91-
pub fn new(ast: parse::Ast) -> (Program, Vec<Option<~str>>) {
91+
pub fn new(ast: parse::Ast) -> (Program, Vec<Option<StrBuf>>) {
9292
let mut c = Compiler {
9393
insts: Vec::with_capacity(100),
9494
names: Vec::with_capacity(10),
@@ -113,7 +113,7 @@ impl Program {
113113
let Compiler { insts, names } = c;
114114
let prog = Program {
115115
insts: insts,
116-
prefix: pre.into_owned(),
116+
prefix: pre,
117117
};
118118
(prog, names)
119119
}
@@ -135,7 +135,7 @@ impl Program {
135135

136136
struct Compiler<'r> {
137137
insts: Vec<Inst>,
138-
names: Vec<Option<~str>>,
138+
names: Vec<Option<StrBuf>>,
139139
}
140140

141141
// The compiler implemented here is extremely simple. Most of the complexity

branches/dist-snap/src/libregex/parse.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct Error {
3232
/// The *approximate* character index of where the error occurred.
3333
pub pos: uint,
3434
/// A message describing the error.
35-
pub msg: ~str,
35+
pub msg: StrBuf,
3636
}
3737

3838
impl fmt::Show for Error {
@@ -59,7 +59,7 @@ pub enum Ast {
5959
Begin(Flags),
6060
End(Flags),
6161
WordBoundary(Flags),
62-
Capture(uint, Option<~str>, Box<Ast>),
62+
Capture(uint, Option<StrBuf>, Box<Ast>),
6363
// Represent concatenation as a flat vector to avoid blowing the
6464
// stack in the compiler.
6565
Cat(Vec<Ast>),
@@ -104,7 +104,7 @@ impl Greed {
104104
#[deriving(Show)]
105105
enum BuildAst {
106106
Ast(Ast),
107-
Paren(Flags, uint, ~str), // '('
107+
Paren(Flags, uint, StrBuf), // '('
108108
Bar, // '|'
109109
}
110110

@@ -131,7 +131,7 @@ impl BuildAst {
131131
}
132132
}
133133

134-
fn capture_name(&self) -> Option<~str> {
134+
fn capture_name(&self) -> Option<StrBuf> {
135135
match *self {
136136
Paren(_, 0, _) => None,
137137
Paren(_, _, ref name) => {
@@ -185,7 +185,7 @@ struct Parser<'a> {
185185
// opening a capture group).
186186
caps: uint,
187187
// A set of all capture group names used only to detect duplicates.
188-
names: Vec<~str>,
188+
names: Vec<StrBuf>,
189189
}
190190

191191
pub fn parse(s: &str) -> Result<Ast, Error> {
@@ -222,7 +222,7 @@ impl<'a> Parser<'a> {
222222
self.caps += 1;
223223
self.stack.push(Paren(self.flags,
224224
self.caps,
225-
"".to_owned()))
225+
"".to_strbuf()))
226226
}
227227
}
228228
')' => {
@@ -470,7 +470,7 @@ impl<'a> Parser<'a> {
470470
FLAG_EMPTY
471471
};
472472
let name = self.slice(name_start, closer - 1);
473-
match find_class(ASCII_CLASSES, name) {
473+
match find_class(ASCII_CLASSES, name.as_slice()) {
474474
None => None,
475475
Some(ranges) => {
476476
self.chari = closer;
@@ -611,7 +611,7 @@ impl<'a> Parser<'a> {
611611
// character).
612612
fn parse_unicode_name(&mut self) -> Result<Ast, Error> {
613613
let negated = if self.cur() == 'P' { FLAG_NEGATED } else { FLAG_EMPTY };
614-
let mut name: ~str;
614+
let mut name: StrBuf;
615615
if self.peek_is(1, '{') {
616616
try!(self.expect('{'))
617617
let closer =
@@ -633,7 +633,7 @@ impl<'a> Parser<'a> {
633633
name = self.slice(self.chari + 1, self.chari + 2);
634634
self.chari += 1;
635635
}
636-
match find_class(UNICODE_CLASSES, name) {
636+
match find_class(UNICODE_CLASSES, name.as_slice()) {
637637
None => return self.err(format!(
638638
"Could not find Unicode class '{}'", name)),
639639
Some(ranges) => {
@@ -657,7 +657,7 @@ impl<'a> Parser<'a> {
657657
}
658658
}
659659
let s = self.slice(start, end);
660-
match num::from_str_radix::<u32>(s, 8) {
660+
match num::from_str_radix::<u32>(s.as_slice(), 8) {
661661
Some(n) => Ok(Literal(try!(self.char_from_u32(n)), FLAG_EMPTY)),
662662
None => self.err(format!(
663663
"Could not parse '{}' as octal number.", s)),
@@ -679,7 +679,7 @@ impl<'a> Parser<'a> {
679679
Some(i) => i,
680680
};
681681
self.chari = closer;
682-
self.parse_hex_digits(self.slice(start, closer))
682+
self.parse_hex_digits(self.slice(start, closer).as_slice())
683683
}
684684

685685
// Parses a two-digit hex number.
@@ -690,7 +690,7 @@ impl<'a> Parser<'a> {
690690
let (start, end) = (self.chari, self.chari + 2);
691691
let bad = self.slice(start - 2, self.chars.len());
692692
try!(self.noteof(format!("Invalid hex escape sequence '{}'", bad)))
693-
self.parse_hex_digits(self.slice(start, end))
693+
self.parse_hex_digits(self.slice(start, end).as_slice())
694694
}
695695

696696
// Parses `s` as a hexadecimal number.
@@ -717,7 +717,7 @@ impl<'a> Parser<'a> {
717717
return self.err("Capture names must have at least 1 character.")
718718
}
719719
let name = self.slice(self.chari, closer);
720-
if !name.chars().all(is_valid_cap) {
720+
if !name.as_slice().chars().all(is_valid_cap) {
721721
return self.err(
722722
"Capture names can only have underscores, letters and digits.")
723723
}
@@ -771,7 +771,7 @@ impl<'a> Parser<'a> {
771771
}
772772
if self.cur() == ':' {
773773
// Save the old flags with the opening paren.
774-
self.stack.push(Paren(self.flags, 0, "".to_owned()));
774+
self.stack.push(Paren(self.flags, 0, "".to_strbuf()));
775775
}
776776
self.flags = flags;
777777
return Ok(())
@@ -892,7 +892,7 @@ impl<'a> Parser<'a> {
892892
fn err<T>(&self, msg: &str) -> Result<T, Error> {
893893
Err(Error {
894894
pos: self.chari,
895-
msg: msg.to_owned(),
895+
msg: msg.to_strbuf(),
896896
})
897897
}
898898

@@ -911,8 +911,8 @@ impl<'a> Parser<'a> {
911911
*self.chars.get(self.chari)
912912
}
913913

914-
fn slice(&self, start: uint, end: uint) -> ~str {
915-
str::from_chars(self.chars.as_slice().slice(start, end))
914+
fn slice(&self, start: uint, end: uint) -> StrBuf {
915+
str::from_chars(self.chars.as_slice().slice(start, end)).to_strbuf()
916916
}
917917
}
918918

branches/dist-snap/src/libregex/re.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ use vm::{CaptureLocs, MatchKind, Exists, Location, Submatches};
2020

2121
/// Escapes all regular expression meta characters in `text` so that it may be
2222
/// safely used in a regular expression as a literal string.
23-
pub fn quote(text: &str) -> ~str {
23+
pub fn quote(text: &str) -> StrBuf {
2424
let mut quoted = StrBuf::with_capacity(text.len());
2525
for c in text.chars() {
2626
if parse::is_punct(c) {
2727
quoted.push_char('\\')
2828
}
2929
quoted.push_char(c);
3030
}
31-
quoted.into_owned()
31+
quoted
3232
}
3333

3434
/// Tests if the given regular expression matches somewhere in the text given.
@@ -107,9 +107,9 @@ pub struct Regex {
107107
/// See the comments for the `program` module in `lib.rs` for a more
108108
/// detailed explanation for what `regex!` requires.
109109
#[doc(hidden)]
110-
pub original: ~str,
110+
pub original: StrBuf,
111111
#[doc(hidden)]
112-
pub names: Vec<Option<~str>>,
112+
pub names: Vec<Option<StrBuf>>,
113113
#[doc(hidden)]
114114
pub p: MaybeNative,
115115
}
@@ -146,7 +146,10 @@ impl Regex {
146146
pub fn new(re: &str) -> Result<Regex, parse::Error> {
147147
let ast = try!(parse::parse(re));
148148
let (prog, names) = Program::new(ast);
149-
Ok(Regex { original: re.to_owned(), names: names, p: Dynamic(prog) })
149+
Ok(Regex {
150+
original: re.to_strbuf(),
151+
names: names, p: Dynamic(prog),
152+
})
150153
}
151154

152155
/// Returns true if and only if the regex matches the string given.
@@ -404,7 +407,7 @@ impl Regex {
404407
/// ```
405408
///
406409
/// But anything satisfying the `Replacer` trait will work. For example,
407-
/// a closure of type `|&Captures| -> ~str` provides direct access to the
410+
/// a closure of type `|&Captures| -> StrBuf` provides direct access to the
408411
/// captures corresponding to a match. This allows one to access
409412
/// submatches easily:
410413
///
@@ -414,7 +417,7 @@ impl Regex {
414417
/// # use regex::Captures; fn main() {
415418
/// let re = regex!(r"([^,\s]+),\s+(\S+)");
416419
/// let result = re.replace("Springsteen, Bruce", |caps: &Captures| {
417-
/// format!("{} {}", caps.at(2), caps.at(1))
420+
/// format_strbuf!("{} {}", caps.at(2), caps.at(1))
418421
/// });
419422
/// assert_eq!(result.as_slice(), "Bruce Springsteen");
420423
/// # }
@@ -526,7 +529,7 @@ impl<'t> Replacer for &'t str {
526529
}
527530
}
528531

529-
impl<'a> Replacer for |&Captures|: 'a -> ~str {
532+
impl<'a> Replacer for |&Captures|: 'a -> StrBuf {
530533
fn reg_replace<'r>(&'r mut self, caps: &Captures) -> MaybeOwned<'r> {
531534
Owned((*self)(caps).into_owned())
532535
}
@@ -605,7 +608,7 @@ impl<'r, 't> Iterator<&'t str> for RegexSplitsN<'r, 't> {
605608
pub struct Captures<'t> {
606609
text: &'t str,
607610
locs: CaptureLocs,
608-
named: Option<HashMap<~str, uint>>,
611+
named: Option<HashMap<StrBuf, uint>>,
609612
}
610613

611614
impl<'t> Captures<'t> {
@@ -624,7 +627,7 @@ impl<'t> Captures<'t> {
624627
match name {
625628
&None => {},
626629
&Some(ref name) => {
627-
named.insert(name.to_owned(), i);
630+
named.insert(name.to_strbuf(), i);
628631
}
629632
}
630633
}
@@ -707,12 +710,14 @@ impl<'t> Captures<'t> {
707710
// How evil can you get?
708711
// FIXME: Don't use regexes for this. It's completely unnecessary.
709712
let re = Regex::new(r"(^|[^$]|\b)\$(\w+)").unwrap();
710-
let text = re.replace_all(text, |refs: &Captures| -> ~str {
713+
let text = re.replace_all(text, |refs: &Captures| -> StrBuf {
711714
let (pre, name) = (refs.at(1), refs.at(2));
712-
pre + match from_str::<uint>(name) {
713-
None => self.name(name).to_owned(),
714-
Some(i) => self.at(i).to_owned(),
715-
}
715+
format_strbuf!("{}{}",
716+
pre,
717+
match from_str::<uint>(name.as_slice()) {
718+
None => self.name(name).to_strbuf(),
719+
Some(i) => self.at(i).to_strbuf(),
720+
})
716721
});
717722
let re = Regex::new(r"\$\$").unwrap();
718723
re.replace_all(text.as_slice(), NoExpand("$"))

branches/dist-snap/src/libregex/test/bench.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ macro_rules! throughput(
140140
fn $name(b: &mut Bencher) {
141141
let text = gen_text($size);
142142
b.bytes = $size;
143-
b.iter(|| if $regex.is_match(text) { fail!("match") });
143+
b.iter(|| if $regex.is_match(text.as_slice()) { fail!("match") });
144144
}
145145
);
146146
)
@@ -151,15 +151,15 @@ fn medium() -> Regex { regex!("[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$") }
151151
fn hard() -> Regex { regex!("[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$") }
152152

153153
#[allow(deprecated_owned_vector)]
154-
fn gen_text(n: uint) -> ~str {
154+
fn gen_text(n: uint) -> StrBuf {
155155
let mut rng = task_rng();
156156
let mut bytes = rng.gen_ascii_str(n).into_bytes();
157157
for (i, b) in bytes.mut_iter().enumerate() {
158158
if i % 20 == 0 {
159159
*b = '\n' as u8
160160
}
161161
}
162-
str::from_utf8(bytes).unwrap().to_owned()
162+
str::from_utf8(bytes).unwrap().to_strbuf()
163163
}
164164

165165
throughput!(easy0_32, easy0(), 32)

branches/dist-snap/src/libregex_macros/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ struct NfaGen<'a> {
105105
cx: &'a ExtCtxt<'a>,
106106
sp: codemap::Span,
107107
prog: Program,
108-
names: Vec<Option<~str>>,
109-
original: ~str,
108+
names: Vec<Option<StrBuf>>,
109+
original: StrBuf,
110110
}
111111

112112
impl<'a> NfaGen<'a> {
@@ -119,7 +119,7 @@ impl<'a> NfaGen<'a> {
119119
|cx, name| match *name {
120120
Some(ref name) => {
121121
let name = name.as_slice();
122-
quote_expr!(cx, Some($name.to_owned()))
122+
quote_expr!(cx, Some($name.to_strbuf()))
123123
}
124124
None => cx.expr_none(self.sp),
125125
}
@@ -311,7 +311,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
311311
}
312312

313313
::regex::Regex {
314-
original: $regex.to_owned(),
314+
original: $regex.to_strbuf(),
315315
names: vec!$cap_names,
316316
p: ::regex::native::Native(exec),
317317
}
@@ -601,14 +601,14 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
601601

602602
/// Looks for a single string literal and returns it.
603603
/// Otherwise, logs an error with cx.span_err and returns None.
604-
fn parse(cx: &mut ExtCtxt, tts: &[ast::TokenTree]) -> Option<~str> {
604+
fn parse(cx: &mut ExtCtxt, tts: &[ast::TokenTree]) -> Option<StrBuf> {
605605
let mut parser = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(),
606606
Vec::from_slice(tts));
607607
let entry = cx.expand_expr(parser.parse_expr());
608608
let regex = match entry.node {
609609
ast::ExprLit(lit) => {
610610
match lit.node {
611-
ast::LitStr(ref s, _) => s.to_str(),
611+
ast::LitStr(ref s, _) => s.to_str().to_strbuf(),
612612
_ => {
613613
cx.span_err(entry.span, format!(
614614
"expected string literal but got `{}`",

0 commit comments

Comments
 (0)