mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 15:10:46 +03:00
Merge remote-tracking branch 'upstream/stable' into merge_stable
This commit is contained in:
commit
f127643ed7
3 changed files with 107 additions and 17 deletions
40
changelog.dd
40
changelog.dd
|
@ -8,7 +8,15 @@ $(BUGSTITLE Library Changes,
|
||||||
|
|
||||||
$(LI $(RELATIVE_LINK2 more-rangified-functions, More phobos functions were rangified.))
|
$(LI $(RELATIVE_LINK2 more-rangified-functions, More phobos functions were rangified.))
|
||||||
$(LI $(RELATIVE_LINK2 std-algorithm-moveEmplace, `moveEmplace` was added))
|
$(LI $(RELATIVE_LINK2 std-algorithm-moveEmplace, `moveEmplace` was added))
|
||||||
|
$(LI $(RELATIVE_LINK2 std-algorithm-isPermutation, `isPermutation` was added))
|
||||||
|
$(LI $(RELATIVE_LINK2 std-algorithm-isSameLength, `isSameLength` was added))
|
||||||
$(LI $(RELATIVE_LINK2 curl-dynamic-loading, libcurl is now loaded dynamically))
|
$(LI $(RELATIVE_LINK2 curl-dynamic-loading, libcurl is now loaded dynamically))
|
||||||
|
$(LI $(XREF traits, getUDAs) was added to help get
|
||||||
|
user-defined attributes of specific types from symbols.)
|
||||||
|
$(LI $(XREF traits, getSymbolsByUDA) was
|
||||||
|
added to find symbols with specific user-defined attributes.)
|
||||||
|
$(LI $(XREF math, cmp) was added, defining total ordering on
|
||||||
|
floating-point numbers, including NaN.)
|
||||||
$(LI FreeBSD now also ships with a shared libphobos2.so library ($(LINK2 http://dlang.org/dll-linux.html, usage info)).)
|
$(LI FreeBSD now also ships with a shared libphobos2.so library ($(LINK2 http://dlang.org/dll-linux.html, usage info)).)
|
||||||
$(LI The package $(STDMODREF experimental_allocator, std.experimental.allocator) was added.)
|
$(LI The package $(STDMODREF experimental_allocator, std.experimental.allocator) was added.)
|
||||||
|
|
||||||
|
@ -61,7 +69,7 @@ $(LI $(LNAME2 more-rangified-functions, More phobos functions were rangified.)
|
||||||
|
|
||||||
$(LI $(LNAME2 std-algorithm-moveEmplace, A combined `moveEmplace` was added.)
|
$(LI $(LNAME2 std-algorithm-moveEmplace, A combined `moveEmplace` was added.)
|
||||||
|
|
||||||
$(P $(XREF algorithm_mutation, MoveEmplace) efficiently combines $(XREF
|
$(P $(XREF algorithm_mutation, moveEmplace) efficiently combines $(XREF
|
||||||
algorithm_mutation, move) with $(XREF conv, emplace) thus avoids having
|
algorithm_mutation, move) with $(XREF conv, emplace) thus avoids having
|
||||||
to initialize and destroy a value before moving into uninitialized data.
|
to initialize and destroy a value before moving into uninitialized data.
|
||||||
)
|
)
|
||||||
|
@ -83,6 +91,36 @@ $(LI $(LNAME2 std-algorithm-moveEmplace, A combined `moveEmplace` was added.)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$(LI $(LNAME2 std-algorithm-isPermutation, `isPermutation` was added.)
|
||||||
|
|
||||||
|
$(P $(XREF algorithm_comparison, isPermuatation) compares two forward ranges to
|
||||||
|
determine if they are permuations of each other.
|
||||||
|
)
|
||||||
|
|
||||||
|
------
|
||||||
|
auto r1 = [10, 15, 7, 12, 30];
|
||||||
|
auto r2 = [7, 10, 12, 15, 30];
|
||||||
|
|
||||||
|
assert(r1.isPermutation(r2));
|
||||||
|
------
|
||||||
|
)
|
||||||
|
|
||||||
|
$(LI $(LNAME2 std-algorithm-isSameLength, `isSameLength` was added.)
|
||||||
|
|
||||||
|
$(P $(XREF algorithm_comparison, isSameLength) compares two input ranges to
|
||||||
|
determine if they have the same length. This algorithm always takes advantage
|
||||||
|
of the `length` range primitive if it exists. Otherwise, this algorithm will
|
||||||
|
walk the ranges to find their length.
|
||||||
|
)
|
||||||
|
|
||||||
|
------
|
||||||
|
auto r1 = [1, 10, 100, 1000, 10000];
|
||||||
|
auto r2 = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
|
assert(r1.isSameLength(r2));
|
||||||
|
------
|
||||||
|
)
|
||||||
|
|
||||||
$(LI $(RELATIVE_LINK2 curl-dynamic-loading, libcurl is now loaded dynamically)
|
$(LI $(RELATIVE_LINK2 curl-dynamic-loading, libcurl is now loaded dynamically)
|
||||||
|
|
||||||
$(P $(STDMODREF net_curl, std.net.curl) was changed to load curl as shared
|
$(P $(STDMODREF net_curl, std.net.curl) was changed to load curl as shared
|
||||||
|
|
|
@ -1170,7 +1170,7 @@ unittest// Issue 8057
|
||||||
static assert(__traits(compiles, move(x, x) ));
|
static assert(__traits(compiles, move(x, x) ));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Similar to $(LREF move) but assumes `target` is uninitialized. This
|
* Similar to $(LREF move) but assumes `target` is uninitialized. This
|
||||||
* is more efficient because `source` can be blitted over `target`
|
* is more efficient because `source` can be blitted over `target`
|
||||||
* without destroying or initializing it first.
|
* without destroying or initializing it first.
|
||||||
|
|
78
std/string.d
78
std/string.d
|
@ -2460,7 +2460,7 @@ S[] splitLines(S)(S s, in KeepTerminator keepTerm = KeepTerminator.no) @safe pur
|
||||||
*/
|
*/
|
||||||
auto lineSplitter(KeepTerminator keepTerm = KeepTerminator.no, Range)(Range r)
|
auto lineSplitter(KeepTerminator keepTerm = KeepTerminator.no, Range)(Range r)
|
||||||
if ((hasSlicing!Range && hasLength!Range) ||
|
if ((hasSlicing!Range && hasLength!Range) ||
|
||||||
isSomeString!Range)
|
__traits(compiles, StringTypeOf!Range))
|
||||||
{
|
{
|
||||||
import std.uni : lineSep, paraSep;
|
import std.uni : lineSep, paraSep;
|
||||||
import std.conv : unsigned;
|
import std.conv : unsigned;
|
||||||
|
@ -2468,7 +2468,11 @@ if ((hasSlicing!Range && hasLength!Range) ||
|
||||||
static struct Result
|
static struct Result
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
static if (__traits(compiles, StringTypeOf!Range))
|
||||||
|
StringTypeOf!Range _input;
|
||||||
|
else
|
||||||
Range _input;
|
Range _input;
|
||||||
|
|
||||||
alias IndexType = typeof(unsigned(_input.length));
|
alias IndexType = typeof(unsigned(_input.length));
|
||||||
enum IndexType _unComputed = IndexType.max;
|
enum IndexType _unComputed = IndexType.max;
|
||||||
IndexType iStart = _unComputed;
|
IndexType iStart = _unComputed;
|
||||||
|
@ -2493,7 +2497,7 @@ if ((hasSlicing!Range && hasLength!Range) ||
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@property Range front()
|
@property typeof(_input) front()
|
||||||
{
|
{
|
||||||
if (iStart == _unComputed)
|
if (iStart == _unComputed)
|
||||||
{
|
{
|
||||||
|
@ -2613,6 +2617,7 @@ if ((hasSlicing!Range && hasLength!Range) ||
|
||||||
"\rpeter\n\rpaul\r\njerry\u2028ice\u2029cream\n\n" ~
|
"\rpeter\n\rpaul\r\njerry\u2028ice\u2029cream\n\n" ~
|
||||||
"sunday\nmon\u2030day\nschadenfreude\vkindergarten\f\vcookies\u0085"
|
"sunday\nmon\u2030day\nschadenfreude\vkindergarten\f\vcookies\u0085"
|
||||||
);
|
);
|
||||||
|
|
||||||
auto lines = lineSplitter(s).array;
|
auto lines = lineSplitter(s).array;
|
||||||
assert(lines.length == 14);
|
assert(lines.length == 14);
|
||||||
assert(lines[0] == "");
|
assert(lines[0] == "");
|
||||||
|
@ -2678,24 +2683,43 @@ if ((hasSlicing!Range && hasLength!Range) ||
|
||||||
assert(i == witness.length);
|
assert(i == witness.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.file : DirEntry;
|
||||||
|
import std.algorithm.comparison : equal;
|
||||||
|
|
||||||
|
auto s = "std/string.d";
|
||||||
|
auto de = DirEntry(s);
|
||||||
|
auto i = de.lineSplitter();
|
||||||
|
auto j = s.lineSplitter();
|
||||||
|
|
||||||
|
assert(equal(i, j));
|
||||||
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
Strips leading whitespace (as defined by $(XREF uni, isWhite)).
|
Strips leading whitespace (as defined by $(XREF uni, isWhite)).
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
str = string or ForwardRange of characters
|
input = string or ForwardRange of characters
|
||||||
|
|
||||||
Returns: $(D str) stripped of leading whitespace.
|
Returns: $(D input) stripped of leading whitespace.
|
||||||
|
|
||||||
Postconditions: $(D str) and the returned value
|
Postconditions: $(D input) and the returned value
|
||||||
will share the same tail (see $(XREF array, sameTail)).
|
will share the same tail (see $(XREF array, sameTail)).
|
||||||
+/
|
+/
|
||||||
Range stripLeft(Range)(Range str)
|
auto stripLeft(Range)(Range input)
|
||||||
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range))
|
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) ||
|
||||||
|
__traits(compiles, StringTypeOf!Range))
|
||||||
{
|
{
|
||||||
import std.ascii : isASCII, isWhite;
|
import std.ascii : isASCII, isWhite;
|
||||||
import std.uni : isWhite;
|
import std.uni : isWhite;
|
||||||
import std.utf : decodeFront;
|
import std.utf : decodeFront;
|
||||||
|
|
||||||
|
static if (__traits(compiles, StringTypeOf!Range))
|
||||||
|
StringTypeOf!Range str = input;
|
||||||
|
else
|
||||||
|
alias str = input;
|
||||||
|
|
||||||
while (!str.empty)
|
while (!str.empty)
|
||||||
{
|
{
|
||||||
auto c = str.front;
|
auto c = str.front;
|
||||||
|
@ -2737,23 +2761,40 @@ Range stripLeft(Range)(Range str)
|
||||||
"hello world ");
|
"hello world ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
static struct ToString
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
alias s this;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(stripLeft(ToString(" hello")) == "hello");
|
||||||
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
Strips trailing whitespace (as defined by $(XREF uni, isWhite)).
|
Strips trailing whitespace (as defined by $(XREF uni, isWhite)).
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
str = string or random access range of characters
|
input = string or random access range of characters
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
slice of $(D str) stripped of trailing whitespace.
|
slice of $(D input) stripped of trailing whitespace.
|
||||||
+/
|
+/
|
||||||
auto stripRight(Range)(Range str)
|
auto stripRight(Range)(Range input)
|
||||||
if (isSomeString!Range ||
|
if (isSomeString!Range ||
|
||||||
isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range &&
|
(isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range &&
|
||||||
isSomeChar!(ElementEncodingType!Range))
|
isSomeChar!(ElementEncodingType!Range))
|
||||||
|
|| __traits(compiles, StringTypeOf!Range))
|
||||||
{
|
{
|
||||||
alias C = Unqual!(ElementEncodingType!Range);
|
static if (__traits(compiles, StringTypeOf!Range))
|
||||||
static if (isSomeString!Range)
|
StringTypeOf!Range str = input;
|
||||||
|
else
|
||||||
|
alias str = input;
|
||||||
|
|
||||||
|
alias C = Unqual!(ElementEncodingType!(typeof(str)));
|
||||||
|
|
||||||
|
static if (isSomeString!(typeof(str)))
|
||||||
{
|
{
|
||||||
import std.utf : codeLength;
|
import std.utf : codeLength;
|
||||||
foreach_reverse (i, dchar c; str)
|
foreach_reverse (i, dchar c; str)
|
||||||
|
@ -2856,6 +2897,17 @@ unittest
|
||||||
[paraSep] ~ "hello world");
|
[paraSep] ~ "hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
static struct ToString
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
alias s this;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(stripRight(ToString("hello ")) == "hello");
|
||||||
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
import std.utf;
|
import std.utf;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue