String manipulation

Strings are a packed UTF-8 representation of text, stored as null terminated buffers of u8 bytes. Strings should be indexed in bytes, for efficiency, but UTF-8 unsafe operations should be avoided. For some heavy-duty uses, try std::rope.

Const max_five_b

uint

Const max_four_b

uint

Const max_one_b

uint

Const max_three_b

uint

Const max_two_b

uint

Const tag_cont

uint

Const tag_cont_u8

u8

Const tag_five_b

uint

Const tag_four_b

uint

Const tag_six_b

uint

Const tag_three_b

uint

Const tag_two_b

uint

Struct CharRange

pub struct CharRange {
    ch: char,
    next: uint,
}

Interface StrSlice

Method all

fn all(it: &fn(char) -> bool) -> bool

Method any

fn any(it: &fn(char) -> bool) -> bool

Method contains

fn contains(needle: &a/str) -> bool

Method contains_char

fn contains_char(needle: char) -> bool

Method each

fn each(it: &fn(u8) -> bool)

Method eachi

fn eachi(it: &fn(uint, u8) -> bool)

Method each_char

fn each_char(it: &fn(char) -> bool)

Method each_chari

fn each_chari(it: &fn(uint, char) -> bool)

Method ends_with

fn ends_with(needle: &str) -> bool

Method is_empty

fn is_empty() -> bool

Method is_not_empty

fn is_not_empty() -> bool

Method is_whitespace

fn is_whitespace() -> bool

Method is_alphanumeric

fn is_alphanumeric() -> bool

Method len

fn len() -> uint

Method slice

fn slice(begin: uint, end: uint) -> ~str

Method split

fn split(sepfn: &fn(char) -> bool) -> ~[~str]

Method split_char

fn split_char(sep: char) -> ~[~str]

Method split_str

fn split_str(sep: &a/str) -> ~[~str]

Method starts_with

fn starts_with(needle: &a/str) -> bool

Method substr

fn substr(begin: uint, n: uint) -> ~str

Method to_lower

fn to_lower() -> ~str

Method to_upper

fn to_upper() -> ~str

Method escape_default

fn escape_default() -> ~str

Method escape_unicode

fn escape_unicode() -> ~str

Method trim

fn trim() -> ~str

Method trim_left

fn trim_left() -> ~str

Method trim_right

fn trim_right() -> ~str

Method to_owned

fn to_owned() -> ~str

Method to_managed

fn to_managed() -> @str

Method char_at

fn char_at(i: uint) -> char

Interface Trimmable

Method trim

fn trim() -> self

Method trim_left

fn trim_left() -> self

Method trim_right

fn trim_right() -> self

Implementation of Trimmable for ~str

Extension methods for strings

Method trim

fn trim() -> ~str

Returns a string with leading and trailing whitespace removed

Method trim_left

fn trim_left() -> ~str

Returns a string with leading whitespace removed

Method trim_right

fn trim_right() -> ~str

Returns a string with trailing whitespace removed

Implementation of StrSlice for &str

Extension methods for strings

Method all

fn all(it: &fn(char) -> bool) -> bool

Return true if a predicate matches all characters or if the string contains no characters

Method any

fn any(it: &fn(char) -> bool) -> bool

Return true if a predicate matches any character (and false if it matches none or there are no characters)

Method contains

fn contains(needle: &a/str) -> bool

Returns true if one string contains another

Method contains_char

fn contains_char(needle: char) -> bool

Returns true if a string contains a char

Method each

fn each(it: &fn(u8) -> bool)

Iterate over the bytes in a string

Method eachi

fn eachi(it: &fn(uint, u8) -> bool)

Iterate over the bytes in a string, with indices

Method each_char

fn each_char(it: &fn(char) -> bool)

Iterate over the chars in a string

Method each_chari

fn each_chari(it: &fn(uint, char) -> bool)

Iterate over the chars in a string, with indices

Method ends_with

fn ends_with(needle: &str) -> bool

Returns true if one string ends with another

Method is_empty

fn is_empty() -> bool

Returns true if the string has length 0

Method is_not_empty

fn is_not_empty() -> bool

Returns true if the string has length greater than 0

Method is_whitespace

fn is_whitespace() -> bool

Returns true if the string contains only whitespace

Whitespace characters are determined by char::is_whitespace

