Skip to content

Commit 780f827

Browse files
committed
Finish cleanup of core::str
Closes #1849
1 parent 1d2b4b9 commit 780f827

24 files changed

+353
-494
lines changed

src/comp/back/link.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,10 @@ mod write {
109109
// Decides what to call an intermediate file, given the name of the output
110110
// and the extension to use.
111111
fn mk_intermediate_name(output_path: str, extension: str) -> str unsafe {
112-
let stem = alt str::index(output_path, '.') {
113-
option::some(dot_pos) {
114-
str::slice(output_path, 0u, dot_pos)
115-
}
116-
option::none { output_path }
117-
};
118-
112+
let stem = alt str::find_char(output_path, '.') {
113+
some(dot_pos) { str::slice(output_path, 0u, dot_pos) }
114+
none { output_path }
115+
};
119116
ret stem + "." + extension;
120117
}
121118

@@ -566,7 +563,7 @@ fn link_binary(sess: session,
566563
// Converts a library file name into a cc -l argument
567564
fn unlib(config: @session::config, filename: str) -> str unsafe {
568565
let rmlib = fn@(filename: str) -> str {
569-
let found = str::find(filename, "lib");
566+
let found = str::find_str(filename, "lib");
570567
if config.os == session::os_macos ||
571568
(config.os == session::os_linux ||
572569
config.os == session::os_freebsd) &&

src/comp/syntax/codemap.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,20 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
157157

158158
fn get_line(fm: filemap, line: int) -> str unsafe {
159159
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
160-
let end = alt str::index_from(*fm.src, '\n', begin, str::len(*fm.src)) {
160+
let end = alt str::find_char_from(*fm.src, '\n', begin) {
161161
some(e) { e }
162162
none { str::len(*fm.src) }
163163
};
164164
str::slice(*fm.src, begin, end)
165165
}
166166

167167
fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
168-
-> {fm: filemap, pos: uint}
169-
{
170-
fn lookup(pos: file_pos) -> uint { ret pos.ch; }
171-
let {fm,line} = lookup_line(cm,chpos,lookup);
168+
-> {fm: filemap, pos: uint} {
169+
let {fm, line} = lookup_line(cm, chpos, {|pos| pos.ch});
172170
let line_offset = fm.lines[line].byte - fm.start_pos.byte;
173171
let col = chpos - fm.lines[line].ch;
174-
let col_offset = str::substr_len(*fm.src, line_offset, col);
175-
ret {fm: fm, pos: line_offset + col_offset};
172+
let col_offset = str::count_bytes(*fm.src, line_offset, col);
173+
{fm: fm, pos: line_offset + col_offset}
176174
}
177175

178176
fn span_to_snippet(sp: span, cm: codemap::codemap) -> str {

src/comp/syntax/ext/qquote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn finish<T: qq_helper>
214214
if (j < g_len && i == cx.gather[j].lo) {
215215
assert ch == '$';
216216
let repl = #fmt("$%u ", j);
217-
state = skip(str::len_chars(repl));
217+
state = skip(str::char_len(repl));
218218
str2 += repl;
219219
}
220220
alt state {

src/compiletest/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn load_errors(testfile: str) -> [expected_error] {
2525
fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
2626
let error_tag = "//!";
2727
let idx;
28-
alt str::find(line, error_tag) {
28+
alt str::find_str(line, error_tag) {
2929
option::none { ret []; }
3030
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
3131
}

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn parse_name_directive(line: str, directive: str) -> bool {
106106
fn parse_name_value_directive(line: str,
107107
directive: str) -> option<str> unsafe {
108108
let keycolon = directive + ":";
109-
alt str::find(line, keycolon) {
109+
alt str::find_str(line, keycolon) {
110110
option::some(colon) {
111111
let value = str::slice(line, colon + str::len(keycolon),
112112
str::len(line));

src/compiletest/runtest.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn check_error_patterns(props: test_props,
198198

199199
let next_err_idx = 0u;
200200
let next_err_pat = props.error_patterns[next_err_idx];
201-
for line: str in str::split_byte(procres.stderr, '\n' as u8) {
201+
for line: str in str::split_char(procres.stderr, '\n') {
202202
if str::contains(line, next_err_pat) {
203203
#debug("found error pattern %s", next_err_pat);
204204
next_err_idx += 1u;
@@ -245,7 +245,7 @@ fn check_expected_errors(expected_errors: [errors::expected_error],
245245
// filename:line1:col1: line2:col2: *warning:* msg
246246
// where line1:col1: is the starting point, line2:col2:
247247
// is the ending point, and * represents ANSI color codes.
248-
for line: str in str::split_byte(procres.stderr, '\n' as u8) {
248+
for line: str in str::split_char(procres.stderr, '\n') {
249249
let was_expected = false;
250250
vec::iteri(expected_errors) {|i, ee|
251251
if !found_flags[i] {
@@ -350,7 +350,7 @@ fn split_maybe_args(argstr: option<str>) -> [str] {
350350
}
351351

352352
alt argstr {
353-
option::some(s) { rm_whitespace(str::split_byte(s, ' ' as u8)) }
353+
option::some(s) { rm_whitespace(str::split_char(s, ' ')) }
354354
option::none { [] }
355355
}
356356
}
@@ -410,12 +410,10 @@ fn make_out_name(config: config, testfile: str, extension: str) -> str {
410410

411411
fn output_base_name(config: config, testfile: str) -> str {
412412
let base = config.build_base;
413-
let filename =
414-
{
415-
let parts = str::split_byte(fs::basename(testfile), '.' as u8);
416-
parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
417-
str::connect(parts, ".")
418-
};
413+
let filename = {
414+
let parts = str::split_char(fs::basename(testfile), '.');
415+
str::connect(vec::slice(parts, 0u, vec::len(parts) - 1u), ".")
416+
};
419417
#fmt["%s%s.%s", base, filename, config.stage_id]
420418
}
421419

src/libcore/extfmt.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,14 @@ mod rt {
320320
fn conv_str(cv: conv, s: str) -> str unsafe {
321321
// For strings, precision is the maximum characters
322322
// displayed
323-
324-
let unpadded =
325-
alt cv.precision {
326-
count_implied { s }
327-
count_is(max) {
328-
if max as uint < str::len_chars(s) {
329-
str::substr(s, 0u, max as uint)
330-
} else { s }
331-
}
332-
};
323+
let unpadded = alt cv.precision {
324+
count_implied { s }
325+
count_is(max) {
326+
if max as uint < str::char_len(s) {
327+
str::substr(s, 0u, max as uint)
328+
} else { s }
329+
}
330+
};
333331
ret pad(cv, unpadded, pad_nozero);
334332
}
335333
fn conv_float(cv: conv, f: float) -> str {
@@ -368,7 +366,7 @@ mod rt {
368366
""
369367
} else {
370368
let s = uint::to_str(num, radix);
371-
let len = str::len_chars(s);
369+
let len = str::char_len(s);
372370
if len < prec {
373371
let diff = prec - len;
374372
let pad = str_init_elt(diff, '0');
@@ -400,7 +398,7 @@ mod rt {
400398
uwidth = width as uint;
401399
}
402400
}
403-
let strlen = str::len_chars(s);
401+
let strlen = str::char_len(s);
404402
if uwidth <= strlen { ret s; }
405403
let padchar = ' ';
406404
let diff = uwidth - strlen;

0 commit comments

Comments
 (0)