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
andralex committed Feb 23, 2012
2 parents 94b21d3 + 3e4a76d commit 7d1ef0e
Show file tree
Hide file tree
Showing 23 changed files with 840 additions and 876 deletions.
2 changes: 2 additions & 0 deletions changelog.dd
Expand Up @@ -30,6 +30,8 @@ $(VERSION 058, ddd mm, 2012, =================================================,
$(LI std.uni's isUniLower, isUniUpper, toUniLower, toUniUpper, and isUniAlpha
have been deprecated. Please use the versions of these functions which do
not have Uni in their name.)
$(LI Get rid of Windows 3.x and Windows 9x support. Affected modules: std.file,
std.mmfile, std.stream, and std.windows.registry.)
)

$(LIBBUGSFIXED
Expand Down
4 changes: 2 additions & 2 deletions etc/c/sqlite3.d
Expand Up @@ -47,7 +47,7 @@ enum SQLITE_SOURCE_ID = "2011-04-17 17:25:17 154ddbc17120be2915eb03edc52
/**
** CAPI3REF: Run-Time Library Version Numbers
*/
immutable(char)* sqlite3_version;
extern immutable(char)* sqlite3_version;
/// Ditt
immutable(char)* sqlite3_libversion();
/// Ditto
Expand Down Expand Up @@ -1037,7 +1037,7 @@ int sqlite3_sleep(int);
/**
** CAPI3REF: Name Of The Folder Holding Temporary Files
*/
char *sqlite3_temp_directory;
extern char *sqlite3_temp_directory;

/**
** CAPI3REF: Test For Auto-Commit Mode
Expand Down
2 changes: 1 addition & 1 deletion posix.mak
Expand Up @@ -194,7 +194,7 @@ D_FILES = $(addsuffix .d,$(D_MODULES))
# Aggregate all D modules over all OSs (this is for the zip file)
ALL_D_FILES = $(addsuffix .d, $(D_MODULES) \
$(EXTRA_MODULES_LINUX) $(EXTRA_MODULES_OSX) $(EXTRA_MODULES_FREEBSD) $(EXTRA_MODULES_WIN32)) \
std/stdarg.d std/bind.d std/internal/windows/advapi32.d std/__fileinit.d \
std/stdarg.d std/bind.d std/internal/windows/advapi32.d \
std/windows/registry.d std/c/linux/pthread.d std/c/linux/termios.d \
std/c/linux/tipc.d std/net/isemail.d std/net/curl.d

Expand Down
40 changes: 0 additions & 40 deletions std/__fileinit.d

This file was deleted.

59 changes: 48 additions & 11 deletions std/algorithm.d
Expand Up @@ -437,6 +437,8 @@ template map(fun...) if (fun.length >= 1)
{
return _input.length;
}

alias length opDollar;
}

static if (hasSlicing!R)
Expand Down Expand Up @@ -483,6 +485,7 @@ unittest
const int[] arr1Const = arr1;
int[] arr2 = [ 5, 6 ];
auto squares = map!("a * a")(arr1Const);
assert(squares[$ - 1] == 16);
assert(equal(squares, [ 1, 4, 9, 16 ][]));
assert(equal(map!("a * a")(chain(arr1, arr2)), [ 1, 4, 9, 16, 25, 36 ][]));

Expand Down Expand Up @@ -3264,6 +3267,8 @@ public:
{
return needle.length;
}

alias length opDollar;
}

/// Ditto
Expand Down Expand Up @@ -6073,18 +6078,17 @@ unittest
}

/**
Reduces the length of the bidirectional range $(D range) by only
keeping elements that satisfy $(D pred). If $(D s =
SwapStrategy.unstable), elements are moved from the right end of the
range over the elements to eliminate. If $(D s = SwapStrategy.stable)
(the default), elements are moved progressively to front such that
their relative order is preserved. Returns the tail portion of the
range that was moved.
Reduces the length of the bidirectional range $(D range) by removing
elements that satisfy $(D pred). If $(D s = SwapStrategy.unstable),
elements are moved from the right end of the range over the elements
to eliminate. If $(D s = SwapStrategy.stable) (the default),
elements are moved progressively to front such that their relative
order is preserved. Returns the filtered range.
Example:
----
int[] a = [ 1, 2, 3, 2, 3, 4, 5, 2, 5, 6 ];
assert(a[0 .. remove!("a == 2")(a).length] == [ 1, 3, 3, 4, 5, 5, 6 ]);
assert(remove!("a == 2")(a) == [ 1, 3, 3, 4, 5, 5, 6 ]);
----
*/
Range remove(alias pred, SwapStrategy s = SwapStrategy.stable, Range)
Expand Down Expand Up @@ -7777,14 +7781,22 @@ unittest
}
}

// canFind
/**
Forwards to $(D any) for backwards compatibility.
$(RED Scheduled for deprecation in August 2012. Please use $(D any) instead.)
*/
bool canFind(alias pred, Range)(Range range)
{
return any!pred(range);
}

/**
Returns $(D true) if and only if a value $(D v) satisfying the
predicate $(D pred) can be found in the forward range $(D
range). Performs $(BIGOH r.length) evaluations of $(D pred).
*/

bool canFind(alias pred, Range)(Range range)
bool any(alias pred, Range)(Range range)
if (is(typeof(find!pred(range))))
{
return !find!pred(range).empty;
Expand All @@ -7796,6 +7808,29 @@ unittest
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
auto a = [ 1, 2, 0, 4 ];
assert(canFind!"a == 2"(a));
assert(any!"a == 2"(a));
}

/**
Returns $(D true) if and only if all values in $(D range) satisfy the
predicate $(D pred). Performs $(BIGOH r.length) evaluations of $(D pred).
Examples:
---
assert(all!"a & 1"([1, 3, 5, 7, 9]));
assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));
---
*/
bool all(alias pred, R)(R range)
if(isInputRange!R && is(typeof(unaryFun!pred(range.front))))
{
return find!(not!(unaryFun!pred))(range).empty;
}

unittest
{
assert(all!"a & 1"([1, 3, 5, 7, 9]));
assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));
}

// Scheduled for deprecation. Use std.range.SortedRange.canFind.
Expand Down Expand Up @@ -8003,6 +8038,8 @@ public:
}
return result;
}

alias length opDollar;
}
}

Expand Down
58 changes: 39 additions & 19 deletions std/base64.d
Expand Up @@ -715,19 +715,30 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
*/
@safe
pure nothrow size_t decodeLength(in size_t sourceLength)
in
{
static if (Padding == NoPadding)
assert(sourceLength % 4 != 1, "Invalid no-padding Base64 format");
return (sourceLength / 4) * 3 + (sourceLength % 4 < 2 ? 0 : sourceLength % 4 == 2 ? 1 : 2);
else
assert(sourceLength % 4 == 0, "Invalid Base64 format");
return (sourceLength / 4) * 3;
}
body


// Used in decode contracts. Calculates the actual size the decoded
// result should have, taking into account trailing padding.
@safe
pure nothrow private size_t realDecodeLength(R)(R source)
{
static if (Padding == NoPadding)
return (sourceLength / 4) * 3 + (sourceLength % 4 == 0 ? 0 : sourceLength % 4 == 2 ? 1 : 2);
else
return (sourceLength / 4) * 3;
auto expect = decodeLength(source.length);
static if (Padding != NoPadding)
{
if (source.length % 4 == 0)
{
expect -= source.length == 0 ? 0 :
source[$ - 2] == Padding ? 2 :
source[$ - 1] == Padding ? 1 : 0;
}
}
return expect;
}


Expand Down Expand Up @@ -756,9 +767,7 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
}
out(result)
{
immutable expect = decodeLength(source.length) - (source.length == 0 ? 0 :
source[$ - 2] == Padding ? 2 :
source[$ - 1] == Padding ? 1 : 0);
immutable expect = realDecodeLength(source);
assert(result.length == expect, "The length of result is different from the expected length");
}
body
Expand Down Expand Up @@ -900,9 +909,7 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
!is(R2 == ubyte[]) && isOutputRange!(R2, ubyte))
out(result)
{
immutable expect = decodeLength(source.length) - (source.length == 0 ? 0 :
source[$ - 2] == Padding ? 2 :
source[$ - 1] == Padding ? 1 : 0);
immutable expect = realDecodeLength(source);
assert(result == expect, "The result of decode is different from the expected");
}
body
Expand Down Expand Up @@ -1374,7 +1381,7 @@ unittest
{
alias Base64Impl!('!', '=', Base64.NoPadding) Base64Re;

// Test vectors from RPC 4648
// Test vectors from RFC 4648
ubyte[][string] tv = [
"" :cast(ubyte[])"",
"f" :cast(ubyte[])"f",
Expand Down Expand Up @@ -1420,10 +1427,20 @@ unittest
assert(Base64.decode(Base64.encode(tv["fooba"])) == tv["fooba"]);
assert(Base64.decode(Base64.encode(tv["foobar"])) == tv["foobar"]);

try {
Base64.decode("ab|c");
assert(false);
} catch (Exception e) {}
assertThrown(Base64.decode("ab|c"));

// Test decoding incomplete strings. RFC does not specify the correct
// behavior, but the code should never throw Errors on invalid input.

// decodeLength is nothrow
assert(Base64.decodeLength(1) == 0);
assert(Base64.decodeLength(2) <= 1);
assert(Base64.decodeLength(3) <= 2);

// may throw Exceptions, may not throw Errors
collectException(Base64.decode("Zg"));
collectException(Base64.decode("Zg="));
collectException(Base64.decode("Zm8"));
}

{ // No padding
Expand Down Expand Up @@ -1460,6 +1477,9 @@ unittest
assert(Base64Re.decode(Base64Re.encode(tv["foob"])) == tv["foob"]);
assert(Base64Re.decode(Base64Re.encode(tv["fooba"])) == tv["fooba"]);
assert(Base64Re.decode(Base64Re.encode(tv["foobar"])) == tv["foobar"]);

// decodeLength is nothrow
assert(Base64.decodeLength(1) == 0);
}

{ // with OutputRange
Expand Down
2 changes: 1 addition & 1 deletion std/bigint.d
Expand Up @@ -336,7 +336,7 @@ public:
}

///
bool opEquals(Tdummy=void)(ref const BigInt y) const
bool opEquals()(auto ref const BigInt y) const
{
return sign == y.sign && y.data == data;
}
Expand Down
9 changes: 6 additions & 3 deletions std/concurrency.d
Expand Up @@ -496,7 +496,8 @@ private void _send(T...)( Tid tid, T vals )
*/
private void _send(T...)( MsgType type, Tid tid, T vals )
{
tid.mbox.put( Message( type, vals ) );
auto msg = Message( type, vals );
tid.mbox.put( msg );
}


Expand Down Expand Up @@ -1042,7 +1043,8 @@ private
if( *depends && tid != owner )
{
auto e = new LinkTerminated( tid );
if( onStandardMsg( Message( MsgType.standard, e ) ) )
auto msg = Message( MsgType.standard, e );
if( onStandardMsg( msg ) )
return true;
throw e;
}
Expand All @@ -1051,7 +1053,8 @@ private
{
owner = Tid.init;
auto e = new OwnerTerminated( tid );
if( onStandardMsg( Message( MsgType.standard, e ) ) )
auto msg = Message( MsgType.standard, e );
if( onStandardMsg( msg ) )
return true;
throw e;
}
Expand Down
12 changes: 12 additions & 0 deletions std/container.d
Expand Up @@ -922,6 +922,12 @@ Comparison for equality.
Complexity: $(BIGOH min(n, n1)) where $(D n1) is the number of
elements in $(D rhs).
*/
bool opEquals(const SList rhs) const
{
return opEquals(rhs);
}

/// ditto
bool opEquals(ref const SList rhs) const
{
const(Node) * n1 = _root, n2 = rhs._root;
Expand Down Expand Up @@ -1634,6 +1640,12 @@ struct Array(T) if (!is(T : const(bool)))
/**
Comparison for equality.
*/
bool opEquals(const Array rhs) const
{
return opEquals(rhs);
}

/// ditto
bool opEquals(ref const Array rhs) const
{
if (empty) return rhs.empty;
Expand Down
6 changes: 3 additions & 3 deletions std/cstream.d
Expand Up @@ -96,7 +96,7 @@ class CFile : Stream {
* Ditto
*/
override char ungetc(char c) {
return cast(char)std.c.stdio.ungetc(c,cfile);
return cast(char).std.c.stdio.ungetc(c,cfile);
}

/**
Expand Down Expand Up @@ -168,14 +168,14 @@ class CFile : Stream {
auto exp = "Testing stream.d:";
assert(line[0] == 'T');
assert(line.length == exp.length);
assert(!std.string.cmp(line, "Testing stream.d:"));
assert(!.std.string.cmp(line, "Testing stream.d:"));
// jump over "Hello, "
file.seek(7, SeekPos.Current);
version (Windows)
assert(file.position() == 19 + 7);
version (Posix)
assert(file.position() == 18 + 7);
assert(!std.string.cmp(file.readString(6), "world!"));
assert(!.std.string.cmp(file.readString(6), "world!"));
i = 0; file.read(i);
assert(i == 666);
// string#1 + string#2 + int should give exacly that
Expand Down

0 comments on commit 7d1ef0e

Please sign in to comment.