Skip to content

Commit b47b505

Browse files
committed
---
yaml --- r: 55799 b: refs/heads/master c: dd74807 h: refs/heads/master i: 55797: 74158d4 55795: 61ab742 55791: 82efc37 v: v3
1 parent e892551 commit b47b505

File tree

13 files changed

+111
-140
lines changed

13 files changed

+111
-140
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 345d5b82351f4f8309498aa34b9f0348b898300d
2+
refs/heads/master: dd748079574197215da46ac164f16a392df9cc26
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a

trunk/src/compiletest/errors.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ 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-
let kind = str::to_lower(str::slice(line, start_kind, idx).to_owned());
53+
54+
// FIXME: 4318 Instead of to_str_ascii, could use
55+
// to_str_consume to not do a unneccessary copy.
56+
let kind = str::slice(line, start_kind, idx).to_ascii().to_lower().to_str_ascii();
5457

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

trunk/src/libcore/char.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ 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-
109103
/// Indicates whether the character is numeric (Nd, Nl, or No)
110104
#[inline(always)]
111105
pub fn is_digit(c: char) -> bool {
@@ -116,7 +110,7 @@ pub fn is_digit(c: char) -> bool {
116110

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

165159
/**
166-
* Converts a number to the ascii character representing it.
160+
* Converts a number to the character representing it.
167161
*
168162
* Returns `Some(char)` if `num` represents one digit under `radix`,
169163
* using one character of `0-9` or `a-z`, or `None` if it doesn't.
@@ -316,12 +310,6 @@ fn test_to_digit() {
316310
assert!(to_digit('$', 36u).is_none());
317311
}
318312
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-
325313
#[test]
326314
fn test_is_digit() {
327315
assert!(is_digit('2'));

trunk/src/libcore/num/uint-template/u8.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@
1010

1111
//! Operations and constants for `u8`
1212
13-
pub use self::inst::is_ascii;
14-
1513
mod inst {
1614
pub type T = u8;
1715
#[allow(non_camel_case_types)]
1816
pub type T_SIGNED = i8;
1917
pub static bits: uint = 8;
20-
21-
// Type-specific functions here. These must be reexported by the
22-
// parent module so that they appear in core::u8 and not core::u8::u8;
23-
24-
pub fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; }
2518
}

trunk/src/libcore/path.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,9 @@ impl GenericPath for WindowsPath {
753753
fn is_restricted(&self) -> bool {
754754
match self.filestem() {
755755
Some(stem) => {
756-
match stem.to_lower() {
756+
// FIXME: 4318 Instead of to_str_ascii, could use
757+
// to_str_consume to not do a unneccessary copy.
758+
match stem.to_ascii().to_lower().to_str_ascii() {
757759
~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" |
758760
~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true,
759761
_ => false
@@ -809,7 +811,10 @@ impl GenericPath for WindowsPath {
809811
host: copy self.host,
810812
device: match self.device {
811813
None => None,
812-
Some(ref device) => Some(device.to_upper())
814+
815+
// FIXME: 4318 Instead of to_str_ascii, could use
816+
// to_str_consume to not do a unneccessary copy.
817+
Some(ref device) => Some(device.to_ascii().to_upper().to_str_ascii())
813818
},
814819
is_absolute: self.is_absolute,
815820
components: normalize(self.components)

trunk/src/libcore/run.rs

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,16 @@ pub struct RunProgramResult {
4747
handle: *(),
4848
}
4949

50-
/// A value representing a child process
51-
pub struct Program {
52-
priv pid: pid_t,
53-
priv handle: *(),
54-
priv in_fd: c_int,
55-
priv out_file: *libc::FILE,
56-
priv err_file: *libc::FILE,
57-
priv finished: bool,
58-
}
59-
60-
impl Drop for Program {
61-
fn finalize(&self) {
62-
// FIXME #4943: transmute is bad.
63-
let mut_self: &mut Program = unsafe { cast::transmute(self) };
64-
65-
mut_self.finish();
66-
mut_self.close_outputs();
67-
free_handle(self.handle);
68-
}
50+
struct ProgRepr {
51+
pid: pid_t,
52+
handle: *(),
53+
in_fd: c_int,
54+
out_file: *libc::FILE,
55+
err_file: *libc::FILE,
56+
finished: bool,
6957
}
7058

71-
pub impl Program {
72-
73-
/// Returns the process id of the program
74-
fn get_id(&mut self) -> pid_t { self.pid }
75-
76-
/// Returns an io::Writer that can be used to write to stdin
77-
fn input(&mut self) -> @io::Writer {
78-
io::fd_writer(self.in_fd, false)
79-
}
80-
81-
/// Returns an io::Reader that can be used to read from stdout
82-
fn output(&mut self) -> @io::Reader {
83-
io::FILE_reader(self.out_file, false)
84-
}
85-
86-
/// Returns an io::Reader that can be used to read from stderr
87-
fn err(&mut self) -> @io::Reader {
88-
io::FILE_reader(self.err_file, false)
89-
}
90-
91-
/// Closes the handle to the child processes standard input
59+
impl ProgRepr {
9260
fn close_input(&mut self) {
9361
let invalid_fd = -1i32;
9462
if self.in_fd != invalid_fd {
@@ -99,25 +67,21 @@ pub impl Program {
9967
}
10068
}
10169

102-
priv fn close_outputs(&mut self) {
70+
fn close_outputs(&mut self) {
10371
unsafe {
10472
fclose_and_null(&mut self.out_file);
10573
fclose_and_null(&mut self.err_file);
10674
}
10775
}
10876

109-
/**
110-
* Waits for the child process to terminate. Closes the handle
111-
* to stdin if necessary.
112-
*/
11377
fn finish(&mut self) -> int {
11478
if self.finished { return 0; }
11579
self.finished = true;
11680
self.close_input();
11781
return waitpid(self.pid);
11882
}
11983

120-
priv fn destroy_internal(&mut self, force: bool) {
84+
fn destroy(&mut self, force: bool) {
12185
killpid(self.pid, force);
12286
self.finish();
12387
self.close_outputs();
@@ -143,6 +107,57 @@ pub impl Program {
143107
}
144108
}
145109
}
110+
}
111+
112+
/// A value representing a child process
113+
pub struct Program {
114+
priv r: ProgRepr,
115+
}
116+
117+
impl Drop for Program {
118+
fn finalize(&self) {
119+
// FIXME #4943: transmute is bad.
120+
let selfr: &mut ProgRepr = unsafe { cast::transmute(&self.r) };
121+
122+
selfr.finish();
123+
selfr.close_outputs();
124+
free_handle(self.r.handle);
125+
}
126+
}
127+
128+
pub impl Program {
129+
priv fn new(r: ProgRepr) -> Program {
130+
Program {
131+
r: r
132+
}
133+
}
134+
135+
/// Returns the process id of the program
136+
fn get_id(&mut self) -> pid_t { self.r.pid }
137+
138+
/// Returns an io::Writer that can be used to write to stdin
139+
fn input(&mut self) -> @io::Writer {
140+
io::fd_writer(self.r.in_fd, false)
141+
}
142+
143+
/// Returns an io::Reader that can be used to read from stdout
144+
fn output(&mut self) -> @io::Reader {
145+
io::FILE_reader(self.r.out_file, false)
146+
}
147+
148+
/// Returns an io::Reader that can be used to read from stderr
149+
fn err(&mut self) -> @io::Reader {
150+
io::FILE_reader(self.r.err_file, false)
151+
}
152+
153+
/// Closes the handle to the child processes standard input
154+
fn close_input(&mut self) { self.r.close_input(); }
155+
156+
/**
157+
* Waits for the child process to terminate. Closes the handle
158+
* to stdin if necessary.
159+
*/
160+
fn finish(&mut self) -> int { self.r.finish() }
146161

147162
/**
148163
* Terminate the program, giving it a chance to clean itself up if
@@ -151,7 +166,7 @@ pub impl Program {
151166
* On Posix OSs SIGTERM will be sent to the process. On Win32
152167
* TerminateProcess(..) will be called.
153168
*/
154-
fn destroy(&mut self) { self.destroy_internal(false); }
169+
fn destroy(&mut self) { self.r.destroy(false); }
155170

156171
/**
157172
* Terminate the program as soon as possible without giving it a
@@ -160,7 +175,7 @@ pub impl Program {
160175
* On Posix OSs SIGKILL will be sent to the process. On Win32
161176
* TerminateProcess(..) will be called.
162177
*/
163-
fn force_destroy(&mut self) { self.destroy_internal(true); }
178+
fn force_destroy(&mut self) { self.r.destroy(true); }
164179
}
165180

166181

@@ -351,14 +366,16 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
351366
libc::close(pipe_err.out);
352367
}
353368