Method is_alphanumeric

fn is_alphanumeric() -> bool

Returns true if the string contains only alphanumerics

Alphanumeric characters are determined by char::is_alphanumeric

Method len

fn len() -> uint

Returns the size in bytes not counting the null terminator

Method slice

fn slice(begin: uint, end: uint) -> ~str

Returns a slice of the given string from the byte range [begin..end)

Fails when begin and end do not point to valid characters or beyond the last character of the string

Method split

fn split(sepfn: &fn(char) -> bool) -> ~[~str]

Splits a string into substrings using a character function

Method split_char

fn split_char(sep: char) -> ~[~str]

Splits a string into substrings at each occurrence of a given character

Method split_str

fn split_str(sep: &a/str) -> ~[~str]

Splits a string into a vector of the substrings separated by a given string

Method starts_with

fn starts_with(needle: &a/str) -> bool

Returns true if one string starts with another

Method substr

fn substr(begin: uint, n: uint) -> ~str

Take a substring of another.

Returns a string containing n characters starting at byte offset begin.

Method to_lower

fn to_lower() -> ~str

Convert a string to lowercase

Method to_upper

fn to_upper() -> ~str

Convert a string to uppercase

Method escape_default

fn escape_default() -> ~str

Escape each char in s with char::escape_default.

Method escape_unicode

fn escape_unicode() -> ~str

Escape each char in s with char::escape_unicode.

Method trim

fn trim() -> ~str

Returns a string with leading and trailing whitespace removed

Method trim_left

fn trim_left() -> ~str

Returns a string with leading whitespace removed

Method trim_right

fn trim_right() -> ~str

Returns a string with trailing whitespace removed

Method to_owned

fn to_owned() -> ~str

Method to_managed

fn to_managed() -> @str

Method char_at

fn char_at(i: uint) -> char

Function all

fn all(s: &str, it: &fn(char) -> bool) -> bool

Return true if a predicate matches all characters or if the string contains no characters

Function all_between

fn all_between(s: &str, start: uint, end: uint, it: &fn(char) -> bool) -> bool

Loop through a substring, char by char

Safety note

Arguments

Return value

true If execution proceeded correctly, false if it was interrupted, that is if it returned false at any point.

Function any

fn any(ss: &str, pred: &fn(char) -> bool) -> bool

Return true if a predicate matches any character (and false if it matches none or there are no characters)

Function any_between

fn any_between(s: &str, start: uint, end: uint, it: &fn(char) -> bool) -> bool

Loop through a substring, char by char

Safety note

Arguments

Return value

true if it returns true for any character

Function append

fn append(lhs: ~str, rhs: &str) -> ~str

Concatenate two strings together

Function as_buf

fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T

Work with the byte buffer and length of a slice.

The given length is one byte longer than the 'official' indexable length of the string. This is to permit probing the byte past the indexable area for a null byte, as is the case in slices pointing to full strings, or suffixes of them.

Function as_bytes

fn as_bytes<T>(s: &const ~str, f: &fn(&~[u8]) -> T) -> T

Work with the byte buffer of a string.

Allows for unsafe manipulation of strings, which is useful for foreign interop.

Example

let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) };

Function as_bytes_slice

fn as_bytes_slice(s: &a/str) -> &a/[u8]

Work with the byte buffer of a string as a byte slice.

The byte slice does not include the null terminator.

Function as_c_str

fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T

Work with the byte buffer of a string as a null-terminated C string.

Allows for unsafe manipulation of strings, which is useful for foreign interop. This is similar to str::as_buf, but guarantees null-termination. If the given slice is not already null-terminated, this function will allocate a temporary, copy the slice, null terminate it, and pass that instead.

Example

let s = str::as_c_str("PATH", { |path| libc::getenv(path) });

Function byte_slice

fn byte_slice<T>(s: &str, f: &fn(v: &[u8]) -> T) -> T

Work with the string as a byte slice, not including trailing null.

Function bytes_each

fn bytes_each(ss: &str, it: &fn(u8) -> bool)

Iterate over the bytes in a string

Function capacity

fn capacity(s: &const ~str) -> uint

Returns the number of single-byte characters the string can hold without reallocating

Function char_at

fn char_at(s: &str, i: uint) -> char

Pluck a character out of a string

Function char_len

