Skip to content

Commit 7d06297

Browse files
committed
---
yaml --- r: 145001 b: refs/heads/try2 c: b7435cf h: refs/heads/master i: 144999: 75d13a1 v: v3
1 parent dcb2f04 commit 7d06297

File tree

29 files changed

+245
-700
lines changed

29 files changed

+245
-700
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a6be8d353bc25e160bc988e91744571547d12cab
8+
refs/heads/try2: b7435cf44783c9ab6cf16bc387299ed9891ae90d
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/comm.rs

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -90,55 +90,9 @@ pub fn DuplexStream<T:Send,U:Send>()
9090
})
9191
}
9292

93-
/// An extension of `pipes::stream` that provides synchronous message sending.
94-
pub struct SyncChan<T> { priv duplex_stream: DuplexStream<T, ()> }
95-
/// An extension of `pipes::stream` that acknowledges each message received.
96-
pub struct SyncPort<T> { priv duplex_stream: DuplexStream<(), T> }
97-
98-
impl<T: Send> GenericChan<T> for SyncChan<T> {
99-
fn send(&self, val: T) {
100-
assert!(self.try_send(val), "SyncChan.send: receiving port closed");
101-
}
102-
}
103-
104-
impl<T: Send> GenericSmartChan<T> for SyncChan<T> {
105-
/// Sends a message, or report if the receiver has closed the connection before receiving.
106-
fn try_send(&self, val: T) -> bool {
107-
self.duplex_stream.try_send(val) && self.duplex_stream.try_recv().is_some()
108-
}
109-
}
110-
111-
impl<T: Send> GenericPort<T> for SyncPort<T> {
112-
fn recv(&self) -> T {
113-
self.try_recv().expect("SyncPort.recv: sending channel closed")
114-
}
115-
116-
fn try_recv(&self) -> Option<T> {
117-
do self.duplex_stream.try_recv().map_move |val| {
118-
self.duplex_stream.try_send(());
119-
val
120-
}
121-
}
122-
}
123-
124-
impl<T: Send> Peekable<T> for SyncPort<T> {
125-
fn peek(&self) -> bool {
126-
self.duplex_stream.peek()
127-
}
128-
}
129-
130-
/// Creates a stream whose channel, upon sending a message, blocks until the message is received.
131-
pub fn rendezvous<T: Send>() -> (SyncPort<T>, SyncChan<T>) {
132-
let (chan_stream, port_stream) = DuplexStream();
133-
(SyncPort { duplex_stream: port_stream }, SyncChan { duplex_stream: chan_stream })
134-
}
135-
13693
#[cfg(test)]
13794
mod test {
138-
use comm::{DuplexStream, rendezvous};
139-
use std::rt::test::run_in_newsched_task;
140-
use std::task::spawn_unlinked;
141-
95+
use comm::DuplexStream;
14296

14397
#[test]
14498
pub fn DuplexStream1() {
@@ -150,58 +104,4 @@ mod test {
150104
assert!(left.recv() == 123);
151105
assert!(right.recv() == ~"abc");
152106
}
153-
154-
#[test]
155-
pub fn basic_rendezvous_test() {
156-
let (port, chan) = rendezvous();
157-
158-
do spawn {
159-
chan.send("abc");
160-
}
161-
162-
assert!(port.recv() == "abc");
163-
}
164-
165-
#[test]
166-
fn recv_a_lot() {
167-
// Rendezvous streams should be able to handle any number of messages being sent
168-
do run_in_newsched_task {
169-
let (port, chan) = rendezvous();
170-
do spawn {
171-
do 1000000.times { chan.send(()) }
172-
}
173-
do 1000000.times { port.recv() }
174-
}
175-
}
176-
177-
#[test]
178-
fn send_and_fail_and_try_recv() {
179-
let (port, chan) = rendezvous();
180-
do spawn_unlinked {
181-
chan.duplex_stream.send(()); // Can't access this field outside this module
182-
fail!()
183-
}
184-
port.recv()
185-
}
186-
187-
#[test]
188-
fn try_send_and_recv_then_fail_before_ack() {
189-
let (port, chan) = rendezvous();
190-
do spawn_unlinked {
191-
port.duplex_stream.recv();
192-
fail!()
193-
}
194-
chan.try_send(());
195-
}
196-
197-
#[test]
198-
#[should_fail]
199-
fn send_and_recv_then_fail_before_ack() {
200-
let (port, chan) = rendezvous();
201-
do spawn_unlinked {
202-
port.duplex_stream.recv();
203-
fail!()
204-
}
205-
chan.send(());
206-
}
207107
}

branches/try2/src/libextra/glob.rs

Lines changed: 14 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,8 @@ enum PatternToken {
147147
Char(char),
148148
AnyChar,
149149
AnySequence,
150-
AnyWithin(~[CharSpecifier]),
151-
AnyExcept(~[CharSpecifier])
152-
}
153-
154-
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes)]
155-
enum CharSpecifier {
156-
SingleChar(char),
157-
CharRange(char, char)
150+
AnyWithin(~[char]),
151+
AnyExcept(~[char])
158152
}
159153
160154
#[deriving(Eq)]
@@ -170,15 +164,12 @@ impl Pattern {
170164
* This function compiles Unix shell style patterns: `?` matches any single character,
171165
* `*` matches any (possibly empty) sequence of characters and `[...]` matches any character
172166
* inside the brackets, unless the first character is `!` in which case it matches any
173-
* character except those between the `!` and the `]`. Character sequences can also specify
174-
* ranges of characters, as ordered by Unicode, so e.g. `[0-9]` specifies any character
175-
* between 0 and 9 inclusive.
167+
* character except those between the `!` and the `]`.
176168
*
177169
* The metacharacters `?`, `*`, `[`, `]` can be matched by using brackets (e.g. `[?]`).
178170
* When a `]` occurs immediately following `[` or `[!` then it is interpreted as
179171
* being part of, rather then ending, the character set, so `]` and NOT `]` can be
180-
* matched by `[]]` and `[!]]` respectively. The `-` character can be specified inside a
181-
* character sequence pattern by placing it at the start or the end, e.g. `[abc-]`.
172+
* matched by `[]]` and `[!]]` respectively.
182173
*
183174
* When a `[` does not have a closing `]` before the end of the string then the `[` will
184175
* be treated literally.
@@ -208,8 +199,7 @@ impl Pattern {
208199
match chars.slice_from(i + 3).position_elem(&']') {
209200
None => (),
210201
Some(j) => {
211-
let cs = parse_char_specifiers(chars.slice(i + 2, i + 3 + j));
212-
tokens.push(AnyExcept(cs));
202+
tokens.push(AnyExcept(chars.slice(i + 2, i + 3 + j).to_owned()));
213203
i += j + 4;
214204
loop;
215205
}
@@ -219,8 +209,7 @@ impl Pattern {
219209
match chars.slice_from(i + 2).position_elem(&']') {
220210
None => (),
221211
Some(j) => {
222-
let cs = parse_char_specifiers(chars.slice(i + 1, i + 2 + j));
223-
tokens.push(AnyWithin(cs));
212+
tokens.push(AnyWithin(chars.slice(i + 1, i + 2 + j).to_owned()));
224213
i += j + 3;
225214
loop;
226215
}
@@ -346,11 +335,15 @@ impl Pattern {
346335
AnyChar => {
347336
!require_literal(c)
348337
}
349-
AnyWithin(ref specifiers) => {
350-
!require_literal(c) && in_char_specifiers(*specifiers, c, options)
338+
AnyWithin(ref chars) => {
339+
!require_literal(c) &&
340+
chars.iter()
341+
.rposition(|&e| chars_eq(e, c, options.case_sensitive)).is_some()
351342
}
352-
AnyExcept(ref specifiers) => {
353-
!require_literal(c) && !in_char_specifiers(*specifiers, c, options)
343+
AnyExcept(ref chars) => {
344+
!require_literal(c) &&
345+
chars.iter()
346+
.rposition(|&e| chars_eq(e, c, options.case_sensitive)).is_none()
354347
}
355348
Char(c2) => {
356349
chars_eq(c, c2, options.case_sensitive)
@@ -377,63 +370,6 @@ impl Pattern {
377370
378371
}
379372
380-
fn parse_char_specifiers(s: &[char]) -> ~[CharSpecifier] {
381-
let mut cs = ~[];
382-
let mut i = 0;
383-
while i < s.len() {
384-
if i + 3 <= s.len() && s[i + 1] == '-' {
385-
cs.push(CharRange(s[i], s[i + 2]));
386-
i += 3;
387-
} else {
388-
cs.push(SingleChar(s[i]));
389-
i += 1;
390-
}
391-
}
392-
cs
393-
}
394-
395-
fn in_char_specifiers(specifiers: &[CharSpecifier], c: char, options: MatchOptions) -> bool {
396-
397-
for &specifier in specifiers.iter() {
398-
match specifier {
399-
SingleChar(sc) => {
400-
if chars_eq(c, sc, options.case_sensitive) {
401-
return true;
402-
}
403-
}
404-
CharRange(start, end) => {
405-
406-
// FIXME: work with non-ascii chars properly (issue #1347)
407-
if !options.case_sensitive && c.is_ascii() && start.is_ascii() && end.is_ascii() {
408-
409-
let start = start.to_ascii().to_lower();
410-
let end = end.to_ascii().to_lower();
411-
412-
let start_up = start.to_upper();
413-
let end_up = end.to_upper();
414-
415-
// only allow case insensitive matching when
416-
// both start and end are within a-z or A-Z
417-
if start != start_up && end != end_up {
418-
let start = start.to_char();
419-
let end = end.to_char();
420-
let c = c.to_ascii().to_lower().to_char();
421-
if c >= start && c <= end {
422-
return true;
423-
}
424-
}
425-
}
426-
427-
if c >= start && c <= end {
428-
return true;
429-
}
430-
}
431-
}
432-
}
433-
434-
false
435-
}
436-
437373
/// A helper function to determine if two chars are (possibly case-insensitively) equal.
438374
fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
439375
if cfg!(windows) && path::windows::is_sep(a) && path::windows::is_sep(b) {
@@ -736,54 +672,6 @@ mod test {
736672
glob("/*/*/*/*").skip(10000).next();
737673
}
738674

739-
#[test]
740-
fn test_range_pattern() {
741-
742-
let pat = Pattern::new("a[0-9]b");
743-
for i in range(0, 10) {
744-
assert!(pat.matches(fmt!("a%db", i)));
745-
}
746-
assert!(!pat.matches("a_b"));
747-
748-
let pat = Pattern::new("a[!0-9]b");
749-
for i in range(0, 10) {
750-
assert!(!pat.matches(fmt!("a%db", i)));
751-
}
752-
assert!(pat.matches("a_b"));
753-
754-
let pats = ["[a-z123]", "[1a-z23]", "[123a-z]"];
755-
for &p in pats.iter() {
756-
let pat = Pattern::new(p);
757-
for c in "abcdefghijklmnopqrstuvwxyz".iter() {
758-
assert!(pat.matches(c.to_str()));
759-
}
760-
for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".iter() {
761-
let options = MatchOptions {case_sensitive: false, .. MatchOptions::new()};
762-
assert!(pat.matches_with(c.to_str(), options));
763-
}
764-
assert!(pat.matches("1"));
765-
assert!(pat.matches("2"));
766-
assert!(pat.matches("3"));
767-
}
768-
769-
let pats = ["[abc-]", "[-abc]", "[a-c-]"];
770-
for &p in pats.iter() {
771-
let pat = Pattern::new(p);
772-
assert!(pat.matches("a"));
773-
assert!(pat.matches("b"));
774-
assert!(pat.matches("c"));
775-
assert!(pat.matches("-"));
776-
assert!(!pat.matches("d"));
777-
}
778-
779-
let pat = Pattern::new("[2-1]");
780-
assert!(!pat.matches("1"));
781-
assert!(!pat.matches("2"));
782-
783-
assert!(Pattern::new("[-]").matches("-"));
784-
assert!(!Pattern::new("[!-]").matches("-"));
785-
}
786-
787675
#[test]
788676
fn test_unclosed_bracket() {
789677
// unclosed `[` should be treated literally

0 commit comments

Comments
 (0)