summary refs log tree commit diff
path: root/src/libstd/str.rs
AgeCommit message (Collapse)AuthorLines
2013-09-25rustdoc: Change all code-blocks with a scriptAlex Crichton-26/+26
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g' find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g' find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-09-24Do not imply that str is sometimes null-terminated.Simon Sapin-2/+2
2013-09-20auto merge of #9276 : alexcrichton/rust/dox, r=brsonbors-6/+80
Hopefull this will make our libstd docs appear a little more "full".
2013-09-17std: Fix an invalid read in from_c_multistringBrian Anderson-2/+2
When `count` is `Some` this function was reading a byte past the end of the buffer.
2013-09-17Document a few undocumented modules in libstdAlex Crichton-6/+80
Hopefull this will make our libstd docs appear a little more "full".
2013-09-16std: merge conflict cleanup from std::strJeff Olson-1/+0
2013-09-16std: more work on from_c_multistring.. let it take an optional len paramJeff Olson-5/+17
2013-09-16std: win32 os::env() str parsing to str::raw::from_c_multistring + testJeff Olson-0/+37
2013-09-16auto merge of #9108 : blake2-ppc/rust/hazards-on-overflow, r=alexcrichtonbors-105/+78
Fix uint overflow bugs in std::{at_vec, vec, str} Closes #8742 Fix issue #8742, which summarized is: unsafe code in vec and str did assume that a reservation for `X + Y` elements always succeeded, and didn't overflow. Introduce the method `Vec::reserve_additional(n)` to make it easy to check for overflow in `Vec::push` and `Vec::push_all`. In std::str, simplify and remove a lot of the unsafe code and use `push_str` instead. With improvements to `.push_str` and the new function `vec::bytes::push_bytes`, it looks like this change has either no or positive impact on performance. I believe there are many places still where `v.reserve(A + B)` still can overflow. This by itself is not an issue unless followed by (unsafe) code that steps aside boundary checks.
2013-09-17std::str: Fix overflow problems in unsafe codeblake2-ppc-105/+59
See issue #8742
2013-09-16std::str: Add bench tests for StrVector::connect() and for str::push_strblake2-ppc-0/+19
2013-09-16Add an SendStr typeMarvin Löbel-1/+16
A SendStr is a string that can hold either a ~str or a &'static str. This can be useful as an optimization when an allocation is sometimes needed but the common case is statically known. Possible use cases include Maps with both static and owned keys, or propagating error messages across task boundaries. SendStr implements most basic traits in a way that hides the fact that it is an enum; in particular things like order and equality are only determined by the content of the wrapped strings. Replaced std::rt:logging::SendableString with SendStr Added tests for using an SendStr as key in Hash- and Treemaps
2013-09-09rename `std::iterator` to `std::iter`Daniel Micay-8/+8
The trait will keep the `Iterator` naming, but a more concise module name makes using the free functions less verbose. The module will define iterables in addition to iterators, as it deals with iteration in general.
2013-09-05auto merge of #8997 : fhahn/rust/issue_8985, r=catamorphism,brsonbors-48/+48
Patch for #8985
2013-09-05Rename str::from_bytes to str::from_utf8, closes #8985Florian Hahn-48/+48
2013-09-05str: rm `map_chars`, replaced by iteratorsDaniel Micay-11/+0
mapping a function against the elements should not require allocating a new container, but `collect` still provides the functionality as-needed
2013-09-04std::str: Deny surrogates in is_utf8blake2-ppc-3/+12
Reject codepoints \uD800 to \uDFFF which are the surrogates (reserved/unused codepoints that are invalid to encode into UTF-8) The surrogates is the only hole of invalid codepoints in the range from \u0 to \u10FFFF.
2013-09-04auto merge of #8977 : pnkfelix/rust/fsk-followup-on-6009-rebased, r=alexcrichtonbors-1/+1
Fix #6009. Rebased version of #8970. Inherits review from alexcrichton.
2013-09-04stop treating char as an integer typeDaniel Micay-38/+8
Closes #7609
2013-09-04Added explicit pub to several conditions. Enables completion of #6009.Felix S. Klock II-1/+1
2013-09-03auto merge of #8884 : blake2-ppc/rust/exact-size-hint, r=huonwbors-15/+6
The message of the first commit explains (edited for changed trait name): The trait `ExactSize` is introduced to solve a few small niggles: * We can't reverse (`.invert()`) an enumeration iterator * for a vector, we have `v.iter().position(f)` but `v.rposition(f)`. * We can't reverse `Zip` even if both iterators are from vectors `ExactSize` is an empty trait that is intended to indicate that an iterator, for example `VecIterator`, knows its exact finite size and reports it correctly using `.size_hint()`. Only adaptors that preserve this at all times, can expose this trait further. (Where here we say finite for fitting in uint). --- It may seem complicated just to solve these small "niggles", (It's really the reversible enumerate case that's the most interesting) but only a few core iterators need to implement this trait. While we gain more capabilities generically for some iterators, it becomes a tad more complicated to figure out if a type has the right trait impls for it.
2013-09-01std::iterator: Use ExactSize, inheriting DoubleEndedIteratorblake2-ppc-1/+1
Address discussion with acrichto; inherit DoubleEndedIterator so that `.rposition()` can be a default method, and that the nische of the trait is clear. Use assertions when using `.size_hint()` in reverse enumerate and `.rposition()`
2013-08-30remove several 'ne' methodsEric Martin-4/+0
2013-08-30std::str: Use reverse enumerate and .rpositionblake2-ppc-15/+6
Simplify code by using the reversibility of enumerate and use .rposition().
2013-08-30auto merge of #8858 : blake2-ppc/rust/small-bugs, r=alexcrichtonbors-16/+21
Fix a bug in `s.slice_chars(a, b)` that did not accept `a == s.len()`. Fix a bug in `!=` defined for DList. Also simplify NormalizationIterator to use the CharIterator directly instead of mimicing the iteration itself.
2013-08-30auto merge of #8857 : blake2-ppc/rust/std-str-remove, r=thestingerbors-40/+0
These are very easy to replace with methods on string slices, basically `.char_len()` and `.len()`. These are the replacement implementations I did to clean these functions up, but seeing this I propose removal: /// ... pub fn count_chars(s: &str, begin: uint, end: uint) -> uint { // .slice() checks the char boundaries s.slice(begin, end).char_len() } /// Counts the number of bytes taken by the first `n` chars in `s` /// starting from byte index `begin`. /// /// Fails if there are less than `n` chars past `begin` pub fn count_bytes<'b>(s: &'b str, begin: uint, n: uint) -> uint { s.slice_from(begin).slice_chars(0, n).len() }
2013-08-29auto merge of #8842 : jfager/rust/remove-iter-module, r=pnkfelixbors-1/+1
Moves the Times trait to num while the question of whether it should exist at all gets hashed out as a completely separate question.
2013-08-29std::str: Fix bug in .slice_chars()blake2-ppc-0/+4
`s.slice_chars(a, b)` did not allow the case where `a == s.len()`, this is a bug I introduced last time I touched the method; add a test for this case.
2013-08-29std::str: Use CharIterator in NormalizationIteratorblake2-ppc-16/+17
Just to simplify and not have the iteration logic repeated in multiple places.
2013-08-29std::str: Remove functions count_chars, count_bytesblake2-ppc-40/+0
These are very easy to replace with methods on string slices, basically `.char_len()` and `.len()`. These are the replacement implementations I did to clean these functions up, but seeing this I propose removal: /// ... pub fn count_chars(s: &str, begin: uint, end: uint) -> uint { // .slice() checks the char boundaries s.slice(begin, end).char_len() } /// Counts the number of bytes taken by the first `n` chars in `s` /// starting from byte index `begin`. /// /// Fails if there are less than `n` chars past `begin` pub fn count_bytes<'b>(s: &'b str, begin: uint, n: uint) -> uint { s.slice_from(begin).slice_chars(0, n).len() }
2013-08-29Remove the iter module.Jason Fager-1/+1
Moves the Times trait to num while the question of whether it should exist at all gets hashed out as a completely separate question.
2013-08-27Remove offset_inbounds for an unsafe offset functionAlex Crichton-1/+1
2013-08-26Add a Default trait.Corey Richardson-15/+12
2013-08-26auto merge of #8737 : blake2-ppc/rust/std-str-rsplit, r=huonwbors-73/+305
Make CharSplitIterator double-ended which is simple given that the operation is symmetric, once the split-N feature is factored out into its own adaptor. `.rsplitn_iter()` allows splitting `N` times from the back of a string, so it is a completely new feature. With the double-ended impl, `.split_iter()`, `.line_iter()`, `.word_iter()` all allow picking off elements from either end. `split_options_iter` is removed with the factoring of the split- and split-N- iterators, instead there is `split_terminator_iter`. --- Add benchmarks using `#[bench]` and tune CharSplitIterator a bit after Huon Wilson's suggestions Benchmarks 1-5 do the same split using different implementations of `CharEq`, all splitting an ascii string on ascii space. Benchmarks 6-7 split a unicode string on an ascii char. Before this PR test str::bench::split_iter_ascii ... bench: 166 ns/iter (+/- 2) test str::bench::split_iter_closure ... bench: 113 ns/iter (+/- 1) test str::bench::split_iter_extern_fn ... bench: 286 ns/iter (+/- 7) test str::bench::split_iter_not_ascii ... bench: 114 ns/iter (+/- 4) test str::bench::split_iter_slice ... bench: 220 ns/iter (+/- 12) test str::bench::split_iter_unicode_ascii ... bench: 217 ns/iter (+/- 3) test str::bench::split_iter_unicode_not_ascii ... bench: 248 ns/iter (+/- 3) PR, first commit test str::bench::split_iter_ascii ... bench: 331 ns/iter (+/- 9) test str::bench::split_iter_closure ... bench: 114 ns/iter (+/- 2) test str::bench::split_iter_extern_fn ... bench: 314 ns/iter (+/- 6) test str::bench::split_iter_not_ascii ... bench: 132 ns/iter (+/- 1) test str::bench::split_iter_slice ... bench: 157 ns/iter (+/- 3) test str::bench::split_iter_unicode_ascii ... bench: 502 ns/iter (+/- 64) test str::bench::split_iter_unicode_not_ascii ... bench: 250 ns/iter (+/- 3) PR, final version test str::bench::split_iter_ascii ... bench: 106 ns/iter (+/- 4) test str::bench::split_iter_closure ... bench: 107 ns/iter (+/- 1) test str::bench::split_iter_extern_fn ... bench: 267 ns/iter (+/- 6) test str::bench::split_iter_not_ascii ... bench: 108 ns/iter (+/- 1) test str::bench::split_iter_slice ... bench: 170 ns/iter (+/- 8) test str::bench::split_iter_unicode_ascii ... bench: 128 ns/iter (+/- 5) test str::bench::split_iter_unicode_not_ascii ... bench: 252 ns/iter (+/- 3) --- There are several ways to deal with `CharEq::only_ascii`. It is a performance optimization, so with that in mind, we allow passing bogus char (outside ascii) as long as they don't match. We use a byte value check to make sure we don't split on these (would split substrings in the middle of encoded char). (A more principled way would be to only pass the ascii codepoints to the CharEq when it indicates only_ascii, but that undoes some of the performance optimization.)
2013-08-26std::str: Tune CharSplitIterator after benchmarksblake2-ppc-55/+44
Implement Huon Wilson's suggestions (since the benchmarks agree!). Use `self.sep.matches(byte as char) && byte < 128u8` to match in the only_ascii case so that mistaken matches outside the ascii range can't create invalid substrings. Put the conditional on only_ascii outside the loop.
2013-08-26std::str: bench tests for .split_iter()blake2-ppc-0/+83
2013-08-25Add _opt variants to str byte-conversion functionsKevin Ballard-9/+108
Add _opt variants to from_bytes, from_bytes_owned, and from_bytes_slice. These variants return an Option instead of raising a condition/failing.
2013-08-25std::str: Double-ended CharSplitIteratorblake2-ppc-68/+228
Add new methods `.rsplit_iter()` and `.rsplitn_iter()` for &str. Separate out CharSplitIterator and CharSplitNIterator, CharSplitIterator (`split_iter` and `rsplit_iter`) is made double-ended while `splitn_iter` and `rsplitn_iter` (limited to N splits) are not, since these don't have the same symmetry. With CharSplitIterator being double ended, derived iterators like `line_iter` and `word_iter` are too.
2013-08-24Add OwnedStr::into_bytesSteven Fackler-1/+16
My primary use case here is sending strings across the wire where the intermediate storage is a byte array. The new method ends up avoiding a copy.
2013-08-23Add new function str.truncate()Kevin Ballard-0/+42
2013-08-22Enabled unit tests in std and extra.Vadim Chugunov-4/+0
2013-08-21auto merge of #8590 : blake2-ppc/rust/std-str, r=alexcrichtonbors-131/+254
Implement CharIterator as a separate struct, so that it can be .clone()'d. Fix `.char_range_at_reverse` so that it performs better, closer to the forwards version. This makes the reverse iterators and users like `.rfind()` perform better. Before test str::bench::char_iterator ... bench: 146 ns/iter (+/- 0) test str::bench::char_iterator_ascii ... bench: 397 ns/iter (+/- 49) test str::bench::char_iterator_rev ... bench: 576 ns/iter (+/- 8) test str::bench::char_offset_iterator ... bench: 128 ns/iter (+/- 2) test str::bench::char_offset_iterator_rev ... bench: 425 ns/iter (+/- 59) After test str::bench::char_iterator ... bench: 130 ns/iter (+/- 1) test str::bench::char_iterator_ascii ... bench: 307 ns/iter (+/- 5) test str::bench::char_iterator_rev ... bench: 185 ns/iter (+/- 8) test str::bench::char_offset_iterator ... bench: 131 ns/iter (+/- 13) test str::bench::char_offset_iterator_rev ... bench: 183 ns/iter (+/- 2) To be able to use a string slice to represent the CharIterator, a function `slice_unchecked` is added, that does the same as `slice_bytes` but without any boundary checks. It would be possible to implement CharIterator with pointer arithmetic to make it *much more efficient*, but since vec iterator is still improving, it's too early to attempt to re-implement it in other places. Hopefully CharIterator can be implemented on top of vec iterator without any unsafe code later. Additional changes fix the documentation about null termination.
2013-08-22std::str: Add test for CharIterator .clone()blake2-ppc-0/+8
2013-08-21Add support for performing NFD and NFKD on stringsFlorian Zeitz-0/+143
2013-08-19std::str: Use iterators instead of while loops for CharSplitIteratorblake2-ppc-33/+45
Embed an iterator in the CharSplitIterator struct, and combine that with the former bool `only_ascii`; so use an enum instead.
2013-08-19Add externfn macro and correctly label fixed_stack_segmentsNiko Matsakis-0/+1
2013-08-19std::str: Improve comments for CharIteratorblake2-ppc-1/+9
2013-08-19std::str: Use CharOffsetIterator in slice_charsblake2-ppc-13/+14
2013-08-19std::str: Only check char boundary for end index in .slice_to()blake2-ppc-1/+2
2013-08-19std::str: Correct docstrings for lack of null terminator in ~str and &strblake2-ppc-24/+13