fn char_len(s: &str) -> uint

Returns the number of characters that a string holds

Function char_range_at

fn char_range_at(s: &str, i: uint) -> CharRange

Pluck a character out of a string and return the index of the next character.

This function can be used to iterate over the unicode characters of a string.

Example

let s = "中华Việt Nam";
let i = 0u;
while i < str::len(s) {
    let CharRange {ch, next} = str::char_range_at(s, i);
    std::io::println(fmt!("%u: %c",i,ch));
    i = next;
}

Example output

0: 中
3: 华
6: V
7: i
8: ệ
11: t
12:
13: N
14: a
15: m

Arguments

Return value

A record {ch: char, next: uint} containing the char value and the byte index of the next unicode character.

Failure

If i is greater than or equal to the length of the string. If i is not the index of the beginning of a valid UTF-8 character.

Function char_range_at_reverse

fn char_range_at_reverse(ss: &str, start: uint) -> CharRange

Given a byte position and a str, return the previous char and its position

This function can be used to iterate over a unicode string in reverse.

Function chars

fn chars(s: &str) -> ~[char]

Convert a string to a vector of characters

Function chars_each

fn chars_each(s: &str, it: &fn(char) -> bool)

Iterate over the characters in a string

Function concat

fn concat(v: &[~str]) -> ~str

Concatenate a vector of strings

Function connect

fn connect(v: &[~str], sep: &str) -> ~str

Concatenate a vector of strings, placing a given separator between each

Function contains

fn contains(haystack: &a/str, needle: &b/str) -> bool

Returns true if one string contains another

Arguments

Function contains_char

fn contains_char(haystack: &str, needle: char) -> bool

Returns true if a string contains a char.

Arguments

Function count_bytes

fn count_bytes(s: &b/str, start: uint, n: uint) -> uint

Counts the number of bytes taken by the n in s starting from start.

Function count_chars

fn count_chars(s: &str, start: uint, end: uint) -> uint

As char_len but for a slice of a string

Arguments

Return value

The number of Unicode characters in s between the given indices.

Function each

fn each(s: &str, it: &fn(u8) -> bool)

Iterate over the bytes in a string

Function each_char

fn each_char(s: &str, it: &fn(char) -> bool)

Iterates over the chars in a string

Function each_chari

fn each_chari(s: &str, it: &fn(uint, char) -> bool)

Iterates over the chars in a string, with indices

Function eachi

fn eachi(s: &str, it: &fn(uint, u8) -> bool)

Iterate over the bytes in a string, with indices

Function ends_with

fn ends_with(haystack: &a/str, needle: &b/str) -> bool

Returns true if one string ends with another

Arguments

Function escape_default

fn escape_default(s: &str) -> ~str

Escape each char in s with char::escape_default.

Function escape_unicode

fn escape_unicode(s: &str) -> ~str

Escape each char in s with char::escape_unicode.

Function find

fn find(s: &str, f: &fn(char) -> bool) -> Option<uint>

Returns the byte index of the first character that satisfies the given predicate

Arguments

Return value

An option containing the byte index of the first matching character or none if there is no match

Function find_between

fn find_between(s: &str, start: uint, end: uint, f: &fn(char) -> bool) ->
 Option<uint>

Returns the byte index of the first character that satisfies the given predicate, within a given range

Arguments

Return value

An option containing the byte index of the first matching character or none if there is no match

Failure

start must be less than or equal to end and end must be less than or equal to len(s). start must be the index of a character boundary, as defined by is_char_boundary.

Function find_char

fn find_char(s: &str, c: char) -> Option<uint>

Returns the byte index of the first matching character

Arguments

Return value

An option containing the byte index of the first matching character or none if there is no match

Function find_char_between

fn find_char_between(s: &str, c: char, start: uint, end: uint) -> Option<uint>

Returns the byte index of the first matching character within a given range

Arguments

Return value

An option containing the byte index of the first matching character or none if there is no match

Failure

start must be less than or equal to end and end must be less than or equal to len(s). start must be the index of a character boundary, as defined by is_char_boundary.

Function find_char_from

fn find_char_from(s: &str, c: char, start: uint) -> Option<uint>

Returns the byte index of the first matching character beginning from a given byte offset

Arguments

Return value

An option containing the byte index of the first matching character or none if there is no match

Failure