354-
Program {
369+
let repr = ProgRepr {
355370
pid: res.pid,
356371
handle: res.handle,
357372
in_fd: pipe_input.out,
358373
out_file: os::fdopen(pipe_output.in),
359374
err_file: os::fdopen(pipe_err.in),
360375
finished: false,
361-
}
376+
};
377+
378+
Program::new(repr)
362379
}
363380

364381
fn read_all(rd: @io::Reader) -> ~str {

trunk/src/libcore/str.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -787,22 +787,6 @@ pub fn each_split_within<'a>(ss: &'a str,
787787
}
788788
}
789789

790-
/// Convert a string to lowercase. ASCII only
791-
pub fn to_lower(s: &str) -> ~str {
792-
do map(s) |c| {
793-
assert!(char::is_ascii(c));
794-
(unsafe{libc::tolower(c as libc::c_char)}) as char
795-
}
796-
}
797-
798-
/// Convert a string to uppercase. ASCII only
799-
pub fn to_upper(s: &str) -> ~str {
800-
do map(s) |c| {
801-
assert!(char::is_ascii(c));
802-
(unsafe{libc::toupper(c as libc::c_char)}) as char
803-
}
804-
}
805-
806790
/**
807791
* Replace all occurrences of one string with another
808792
*
@@ -1610,13 +1594,6 @@ pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
16101594
Section: String properties
16111595
*/
16121596

