Skip to content

Commit f5e6f56

Browse files
committed
---
yaml --- r: 113083 b: refs/heads/try c: 84da1b2 h: refs/heads/master i: 113081: b874ce2 113079: b71a693 v: v3
1 parent 694ac1c commit f5e6f56

File tree

3 files changed

+60
-47
lines changed

3 files changed

+60
-47
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: abdacecdf86b4b5a4f432560445a24e1c5f4751b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 922c420fcd4dfbfc7e3bce4dd20d9b17a20b39f3
5-
refs/heads/try: e6c5813eab756d7d0ed41b2af9831ed2d4775025
5+
refs/heads/try: 84da1b26c760128dfc0cf3b9de00a1a12dd1450e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/ascii.rs

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ pub trait OwnedAsciiCast {
217217

218218
/// Take ownership and cast to an ascii vector. Fail on non-ASCII input.
219219
#[inline]
220-
fn into_ascii(self) -> ~[Ascii] {
220+
fn into_ascii(self) -> Vec<Ascii> {
221221
assert!(self.is_ascii());
222222
unsafe {self.into_ascii_nocheck()}
223223
}
224224

225225
/// Take ownership and cast to an ascii vector. Return None on non-ASCII input.
226226
#[inline]
227-
fn into_ascii_opt(self) -> Option<~[Ascii]> {
227+
fn into_ascii_opt(self) -> Option<Vec<Ascii>> {
228228
if self.is_ascii() {
229229
Some(unsafe { self.into_ascii_nocheck() })
230230
} else {
@@ -234,7 +234,7 @@ pub trait OwnedAsciiCast {
234234

235235
/// Take ownership and cast to an ascii vector.
236236
/// Does not perform validation checks.
237-
unsafe fn into_ascii_nocheck(self) -> ~[Ascii];
237+
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii>;
238238
}
239239

240240
impl OwnedAsciiCast for ~[u8] {
@@ -244,8 +244,8 @@ impl OwnedAsciiCast for ~[u8] {
244244
}
245245

246246
#[inline]
247-
unsafe fn into_ascii_nocheck(self) -> ~[Ascii] {
248-
cast::transmute(self)
247+
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
248+
cast::transmute(Vec::from_slice(self.as_slice()))
249249
}
250250
}
251251

@@ -256,7 +256,20 @@ impl OwnedAsciiCast for ~str {
256256
}
257257

258258
#[inline]
259-
unsafe fn into_ascii_nocheck(self) -> ~[Ascii] {
259+
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
260+
let v: ~[u8] = cast::transmute(self);
261+
v.into_ascii_nocheck()
262+
}
263+
}
264+
265+
impl OwnedAsciiCast for Vec<u8> {
266+
#[inline]
267+
fn is_ascii(&self) -> bool {
268+
self.as_slice().is_ascii()
269+
}
270+
271+
#[inline]
272+
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
260273
cast::transmute(self)
261274
}
262275
}
@@ -268,10 +281,10 @@ pub trait AsciiStr {
268281
fn as_str_ascii<'a>(&'a self) -> &'a str;
269282

270283
/// Convert to vector representing a lower cased ascii string.
271-
fn to_lower(&self) -> ~[Ascii];
284+
fn to_lower(&self) -> Vec<Ascii>;
272285

273286
/// Convert to vector representing a upper cased ascii string.
274-
fn to_upper(&self) -> ~[Ascii];
287+
fn to_upper(&self) -> Vec<Ascii>;
275288

276289
/// Compares two Ascii strings ignoring case.
277290
fn eq_ignore_case(self, other: &[Ascii]) -> bool;
@@ -284,12 +297,12 @@ impl<'a> AsciiStr for &'a [Ascii] {
284297
}
285298

286299
#[inline]
287-
fn to_lower(&self) -> ~[Ascii] {
300+
fn to_lower(&self) -> Vec<Ascii> {
288301
self.iter().map(|a| a.to_lower()).collect()
289302
}
290303

291304
#[inline]
292-
fn to_upper(&self) -> ~[Ascii] {
305+
fn to_upper(&self) -> Vec<Ascii> {
293306
self.iter().map(|a| a.to_upper()).collect()
294307
}
295308

@@ -309,19 +322,21 @@ impl IntoStr for ~[Ascii] {
309322
impl IntoStr for Vec<Ascii> {
310323
#[inline]
311324
fn into_str(self) -> ~str {
312-
let v: ~[Ascii] = self.move_iter().collect();
313-
unsafe { cast::transmute(v) }
325+
unsafe {
326+
let s: &str = cast::transmute(self.as_slice());
327+
s.to_owned()
328+
}
314329
}
315330
}
316331

317-
/// Trait to convert to an owned byte array by consuming self
332+
/// Trait to convert to an owned byte vector by consuming self
318333
pub trait IntoBytes {
319-
/// Converts to an owned byte array by consuming self
320-
fn into_bytes(self) -> ~[u8];
334+
/// Converts to an owned byte vector by consuming self
335+
fn into_bytes(self) -> Vec<u8>;
321336
}
322337

323-
impl IntoBytes for ~[Ascii] {
324-
fn into_bytes(self) -> ~[u8] {
338+
impl IntoBytes for Vec<Ascii> {
339+
fn into_bytes(self) -> Vec<u8> {
325340
unsafe { cast::transmute(self) }
326341
}
327342
}
@@ -404,9 +419,11 @@ unsafe fn str_map_bytes(string: ~str, map: &'static [u8]) -> ~str {
404419

405420
#[inline]
406421
unsafe fn str_copy_map_bytes(string: &str, map: &'static [u8]) -> ~str {
407-
let bytes = string.bytes().map(|b| map[b as uint]).collect::<~[_]>();
408-
409-
str::raw::from_utf8_owned(bytes)
422+
let mut s = string.to_owned();
423+
for b in str::raw::as_owned_vec(&mut s).mut_iter() {
424+
*b = map[*b as uint];
425+
}
426+
s
410427
}
411428

412429
static ASCII_LOWER_MAP: &'static [u8] = &[
@@ -492,7 +509,6 @@ mod tests {
492509
macro_rules! v2ascii (
493510
( [$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
494511
(&[$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
495-
(~[$($e:expr),*]) => (box [$(Ascii{chr:$e}),*]);
496512
)
497513

498514
macro_rules! vec2ascii (
@@ -556,20 +572,17 @@ mod tests {
556572

557573
#[test]
558574
fn test_ascii_vec_ng() {
559-
assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_lower()).into_str(),
560-
"abcdef&?#".to_owned());
561-
assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_upper()).into_str(),
562-
"ABCDEF&?#".to_owned());
563-
assert_eq!(Vec::from_slice("".to_ascii().to_lower()).into_str(), "".to_owned());
564-
assert_eq!(Vec::from_slice("YMCA".to_ascii().to_lower()).into_str(), "ymca".to_owned());
565-
assert_eq!(Vec::from_slice("abcDEFxyz:.;".to_ascii().to_upper()).into_str(),
566-
"ABCDEFXYZ:.;".to_owned());
575+
assert_eq!("abCDef&?#".to_ascii().to_lower().into_str(), "abcdef&?#".to_owned());
576+
assert_eq!("abCDef&?#".to_ascii().to_upper().into_str(), "ABCDEF&?#".to_owned());
577+
assert_eq!("".to_ascii().to_lower().into_str(), "".to_owned());
578+
assert_eq!("YMCA".to_ascii().to_lower().into_str(), "ymca".to_owned());
579+
assert_eq!("abcDEFxyz:.;".to_ascii().to_upper().into_str(), "ABCDEFXYZ:.;".to_owned());
567580
}
568581

569582
#[test]
570583
fn test_owned_ascii_vec() {
571-
assert_eq!(("( ;".to_owned()).into_ascii(), v2ascii!(~[40, 32, 59]));
572-
assert_eq!((box [40u8, 32u8, 59u8]).into_ascii(), v2ascii!(~[40, 32, 59]));
584+
assert_eq!(("( ;".to_owned()).into_ascii(), vec2ascii![40, 32, 59]);
585+
assert_eq!((box [40u8, 32u8, 59u8]).into_ascii(), vec2ascii![40, 32, 59]);
573586
}
574587

575588
#[test]
@@ -580,13 +593,13 @@ mod tests {
580593

581594
#[test]
582595
fn test_ascii_into_str() {
583-
assert_eq!(v2ascii!(~[40, 32, 59]).into_str(), "( ;".to_owned());
596+
assert_eq!(vec2ascii![40, 32, 59].into_str(), "( ;".to_owned());
584597
assert_eq!(vec2ascii!(40, 32, 59).into_str(), "( ;".to_owned());
585598
}
586599

587600
#[test]
588601
fn test_ascii_to_bytes() {
589-
assert_eq!(v2ascii!(~[40, 32, 59]).into_bytes(), box [40u8, 32u8, 59u8]);
602+
assert_eq!(vec2ascii![40, 32, 59].into_bytes(), vec![40u8, 32u8, 59u8]);
590603
}
591604

592605
#[test] #[should_fail]
@@ -625,10 +638,10 @@ mod tests {
625638
assert_eq!(v.to_ascii_opt(), Some(v2));
626639
assert_eq!("zoä华".to_ascii_opt(), None);
627640

628-
assert_eq!((box [40u8, 32u8, 59u8]).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
629-
assert_eq!((box [127u8, 128u8, 255u8]).into_ascii_opt(), None);
641+
assert_eq!((vec![40u8, 32u8, 59u8]).into_ascii_opt(), Some(vec2ascii![40, 32, 59]));
642+
assert_eq!((vec![127u8, 128u8, 255u8]).into_ascii_opt(), None);
630643

631-
assert_eq!(("( ;".to_owned()).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
644+
assert_eq!(("( ;".to_owned()).into_ascii_opt(), Some(vec2ascii![40, 32, 59]));
632645
assert_eq!(("zoä华".to_owned()).into_ascii_opt(), None);
633646
}
634647

branches/try/src/libstd/num/strconv.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use option::{None, Option, Some};
2222
use slice::OwnedVector;
2323
use slice::{CloneableVector, ImmutableVector, MutableVector};
2424
use std::cmp::{Ord, Eq};
25-
use str::{StrSlice};
26-
use str;
25+
use str::{Str, StrSlice};
26+
use strbuf::StrBuf;
2727
use vec::Vec;
2828

2929
/// A flag that specifies whether to use exponential (scientific) notation.
@@ -262,7 +262,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+
262262
Div<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>(
263263
num: T, radix: uint, negative_zero: bool,
264264
sign: SignFormat, digits: SignificantDigits, exp_format: ExponentFormat, exp_upper: bool
265-
) -> (~[u8], bool) {
265+
) -> (Vec<u8>, bool) {
266266
assert!(2 <= radix && radix <= 36);
267267
match exp_format {
268268
ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e'
@@ -278,17 +278,17 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+
278278
let _1: T = One::one();
279279

280280
match num.classify() {
281-
FPNaN => { return ("NaN".as_bytes().to_owned(), true); }
281+
FPNaN => { return (Vec::from_slice("NaN".as_bytes()), true); }
282282
FPInfinite if num > _0 => {
283283
return match sign {
284-
SignAll => ("+inf".as_bytes().to_owned(), true),
285-
_ => ("inf".as_bytes().to_owned(), true)
284+
SignAll => (Vec::from_slice("+inf".as_bytes()), true),
285+
_ => (Vec::from_slice("inf".as_bytes()), true)
286286
};
287287
}
288288
FPInfinite if num < _0 => {
289289
return match sign {
290-
SignNone => ("inf".as_bytes().to_owned(), true),
291-
_ => ("-inf".as_bytes().to_owned(), true),
290+
SignNone => (Vec::from_slice("inf".as_bytes()), true),
291+
_ => (Vec::from_slice("-inf".as_bytes()), true),
292292
};
293293
}
294294
_ => {}
@@ -483,7 +483,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+
483483
}
484484
}
485485

486-
(buf.move_iter().collect(), false)
486+
(buf, false)
487487
}
488488

489489
/**
@@ -498,7 +498,7 @@ pub fn float_to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Float+
498498
) -> (~str, bool) {
499499
let (bytes, special) = float_to_str_bytes_common(num, radix,
500500
negative_zero, sign, digits, exp_format, exp_capital);
501-
(str::from_utf8_owned(bytes).unwrap(), special)
501+
(StrBuf::from_utf8(bytes).unwrap().into_owned(), special)
502502
}
503503

504504
// Some constants for from_str_bytes_common's input validation,

0 commit comments

Comments
 (0)