mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 09:00:22 +03:00
Merge pull request #1576 from tom-tan/safe-pure-nothrow-array-split
Mark std.array.split and splitter as @safe, pure and nothrow
This commit is contained in:
commit
55ec22276b
1 changed files with 10 additions and 12 deletions
22
std/array.d
22
std/array.d
|
@ -1299,7 +1299,7 @@ unittest
|
||||||
Split the string $(D s) into an array of words, using whitespace as
|
Split the string $(D s) into an array of words, using whitespace as
|
||||||
delimiter. Runs of whitespace are merged together (no empty words are produced).
|
delimiter. Runs of whitespace are merged together (no empty words are produced).
|
||||||
*/
|
*/
|
||||||
S[] split(S)(S s) if (isSomeString!S)
|
S[] split(S)(S s) @safe pure if (isSomeString!S)
|
||||||
{
|
{
|
||||||
size_t istart;
|
size_t istart;
|
||||||
bool inword = false;
|
bool inword = false;
|
||||||
|
@ -1348,20 +1348,21 @@ unittest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Splits a string by whitespace.
|
Splits a string by whitespace.
|
||||||
|
|
||||||
Example:
|
|
||||||
----
|
|
||||||
auto a = " a bcd ef gh ";
|
|
||||||
assert(equal(splitter(a), ["", "a", "bcd", "ef", "gh"][]));
|
|
||||||
----
|
|
||||||
*/
|
*/
|
||||||
auto splitter(C)(C[] s)
|
auto splitter(C)(C[] s) @safe pure
|
||||||
if(isSomeString!(C[]))
|
if(isSomeString!(C[]))
|
||||||
{
|
{
|
||||||
return std.algorithm.splitter!(std.uni.isWhite)(s);
|
return std.algorithm.splitter!(std.uni.isWhite)(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
///
|
||||||
|
@safe pure unittest
|
||||||
|
{
|
||||||
|
auto a = " a bcd ef gh ";
|
||||||
|
assert(equal(splitter(a), ["", "a", "bcd", "ef", "gh"][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@safe*/ pure unittest
|
||||||
{
|
{
|
||||||
foreach(S; TypeTuple!(string, wstring, dstring))
|
foreach(S; TypeTuple!(string, wstring, dstring))
|
||||||
{
|
{
|
||||||
|
@ -1370,9 +1371,6 @@ unittest
|
||||||
a = "";
|
a = "";
|
||||||
assert(splitter(a).empty);
|
assert(splitter(a).empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
immutable string s = " a bcd ef gh ";
|
|
||||||
assert(equal(splitter(s), ["", "a", "bcd", "ef", "gh"][]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue