Skip to content

Commit d3ef547

Browse files
committed
---
yaml --- r: 57182 b: refs/heads/try c: 11d04d4 h: refs/heads/master v: v3
1 parent e347519 commit d3ef547

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1054
-1902
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: dcd49ccd0ba5616995da00454389b6454423813c
5+
refs/heads/try: 11d04d452fa8fd8adde10f8de902bfffc59ab704
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/doc/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ An example of `use` declarations:
802802

803803
~~~~
804804
use core::float::sin;
805-
use core::str::{slice, contains};
805+
use core::str::{slice, to_upper};
806806
use core::option::Some;
807807
808808
fn main() {
@@ -813,8 +813,8 @@ fn main() {
813813
info!(Some(1.0));
814814
815815
// Equivalent to
816-
// 'info!(core::str::contains(core::str::slice("foo", 0, 1), "oo"));'
817-
info!(contains(slice("foo", 0, 1), "oo"));
816+
// 'info!(core::str::to_upper(core::str::slice("foo", 0, 1)));'
817+
info!(to_upper(slice("foo", 0, 1)));
818818
}
819819
~~~~
820820

branches/try/src/compiletest/errors.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
5050
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
5151
let start_kind = idx;
5252
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
53-
54-
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
55-
// to_ascii_consume and to_str_consume to not do a unnecessary copy.
56-
let kind = str::slice(line, start_kind, idx);
57-
let kind = kind.to_ascii().to_lower().to_str_ascii();
53+
let kind = str::to_lower(str::slice(line, start_kind, idx).to_owned());
5854

5955
// Extract msg:
6056
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }

branches/try/src/libcore/char.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ pub fn is_alphanumeric(c: char) -> bool {
100100
unicode::general_category::No(c);
101101
}
102102

103+
/// Indicates whether the character is an ASCII character
104+
#[inline(always)]
105+
pub fn is_ascii(c: char) -> bool {
106+
c - ('\x7F' & c) == '\x00'
107+
}
108+
103109
/// Indicates whether the character is numeric (Nd, Nl, or No)
104110
#[inline(always)]
105111
pub fn is_digit(c: char) -> bool {
@@ -110,7 +116,7 @@ pub fn is_digit(c: char) -> bool {
110116

111117
/**
112118
* Checks if a character parses as a numeric digit in the given radix.
113-
* Compared to `is_digit()`, this function only recognizes the
119+
* Compared to `is_digit()`, this function only recognizes the ascii
114120
* characters `0-9`, `a-z` and `A-Z`.
115121
*
116122
* Returns `true` if `c` is a valid digit under `radix`, and `false`
@@ -157,7 +163,7 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
157163
}
158164

159165
/**
160-
* Converts a number to the character representing it.
166+
* Converts a number to the ascii character representing it.
161167
*
162168
* Returns `Some(char)` if `num` represents one digit under `radix`,
163169
* using one character of `0-9` or `a-z`, or `None` if it doesn't.
@@ -310,6 +316,12 @@ fn test_to_digit() {
310316
assert!(to_digit('$', 36u).is_none());
311317
}
312318
319+
#[test]
320+
fn test_is_ascii() {
321+
assert!(str::all(~"banana", is_ascii));
322+
assert!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
323+
}
324+
313325
#[test]
314326
fn test_is_digit() {
315327
assert!(is_digit('2'));

branches/try/src/libcore/core.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ pub use kinds::{Const, Copy, Owned, Durable};
7777
pub use ops::{Drop};
7878
#[cfg(stage0)]
7979
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not};
80-
#[cfg(not(stage0))]
80+
#[cfg(stage1)]
81+
#[cfg(stage2)]
82+
#[cfg(stage3)]
8183
pub use ops::{Add, Sub, Mul, Quot, Rem, Neg, Not};
8284
pub use ops::{BitAnd, BitOr, BitXor};
8385
pub use ops::{Shl, Shr, Index};
@@ -104,8 +106,6 @@ pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
104106
pub use iter::{ExtendedMutableIter};
105107

106108
pub use num::{Num, NumCast};
107-
pub use num::{Signed, Unsigned, Integer};
108-
pub use num::{Fractional, Real, RealExt};
109109
pub use ptr::Ptr;
110110
pub use to_str::ToStr;
111111
pub use clone::Clone;

branches/try/src/libcore/flate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
8585
#[test]
8686
#[allow(non_implicitly_copyable_typarams)]
8787
fn test_flate_round_trip() {
88-
let r = rand::rng();
88+
let r = rand::Rng();
8989
let mut words = ~[];
9090
for 20.times {
9191
words.push(r.gen_bytes(r.gen_uint_range(1, 10)));

branches/try/src/libcore/hashmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn resize_at(capacity: uint) -> uint {
5656
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
5757
initial_capacity: uint) -> HashMap<K, V> {
5858
let r = rand::task_rng();
59-
linear_map_with_capacity_and_keys(r.gen(), r.gen(),
59+
linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(),
6060
initial_capacity)
6161
}
6262

branches/try/src/libcore/iterator.rs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ impl<A, T: Iterator<A>> Iterator<A> for TakeIterator<T> {
312312
}
313313
}
314314

315+
pub struct ScanIterator<'self, A, B, T, St> {
316+
priv iter: T,
317+
priv f: &'self fn(&mut St, A) -> Option<B>,
318+
state: St
319+
}
320+
321+
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
322+
#[inline]
323+
fn next(&mut self) -> Option<B> {
324+
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
325+
}
326+
}
327+
315328
pub struct UnfoldrIterator<'self, A, St> {
316329
priv f: &'self fn(&mut St) -> Option<A>,
317330
state: St
@@ -335,16 +348,25 @@ impl<'self, A, St> Iterator<A> for UnfoldrIterator<'self, A, St> {
335348
}
336349
}
337350

338-
pub struct ScanIterator<'self, A, B, T, St> {
339-
priv iter: T,
340-
priv f: &'self fn(&mut St, A) -> Option<B>,
341-
state: St
351+
/// An infinite iterator starting at `start` and advancing by `step` with each iteration
352+
pub struct Counter<A> {
353+
state: A,
354+
step: A
342355
}
343356

344-
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
345-
#[inline]
346-
fn next(&mut self) -> Option<B> {
347-
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
357+
pub impl<A> Counter<A> {
358+
#[inline(always)]
359+
fn new(start: A, step: A) -> Counter<A> {
360+
Counter{state: start, step: step}
361+
}
362+
}
363+
364+
impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
365+
#[inline(always)]
366+
fn next(&mut self) -> Option<A> {
367+
let result = self.state.clone();
368+
self.state = self.state.add(&self.step); // FIXME: #6050
369+
Some(result)
348370
}
349371
}
350372

@@ -353,6 +375,13 @@ mod tests {
353375
use super::*;
354376
use prelude::*;
355377

378+
#[test]
379+
fn test_counter_to_vec() {
380+
let mut it = Counter::new(0, 5).take(10);
381+
let xs = iter::iter_to_vec(|f| it.advance(f));
382+
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
383+
}
384+
356385
#[test]
357386
fn test_iterator_chain() {
358387
let xs = [0u, 1, 2, 3, 4, 5];

0 commit comments

Comments
 (0)