start must be less than or equal to len(s). start must be the index of a character boundary, as defined by is_char_boundary.

Function find_from

fn find_from(s: &str, start: uint, f: &fn(char) -> bool) -> Option<uint>

Returns the byte index of the first character that satisfies the given predicate, beginning from a given byte offset

Arguments

Return value

An option containing the byte index of the first matching charactor or none if there is no match

Failure

start must be less than or equal to len(s). start must be the index of a character boundary, as defined by is_char_boundary.

Function find_str

fn find_str(haystack: &a/str, needle: &b/str) -> Option<uint>

Returns the byte index of the first matching substring

Arguments

Return value

An option containing the byte index of the first matching substring or none if there is no match

Function find_str_between

fn find_str_between(haystack: &a/str, needle: &b/str, start: uint, end: uint)
 -> Option<uint>

Returns the byte index of the first matching substring within a given range

Arguments

Return value

An option containing the byte index of the first matching character or none if there is no match

Failure

start must be less than or equal to end and end must be less than or equal to len(s).

Function find_str_from

fn find_str_from(haystack: &a/str, needle: &b/str, start: uint) ->
 Option<uint>

Returns the byte index of the first matching substring beginning from a given byte offset

Arguments

Return value

An option containing the byte index of the last matching character or none if there is no match

Failure

start must be less than or equal to len(s)

Function from_byte

fn from_byte(b: u8) -> ~str

Convert a byte to a UTF-8 string

Failure

Fails if invalid UTF-8

Function from_bytes

fn from_bytes(vv: &[const u8]) -> ~str

Convert a vector of bytes to a UTF-8 string

Failure

Fails if invalid UTF-8

Function from_char

fn from_char(ch: char) -> ~str

Convert a char to a string

Function from_chars

fn from_chars(chs: &[char]) -> ~str

Convert a vector of chars to a string

Function from_slice

fn from_slice(s: &str) -> ~str

Copy a slice into a new unique str

Function from_utf16

fn from_utf16(v: &[u16]) -> ~str

Function ge

fn ge(a: &str, b: &str) -> bool

Bytewise greater than or equal

Function gt

fn gt(a: &str, b: &str) -> bool

Bytewise greater than

Function is_alphanumeric

fn is_alphanumeric(s: &str) -> bool

Returns true if the string contains only alphanumerics

Alphanumeric characters are determined by char::is_alphanumeric

Function is_ascii

fn is_ascii(s: &str) -> bool

Determines if a string contains only ASCII characters

Function is_char_boundary

fn is_char_boundary(s: &str, index: uint) -> bool

Returns false if the index points into the middle of a multi-byte character sequence.

Function is_empty

fn is_empty(s: &str) -> bool

Returns true if the string has length 0

Function is_not_empty

fn is_not_empty(s: &str) -> bool

Returns true if the string has length greater than 0

Function is_utf16

fn is_utf16(v: &[u16]) -> bool

Determines if a vector of u16 contains valid UTF-16

Function is_utf8

fn is_utf8(v: &[const u8]) -> bool

Determines if a vector of bytes contains valid UTF-8

Function is_whitespace

fn is_whitespace(s: &str) -> bool

Returns true if the string contains only whitespace

Whitespace characters are determined by char::is_whitespace

Function iter_between_matches

fn iter_between_matches(s: &a/str, sep: &b/str, f: &fn(uint, uint))

Function iter_matches

fn iter_matches(s: &a/str, sep: &b/str, f: &fn(uint, uint))

Function le

fn le(a: &str, b: &str) -> bool

Bytewise less than or equal

Function len

fn len(s: &str) -> uint

Returns the string length/size in bytes not counting the null terminator

Function lines

fn lines(s: &str) -> ~[~str]

Splits a string into a vector of the substrings separated by LF ('\n')

Function lines_any

fn lines_any(s: &str) -> ~[~str]

Splits a string into a vector of the substrings separated by LF ('\n') and/or CR LF ("\r\n")

Function lines_each

fn lines_each(ss: &str, ff: &fn(v: &str) -> bool)

Apply a function to each line (by '\n')

Function lt

fn lt(a: &str, b: &str) -> bool

Bytewise slice less than

Function map

fn map(ss: &str, ff: &fn(char) -> char) -> ~str

Apply a function to each character

Function match_at

