summary refs log tree commit diff
path: root/src/libstd/str.rs
AgeCommit message (Collapse)AuthorLines
2014-03-30Rename `from_iterator` to `from_iter` for consistency.Brian Anderson-1/+1
2014-03-29auto merge of #13183 : erickt/rust/remove-list, r=alexcrichtonbors-1/+1
`collections::list::List` was decided in a [team meeting](https://github.com/mozilla/rust/wiki/Meeting-weekly-2014-03-25) that it was unnecessary, so this PR removes it. Additionally, it removes an old and redundant purity test and fixes some warnings.
2014-03-28Convert most code to new inner attribute syntax.Brian Anderson-1/+1
Closes #2569
2014-03-28std and green: fix some warningsErick Tryzelaar-1/+1
2014-03-25Changed `iter::Extendable` and `iter::FromIterator` to take a `Iterator` by ↵Marvin Löbel-4/+4
value
2014-03-23auto merge of #13102 : huonw/rust/totaleq-deriving, r=thestingerbors-22/+5
std: remove the `equals` method from `TotalEq`. `TotalEq` is now just an assertion about the `Eq` impl of a type (i.e. `==` is a total equality if a type implements `TotalEq`) so the extra method is just confusing. Also, a new method magically appeared as a hack to allow deriving to assert that the contents of a struct/enum are also TotalEq, because the deriving infrastructure makes it very hard to do anything but create a trait method. (You didn't hear about this horrible work-around from me :(.)
2014-03-23std: remove the `equals` method from `TotalEq`.Huon Wilson-22/+5
`TotalEq` is now just an assertion about the `Eq` impl of a type (i.e. `==` is a total equality if a type implements `TotalEq`) so the extra method is just confusing. Also, a new method magically appeared as a hack to allow deriving to assert that the contents of a struct/enum are also TotalEq, because the deriving infrastructure makes it very hard to do anything but create a trait method. (You didn't hear about this horrible work-around from me :(.)
2014-03-23iter: remove `to_owned_vec`Daniel Micay-1/+1
This needs to be removed as part of removing `~[T]`. Partial type hints are now allowed, and will remove the need to add a version of this method for `Vec<T>`. For now, this involves a few workarounds for partial type hints not completely working.
2014-03-21libstd: Add some methods to `Vec<T>`.Patrick Walton-0/+1
2014-03-20rename std::vec_ng -> std::vecDaniel Micay-1/+1
Closes #12771
2014-03-20rename std::vec -> std::sliceDaniel Micay-14/+14
Closes #12702
2014-03-18remove duplicate methods in implsCorey Richardson-3/+0
2014-03-16`strdup_uniq` doesn't have to be `pub`.Lindsey Kuper-2/+1
2014-03-12Use generic impls for `Hash`Erick Tryzelaar-4/+7
2014-03-10libstd: Update docs for `slice_shift_char` and {shift,pop}_{char,byte}Piotr Czarnecki-17/+10
2014-03-10libstd: Add unit tests for `slice_shift_char`Piotr Czarnecki-0/+12
2014-03-10libstd: Change `slice_shift_char`, `shift_char`, `pop_char`, `shift_byte` ↵Piotr Czarnecki-34/+53
and `pop_byte` to return an Option instead of failing
2014-03-08Removed DeepClone. Issue #12698.Michael Darakananda-25/+1
2014-03-05Str::slice_chars() is O(end), not O(end - begin)Simon Sapin-2/+2
2014-03-04Rename all variables that have uppercase characters in their names to use ↵Palmer Cox-9/+9
only lowercase characters
2014-02-28std: Change assert_eq!() to use {} instead of {:?}Alex Crichton-4/+4
Formatting via reflection has been a little questionable for some time now, and it's a little unfortunate that one of the standard macros will silently use reflection when you weren't expecting it. This adds small bits of code bloat to libraries, as well as not always being necessary. In light of this information, this commit switches assert_eq!() to using {} in the error message instead of {:?}. In updating existing code, there were a few error cases that I encountered: * It's impossible to define Show for [T, ..N]. I think DST will alleviate this because we can define Show for [T]. * A few types here and there just needed a #[deriving(Show)] * Type parameters needed a Show bound, I often moved this to `assert!(a == b)` * `Path` doesn't implement `Show`, so assert_eq!() cannot be used on two paths. I don't think this is much of a regression though because {:?} on paths looks awful (it's a byte array). Concretely speaking, this shaved 10K off a 656K binary. Not a lot, but sometime significant for smaller binaries.
2014-02-24Remove std::default::Default from the preludeBrendan Zabarauskas-0/+1
2014-02-23Remove all ToStr impls, add Show implsAlex Crichton-16/+0
This commit changes the ToStr trait to: impl<T: fmt::Show> ToStr for T { fn to_str(&self) -> ~str { format!("{}", *self) } } The ToStr trait has been on the chopping block for quite awhile now, and this is the final nail in its coffin. The trait and the corresponding method are not being removed as part of this commit, but rather any implementations of the `ToStr` trait are being forbidden because of the generic impl. The new way to get the `to_str()` method to work is to implement `fmt::Show`. Formatting into a `&mut Writer` (as `format!` does) is much more efficient than `ToStr` when building up large strings. The `ToStr` trait forces many intermediate allocations to be made while the `fmt::Show` trait allows incremental buildup in the same heap allocated buffer. Additionally, the `fmt::Show` trait is much more extensible in terms of interoperation with other `Writer` instances and in more situations. By design the `ToStr` trait requires at least one allocation whereas the `fmt::Show` trait does not require any allocations. Closes #8242 Closes #9806
2014-02-23Merge remote-tracking branch 'huonw/inline-helpers'Brian Anderson-0/+1
2014-02-24Transition to new `Hash`, removing IterBytes and std::to_bytes.Huon Wilson-7/+4
2014-02-23std: Move raw to std::rawBrian Anderson-2/+2
Issue #1457
2014-02-23std: mark two helper functions #[inline].Huon Wilson-0/+1
`str::utf8_char_width` and `char::from_u32` are tiny, which means it's a big performance hit to call them in a tight loop outside libstd.
2014-02-21auto merge of #12421 : Hywan/rust/api_doc, r=alexcrichtonbors-3/+3
I was reading the code and saw this. Not the best contribution of my life ;-).
2014-02-21libstd: Implement some convenience methods on vectorsPatrick Walton-0/+13
2014-02-20Fix some typos.Ivan Enderlin-3/+3
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