about summary refs log tree commit diff
path: root/src/libstd/str.rs
AgeCommit message (Collapse)AuthorLines
2013-08-19Add externfn macro and correctly label fixed_stack_segmentsNiko Matsakis-0/+1
2013-08-18auto merge of #8555 : chris-morgan/rust/time-clone, r=huonwbors-1/+15
I need `Clone` for `Tm` for my latest work on [rust-http](https://github.com/chris-morgan/rust-http) (static typing for headers, and headers like `Date` are a time), so here it is. @huonw recommended deriving DeepClone while I was at it. I also had to implement `DeepClone` for `~str` to get a derived implementation of `DeepClone` for `Tm`; I did `@str` while I was at it, for consistency.
2013-08-16Implement DeepClone for str types.Chris Morgan-1/+15
2013-08-16doc: correct spelling in documentation.Huon Wilson-2/+2
2013-08-15auto merge of #8490 : huonw/rust/fromiterator-extendable, r=catamorphismbors-4/+4
If they are on the trait then it is extremely annoying to use them as generic parameters to a function, e.g. with the iterator param on the trait itself, if one was to pass an Extendable<int> to a function that filled it either from a Range or a Map<VecIterator>, one needs to write something like: fn foo<E: Extendable<int, Range<int>> + Extendable<int, Map<&'self int, int, VecIterator<int>>> (e: &mut E, ...) { ... } since using a generic, i.e. `foo<E: Extendable<int, I>, I: Iterator<int>>` means that `foo` takes 2 type parameters, and the caller has to specify them (which doesn't work anyway, as they'll mismatch with the iterators used in `foo` itself). This patch changes it to: fn foo<E: Extendable<int>>(e: &mut E, ...) { ... }
2013-08-15std: Move the iterator param on FromIterator and Extendable to the method.Huon Wilson-4/+4
If they are on the trait then it is extremely annoying to use them as generic parameters to a function, e.g. with the iterator param on the trait itself, if one was to pass an Extendable<int> to a function that filled it either from a Range or a Map<VecIterator>, one needs to write something like: fn foo<E: Extendable<int, Range<int>> + Extendable<int, Map<&'self int, int, VecIterator<int>>> (e: &mut E, ...) { ... } since using a generic, i.e. `foo<E: Extendable<int, I>, I: Iterator<int>>` means that `foo` takes 2 type parameters, and the caller has to specify them (which doesn't work anyway, as they'll mismatch with the iterators used in `foo` itself). This patch changes it to: fn foo<E: Extendable<int>>(e: &mut E, ...) { ... }
2013-08-14Methodyfied the string ascii extionsion functionsMarvin Löbel-1/+1
Added into_owned() method for vectors Added DoubleEnded Iterator impl to Option Renamed nil.rs to unit.rs
2013-08-13auto merge of #8446 : alexcrichton/rust/ifmt++, r=graydonbors-41/+12
This includes a number of improvements to `ifmt!` * Implements formatting arguments -- `{:0.5x}` works now * Formatting now works on all integer widths, not just `int` and `uint` * Added a large doc block to `std::fmt` which should help explain what `ifmt!` is all about * Added floating point formatters, although they have the same pitfalls from before (they're just proof-of-concept now) Closed a couple of issues along the way, yay! Once this gets into a snapshot, I'll start looking into removing all of `fmt`
2013-08-12Forbid pub/priv where it has no effectAlex Crichton-6/+6
Closes #5495
2013-08-12Implement formatting arguments for strings and integersAlex Crichton-41/+12
Closes #1651
2013-08-12fix build with the new snapshot compilerDaniel Micay-426/+2
2013-08-11move `strdup_uniq` lang item to std::strDaniel Micay-0/+8
2013-08-11str: optimize `with_capacity`Daniel Micay-3/+21
before: test bench_with_capacity ... bench: 104 ns/iter (+/- 4) after: test bench_with_capacity ... bench: 56 ns/iter (+/- 1)
2013-08-10std: fix the non-stage0 str::raw::slice_bytes which broke in a mergeErick Tryzelaar-1/+1
2013-08-10std: Transform.find_ -> .findErick Tryzelaar-2/+2
2013-08-10std: Iterator.len_ -> .lenErick Tryzelaar-1/+1
2013-08-10std: Rename Iterator.transform -> .mapErick Tryzelaar-8/+8
cc #5898
2013-08-10std: merge Iterator and IteratorUtilErick Tryzelaar-2/+1
2013-08-10std: merge iterator::DoubleEndedIterator and DoubleEndedIteratorUtilErick Tryzelaar-1/+1
2013-08-09Merge remote-tracking branch 'remotes/origin/master' into ↵Erick Tryzelaar-18/+0
remove-str-trailing-nulls
2013-08-09Remove redundant Ord method impls.OGINO Masanori-18/+0
Basically, generic containers should not use the default methods since a type of elements may not guarantees total order. str could use them since u8's Ord guarantees total order. Floating point numbers are also broken with the default methods because of NaN. Thanks for @thestinger. Timespec also guarantees total order AIUI. I'm unsure whether extra::semver::Identifier does so I left it alone. Proof needed. Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2013-08-08Merge remote-tracking branch 'remotes/origin/master' into ↵Erick Tryzelaar-11/+11
remove-str-trailing-nulls
2013-08-07Forbid `priv` where it has no effectAlex Crichton-10/+10
This is everywhere except struct fields and enum variants.
2013-08-07Merge remote-tracking branch 'remotes/origin/master' into ↵Erick Tryzelaar-11/+14
remove-str-trailing-nulls
2013-08-07auto merge of #8294 : erickt/rust/map-move, r=bblumbors-1/+1
According to #7887, we've decided to use the syntax of `fn map<U>(f: &fn(&T) -> U) -> U`, which passes a reference to the closure, and to `fn map_move<U>(f: &fn(T) -> U) -> U` which moves the value into the closure. This PR adds these `.map_move()` functions to `Option` and `Result`. In addition, it has these other minor features: * Replaces a couple uses of `option.get()`, `result.get()`, and `result.get_err()` with `option.unwrap()`, `result.unwrap()`, and `result.unwrap_err()`. (See #8268 and #8288 for a more thorough adaptation of this functionality. * Removes `option.take_map()` and `option.take_map_default()`. These two functions can be easily written as `.take().map_move(...)`. * Adds a better error message to `result.unwrap()` and `result.unwrap_err()`.
2013-08-07core: option.map_consume -> option.map_moveErick Tryzelaar-1/+1
2013-08-07auto merge of #8305 : huonw/rust/triage-fixes, r=cmrbors-11/+14
The two deletions are because the test cases are very old (still using `class` and modes!), and, as far as I can tell (since they are so old), the areas they test are well tested by other rpass tests.
2013-08-07std: adjust str::test_add so that the macro expands to all 3 items (#8012).Huon Wilson-11/+14
Closes #3682.
2013-08-06Merge remote-tracking branch 'remotes/origin/master' into ↵Erick Tryzelaar-3/+3
remove-str-trailing-nulls
2013-08-06std: update str.push_byte to work without str trailing nullsErick Tryzelaar-1/+10
2013-08-06Merge commit 'd89ff7eef969aee6b493bc846b64d68358fafbcd' into ↵Erick Tryzelaar-1/+8
remove-str-trailing-nulls
2013-08-06auto merge of #8308 : blake2-ppc/rust/str-slice-bytes, r=alexcrichtonbors-1/+1
`fn slice_bytes` is marked unsafe since it allows violating the valid string encoding property; but the function did also allow extending the lifetime of the slice by mistake, since it's returning `&str`. Use the annotation `slice_bytes<'a>(&'a str, ...) -> &'a str` so that all uses of `slice_bytes` are region checked correctly.
2013-08-05Updated std::Option, std::Either and std::ResultMarvin Löbel-2/+2
- Made naming schemes consistent between Option, Result and Either - Changed Options Add implementation to work like the maybe monad (return None if any of the inputs is None) - Removed duplicate Option::get and renamed all related functions to use the term `unwrap` instead
2013-08-05std: Use correct lifetime parameter on str::raw::slice_bytesblake2-ppc-1/+1
fn slice_bytes is marked unsafe since it allows violating the valid string encoding property; but the function did also allow extending the lifetime of the slice by mistake, since it's returning `&str`. Use the annotation `slice_bytes<'a>(&'a str, ...) -> &'a str` so that all uses of slice_bytes are region checked correctly.
2013-08-05auto merge of #8289 : sfackler/rust/push_byte, r=ericktbors-1/+8
It was previously pushing the byte on top of the string's null terminator. I added a test to make sure it doesn't break in the future.
2013-08-04Merge remote-tracking branch 'remotes/origin/master' into str-remove-nullErick Tryzelaar-67/+99
2013-08-04Remove trailing null from stringsErick Tryzelaar-10/+374
2013-08-04std: merge str::raw::from_buf and str::raw::from_c_strErick Tryzelaar-22/+12
2013-08-04std: replace str::as_c_str with std::c_strErick Tryzelaar-98/+0
2013-08-04std: remove str::from_bytes_with_nullErick Tryzelaar-82/+0
2013-08-04std: add test for str::as_c_strErick Tryzelaar-0/+23
2013-08-04std: remove str::NullTerminatedStrErick Tryzelaar-54/+1
2013-08-04std: add str.to_c_str()Erick Tryzelaar-0/+26
2013-08-04Fixed str::raw::push_byteSteven Fackler-1/+8
It was previously pushing the byte on top of the string's null terminator. I added a test to make sure it doesn't break in the future.
2013-08-04auto merge of #8237 : blake2-ppc/rust/faster-utf8, r=brsonbors-35/+67
Use unchecked vec indexing since the vector bounds are checked by the loop. Iterators are not easy to use in this case since we skip 1-4 bytes each lap. This part of the commit speeds up is_utf8 for ASCII input. Check codepoint ranges by checking the byte ranges manually instead of computing a full decoding for multibyte encodings. This is easy to read and corresponds to the UTF-8 syntax in the RFC. No changes to what we accept. A comment notes that surrogate halves are accepted. Before: test str::bench::is_utf8_100_ascii ... bench: 165 ns/iter (+/- 3) test str::bench::is_utf8_100_multibyte ... bench: 218 ns/iter (+/- 5) After: test str::bench::is_utf8_100_ascii ... bench: 130 ns/iter (+/- 1) test str::bench::is_utf8_100_multibyte ... bench: 156 ns/iter (+/- 3) An improvement upon the previous pull #8133
2013-08-03remove obsolete `foreach` keywordDaniel Micay-30/+30
this has been replaced by `for`
2013-08-02std: Speed up str::is_utf8blake2-ppc-35/+67
Use unchecked vec indexing since the vector bounds are checked by the loop. Iterators are not easy to use in this case since we skip 1-4 bytes each lap. This part of the commit speeds up is_utf8 for ASCII input. Check codepoint ranges by checking the byte ranges manually instead of computing a full decoding for multibyte encodings. This is easy to read and corresponds to the UTF-8 syntax in the RFC. No changes to what we accept. A comment notes that surrogate halves are accepted. Before: test str::bench::is_utf8_100_ascii ... bench: 165 ns/iter (+/- 3) test str::bench::is_utf8_100_multibyte ... bench: 218 ns/iter (+/- 5) After: test str::bench::is_utf8_100_ascii ... bench: 130 ns/iter (+/- 1) test str::bench::is_utf8_100_multibyte ... bench: 156 ns/iter (+/- 3)
2013-08-01str: Add method .into_owned(self) -> ~str to StrKevin Ballard-0/+12
The method .into_owned() is meant to be used as an optimization when you need to get a ~str from a Str, but don't want to unnecessarily copy it if it's already a ~str. This is meant to ease functions that look like fn foo<S: Str>(strs: &[S]) Previously they could work with the strings as slices using .as_slice(), but producing ~str required copying the string, even if the vector turned out be a &[~str] already.
2013-08-01std: Change `Times` trait to use `do` instead of `for`blake2-ppc-1/+1
Change the former repetition:: for 5.times { } to:: do 5.times { } .times() cannot be broken with `break` or `return` anymore; for those cases, use a numerical range loop instead.
2013-08-01migrate many `for` loops to `foreach`Daniel Micay-31/+32