fn match_at(haystack: &a/str, needle: &b/str, at: uint) -> bool

Function pop_char

fn pop_char(s: &mut ~str) -> char

Remove the final character from a string and return it

Failure

If the string does not contain any characters

Function push_char

fn push_char(s: &mut ~str, ch: char)

Appends a character at the end of a string

Function push_str

fn push_str(lhs: &mut ~str, rhs: &str)

Appends a string slice to the back of a string

Function push_str_no_overallocate

fn push_str_no_overallocate(lhs: &mut ~str, rhs: &str)

Appends a string slice to the back of a string, without overallocating

Function repeat

fn repeat(ss: &str, nn: uint) -> ~str

Given a string, make a new string with repeated copies of it

Function replace

fn replace(s: &str, from: &str, to: &str) -> ~str

Replace all occurrences of one string with another

Arguments

Return value

The original string with all occurances of from replaced with to

Function reserve

fn reserve(s: &mut ~str, n: uint)

Reserves capacity for exactly n bytes in the given string, not including the null terminator.

Assuming single-byte characters, the resulting string will be large enough to hold a string of length n. To account for the null terminator, the underlying buffer will have the size n + 1.

If the capacity for s is already equal to or greater than the requested capacity, then no action is taken.

Arguments

Function reserve_at_least

fn reserve_at_least(s: &mut ~str, n: uint)

Reserves capacity for at least n bytes in the given string, not including the null terminator.

Assuming single-byte characters, the resulting string will be large enough to hold a string of length n. To account for the null terminator, the underlying buffer will have the size n + 1.

This function will over-allocate in order to amortize the allocation costs in scenarios where the caller may need to repeatedly reserve additional space.

If the capacity for s is already equal to or greater than the requested capacity, then no action is taken.

Arguments

Function rfind

fn rfind(s: &str, f: &fn(char) -> bool) -> Option<uint>

Returns the byte index of the last character that satisfies the given predicate

Arguments

Return value

An option containing the byte index of the last matching character or none if there is no match

Function rfind_between

fn rfind_between(s: &str, start: uint, end: uint, f: &fn(char) -> bool) ->
 Option<uint>

Returns the byte index of the last character that satisfies the given predicate, within a given range

Arguments

Return value

An option containing the byte index of the last matching character or none if there is no match

Failure

end must be less than or equal to start and start must be less than or equal to len(s). start must be the index of a character boundary, as defined by is_char_boundary

Function rfind_char

fn rfind_char(s: &str, c: char) -> Option<uint>

Returns the byte index of the last matching character

Arguments

Return value

An option containing the byte index of the last matching character or none if there is no match

Function rfind_char_between

fn rfind_char_between(s: &str, c: char, start: uint, end: uint) ->
 Option<uint>

Returns the byte index of the last matching character within a given range

Arguments

Return value

An option containing the byte index of the last matching character or none if there is no match

Failure

end must be less than or equal to start and start must be less than or equal to len(s). start must be the index of a character boundary, as defined by is_char_boundary.

Function rfind_char_from

fn rfind_char_from(s: &str, c: char, start: uint) -> Option<uint>

Returns the byte index of the last matching character beginning from a given byte offset

Arguments

Return value

An option containing the byte index of the last matching character or none if there is no match

Failure

start must be less than or equal to len(s). start must be the index of a character boundary, as defined by is_char_boundary.

Function rfind_from

fn rfind_from(s: &str, start: uint, f: &fn(char) -> bool) -> Option<uint>

Returns the byte index of the last character that satisfies the given predicate, beginning from a given byte offset

Arguments

Return value

An option containing the byte index of the last matching character or none if there is no match

Failure

start must be less than or equal to len(s)',startmust be the index of a character boundary, as defined byis_char_boundary`

Function shift_char

fn shift_char(s: &mut ~str) -> char

Remove the first character from a string and return it

Failure

If the string does not contain any characters

Function slice

fn slice(s: &str, begin: uint, end: uint) -> ~str

Returns a slice of the given string from the byte range [begin..end)

Fails when begin and end do not point to valid characters or beyond the last character of the string

Function split

fn split(s: &str, sepfn: &fn(char) -> bool) -> ~[~str]

Splits a string into substrings using a character function

Function split_char

fn split_char(s: &str, sep: char) -> ~[~str]

