Skip to content

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/phobos
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Nov 4, 2012
2 parents 49cbab4 + 941b46a commit d8cc002
Show file tree
Hide file tree
Showing 24 changed files with 2,222 additions and 636 deletions.
1 change: 1 addition & 0 deletions changelog.dd
Expand Up @@ -3,6 +3,7 @@ $(VERSION 061, ddd mm, 2012, =================================================,
$(LI std.digest: Added new package for digests. This replaces std.md5 and the internal crc32
implementation.)
$(LI std.digest.sha: Added SHA1 digest implementation.)
$(LI std.digest.ripemd: Added RIPEMD-160 digest implementation.)
$(LI std.uuid: Support SHA1 UUIDs.)
$(LI std.uuid: md5UUID and sha1UUID can now be used in pure code.)
$(LI std.net.curl: Added operationTimeout.)
Expand Down
2 changes: 1 addition & 1 deletion posix.mak
Expand Up @@ -173,7 +173,7 @@ STD_MODULES = $(addprefix std/, algorithm array ascii base64 bigint \

STD_NET_MODULES = $(addprefix std/net/, isemail curl)

STD_DIGEST_MODULES = $(addprefix std/digest/, digest crc md sha)
STD_DIGEST_MODULES = $(addprefix std/digest/, digest crc md ripemd sha)

# OS-specific D modules
EXTRA_MODULES_LINUX := $(addprefix std/c/linux/, linux socket)
Expand Down
12 changes: 7 additions & 5 deletions std/algorithm.d
Expand Up @@ -878,6 +878,8 @@ assert(a == [ 5, 5, 5, 5 ]);
void fill(Range, Value)(Range range, Value filler)
if (isInputRange!Range && is(typeof(range.front = filler)))
{
alias ElementType!Range T;

static if (is(typeof(range[] = filler)))
{
range[] = filler;
Expand Down Expand Up @@ -3177,7 +3179,7 @@ if (isRandomAccessRange!R1 && isBidirectionalRange!R2
&& is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))
{
if (needle.empty) return haystack;
const needleLength = walkLength(needle);
const needleLength = walkLength(needle.save);
if (needleLength > haystack.length)
{
// @@@BUG@@@
Expand Down Expand Up @@ -3774,7 +3776,7 @@ ranges. $(D result[0]) is the portion of $(D haystack) before $(D
needle), $(D result[1]) is the portion of $(D haystack) that matches
$(D needle), and $(D result[2]) is the portion of $(D haystack) after
the match. If $(D needle) was not found, $(D result[0])
comprehends $(D haystack) entirely and $(D result[1]) and $(D result[2]
comprehends $(D haystack) entirely and $(D result[1]) and $(D result[2])
are empty.
$(D findSplitBefore) returns a tuple $(D result) containing two
Expand Down Expand Up @@ -5045,7 +5047,7 @@ nesting is allowed.
Example:
----
auto s = "1 + (2 * (3 + 1 / 2)";
auto s = "1 + $(LPAREN)2 * (3 + 1 / 2)";
assert(!balancedParens(s, '(', ')'));
s = "1 + (2 * (3 + 1) / 2)";
assert(balancedParens(s, '(', ')'));
Expand Down Expand Up @@ -5741,7 +5743,7 @@ struct Levenshtein(Range, alias equals, CostType = size_t)

CostType distance(Range s, Range t)
{
auto slen = walkLength(s), tlen = walkLength(t);
auto slen = walkLength(s.save), tlen = walkLength(t.save);
AllocMatrix(slen + 1, tlen + 1);
foreach (i; 1 .. rows)
{
Expand Down Expand Up @@ -7053,7 +7055,7 @@ Example:
----
auto a = [ 8, 3, 4, 1, 4, 7, 4 ];
auto pieces = partition3(a, 4);
assert(a == [ 1, 3, 4, 4, 4, 7, 8 ];
assert(a == [ 1, 3, 4, 4, 4, 7, 8 ]);
assert(pieces[0] == [ 1, 3 ]);
assert(pieces[1] == [ 4, 4, 4 ]);
assert(pieces[2] == [ 7, 8 ]);
Expand Down
17 changes: 5 additions & 12 deletions std/array.d
Expand Up @@ -393,16 +393,8 @@ if (isNarrowString!S && isMutable!S && !isStaticArray!S)
immutable c = str[0];
if(c < 0x80)
{
if(__ctfe)
{
//The ptr trick doesn't work in CTFE.
str = str[1 .. $];
}
else
{
//ptr is used to avoid unnnecessary bounds checking.
str = str.ptr[1 .. str.length];
}
//ptr is used to avoid unnnecessary bounds checking.
str = str.ptr[1 .. str.length];
}
else
{
Expand Down Expand Up @@ -623,6 +615,7 @@ unittest

// overlap
/*
NOTE: Undocumented for now, overlap does not yet work with ctfe.
Returns the overlapping portion, if any, of two arrays. Unlike $(D
equal), $(D overlap) only compares the pointers in the ranges, not the
values referred by them. If $(D r1) and $(D r2) have an overlapping
Expand Down Expand Up @@ -1555,11 +1548,11 @@ if (isDynamicArray!(E[]) && isForwardRange!R1 && isForwardRange!R2
}

/++
Same as above, but outputs the result via OutputRange $(D sink).
Same as above, but outputs the result via OutputRange $(D sink).
If no match is found the original array is transfered to $(D sink) as is.
+/
void replaceInto(E, Sink, R1, R2)(Sink sink, E[] subject, R1 from, R2 to)
if (isOutputRange!(Sink, E) && isDynamicArray!(E[])
if (isOutputRange!(Sink, E) && isDynamicArray!(E[])
&& isForwardRange!R1 && isForwardRange!R2
&& (hasLength!R2 || isSomeString!R2))
{
Expand Down
3 changes: 1 addition & 2 deletions std/bigint.d
Expand Up @@ -493,9 +493,8 @@ private:
// Generate a runtime error if division by zero occurs
void checkDivByZero() pure const
{
assert(!isZero(), "BigInt division by zero");
if (isZero())
auto x = 1/toInt(); // generate a div by zero error
throw new Error("BigInt division by zero");
}
}

Expand Down
61 changes: 43 additions & 18 deletions std/bitmanip.d
Expand Up @@ -115,7 +115,7 @@ private template createAccessors(
~"assert(v >= "~name~"_min); "
~"assert(v <= "~name~"_max); "
~store~" = cast(typeof("~store~"))"
" (("~store~" & ~"~myToString(maskAllElse)~")"
" (("~store~" & ~cast(typeof("~store~"))"~myToString(maskAllElse)~")"
" | ((cast(typeof("~store~")) v << "~myToString(offset)~")"
" & "~myToString(maskAllElse)~"));}\n"
// constants
Expand Down Expand Up @@ -241,24 +241,49 @@ unittest

unittest
{
static struct Integrals {
bool checkExpectations(bool eb, int ei, short es) { return b == eb && i == ei && s == es; }
{
static struct Integrals {
bool checkExpectations(bool eb, int ei, short es) { return b == eb && i == ei && s == es; }

mixin(bitfields!(
bool, "b", 1,
uint, "i", 3,
short, "s", 4));
}
Integrals i;
assert(i.checkExpectations(false, 0, 0));
i.b = true;
assert(i.checkExpectations(true, 0, 0));
i.i = 7;
assert(i.checkExpectations(true, 7, 0));
i.s = -8;
assert(i.checkExpectations(true, 7, -8));
i.s = 7;
assert(i.checkExpectations(true, 7, 7));
mixin(bitfields!(
bool, "b", 1,
uint, "i", 3,
short, "s", 4));
}
Integrals i;
assert(i.checkExpectations(false, 0, 0));
i.b = true;
assert(i.checkExpectations(true, 0, 0));
i.i = 7;
assert(i.checkExpectations(true, 7, 0));
i.s = -8;
assert(i.checkExpectations(true, 7, -8));
i.s = 7;
assert(i.checkExpectations(true, 7, 7));
}

//Bug# 8876
{
struct MoreIntegrals {
bool checkExpectations(uint eu, ushort es, uint ei) { return u == eu && s == es && i == ei; }

mixin(bitfields!(
uint, "u", 24,
short, "s", 16,
int, "i", 24));
}

MoreIntegrals i;
assert(i.checkExpectations(0, 0, 0));
i.s = 20;
assert(i.checkExpectations(0, 20, 0));
i.i = 72;
assert(i.checkExpectations(0, 20, 72));
i.u = 8;
assert(i.checkExpectations(8, 20, 72));
i.s = 7;
assert(i.checkExpectations(8, 7, 72));
}

enum A { True, False }
enum B { One, Two, Three, Four }
Expand Down

0 comments on commit d8cc002

Please sign in to comment.