about summary refs log tree commit diff
path: root/src/libstd/str.rs
AgeCommit message (Collapse)AuthorLines
2014-02-20move extra::test to libtestLiigo Zhuang-1/+2
2014-02-18auto merge of #12317 : huonw/rust/utf16, r=alexcrichtonbors-45/+291
Iterators! Use them (in `is_utf16`), create them (in `utf16_items`). Handle errors gracefully (`from_utf16_lossy`) and `from_utf16` returning `Option<~str>` instead of failing. Add a pile of tests.
2014-02-19str: add a function for truncating a vector of u16 at NUL.Huon Wilson-0/+44
Many of the functions interacting with Windows APIs allocate a vector of 0's and do not retrieve a length directly from the API call, and so need to be sure to remove the unmodified junk at the end of the vector.
2014-02-18std: convert first_non_utf8_byte to use the iterator.Huon Wilson-61/+11
This makes it very slightly faster, especially when the string is valid UTF-8, and completely removes the use of `unsafe` from the first half. Before: from_utf8_lossy_100_ascii ... bench: 151 ns/iter (+/- 17) from_utf8_lossy_100_invalid ... bench: 447 ns/iter (+/- 33) from_utf8_lossy_100_multibyte ... bench: 135 ns/iter (+/- 4) from_utf8_lossy_invalid ... bench: 124 ns/iter (+/- 10 After: from_utf8_lossy_100_ascii ... bench: 119 ns/iter (+/- 8) from_utf8_lossy_100_invalid ... bench: 454 ns/iter (+/- 16) from_utf8_lossy_100_multibyte ... bench: 116 ns/iter (+/- 9) from_utf8_lossy_invalid ... bench: 119 ns/iter (+/- 9)
2014-02-18std::str: safen and optimize is_utf8.Huon Wilson-2/+77
This uses a vector iterator to avoid the necessity for unsafe indexing, and makes this function slightly faster. Unfortunately #11751 means that the iterator comes with repeated `null` checks which means the pure-ASCII case still has room for significant improvement (and the other cases too, but it's most significant for just ASCII). Before: is_utf8_100_ascii ... bench: 143 ns/iter (+/- 6) is_utf8_100_multibyte ... bench: 134 ns/iter (+/- 4) After: is_utf8_100_ascii ... bench: 123 ns/iter (+/- 4) is_utf8_100_multibyte ... bench: 115 ns/iter (+/- 5)
2014-02-18std: make str::from_utf16 return an Option.Huon Wilson-18/+36
The rest of the codebase is moving toward avoiding `fail!` so we do it here too!
2014-02-17std: decode even numbered non-BMP planes in the UTF-16 decoder.Huon Wilson-2/+5
Fixes #12318.
2014-02-17str: provide lossy UTF-16 support.Huon Wilson-23/+133
This replaces the iterator with one that handles lone surrogates gracefully and uses that to implement `from_utf16_lossy` which replaces invalid `u16`s with U+FFFD.
2014-02-17std: convert str::from_utf16 to an external iterator.Huon Wilson-27/+38
Fixes #12316.
2014-02-17std: iteratize str::is_utf16 & add tests.Huon Wilson-18/+78
Most of the tests are randomly generated with Python 3 and rely on it's UTF-16be encoder/decoder being correct.
2014-02-17Remove CloneableTuple and ImmutableTuple traitsBrendan Zabarauskas-3/+3
These are adequately covered by the Tuple2 trait.
2014-02-14Fix all code examplesAlex Crichton-1/+1
2014-02-14return value/use extra::test::black_box in benchmarkslpy-3/+3
2014-02-13remove duplicate function from std::ptr (is_null, is_not_null, offset, ↵JeremyLetang-8/+7
mut_offset)
2014-02-13Add some missing Show implementations in libstdBrendan Zabarauskas-0/+2
2014-02-11str -- borrow fields of self for use in closure since self.iter is borrowedNiko Matsakis-5/+7
2014-02-07Delete send_str, rewrite clients on top of MaybeOwned<'static>Kevin Ballard-63/+234
Declare a `type SendStr = MaybeOwned<'static>` to ease readibility of types that needed the old SendStr behavior. Implement all the traits for MaybeOwned that SendStr used to implement.
2014-02-07Tweak from_utf8_lossy to return a new MaybeOwned enumKevin Ballard-27/+94
MaybeOwned allows from_utf8_lossy to avoid allocation if there are no invalid bytes in the input.
2014-02-06Add new function str::from_utf8_lossy()Kevin Ballard-6/+179
from_utf8_lossy() takes a byte vector and produces a ~str, converting any invalid UTF-8 sequence into the U+FFFD REPLACEMENT CHARACTER. The replacement follows the guidelines in §5.22 Best Practice for U+FFFD Substitution from the Unicode Standard (Version 6.2)[1], which also matches the WHATWG rules for utf-8 decoding[2]. [1]: http://www.unicode.org/versions/Unicode6.2.0/ch05.pdf [2]: http://encoding.spec.whatwg.org/#utf-8
2014-02-04auto merge of #11951 : dmanescu/rust/reserve-rename, r=huonwbors-21/+15
Changes in std::{str,vec,hashmap} and extra::{priority_queue,ringbuf}. Fixes #11949
2014-02-04Rename reserve to reserve_exact and reserve_at_least to reserveDavid Manescu-21/+15
Changes in std::{str,vec,hashmap} and extra::{priority_queue,ringbuf}. Fixes #11949
2014-02-02librustc: Remove `@str` from the languagePatrick Walton-1/+0
2014-02-02libextra: Remove `@str` from all the librariesPatrick Walton-119/+11
2014-02-01auto merge of #11930 : bjz/rust/next_power_of_two, r=huonwbors-3/+2
2014-01-31Fix minor doc typosVirgile Andreani-2/+2
2014-02-01Remove some unused importsBrendan Zabarauskas-1/+0
2014-02-01Make next_power_of_two generic for unsigned integersBrendan Zabarauskas-2/+2
Also rename `next_power_of_two_opt` to `checked_next_power_of_two`.
2014-01-28Rename CopyableTuple to CloneableTupleVirgile Andreani-1/+1
2014-01-28Rename OwnedCopyableVector to OwnedCloneableVectorVirgile Andreani-1/+1
2014-01-26std,extra: Make some types public and other private.Huon Wilson-1/+1
These are either returned from public functions, and really should appear in the documentation, but don't since they're private, or are implementation details that are currently public.
2014-01-23Update flip() to be rev().Sean Chalmers-12/+12
Consensus leaned in favour of using rev instead of flip.
2014-01-23Rename Invert to Flip - Issue 10632Sean Chalmers-12/+12
Renamed the invert() function in iter.rs to flip(). Also renamed the Invert<T> type to Flip<T>. Some related code comments changed. Documentation that I could find has been updated, and all the instances I could locate where the function/type were called have been updated as well.
2014-01-21[std::str] Remove the now unused not_utf8 condition.Simon Sapin-8/+0
2014-01-21[std::str] Rename from_utf8_owned_opt() to from_utf8_owned(), drop the old ↵Simon Sapin-30/+4
from_utf8_owned() behavior
2014-01-21[std::str] Rename from_utf8_opt() to from_utf8(), drop the old from_utf8() ↵Simon Sapin-30/+5
behavior
2014-01-21[std::vec] Rename .shift_opt() to .shift(), drop the old .shift() behaviorSimon Sapin-1/+1
2014-01-21[std::vec] Rename .head_opt() to .head(), drop the old .head() behaviorSimon Sapin-1/+1
2014-01-21Remove unnecessary parentheses.Huon Wilson-3/+3
2014-01-18Rename iterators for consistencyPalmer Cox-78/+78
Rename existing iterators to get rid of the Iterator suffix and to give them names that better describe the things being iterated over.
2014-01-11Remove re-exports of std::io::stdio::{print, println} in the prelude.Brendan Zabarauskas-2/+2
The `print!` and `println!` macros are now the preferred method of printing, and so there is no reason to export the `stdio` functions in the prelude. The functions have also been replaced by their macro counterparts in the tutorial and other documentation so that newcomers don't get confused about what they should be using.
2014-01-07stdtest: Fix all leaked trait importsAlex Crichton-5/+2
2014-01-07std: Fill in all missing importsAlex Crichton-4/+8
Fallout from the previous commits
2014-01-07auto merge of #11329 : fhahn/rust/unused-cast-lint2, r=alexcrichtonbors-2/+2
Updates as mentioned in #11135
2014-01-06auto merge of #10826 : SimonSapin/rust/str-insert, r=brsonbors-0/+42
I could not run the tests because of unrelated building issue, sorry about that.
2014-01-06Remove some unnecessary type castsFlorian Hahn-2/+2
Conflicts: src/librustc/middle/lint.rs
2014-01-04Don't allow newtype structs to be dereferenced. #6246Brian Anderson-2/+6
2013-12-31Add .insert() and .insert_char() methods to ~str.Simon Sapin-0/+42
2013-12-31Fix testsAlan Andrade-5/+9
2013-12-27std: uniform modules titles for docLuca Bruno-1/+1
This commit uniforms the short title of modules provided by libstd, in order to make their roles more explicit when glancing at the index. Signed-off-by: Luca Bruno <lucab@debian.org>
2013-12-23std: Fix all code examplesAlex Crichton-6/+8