Splits a string into substrings at each occurrence of a given character

Function split_char_each

fn split_char_each(ss: &str, cc: char, ff: &fn(v: &str) -> bool)

Apply a function to each substring after splitting by character

Function split_char_inner

fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool) ->
 ~[~str]

Function split_char_nonempty

fn split_char_nonempty(s: &str, sep: char) -> ~[~str]

Like split_char, but omits empty strings from the returned vector

Function split_inner

fn split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint,
               allow_empty: bool) -> ~[~str]

Function split_nonempty

fn split_nonempty(s: &str, sepfn: &fn(char) -> bool) -> ~[~str]

Like split, but omits empty strings from the returned vector

Function split_str

fn split_str(s: &a/str, sep: &b/str) -> ~[~str]

Splits a string into a vector of the substrings separated by a given string

Example

assert ["", "XXX", "YYY", ""] == split_str(".XXX.YYY.", ".")

Function split_str_nonempty

fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str]

Function split_within

fn split_within(ss: &str, lim: uint) -> ~[~str]

Split a string into a vector of substrings, * each of which is less than a limit

Function splitn

fn splitn(s: &str, sepfn: &fn(char) -> bool, count: uint) -> ~[~str]

Splits a string into substrings using a character function, cutting at most count times.

Function splitn_char

fn splitn_char(s: &str, sep: char, count: uint) -> ~[~str]

Splits a string into substrings at each occurrence of a given character up to 'count' times

The byte must be a valid UTF-8/ASCII byte

Function splitn_char_each

fn splitn_char_each(ss: &str, sep: char, count: uint,
                    ff: &fn(v: &str) -> bool)

Apply a function to each substring after splitting by character, up to count times

Function starts_with

fn starts_with(haystack: &a/str, needle: &b/str) -> bool

Returns true if one string starts with another

Arguments

Function substr

fn substr(s: &str, begin: uint, n: uint) -> ~str

Take a substring of another.

Returns a string containing n characters starting at byte offset begin.

Function to_bytes

fn to_bytes(s: &str) -> ~[u8]

Converts a string to a vector of bytes

The result vector is not null-terminated.

Function to_lower

fn to_lower(s: &str) -> ~str

Convert a string to lowercase. ASCII only

Function to_upper

fn to_upper(s: &str) -> ~str

Convert a string to uppercase. ASCII only

Function to_utf16

fn to_utf16(s: &str) -> ~[u16]

Converts to a vector of u16 encoded as UTF-16

Function trim

fn trim(s: &str) -> ~str

Returns a string with leading and trailing whitespace removed

Function trim_chars

fn trim_chars(s: &str, chars_to_trim: &[char]) -> ~str

Returns a string with leading and trailing chars_to_trim removed.

Arguments

Function trim_left

fn trim_left(s: &str) -> ~str

Returns a string with leading whitespace removed

Function trim_left_chars

fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str

Returns a string with leading chars_to_trim removed.

Arguments

Function trim_right

fn trim_right(s: &str) -> ~str

Returns a string with trailing whitespace removed

Function trim_right_chars

fn trim_right_chars(s: &str, chars_to_trim: &[char]) -> ~str

Returns a string with trailing chars_to_trim removed.

Arguments

Function unshift_char

fn unshift_char(s: &mut ~str, ch: char)

Prepend a char to a string

Function utf16_chars

fn utf16_chars(v: &[u16], f: &fn(char))

Function utf8_char_width

fn utf8_char_width(b: u8) -> uint

Given a first byte, determine how many bytes are in this UTF-8 character

Function view

fn view(s: &a/str, begin: uint, end: uint) -> &a/str

Returns a view of the given string from the byte range [begin..end)

Fails when begin and end do not point to valid characters or beyond the last character of the string

Function view_shift_char

fn view_shift_char(s: &a/str) -> (char, &a/str)

Removes the first character from a string slice and returns it. This does not allocate a new string; instead, it mutates a slice to point one character beyond the character that was shifted.

Failure

If the string does not contain any characters

Function with_capacity

fn with_capacity(capacity: uint) -> ~str

Function words

fn words(s: &str) -> ~[~str]

Splits a string into a vector of the substrings separated by whitespace

Function words_each

fn words_each(ss: &str, ff: &fn(v: &str) -> bool)

Apply a function to each word