1613-
/// Determines if a string contains only ASCII characters
1614-
pub fn is_ascii(s: &str) -> bool {
1615-
let mut i: uint = len(s);
1616-
while i > 0u { i -= 1u; if !u8::is_ascii(s[i]) { return false; } }
1617-
return true;
1618-
}
1619-
16201597
/// Returns true if the string has length 0
16211598
pub fn is_empty(s: &str) -> bool { len(s) == 0u }
16221599

@@ -2403,8 +2380,6 @@ pub trait StrSlice<'self> {
24032380
fn each_split_str<'a>(&self, sep: &'a str, it: &fn(&'self str) -> bool);
24042381
fn starts_with<'a>(&self, needle: &'a str) -> bool;
24052382
fn substr(&self, begin: uint, n: uint) -> &'self str;
2406-
fn to_lower(&self) -> ~str;
2407-
fn to_upper(&self) -> ~str;
24082383
fn escape_default(&self) -> ~str;
24092384
fn escape_unicode(&self) -> ~str;
24102385
fn trim(&self) -> &'self str;
@@ -2565,12 +2540,6 @@ impl<'self> StrSlice<'self> for &'self str {
25652540
fn substr(&self, begin: uint, n: uint) -> &'self str {
25662541
substr(*self, begin, n)
25672542
}
2568-
/// Convert a string to lowercase
2569-
#[inline]
2570-
fn to_lower(&self) -> ~str { to_lower(*self) }
2571-
/// Convert a string to uppercase
2572-
#[inline]
2573-
fn to_upper(&self) -> ~str { to_upper(*self) }
25742543
/// Escape each char in `s` with char::escape_default.
25752544
#[inline]
25762545
fn escape_default(&self) -> ~str { escape_default(*self) }
@@ -3084,27 +3053,6 @@ mod tests {
30843053
assert!(repeat(~"hi", 0) == ~"");
30853054
}
30863055
3087-
#[test]
3088-
fn test_to_upper() {
3089-
// libc::toupper, and hence str::to_upper
3090-
// are culturally insensitive: they only work for ASCII
3091-
// (see Issue #1347)
3092-
let unicode = ~""; //"\u65e5\u672c"; // uncomment once non-ASCII works
3093-
let input = ~"abcDEF" + unicode + ~"xyz:.;";
3094-
let expected = ~"ABCDEF" + unicode + ~"XYZ:.;";
3095-
let actual = to_upper(input);
3096-
assert!(expected == actual);
3097-
}
3098-
3099-
#[test]
3100-
fn test_to_lower() {
3101-
// libc::tolower, and hence str::to_lower
3102-
// are culturally insensitive: they only work for ASCII
3103-
// (see Issue #1347)
3104-
assert!(~"" == to_lower(""));
3105-
assert!(~"ymca" == to_lower("YMCA"));
3106-
}
3107-
31083056
#[test]
31093057
fn test_unsafe_slice() {
31103058
assert!("ab" == unsafe {raw::slice_bytes("abc", 0, 2)});
@@ -3337,13 +3285,6 @@ mod tests {
33373285
assert!((!is_whitespace(~" _ ")));
33383286
}
33393287
3340-
#[test]
3341-
fn test_is_ascii() {
3342-
assert!((is_ascii(~"")));
3343-
assert!((is_ascii(~"a")));
3344-
assert!((!is_ascii(~"\u2009")));
3345-
}
3346-
33473288
#[test]
33483289
fn test_shift_byte() {
33493290
let mut s = ~"ABC";

0 commit comments

Comments
 (0)