mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 21:51:40 +03:00
phobos 0.148
This commit is contained in:
parent
b029d8c452
commit
110cfd9da7
31 changed files with 1179 additions and 392 deletions
|
@ -87,6 +87,8 @@ void[] _d_arraycast_frombit(uint tsize, void[] a)
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
|
version (D_Bits)
|
||||||
|
{
|
||||||
bit[int.sizeof * 3 * 8] b;
|
bit[int.sizeof * 3 * 8] b;
|
||||||
int[] i;
|
int[] i;
|
||||||
short[] s;
|
short[] s;
|
||||||
|
@ -96,6 +98,7 @@ unittest
|
||||||
|
|
||||||
s = cast(short[])b;
|
s = cast(short[])b;
|
||||||
assert(s.length == 6);
|
assert(s.length == 6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ extern (C) void _moduleCtor();
|
||||||
extern (C) void _moduleDtor();
|
extern (C) void _moduleDtor();
|
||||||
extern (C) void _moduleUnitTests();
|
extern (C) void _moduleUnitTests();
|
||||||
|
|
||||||
|
extern (C) bool no_catch_exceptions = false;
|
||||||
|
|
||||||
/***********************************
|
/***********************************
|
||||||
* The D main() function supplied by the user's program
|
* The D main() function supplied by the user's program
|
||||||
*/
|
*/
|
||||||
|
@ -56,7 +58,7 @@ extern (C) int main(int argc, char **argv)
|
||||||
am = cast(char[] *) alloca(argc * (char[]).sizeof);
|
am = cast(char[] *) alloca(argc * (char[]).sizeof);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
if (no_catch_exceptions)
|
||||||
{
|
{
|
||||||
_moduleCtor();
|
_moduleCtor();
|
||||||
_moduleUnitTests();
|
_moduleUnitTests();
|
||||||
|
@ -73,12 +75,33 @@ extern (C) int main(int argc, char **argv)
|
||||||
_moduleDtor();
|
_moduleDtor();
|
||||||
gc_term();
|
gc_term();
|
||||||
}
|
}
|
||||||
catch (Object o)
|
else
|
||||||
{
|
{
|
||||||
printf("Error: ");
|
try
|
||||||
o.print();
|
{
|
||||||
exit(EXIT_FAILURE);
|
_moduleCtor();
|
||||||
|
_moduleUnitTests();
|
||||||
|
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
{
|
||||||
|
int len = strlen(argv[i]);
|
||||||
|
am[i] = argv[i][0 .. len];
|
||||||
|
}
|
||||||
|
|
||||||
|
args = am[0 .. argc];
|
||||||
|
|
||||||
|
result = main(args);
|
||||||
|
_moduleDtor();
|
||||||
|
gc_term();
|
||||||
|
}
|
||||||
|
catch (Object o)
|
||||||
|
{
|
||||||
|
printf("Error: ");
|
||||||
|
o.print();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
version (linux)
|
version (linux)
|
||||||
{
|
{
|
||||||
free(am);
|
free(am);
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2006 by Digital Mars, www.digitalmars.com
|
|
||||||
* Written by Walter Bright
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, in both source and binary form, subject to the following
|
|
||||||
* restrictions:
|
|
||||||
*
|
|
||||||
* o The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
* o Altered source versions must be plainly marked as such, and must not
|
|
||||||
* be misrepresented as being the original software.
|
|
||||||
* o This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module internal.match;
|
|
||||||
|
|
||||||
import std.regexp;
|
|
||||||
|
|
||||||
/******************************
|
|
||||||
* Return handle to results if input[] matches regular expression pattern[],
|
|
||||||
* null if not.
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern (C) _Match* _d_match(char[] pattern, char[] input)
|
|
||||||
{
|
|
||||||
return cast(_Match*)std.regexp.search(input, pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************
|
|
||||||
* Returns !=null for next match.
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern (C) _Match* _d_match_next(_Match* h)
|
|
||||||
{
|
|
||||||
RegExp r = cast(RegExp)h;
|
|
||||||
return r.test() ? h : null;
|
|
||||||
}
|
|
|
@ -43,7 +43,7 @@ extern (C)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Standard boolean type. Implemented as a $(B bit) type.
|
/// Standard boolean type. Implemented as a $(B bit) type.
|
||||||
alias bit bool;
|
alias bool bit;
|
||||||
|
|
||||||
version (X86_64)
|
version (X86_64)
|
||||||
{
|
{
|
||||||
|
@ -612,42 +612,3 @@ class Error : Exception
|
||||||
|
|
||||||
//extern (C) int nullext = 0;
|
//extern (C) int nullext = 0;
|
||||||
|
|
||||||
/* ***************************** _Match **************************** */
|
|
||||||
|
|
||||||
/* **
|
|
||||||
* Default type for _match.
|
|
||||||
* Implemented as a proxy for RegExp, so that object doesn't pull in
|
|
||||||
* the entire std.regexp.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import std.regexp;
|
|
||||||
|
|
||||||
struct _Match
|
|
||||||
{
|
|
||||||
char[] match(size_t n)
|
|
||||||
{
|
|
||||||
return (cast(RegExp)this).match(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
_Match* opNext()
|
|
||||||
{
|
|
||||||
RegExp r = (cast(RegExp)this).opNext();
|
|
||||||
if (r)
|
|
||||||
return cast(_Match*)this;
|
|
||||||
r = cast(RegExp)this;
|
|
||||||
delete r;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
char[] pre()
|
|
||||||
{
|
|
||||||
return (cast(RegExp)this).pre();
|
|
||||||
}
|
|
||||||
|
|
||||||
char[] post()
|
|
||||||
{
|
|
||||||
return (cast(RegExp)this).post();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
20
linux.mak
20
linux.mak
|
@ -57,18 +57,18 @@ OBJS= asserterror.o deh2.o switch.o complex.o gcstats.o \
|
||||||
process.o syserror.o \
|
process.o syserror.o \
|
||||||
socket.o socketstream.o stdarg.o stdio.o format.o \
|
socket.o socketstream.o stdarg.o stdio.o format.o \
|
||||||
perf.o openrj.o uni.o trace.o boxer.o \
|
perf.o openrj.o uni.o trace.o boxer.o \
|
||||||
demangle.o cover.o mangle.o \
|
demangle.o cover.o bitarray.o \
|
||||||
ti_wchar.o ti_uint.o ti_short.o ti_ushort.o \
|
ti_wchar.o ti_uint.o ti_short.o ti_ushort.o \
|
||||||
ti_byte.o ti_ubyte.o ti_long.o ti_ulong.o ti_ptr.o \
|
ti_byte.o ti_ubyte.o ti_long.o ti_ulong.o ti_ptr.o \
|
||||||
ti_float.o ti_double.o ti_real.o ti_delegate.o \
|
ti_float.o ti_double.o ti_real.o ti_delegate.o \
|
||||||
ti_creal.o ti_ireal.o ti_cfloat.o ti_ifloat.o \
|
ti_creal.o ti_ireal.o ti_cfloat.o ti_ifloat.o \
|
||||||
ti_cdouble.o ti_idouble.o \
|
ti_cdouble.o ti_idouble.o \
|
||||||
ti_Aa.o ti_AC.o ti_Ag.o ti_Aubyte.o ti_Aushort.o ti_Ashort.o \
|
ti_Aa.o ti_AC.o ti_Ag.o ti_Aubyte.o ti_Aushort.o ti_Ashort.o \
|
||||||
ti_C.o ti_int.o ti_char.o ti_dchar.o ti_Adchar.o ti_bit.o \
|
ti_C.o ti_int.o ti_char.o ti_dchar.o ti_Adchar.o \
|
||||||
ti_Aint.o ti_Auint.o ti_Along.o ti_Aulong.o ti_Awchar.o \
|
ti_Aint.o ti_Auint.o ti_Along.o ti_Aulong.o ti_Awchar.o \
|
||||||
ti_Afloat.o ti_Adouble.o ti_Areal.o \
|
ti_Afloat.o ti_Adouble.o ti_Areal.o \
|
||||||
ti_Acfloat.o ti_Acdouble.o ti_Acreal.o \
|
ti_Acfloat.o ti_Acdouble.o ti_Acreal.o \
|
||||||
ti_Abit.o ti_void.o \
|
ti_void.o \
|
||||||
date.o dateparse.o llmath.o math2.o Czlib.o Dzlib.o zip.o recls.o
|
date.o dateparse.o llmath.o math2.o Czlib.o Dzlib.o zip.o recls.o
|
||||||
|
|
||||||
ZLIB_OBJS= etc/c/zlib/adler32.o etc/c/zlib/compress.o \
|
ZLIB_OBJS= etc/c/zlib/adler32.o etc/c/zlib/compress.o \
|
||||||
|
@ -100,7 +100,7 @@ SRC_STD= std/zlib.d std/zip.d std/stdint.d std/conv.d std/utf.d std/uri.d \
|
||||||
std/regexp.d std/random.d std/stream.d std/process.d std/recls.d \
|
std/regexp.d std/random.d std/stream.d std/process.d std/recls.d \
|
||||||
std/socket.d std/socketstream.d std/loader.d std/stdarg.d \
|
std/socket.d std/socketstream.d std/loader.d std/stdarg.d \
|
||||||
std/stdio.d std/format.d std/perf.d std/openrj.d std/uni.d \
|
std/stdio.d std/format.d std/perf.d std/openrj.d std/uni.d \
|
||||||
std/boxer.d std/cstream.d std/demangle.d std/cover.d
|
std/boxer.d std/cstream.d std/demangle.d std/cover.d std/bitarray.d
|
||||||
|
|
||||||
SRC_STD_C= std/c/process.d std/c/stdlib.d std/c/time.d std/c/stdio.d \
|
SRC_STD_C= std/c/process.d std/c/stdlib.d std/c/time.d std/c/stdio.d \
|
||||||
std/c/math.d std/c/stdarg.d std/c/stddef.d
|
std/c/math.d std/c/stdarg.d std/c/stddef.d
|
||||||
|
@ -110,7 +110,7 @@ SRC_TI= \
|
||||||
std/typeinfo/ti_short.d std/typeinfo/ti_ushort.d \
|
std/typeinfo/ti_short.d std/typeinfo/ti_ushort.d \
|
||||||
std/typeinfo/ti_byte.d std/typeinfo/ti_ubyte.d \
|
std/typeinfo/ti_byte.d std/typeinfo/ti_ubyte.d \
|
||||||
std/typeinfo/ti_long.d std/typeinfo/ti_ulong.d \
|
std/typeinfo/ti_long.d std/typeinfo/ti_ulong.d \
|
||||||
std/typeinfo/ti_ptr.d std/typeinfo/ti_bit.d \
|
std/typeinfo/ti_ptr.d \
|
||||||
std/typeinfo/ti_float.d std/typeinfo/ti_double.d \
|
std/typeinfo/ti_float.d std/typeinfo/ti_double.d \
|
||||||
std/typeinfo/ti_real.d std/typeinfo/ti_delegate.d \
|
std/typeinfo/ti_real.d std/typeinfo/ti_delegate.d \
|
||||||
std/typeinfo/ti_creal.d std/typeinfo/ti_ireal.d \
|
std/typeinfo/ti_creal.d std/typeinfo/ti_ireal.d \
|
||||||
|
@ -127,7 +127,7 @@ SRC_TI= \
|
||||||
std/typeinfo/ti_Areal.d \
|
std/typeinfo/ti_Areal.d \
|
||||||
std/typeinfo/ti_Acfloat.d std/typeinfo/ti_Acdouble.d \
|
std/typeinfo/ti_Acfloat.d std/typeinfo/ti_Acdouble.d \
|
||||||
std/typeinfo/ti_Acreal.d \
|
std/typeinfo/ti_Acreal.d \
|
||||||
std/typeinfo/ti_Abit.d std/typeinfo/ti_void.d \
|
std/typeinfo/ti_void.d \
|
||||||
std/typeinfo/ti_Awchar.d std/typeinfo/ti_dchar.d
|
std/typeinfo/ti_Awchar.d std/typeinfo/ti_dchar.d
|
||||||
|
|
||||||
SRC_INT= \
|
SRC_INT= \
|
||||||
|
@ -137,7 +137,7 @@ SRC_INT= \
|
||||||
internal/memset.d internal/arraycast.d internal/aaA.d internal/adi.d \
|
internal/memset.d internal/arraycast.d internal/aaA.d internal/adi.d \
|
||||||
internal/dmain2.d internal/cast.d internal/qsort.d internal/deh2.d \
|
internal/dmain2.d internal/cast.d internal/qsort.d internal/deh2.d \
|
||||||
internal/cmath2.d internal/obj.d internal/mars.h internal/aApply.d \
|
internal/cmath2.d internal/obj.d internal/mars.h internal/aApply.d \
|
||||||
internal/object.d internal/trace.d internal/qsort2.d internal/match.d
|
internal/object.d internal/trace.d internal/qsort2.d
|
||||||
|
|
||||||
SRC_STD_WIN= std/windows/registry.d \
|
SRC_STD_WIN= std/windows/registry.d \
|
||||||
std/windows/iunknown.d std/windows/charset.d
|
std/windows/iunknown.d std/windows/charset.d
|
||||||
|
@ -438,9 +438,6 @@ invariant.o : internal/invariant.d
|
||||||
llmath.o : internal/llmath.d
|
llmath.o : internal/llmath.d
|
||||||
$(DMD) -c $(DFLAGS) internal/llmath.d
|
$(DMD) -c $(DFLAGS) internal/llmath.d
|
||||||
|
|
||||||
match.o : internal/match.d
|
|
||||||
$(DMD) -c $(DFLAGS) internal/match.d
|
|
||||||
|
|
||||||
memset.o : internal/memset.d
|
memset.o : internal/memset.d
|
||||||
$(DMD) -c $(DFLAGS) internal/memset.d
|
$(DMD) -c $(DFLAGS) internal/memset.d
|
||||||
|
|
||||||
|
@ -476,6 +473,9 @@ asserterror.o : std/asserterror.d
|
||||||
base64.o : std/base64.d
|
base64.o : std/base64.d
|
||||||
$(DMD) -c $(DFLAGS) std/base64.d
|
$(DMD) -c $(DFLAGS) std/base64.d
|
||||||
|
|
||||||
|
bitarray.o : std/bitarray.d
|
||||||
|
$(DMD) -c $(DFLAGS) std/bitarray.d
|
||||||
|
|
||||||
boxer.o : std/boxer.d
|
boxer.o : std/boxer.d
|
||||||
$(DMD) -c $(DFLAGS) std/boxer.d
|
$(DMD) -c $(DFLAGS) std/boxer.d
|
||||||
|
|
||||||
|
|
14
object.d
14
object.d
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
module object;
|
module object;
|
||||||
|
|
||||||
alias bit bool;
|
//alias bit bool;
|
||||||
|
alias bool bit;
|
||||||
|
|
||||||
alias typeof(int.sizeof) size_t;
|
alias typeof(int.sizeof) size_t;
|
||||||
alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
|
alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
|
||||||
|
@ -129,14 +130,3 @@ class Error : Exception
|
||||||
this(char[] msg, Error next);
|
this(char[] msg, Error next);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default type for _match
|
|
||||||
|
|
||||||
struct _Match
|
|
||||||
{
|
|
||||||
void* handle;
|
|
||||||
|
|
||||||
char[] match(size_t n);
|
|
||||||
_Match* opNext();
|
|
||||||
char[] pre();
|
|
||||||
char[] post();
|
|
||||||
}
|
|
||||||
|
|
935
std/bitarray.d
Normal file
935
std/bitarray.d
Normal file
|
@ -0,0 +1,935 @@
|
||||||
|
/***********************
|
||||||
|
* Macros:
|
||||||
|
* WIKI = StdBitarray
|
||||||
|
*/
|
||||||
|
|
||||||
|
module std.bitarray;
|
||||||
|
|
||||||
|
//debug = bitarray; // uncomment to turn on debugging printf's
|
||||||
|
|
||||||
|
private import std.intrinsic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of bits.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct BitArray
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
uint* ptr;
|
||||||
|
|
||||||
|
size_t dim()
|
||||||
|
{
|
||||||
|
return (len + 31) / 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t length()
|
||||||
|
{
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void length(size_t newlen)
|
||||||
|
{
|
||||||
|
if (newlen != len)
|
||||||
|
{
|
||||||
|
size_t olddim = dim();
|
||||||
|
size_t newdim = (newlen + 31) / 32;
|
||||||
|
|
||||||
|
if (newdim != olddim)
|
||||||
|
{
|
||||||
|
// Create a fake array so we can use D's realloc machinery
|
||||||
|
uint[] b = ptr[0 .. olddim];
|
||||||
|
b.length = newdim; // realloc
|
||||||
|
ptr = b.ptr;
|
||||||
|
if (newdim & 31)
|
||||||
|
{ // Set any pad bits to 0
|
||||||
|
ptr[newdim - 1] &= ~(~0 << (newdim & 31));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len = newlen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************
|
||||||
|
* Support for [$(I index)] operation for BitArray.
|
||||||
|
*/
|
||||||
|
bool opIndex(size_t i)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(i < len);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
return cast(bool)bt(ptr, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ditto */
|
||||||
|
bool opIndexAssign(bool b, size_t i)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(i < len);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
if (b)
|
||||||
|
bts(ptr, i);
|
||||||
|
else
|
||||||
|
btr(ptr, i);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************
|
||||||
|
* Support for array.dup property for BitArray.
|
||||||
|
*/
|
||||||
|
BitArray dup()
|
||||||
|
{
|
||||||
|
BitArray ba;
|
||||||
|
|
||||||
|
uint[] b = ptr[0 .. dim].dup;
|
||||||
|
ba.len = len;
|
||||||
|
ba.ptr = b.ptr;
|
||||||
|
return ba;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
BitArray a;
|
||||||
|
BitArray b;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
debug(bitarray) printf("BitArray.dup.unittest\n");
|
||||||
|
|
||||||
|
a.length = 3;
|
||||||
|
a[0] = 1; a[1] = 0; a[2] = 1;
|
||||||
|
b = a.dup;
|
||||||
|
assert(b.length == 3);
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
{ debug(bitarray) printf("b[%d] = %d\n", i, b[i]);
|
||||||
|
assert(b[i] == (((i ^ 1) & 1) ? true : false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************
|
||||||
|
* Support for foreach loops for BitArray.
|
||||||
|
*/
|
||||||
|
int opApply(int delegate(inout bool) dg)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
|
{ bool b = opIndex(i);
|
||||||
|
result = dg(b);
|
||||||
|
if (result)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ditto */
|
||||||
|
int opApply(int delegate(inout size_t, inout bool) dg)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
|
{ bool b = opIndex(i);
|
||||||
|
result = dg(i, b);
|
||||||
|
if (result)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opApply unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
foreach (b;a)
|
||||||
|
{
|
||||||
|
switch (i)
|
||||||
|
{ case 0: assert(b == true); break;
|
||||||
|
case 1: assert(b == false); break;
|
||||||
|
case 2: assert(b == true); break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (j,b;a)
|
||||||
|
{
|
||||||
|
switch (j)
|
||||||
|
{ case 0: assert(b == true); break;
|
||||||
|
case 1: assert(b == false); break;
|
||||||
|
case 2: assert(b == true); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************
|
||||||
|
* Support for array.reverse property for BitArray.
|
||||||
|
*/
|
||||||
|
|
||||||
|
BitArray reverse()
|
||||||
|
out (result)
|
||||||
|
{
|
||||||
|
assert(result == *this);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
if (len >= 2)
|
||||||
|
{
|
||||||
|
bool t;
|
||||||
|
size_t lo, hi;
|
||||||
|
|
||||||
|
lo = 0;
|
||||||
|
hi = len - 1;
|
||||||
|
for (; lo < hi; lo++, hi--)
|
||||||
|
{
|
||||||
|
t = (*this)[lo];
|
||||||
|
(*this)[lo] = (*this)[hi];
|
||||||
|
(*this)[hi] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.reverse.unittest\n");
|
||||||
|
|
||||||
|
BitArray b;
|
||||||
|
static bool[5] data = [1,0,1,1,0];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
b.init(data);
|
||||||
|
b.reverse;
|
||||||
|
for (i = 0; i < data.length; i++)
|
||||||
|
{
|
||||||
|
assert(b[i] == data[4 - i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************
|
||||||
|
* Support for array.sort property for BitArray.
|
||||||
|
*/
|
||||||
|
|
||||||
|
BitArray sort()
|
||||||
|
out (result)
|
||||||
|
{
|
||||||
|
assert(result == *this);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
if (len >= 2)
|
||||||
|
{
|
||||||
|
size_t lo, hi;
|
||||||
|
|
||||||
|
lo = 0;
|
||||||
|
hi = len - 1;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if (lo >= hi)
|
||||||
|
goto Ldone;
|
||||||
|
if ((*this)[lo] == true)
|
||||||
|
break;
|
||||||
|
lo++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if (lo >= hi)
|
||||||
|
goto Ldone;
|
||||||
|
if ((*this)[hi] == false)
|
||||||
|
break;
|
||||||
|
hi--;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*this)[lo] = false;
|
||||||
|
(*this)[hi] = true;
|
||||||
|
|
||||||
|
lo++;
|
||||||
|
hi--;
|
||||||
|
}
|
||||||
|
Ldone:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.sort.unittest\n");
|
||||||
|
|
||||||
|
static uint x = 0b1100011000;
|
||||||
|
static BitArray ba = { 10, &x };
|
||||||
|
ba.sort;
|
||||||
|
for (size_t i = 0; i < 6; i++)
|
||||||
|
assert(ba[i] == false);
|
||||||
|
for (size_t i = 6; i < 10; i++)
|
||||||
|
assert(ba[i] == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for operators == and != for bit arrays.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int opEquals(BitArray a2)
|
||||||
|
{ int i;
|
||||||
|
|
||||||
|
if (this.length != a2.length)
|
||||||
|
return 0; // not equal
|
||||||
|
byte *p1 = cast(byte*)this.ptr;
|
||||||
|
byte *p2 = cast(byte*)a2.ptr;
|
||||||
|
uint n = this.length / 8;
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
if (p1[i] != p2[i])
|
||||||
|
return 0; // not equal
|
||||||
|
}
|
||||||
|
|
||||||
|
ubyte mask;
|
||||||
|
|
||||||
|
n = this.length & 7;
|
||||||
|
mask = (1 << n) - 1;
|
||||||
|
//printf("i = %d, n = %d, mask = %x, %x, %x\n", i, n, mask, p1[i], p2[i]);
|
||||||
|
return (mask == 0) || (p1[i] & mask) == (p2[i] & mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opEquals unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1];
|
||||||
|
static bool[] bc = [1,0,1,0,1,0,1];
|
||||||
|
static bool[] bd = [1,0,1,1,1];
|
||||||
|
static bool[] be = [1,0,1,0,1];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
BitArray c; c.init(bc);
|
||||||
|
BitArray d; d.init(bd);
|
||||||
|
BitArray e; e.init(be);
|
||||||
|
|
||||||
|
assert(a != b);
|
||||||
|
assert(a != c);
|
||||||
|
assert(a != d);
|
||||||
|
assert(a == e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Implement comparison operators.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int opCmp(BitArray a2)
|
||||||
|
{
|
||||||
|
uint len;
|
||||||
|
uint i;
|
||||||
|
|
||||||
|
len = this.length;
|
||||||
|
if (a2.length < len)
|
||||||
|
len = a2.length;
|
||||||
|
ubyte* p1 = cast(ubyte*)this.ptr;
|
||||||
|
ubyte* p2 = cast(ubyte*)a2.ptr;
|
||||||
|
uint n = len / 8;
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
if (p1[i] != p2[i])
|
||||||
|
break; // not equal
|
||||||
|
}
|
||||||
|
for (uint j = i * 8; j < len; j++)
|
||||||
|
{ ubyte mask = 1 << j;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = cast(int)(p1[i] & mask) - cast(int)(p2[i] & mask);
|
||||||
|
if (c)
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
return cast(int)this.len - cast(int)a2.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opCmp unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1];
|
||||||
|
static bool[] bc = [1,0,1,0,1,0,1];
|
||||||
|
static bool[] bd = [1,0,1,1,1];
|
||||||
|
static bool[] be = [1,0,1,0,1];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
BitArray c; c.init(bc);
|
||||||
|
BitArray d; d.init(bd);
|
||||||
|
BitArray e; e.init(be);
|
||||||
|
|
||||||
|
assert(a > b);
|
||||||
|
assert(a >= b);
|
||||||
|
assert(a < c);
|
||||||
|
assert(a <= c);
|
||||||
|
assert(a < d);
|
||||||
|
assert(a <= d);
|
||||||
|
assert(a == e);
|
||||||
|
assert(a <= e);
|
||||||
|
assert(a >= e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Set BitArray to contents of ba[]
|
||||||
|
*/
|
||||||
|
|
||||||
|
void init(bool[] ba)
|
||||||
|
{
|
||||||
|
length = ba.length;
|
||||||
|
foreach (i, b; ba)
|
||||||
|
{
|
||||||
|
(*this)[i] = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Map BitArray onto v[], with numbits being the number of bits
|
||||||
|
* in the array. Does not copy the data.
|
||||||
|
*
|
||||||
|
* This is the inverse of opCast.
|
||||||
|
*/
|
||||||
|
void init(void[] v, size_t numbits)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(numbits <= v.length * 8);
|
||||||
|
assert((v.length & 3) == 0);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
ptr = cast(uint*)v.ptr;
|
||||||
|
len = numbits;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.init unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b;
|
||||||
|
void[] v;
|
||||||
|
|
||||||
|
v = cast(void[])a;
|
||||||
|
b.init(v, a.length);
|
||||||
|
|
||||||
|
assert(b[0] == 1);
|
||||||
|
assert(b[1] == 0);
|
||||||
|
assert(b[2] == 1);
|
||||||
|
assert(b[3] == 0);
|
||||||
|
assert(b[4] == 1);
|
||||||
|
|
||||||
|
a[0] = 0;
|
||||||
|
assert(b[0] == 0);
|
||||||
|
|
||||||
|
assert(a == b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Convert to void[].
|
||||||
|
*/
|
||||||
|
void[] opCast()
|
||||||
|
{
|
||||||
|
return cast(void[])ptr[0 .. dim];
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opCast unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
void[] v = cast(void[])a;
|
||||||
|
|
||||||
|
assert(v.length == a.dim * uint.sizeof);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for unary operator ~ for bit arrays.
|
||||||
|
*/
|
||||||
|
BitArray opCom()
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
BitArray result;
|
||||||
|
|
||||||
|
result.length = len;
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
result.ptr[i] = ~this.ptr[i];
|
||||||
|
if (len & 31)
|
||||||
|
result.ptr[dim - 1] &= ~(~0 << (len & 31));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opCom unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b = ~a;
|
||||||
|
|
||||||
|
assert(b[0] == 0);
|
||||||
|
assert(b[1] == 1);
|
||||||
|
assert(b[2] == 0);
|
||||||
|
assert(b[3] == 1);
|
||||||
|
assert(b[4] == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for binary operator & for bit arrays.
|
||||||
|
*/
|
||||||
|
BitArray opAnd(BitArray e2)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(len == e2.length);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
BitArray result;
|
||||||
|
|
||||||
|
result.length = len;
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
result.ptr[i] = this.ptr[i] & e2.ptr[i];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opAnd unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
|
||||||
|
BitArray c = a & b;
|
||||||
|
|
||||||
|
assert(c[0] == 1);
|
||||||
|
assert(c[1] == 0);
|
||||||
|
assert(c[2] == 1);
|
||||||
|
assert(c[3] == 0);
|
||||||
|
assert(c[4] == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for binary operator | for bit arrays.
|
||||||
|
*/
|
||||||
|
BitArray opOr(BitArray e2)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(len == e2.length);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
BitArray result;
|
||||||
|
|
||||||
|
result.length = len;
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
result.ptr[i] = this.ptr[i] | e2.ptr[i];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opOr unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
|
||||||
|
BitArray c = a | b;
|
||||||
|
|
||||||
|
assert(c[0] == 1);
|
||||||
|
assert(c[1] == 0);
|
||||||
|
assert(c[2] == 1);
|
||||||
|
assert(c[3] == 1);
|
||||||
|
assert(c[4] == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for binary operator ^ for bit arrays.
|
||||||
|
*/
|
||||||
|
BitArray opXor(BitArray e2)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(len == e2.length);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
BitArray result;
|
||||||
|
|
||||||
|
result.length = len;
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
result.ptr[i] = this.ptr[i] ^ e2.ptr[i];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opXor unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
|
||||||
|
BitArray c = a ^ b;
|
||||||
|
|
||||||
|
assert(c[0] == 0);
|
||||||
|
assert(c[1] == 0);
|
||||||
|
assert(c[2] == 0);
|
||||||
|
assert(c[3] == 1);
|
||||||
|
assert(c[4] == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for binary operator - for bit arrays.
|
||||||
|
*
|
||||||
|
* $(I a - b) for BitArrays means the same thing as $(I a & ~b).
|
||||||
|
*/
|
||||||
|
BitArray opSub(BitArray e2)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(len == e2.length);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
BitArray result;
|
||||||
|
|
||||||
|
result.length = len;
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
result.ptr[i] = this.ptr[i] & ~e2.ptr[i];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opSub unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
|
||||||
|
BitArray c = a - b;
|
||||||
|
|
||||||
|
assert(c[0] == 0);
|
||||||
|
assert(c[1] == 0);
|
||||||
|
assert(c[2] == 0);
|
||||||
|
assert(c[3] == 0);
|
||||||
|
assert(c[4] == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for operator &= bit arrays.
|
||||||
|
*/
|
||||||
|
BitArray opAndAssign(BitArray e2)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(len == e2.length);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
ptr[i] &= e2.ptr[i];
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opAndAssign unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
|
||||||
|
a &= b;
|
||||||
|
assert(a[0] == 1);
|
||||||
|
assert(a[1] == 0);
|
||||||
|
assert(a[2] == 1);
|
||||||
|
assert(a[3] == 0);
|
||||||
|
assert(a[4] == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for operator |= for bit arrays.
|
||||||
|
*/
|
||||||
|
BitArray opOrAssign(BitArray e2)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(len == e2.length);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
ptr[i] |= e2.ptr[i];
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opOrAssign unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
|
||||||
|
a |= b;
|
||||||
|
assert(a[0] == 1);
|
||||||
|
assert(a[1] == 0);
|
||||||
|
assert(a[2] == 1);
|
||||||
|
assert(a[3] == 1);
|
||||||
|
assert(a[4] == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for operator ^= for bit arrays.
|
||||||
|
*/
|
||||||
|
BitArray opXorAssign(BitArray e2)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(len == e2.length);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
ptr[i] ^= e2.ptr[i];
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opXorAssign unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
|
||||||
|
a ^= b;
|
||||||
|
assert(a[0] == 0);
|
||||||
|
assert(a[1] == 0);
|
||||||
|
assert(a[2] == 0);
|
||||||
|
assert(a[3] == 1);
|
||||||
|
assert(a[4] == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for operator -= for bit arrays.
|
||||||
|
*
|
||||||
|
* $(I a -= b) for BitArrays means the same thing as $(I a &= ~b).
|
||||||
|
*/
|
||||||
|
BitArray opSubAssign(BitArray e2)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
assert(len == e2.length);
|
||||||
|
}
|
||||||
|
body
|
||||||
|
{
|
||||||
|
auto dim = this.dim();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < dim; i++)
|
||||||
|
ptr[i] &= ~e2.ptr[i];
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opSubAssign unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
static bool[] bb = [1,0,1,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
|
||||||
|
a -= b;
|
||||||
|
assert(a[0] == 0);
|
||||||
|
assert(a[1] == 0);
|
||||||
|
assert(a[2] == 0);
|
||||||
|
assert(a[3] == 0);
|
||||||
|
assert(a[4] == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for operator ~= for bit arrays.
|
||||||
|
*/
|
||||||
|
|
||||||
|
BitArray opCatAssign(bool b)
|
||||||
|
{
|
||||||
|
length = len + 1;
|
||||||
|
(*this)[len - 1] = b;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opCatAssign unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0,1,0,1];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b;
|
||||||
|
|
||||||
|
b = (a ~= true);
|
||||||
|
assert(a[0] == 1);
|
||||||
|
assert(a[1] == 0);
|
||||||
|
assert(a[2] == 1);
|
||||||
|
assert(a[3] == 0);
|
||||||
|
assert(a[4] == 1);
|
||||||
|
assert(a[5] == 1);
|
||||||
|
|
||||||
|
assert(b == a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* ditto
|
||||||
|
*/
|
||||||
|
|
||||||
|
BitArray opCatAssign(BitArray b)
|
||||||
|
{
|
||||||
|
auto istart = len;
|
||||||
|
length = len + b.length;
|
||||||
|
for (auto i = istart; i < len; i++)
|
||||||
|
(*this)[i] = b[i - istart];
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opCatAssign unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0];
|
||||||
|
static bool[] bb = [0,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
BitArray c;
|
||||||
|
|
||||||
|
c = (a ~= b);
|
||||||
|
assert(a.length == 5);
|
||||||
|
assert(a[0] == 1);
|
||||||
|
assert(a[1] == 0);
|
||||||
|
assert(a[2] == 0);
|
||||||
|
assert(a[3] == 1);
|
||||||
|
assert(a[4] == 0);
|
||||||
|
|
||||||
|
assert(c == a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************
|
||||||
|
* Support for binary operator ~ for bit arrays.
|
||||||
|
*/
|
||||||
|
BitArray opCat(bool b)
|
||||||
|
{
|
||||||
|
BitArray r;
|
||||||
|
|
||||||
|
r = this.dup;
|
||||||
|
r.length = len + 1;
|
||||||
|
r[len] = b;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ditto */
|
||||||
|
BitArray opCat_r(bool b)
|
||||||
|
{
|
||||||
|
BitArray r;
|
||||||
|
|
||||||
|
r.length = len + 1;
|
||||||
|
r[0] = b;
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
|
r[1 + i] = (*this)[i];
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ditto */
|
||||||
|
BitArray opCat(BitArray b)
|
||||||
|
{
|
||||||
|
BitArray r;
|
||||||
|
|
||||||
|
r = this.dup();
|
||||||
|
r ~= b;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
debug(bitarray) printf("BitArray.opCat unittest\n");
|
||||||
|
|
||||||
|
static bool[] ba = [1,0];
|
||||||
|
static bool[] bb = [0,1,0];
|
||||||
|
|
||||||
|
BitArray a; a.init(ba);
|
||||||
|
BitArray b; b.init(bb);
|
||||||
|
BitArray c;
|
||||||
|
|
||||||
|
c = (a ~ b);
|
||||||
|
assert(c.length == 5);
|
||||||
|
assert(c[0] == 1);
|
||||||
|
assert(c[1] == 0);
|
||||||
|
assert(c[2] == 0);
|
||||||
|
assert(c[3] == 1);
|
||||||
|
assert(c[4] == 0);
|
||||||
|
|
||||||
|
c = (a ~ true);
|
||||||
|
assert(c.length == 3);
|
||||||
|
assert(c[0] == 1);
|
||||||
|
assert(c[1] == 0);
|
||||||
|
assert(c[2] == 1);
|
||||||
|
|
||||||
|
c = (false ~ a);
|
||||||
|
assert(c.length == 3);
|
||||||
|
assert(c[0] == 0);
|
||||||
|
assert(c[1] == 1);
|
||||||
|
assert(c[2] == 0);
|
||||||
|
}
|
||||||
|
}
|
42
std/boxer.d
42
std/boxer.d
|
@ -49,12 +49,12 @@ private import std.utf;
|
||||||
* Finally, you can discover whether unboxing as a certain type is legal by
|
* Finally, you can discover whether unboxing as a certain type is legal by
|
||||||
* using the unboxable template or method:
|
* using the unboxable template or method:
|
||||||
*
|
*
|
||||||
* bit unboxable!(T) (Box value);
|
* bool unboxable!(T) (Box value);
|
||||||
* bit Box.unboxable(TypeInfo T);
|
* bool Box.unboxable(TypeInfo T);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Return the next type in an array typeinfo, or null if there is none. */
|
/** Return the next type in an array typeinfo, or null if there is none. */
|
||||||
private bit isArrayTypeInfo(TypeInfo type)
|
private bool isArrayTypeInfo(TypeInfo type)
|
||||||
{
|
{
|
||||||
char[] name = type.classinfo.name;
|
char[] name = type.classinfo.name;
|
||||||
return name.length >= 10 && name[9] == 'A' && name != "TypeInfo_AssociativeArray";
|
return name.length >= 10 && name[9] == 'A' && name != "TypeInfo_AssociativeArray";
|
||||||
|
@ -63,7 +63,8 @@ private bit isArrayTypeInfo(TypeInfo type)
|
||||||
/** The type class returned from Box.findTypeClass; the order of entries is important. */
|
/** The type class returned from Box.findTypeClass; the order of entries is important. */
|
||||||
private enum TypeClass
|
private enum TypeClass
|
||||||
{
|
{
|
||||||
Bit, /**< bit */
|
Bool, /**< bool */
|
||||||
|
Bit = Bool, // for backwards compatibility
|
||||||
Integer, /**< byte, ubyte, short, ushort, int, uint, long, ulong */
|
Integer, /**< byte, ubyte, short, ushort, int, uint, long, ulong */
|
||||||
Float, /**< float, double, real */
|
Float, /**< float, double, real */
|
||||||
Complex, /**< cfloat, cdouble, creal */
|
Complex, /**< cfloat, cdouble, creal */
|
||||||
|
@ -105,7 +106,8 @@ struct Box
|
||||||
return TypeClass.Other;
|
return TypeClass.Other;
|
||||||
switch (type.classinfo.name[9])
|
switch (type.classinfo.name[9])
|
||||||
{
|
{
|
||||||
case 'b': return TypeClass.Bit;
|
//case 'b': return TypeClass.Bit;
|
||||||
|
case 'x': return TypeClass.Bool;
|
||||||
case 'g', 'h', 's', 't', 'i', 'k', 'l', 'm': return TypeClass.Integer;
|
case 'g', 'h', 's', 't', 'i', 'k', 'l', 'm': return TypeClass.Integer;
|
||||||
case 'f', 'd', 'e': return TypeClass.Float;
|
case 'f', 'd', 'e': return TypeClass.Float;
|
||||||
case 'q', 'r', 'c': return TypeClass.Complex;
|
case 'q', 'r', 'c': return TypeClass.Complex;
|
||||||
|
@ -118,7 +120,7 @@ struct Box
|
||||||
/* Use the name returned from toString, which might (but hopefully doesn't) include an allocation. */
|
/* Use the name returned from toString, which might (but hopefully doesn't) include an allocation. */
|
||||||
switch (type.toString)
|
switch (type.toString)
|
||||||
{
|
{
|
||||||
case "bit": return TypeClass.Bit;
|
case "bool": return TypeClass.Bool;
|
||||||
case "byte", "ubyte", "short", "ushort", "int", "uint", "long", "ulong": return TypeClass.Integer;
|
case "byte", "ubyte", "short", "ushort", "int", "uint", "long", "ulong": return TypeClass.Integer;
|
||||||
case "float", "real", "double": return TypeClass.Float;
|
case "float", "real", "double": return TypeClass.Float;
|
||||||
case "cfloat", "cdouble", "creal": return TypeClass.Complex;
|
case "cfloat", "cdouble", "creal": return TypeClass.Complex;
|
||||||
|
@ -129,7 +131,7 @@ struct Box
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return whether this value could be unboxed as the given type without throwing. */
|
/** Return whether this value could be unboxed as the given type without throwing. */
|
||||||
bit unboxable(TypeInfo test)
|
bool unboxable(TypeInfo test)
|
||||||
{
|
{
|
||||||
if (type is test)
|
if (type is test)
|
||||||
return true;
|
return true;
|
||||||
|
@ -158,7 +160,7 @@ struct Box
|
||||||
return (cast(TypeInfo_Pointer)type).next is (cast(TypeInfo_Pointer)test).next;
|
return (cast(TypeInfo_Pointer)type).next is (cast(TypeInfo_Pointer)test).next;
|
||||||
|
|
||||||
if ((ta == tb && ta != TypeClass.Other)
|
if ((ta == tb && ta != TypeClass.Other)
|
||||||
|| (ta == TypeClass.Bit && tb == TypeClass.Integer)
|
|| (ta == TypeClass.Bool && tb == TypeClass.Integer)
|
||||||
|| (ta <= TypeClass.Integer && tb == TypeClass.Float)
|
|| (ta <= TypeClass.Integer && tb == TypeClass.Float)
|
||||||
|| (ta <= TypeClass.Imaginary && tb == TypeClass.Complex))
|
|| (ta <= TypeClass.Imaginary && tb == TypeClass.Complex))
|
||||||
return true;
|
return true;
|
||||||
|
@ -207,7 +209,7 @@ struct Box
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bit opEqualsInternal(Box other, bit inverted)
|
private bool opEqualsInternal(Box other, bool inverted)
|
||||||
{
|
{
|
||||||
if (type != other.type)
|
if (type != other.type)
|
||||||
{
|
{
|
||||||
|
@ -238,16 +240,16 @@ struct Box
|
||||||
assert (0);
|
assert (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cast(bit)type.equals(data, other.data);
|
return cast(bool)type.equals(data, other.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Implement the equals operator. */
|
/** Implement the equals operator. */
|
||||||
bit opEquals(Box other)
|
bool opEquals(Box other)
|
||||||
{
|
{
|
||||||
return opEqualsInternal(other, false);
|
return opEqualsInternal(other, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float opCmpInternal(Box other, bit inverted)
|
private float opCmpInternal(Box other, bool inverted)
|
||||||
{
|
{
|
||||||
if (type != other.type)
|
if (type != other.type)
|
||||||
{
|
{
|
||||||
|
@ -434,8 +436,8 @@ private template unboxCastInteger(T)
|
||||||
return cast(T) *cast(long*) value.data;
|
return cast(T) *cast(long*) value.data;
|
||||||
if (value.type is typeid(ulong))
|
if (value.type is typeid(ulong))
|
||||||
return cast(T) *cast(ulong*) value.data;
|
return cast(T) *cast(ulong*) value.data;
|
||||||
if (value.type is typeid(bit))
|
if (value.type is typeid(bool))
|
||||||
return cast(T) *cast(bit*) value.data;
|
return cast(T) *cast(bool*) value.data;
|
||||||
if (value.type is typeid(byte))
|
if (value.type is typeid(byte))
|
||||||
return cast(T) *cast(byte*) value.data;
|
return cast(T) *cast(byte*) value.data;
|
||||||
if (value.type is typeid(ubyte))
|
if (value.type is typeid(ubyte))
|
||||||
|
@ -602,7 +604,7 @@ template unbox(T : void*)
|
||||||
*/
|
*/
|
||||||
template unboxable(T)
|
template unboxable(T)
|
||||||
{
|
{
|
||||||
bit unboxable(Box value)
|
bool unboxable(Box value)
|
||||||
{
|
{
|
||||||
return value.unboxable(typeid(T));
|
return value.unboxable(typeid(T));
|
||||||
}
|
}
|
||||||
|
@ -614,7 +616,7 @@ private template unboxTest(T)
|
||||||
T unboxTest(Box value)
|
T unboxTest(Box value)
|
||||||
{
|
{
|
||||||
T result;
|
T result;
|
||||||
bit unboxable = value.unboxable(typeid(T));
|
bool unboxable = value.unboxable(typeid(T));
|
||||||
|
|
||||||
try result = unbox!(T) (value);
|
try result = unbox!(T) (value);
|
||||||
catch (UnboxException error)
|
catch (UnboxException error)
|
||||||
|
@ -641,7 +643,7 @@ unittest
|
||||||
Box a, b;
|
Box a, b;
|
||||||
|
|
||||||
/* Call the function, catch UnboxException, return that it threw correctly. */
|
/* Call the function, catch UnboxException, return that it threw correctly. */
|
||||||
bit fails(void delegate()func)
|
bool fails(void delegate()func)
|
||||||
{
|
{
|
||||||
try func();
|
try func();
|
||||||
catch (UnboxException error)
|
catch (UnboxException error)
|
||||||
|
@ -719,7 +721,7 @@ unittest
|
||||||
assert (box(4) > box(3.0));
|
assert (box(4) > box(3.0));
|
||||||
assert (box(0+3i) < box(0+4i));
|
assert (box(0+3i) < box(0+4i));
|
||||||
|
|
||||||
/* Assert that casting from bit to int works. */
|
/* Assert that casting from bool to int works. */
|
||||||
assert (1 == unboxTest!(int)(box(true)));
|
assert (1 == unboxTest!(int)(box(true)));
|
||||||
assert (box(1) == box(true));
|
assert (box(1) == box(true));
|
||||||
|
|
||||||
|
@ -746,8 +748,8 @@ unittest
|
||||||
assert (unboxTest!(void*)(box(p))); // int[]
|
assert (unboxTest!(void*)(box(p))); // int[]
|
||||||
assert (unboxTest!(void*)(box(new A))); // Object
|
assert (unboxTest!(void*)(box(new A))); // Object
|
||||||
|
|
||||||
/* Assert that we can't unbox an integer as bit. */
|
/* Assert that we can't unbox an integer as bool. */
|
||||||
assert (!unboxable!(bit) (box(4)));
|
assert (!unboxable!(bool) (box(4)));
|
||||||
|
|
||||||
/* Assert that we can't unbox a struct as another struct. */
|
/* Assert that we can't unbox a struct as another struct. */
|
||||||
SA sa;
|
SA sa;
|
||||||
|
|
30
std/conv.d
30
std/conv.d
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
// Written by Walter Bright
|
// Written by Walter Bright
|
||||||
// Copyright (c) 2002-2003 Digital Mars
|
// Copyright (c) 2002-2006 Digital Mars
|
||||||
// All Rights Reserved
|
// All Rights Reserved
|
||||||
// www.digitalmars.com
|
// www.digitalmars.com
|
||||||
// Some parts contributed by David L. Davis
|
// Some parts contributed by David L. Davis
|
||||||
|
@ -1174,7 +1174,7 @@ cfloat toCfloat(in char[] s)
|
||||||
real r1;
|
real r1;
|
||||||
real r2;
|
real r2;
|
||||||
cfloat cf;
|
cfloat cf;
|
||||||
bit b = 0;
|
bool b = 0;
|
||||||
char* endptr;
|
char* endptr;
|
||||||
|
|
||||||
if (!s.length)
|
if (!s.length)
|
||||||
|
@ -1255,7 +1255,7 @@ cdouble toCdouble(in char[] s)
|
||||||
real r1;
|
real r1;
|
||||||
real r2;
|
real r2;
|
||||||
cdouble cd;
|
cdouble cd;
|
||||||
bit b = 0;
|
bool b = 0;
|
||||||
char* endptr;
|
char* endptr;
|
||||||
|
|
||||||
if (!s.length)
|
if (!s.length)
|
||||||
|
@ -1332,7 +1332,7 @@ creal toCreal(in char[] s)
|
||||||
real r1;
|
real r1;
|
||||||
real r2;
|
real r2;
|
||||||
creal cr;
|
creal cr;
|
||||||
bit b = 0;
|
bool b = 0;
|
||||||
char* endptr;
|
char* endptr;
|
||||||
|
|
||||||
if (!s.length)
|
if (!s.length)
|
||||||
|
@ -1419,7 +1419,7 @@ unittest
|
||||||
* Grammar:
|
* Grammar:
|
||||||
* ['+'|'-'] string floating-point digit {digit}
|
* ['+'|'-'] string floating-point digit {digit}
|
||||||
*/
|
*/
|
||||||
private bit getComplexStrings(in char[] s, out char[] s1, out char[] s2)
|
private bool getComplexStrings(in char[] s, out char[] s1, out char[] s2)
|
||||||
{
|
{
|
||||||
int len = s.length;
|
int len = s.length;
|
||||||
|
|
||||||
|
@ -1471,18 +1471,18 @@ private bit getComplexStrings(in char[] s, out char[] s1, out char[] s2)
|
||||||
/****************************************
|
/****************************************
|
||||||
* Main function to compare reals with given precision
|
* Main function to compare reals with given precision
|
||||||
*/
|
*/
|
||||||
private bit feq(in real rx, in real ry, in real precision)
|
private bool feq(in real rx, in real ry, in real precision)
|
||||||
{
|
{
|
||||||
if (rx == ry)
|
if (rx == ry)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (isnan(rx))
|
if (isnan(rx))
|
||||||
return cast(bit)isnan(ry);
|
return cast(bool)isnan(ry);
|
||||||
|
|
||||||
if (isnan(ry))
|
if (isnan(ry))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return cast(bit)(fabs(rx - ry) <= precision);
|
return cast(bool)(fabs(rx - ry) <= precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************
|
/****************************************
|
||||||
|
@ -1493,24 +1493,24 @@ private bit feq(in real rx, in real ry, in real precision)
|
||||||
* 1 match
|
* 1 match
|
||||||
* 0 nomatch
|
* 0 nomatch
|
||||||
*/
|
*/
|
||||||
private bit feq(in real r1, in real r2)
|
private bool feq(in real r1, in real r2)
|
||||||
{
|
{
|
||||||
if (r1 == r2)
|
if (r1 == r2)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (isnan(r1))
|
if (isnan(r1))
|
||||||
return cast(bit)isnan(r2);
|
return cast(bool)isnan(r2);
|
||||||
|
|
||||||
if (isnan(r2))
|
if (isnan(r2))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return cast(bit)(feq(r1, r2, 0.000001L));
|
return cast(bool)(feq(r1, r2, 0.000001L));
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************
|
/****************************************
|
||||||
* compare ireals with given precision
|
* compare ireals with given precision
|
||||||
*/
|
*/
|
||||||
private bit feq(in ireal r1, in ireal r2)
|
private bool feq(in ireal r1, in ireal r2)
|
||||||
{
|
{
|
||||||
real rx = cast(real)r1;
|
real rx = cast(real)r1;
|
||||||
real ry = cast(real)r2;
|
real ry = cast(real)r2;
|
||||||
|
@ -1519,7 +1519,7 @@ private bit feq(in ireal r1, in ireal r2)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (isnan(rx))
|
if (isnan(rx))
|
||||||
return cast(bit)isnan(ry);
|
return cast(bool)isnan(ry);
|
||||||
|
|
||||||
if (isnan(ry))
|
if (isnan(ry))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1530,7 +1530,7 @@ private bit feq(in ireal r1, in ireal r2)
|
||||||
/****************************************
|
/****************************************
|
||||||
* compare creals with given precision
|
* compare creals with given precision
|
||||||
*/
|
*/
|
||||||
private bit feq(in creal r1, in creal r2)
|
private bool feq(in creal r1, in creal r2)
|
||||||
{
|
{
|
||||||
real r1a = fabs(cast(real)r1.re - cast(real)r2.re);
|
real r1a = fabs(cast(real)r1.re - cast(real)r2.re);
|
||||||
real r2b = fabs(cast(real)r1.im - cast(real)r2.im);
|
real r2b = fabs(cast(real)r1.im - cast(real)r2.im);
|
||||||
|
@ -1540,7 +1540,7 @@ private bit feq(in creal r1, in creal r2)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (isnan(r1a))
|
if (isnan(r1a))
|
||||||
return cast(bit)isnan(r2b);
|
return cast(bool)isnan(r2b);
|
||||||
|
|
||||||
if (isnan(r2b))
|
if (isnan(r2b))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
11
std/cover.d
11
std/cover.d
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2005 by Digital Mars, www.digitalmars.com
|
* Copyright (C) 2005-2006 by Digital Mars, www.digitalmars.com
|
||||||
* Written by Walter Bright
|
* Written by Walter Bright
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
@ -36,20 +36,21 @@ module std.cover;
|
||||||
|
|
||||||
private import std.stdio;
|
private import std.stdio;
|
||||||
private import std.file;
|
private import std.file;
|
||||||
|
private import std.bitarray;
|
||||||
|
|
||||||
private
|
private
|
||||||
{
|
{
|
||||||
struct Cover
|
struct Cover
|
||||||
{
|
{
|
||||||
char[] filename;
|
char[] filename;
|
||||||
bit[] valid;
|
BitArray valid;
|
||||||
uint[] data;
|
uint[] data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cover[] gdata;
|
Cover[] gdata;
|
||||||
char[] srcpath;
|
char[] srcpath;
|
||||||
char[] dstpath;
|
char[] dstpath;
|
||||||
bit merge;
|
bool merge;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************
|
/***********************************
|
||||||
|
@ -78,12 +79,12 @@ void setDestDir(char[] pathname)
|
||||||
* created.
|
* created.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void setMerge(bit flag)
|
void setMerge(bool flag)
|
||||||
{
|
{
|
||||||
merge = flag;
|
merge = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern (C) void _d_cover_register(char[] filename, bit[] valid, uint[] data)
|
extern (C) void _d_cover_register(char[] filename, BitArray valid, uint[] data)
|
||||||
{
|
{
|
||||||
//printf("_d_cover_register()\n");
|
//printf("_d_cover_register()\n");
|
||||||
//printf("\tfilename = '%.*s'\n", filename);
|
//printf("\tfilename = '%.*s'\n", filename);
|
||||||
|
|
|
@ -16,8 +16,8 @@ class CFile : Stream {
|
||||||
this(FILE* cfile, FileMode mode, bool seekable = false) {
|
this(FILE* cfile, FileMode mode, bool seekable = false) {
|
||||||
super();
|
super();
|
||||||
this.file = cfile;
|
this.file = cfile;
|
||||||
readable = cast(bit)(mode & FileMode.In);
|
readable = cast(bool)(mode & FileMode.In);
|
||||||
writeable = cast(bit)(mode & FileMode.Out);
|
writeable = cast(bool)(mode & FileMode.Out);
|
||||||
this.seekable = seekable;
|
this.seekable = seekable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class CFile : Stream {
|
||||||
}
|
}
|
||||||
override size_t readBlock(void* buffer, size_t size) {
|
override size_t readBlock(void* buffer, size_t size) {
|
||||||
size_t n = fread(buffer,1,size,cfile);
|
size_t n = fread(buffer,1,size,cfile);
|
||||||
readEOF = cast(bit)(n == 0);
|
readEOF = cast(bool)(n == 0);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
override size_t writeBlock(void* buffer, size_t size) {
|
override size_t writeBlock(void* buffer, size_t size) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ import std.demangle;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{ char[] buffer;
|
{ char[] buffer;
|
||||||
bit inword;
|
bool inword;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while ((c = fgetc(stdin)) != EOF)
|
while ((c = fgetc(stdin)) != EOF)
|
||||||
|
@ -120,7 +120,7 @@ char[] demangle(char[] name)
|
||||||
name[ni + 2] == 'T')
|
name[ni + 2] == 'T')
|
||||||
{
|
{
|
||||||
size_t nisave = ni;
|
size_t nisave = ni;
|
||||||
bit err;
|
bool err;
|
||||||
ni += 3;
|
ni += 3;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -170,6 +170,7 @@ char[] demangle(char[] name)
|
||||||
{
|
{
|
||||||
case 'v': p = "void"; goto L1;
|
case 'v': p = "void"; goto L1;
|
||||||
case 'b': p = "bit"; goto L1;
|
case 'b': p = "bit"; goto L1;
|
||||||
|
case 'x': p = "bool"; goto L1;
|
||||||
case 'g': p = "byte"; goto L1;
|
case 'g': p = "byte"; goto L1;
|
||||||
case 'h': p = "ubyte"; goto L1;
|
case 'h': p = "ubyte"; goto L1;
|
||||||
case 's': p = "short"; goto L1;
|
case 's': p = "short"; goto L1;
|
||||||
|
|
|
@ -1164,6 +1164,7 @@ struct DirEntry
|
||||||
{ size_t len = std.string.strlen(fd.d_name);
|
{ size_t len = std.string.strlen(fd.d_name);
|
||||||
name = std.path.join(path, fd.d_name[0 .. len]);
|
name = std.path.join(path, fd.d_name[0 .. len]);
|
||||||
d_type = fd.d_type;
|
d_type = fd.d_type;
|
||||||
|
didstat = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int isdir()
|
int isdir()
|
||||||
|
|
14
std/format.d
14
std/format.d
|
@ -38,6 +38,8 @@ private import std.utf;
|
||||||
private import std.c.stdlib;
|
private import std.c.stdlib;
|
||||||
private import std.string;
|
private import std.string;
|
||||||
|
|
||||||
|
alias bool bit;
|
||||||
|
|
||||||
version (Windows)
|
version (Windows)
|
||||||
{
|
{
|
||||||
version (DigitalMars)
|
version (DigitalMars)
|
||||||
|
@ -81,6 +83,7 @@ enum Mangle : char
|
||||||
{
|
{
|
||||||
Tvoid = 'v',
|
Tvoid = 'v',
|
||||||
Tbit = 'b',
|
Tbit = 'b',
|
||||||
|
Tbool = 'x',
|
||||||
Tbyte = 'g',
|
Tbyte = 'g',
|
||||||
Tubyte = 'h',
|
Tubyte = 'h',
|
||||||
Tshort = 's',
|
Tshort = 's',
|
||||||
|
@ -130,6 +133,8 @@ private TypeInfo primitiveTypeInfo(Mangle m)
|
||||||
ti = typeid(void);break;
|
ti = typeid(void);break;
|
||||||
case Mangle.Tbit:
|
case Mangle.Tbit:
|
||||||
ti = typeid(bit);break;
|
ti = typeid(bit);break;
|
||||||
|
case Mangle.Tbool:
|
||||||
|
ti = typeid(bool);break;
|
||||||
case Mangle.Tbyte:
|
case Mangle.Tbyte:
|
||||||
ti = typeid(byte);break;
|
ti = typeid(byte);break;
|
||||||
case Mangle.Tubyte:
|
case Mangle.Tubyte:
|
||||||
|
@ -325,7 +330,7 @@ $(I FormatChar):
|
||||||
<dd>The corresponding argument is formatted in a manner consistent
|
<dd>The corresponding argument is formatted in a manner consistent
|
||||||
with its type:
|
with its type:
|
||||||
<dl>
|
<dl>
|
||||||
<dt>$(B bit)
|
<dt>$(B bool)
|
||||||
<dd>The result is <tt>'true'</tt> or <tt>'false'</tt>.
|
<dd>The result is <tt>'true'</tt> or <tt>'false'</tt>.
|
||||||
<dt>integral types
|
<dt>integral types
|
||||||
<dd>The $(B %d) format is used.
|
<dd>The $(B %d) format is used.
|
||||||
|
@ -351,7 +356,7 @@ $(I FormatChar):
|
||||||
and is formatted as an integer. If the argument is a signed type
|
and is formatted as an integer. If the argument is a signed type
|
||||||
and the $(I FormatChar) is $(B d) it is converted to
|
and the $(I FormatChar) is $(B d) it is converted to
|
||||||
a signed string of characters, otherwise it is treated as
|
a signed string of characters, otherwise it is treated as
|
||||||
unsigned. An argument of type $(B bit) is formatted as '1'
|
unsigned. An argument of type $(B bool) is formatted as '1'
|
||||||
or '0'. The base used is binary for $(B b), octal for $(B o),
|
or '0'. The base used is binary for $(B b), octal for $(B o),
|
||||||
decimal
|
decimal
|
||||||
for $(B d), and hexadecimal for $(B x) or $(B X).
|
for $(B d), and hexadecimal for $(B x) or $(B X).
|
||||||
|
@ -456,7 +461,7 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr)
|
||||||
|
|
||||||
void formatArg(char fc)
|
void formatArg(char fc)
|
||||||
{
|
{
|
||||||
bit vbit;
|
bool vbit;
|
||||||
ulong vnumber;
|
ulong vnumber;
|
||||||
char vchar;
|
char vchar;
|
||||||
dchar vdchar;
|
dchar vdchar;
|
||||||
|
@ -604,7 +609,8 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr)
|
||||||
switch (m)
|
switch (m)
|
||||||
{
|
{
|
||||||
case Mangle.Tbit:
|
case Mangle.Tbit:
|
||||||
vbit = va_arg!(bit)(argptr);
|
case Mangle.Tbool:
|
||||||
|
vbit = va_arg!(bool)(argptr);
|
||||||
if (fc != 's')
|
if (fc != 's')
|
||||||
{ vnumber = vbit;
|
{ vnumber = vbit;
|
||||||
goto Lnumber;
|
goto Lnumber;
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
|
|
||||||
|
|
||||||
// Copyright (c) 1999-2003 by Digital Mars
|
|
||||||
// All Rights Reserved
|
|
||||||
// written by Walter Bright
|
// written by Walter Bright
|
||||||
// www.digitalmars.com
|
// www.digitalmars.com
|
||||||
|
// Placed into the public domain
|
||||||
|
|
||||||
/* These functions are built-in intrinsics to the compiler.
|
/** These functions are built-in intrinsics to the compiler.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module std.intrinsic;
|
module std.intrinsic;
|
||||||
|
|
|
@ -1677,13 +1677,13 @@ private int mfeq(real x, real y, real precision)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if x is +0.0 (This function is used in unit tests)
|
// Returns true if x is +0.0 (This function is used in unit tests)
|
||||||
bit isPosZero(real x)
|
bool isPosZero(real x)
|
||||||
{
|
{
|
||||||
return (x == 0) && (signbit(x) == 0);
|
return (x == 0) && (signbit(x) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if x is -0.0 (This function is used in unit tests)
|
// Returns true if x is -0.0 (This function is used in unit tests)
|
||||||
bit isNegZero(real x)
|
bool isNegZero(real x)
|
||||||
{
|
{
|
||||||
return (x == 0) && signbit(x);
|
return (x == 0) && signbit(x);
|
||||||
}
|
}
|
||||||
|
|
10
std/math2.d
10
std/math2.d
|
@ -20,12 +20,12 @@ private import std.math, std.string, std.c.stdlib, std.c.stdio;
|
||||||
* compare floats with given precision
|
* compare floats with given precision
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bit feq(real a, real b)
|
bool feq(real a, real b)
|
||||||
{
|
{
|
||||||
return feq(a, b, 0.000001);
|
return feq(a, b, 0.000001);
|
||||||
}
|
}
|
||||||
|
|
||||||
bit feq(real a, real b, real eps)
|
bool feq(real a, real b, real eps)
|
||||||
{
|
{
|
||||||
return abs(a - b) <= eps;
|
return abs(a - b) <= eps;
|
||||||
}
|
}
|
||||||
|
@ -761,7 +761,7 @@ real atof(char[] s)
|
||||||
while (s[i] == '\t' || s[i] == ' ')
|
while (s[i] == '\t' || s[i] == ' ')
|
||||||
if (++i >= s.length)
|
if (++i >= s.length)
|
||||||
return real.nan;
|
return real.nan;
|
||||||
bit neg = false;
|
bool neg = false;
|
||||||
if (s[i] == '-')
|
if (s[i] == '-')
|
||||||
{
|
{
|
||||||
neg = true;
|
neg = true;
|
||||||
|
@ -771,7 +771,7 @@ real atof(char[] s)
|
||||||
i++;
|
i++;
|
||||||
if (i >= s.length)
|
if (i >= s.length)
|
||||||
return real.nan;
|
return real.nan;
|
||||||
bit hex;
|
bool hex;
|
||||||
if (s[s.length - 1] == 'h')
|
if (s[s.length - 1] == 'h')
|
||||||
{
|
{
|
||||||
hex = true;
|
hex = true;
|
||||||
|
@ -859,7 +859,7 @@ real atof(char[] s)
|
||||||
}
|
}
|
||||||
if (++i >= s.length)
|
if (++i >= s.length)
|
||||||
return real.nan;
|
return real.nan;
|
||||||
bit eneg = false;
|
bool eneg = false;
|
||||||
if (s[i] == '-')
|
if (s[i] == '-')
|
||||||
{
|
{
|
||||||
eneg = true;
|
eneg = true;
|
||||||
|
|
|
@ -259,7 +259,7 @@ class MmFile
|
||||||
errNo();
|
errNo();
|
||||||
}
|
}
|
||||||
|
|
||||||
data = p[0 .. size];
|
data = p[0 .. initial_map];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
10
std/path.d
10
std/path.d
|
@ -3,8 +3,7 @@
|
||||||
* Macros:
|
* Macros:
|
||||||
* WIKI = StdPath
|
* WIKI = StdPath
|
||||||
* Copyright:
|
* Copyright:
|
||||||
* Copyright (c) 2001-2006 by Digital Mars
|
* Placed into public domain.
|
||||||
* All Rights Reserved
|
|
||||||
* www.digitalmars.com
|
* www.digitalmars.com
|
||||||
*
|
*
|
||||||
* Grzegorz Adam Hankiewicz added some documentation.
|
* Grzegorz Adam Hankiewicz added some documentation.
|
||||||
|
@ -537,7 +536,12 @@ int isabs(char[] path)
|
||||||
{
|
{
|
||||||
char[] d = getDrive(path);
|
char[] d = getDrive(path);
|
||||||
|
|
||||||
return d.length < path.length && path[d.length] == sep[0];
|
version (Windows)
|
||||||
|
{
|
||||||
|
return d.length && d.length < path.length && path[d.length] == sep[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return d.length < path.length && path[d.length] == sep[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
|
87
std/regexp.d
87
std/regexp.d
|
@ -100,6 +100,7 @@ private
|
||||||
import std.string;
|
import std.string;
|
||||||
import std.ctype;
|
import std.ctype;
|
||||||
import std.outbuffer;
|
import std.outbuffer;
|
||||||
|
import std.bitarray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Regular expression to extract an _email address */
|
/** Regular expression to extract an _email address */
|
||||||
|
@ -335,6 +336,21 @@ unittest
|
||||||
* attributes = Regular expression attributes.
|
* attributes = Regular expression attributes.
|
||||||
* Returns:
|
* Returns:
|
||||||
* corresponding RegExp if found, null if not.
|
* corresponding RegExp if found, null if not.
|
||||||
|
* Example:
|
||||||
|
* ---
|
||||||
|
* import std.stdio;
|
||||||
|
* import std.regexp;
|
||||||
|
*
|
||||||
|
* void main()
|
||||||
|
* {
|
||||||
|
* if (m; std.regexp.search("abcdef", "c"))
|
||||||
|
* {
|
||||||
|
* writefln("%s[%s]%s", m.pre, m.match(0), m.post);
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* // Prints:
|
||||||
|
* // ab[c]def
|
||||||
|
* ---
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RegExp search(char[] string, char[] pattern, char[] attributes = null)
|
RegExp search(char[] string, char[] pattern, char[] attributes = null)
|
||||||
|
@ -388,41 +404,51 @@ class RegExp
|
||||||
return new RegExp(pattern, attributes);
|
return new RegExp(pattern, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********
|
/************************************
|
||||||
* Determine if there is an initial match with string[].
|
* Set up for start of foreach loop.
|
||||||
* Returns:
|
* Returns:
|
||||||
* $(B this) if there is a match, null if not
|
* search() returns instance of RegExp set up to _search string[].
|
||||||
* Example:
|
* Example:
|
||||||
* This makes it possible
|
|
||||||
* to use RegExp's in a $(I MatchExpression):
|
|
||||||
* ---
|
* ---
|
||||||
* if (RegExp("^abc") ~~ string)
|
* import std.stdio;
|
||||||
* writefln("string starts with 'abc'");
|
* import std.regexp;
|
||||||
|
*
|
||||||
|
* void main()
|
||||||
|
* {
|
||||||
|
* foreach(m; RegExp("ab").search("abcabcabab"))
|
||||||
|
* {
|
||||||
|
* writefln("%s[%s]%s", m.pre, m.match(0), m.post);
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* // Prints:
|
||||||
|
* // [ab]cabcabab
|
||||||
|
* // abc[ab]cabab
|
||||||
|
* // abcabc[ab]ab
|
||||||
|
* // abcabcab[ab]
|
||||||
* ---
|
* ---
|
||||||
*/
|
*/
|
||||||
public RegExp opMatch(char[] string)
|
|
||||||
|
public RegExp search(rchar[] string)
|
||||||
{
|
{
|
||||||
return test(input, 0) ? this : null;
|
input = string;
|
||||||
|
pmatch[0].rm_eo = 0;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************
|
/** ditto */
|
||||||
* Determine next match in string.
|
public int opApply(int delegate(inout RegExp) dg)
|
||||||
* Returns:
|
|
||||||
* $(B this) if there is a match, null if not
|
|
||||||
* Example:
|
|
||||||
* This makes it possible, along with $(B opMatch) operator overload,
|
|
||||||
* to use RegExp's in a $(I WhileStatement):
|
|
||||||
* ---
|
|
||||||
* RegExp r = new RegExp("[a..c]");
|
|
||||||
* writef("'");
|
|
||||||
* while (r ~~ "abdd3cce")
|
|
||||||
* writef(_match.match(0));
|
|
||||||
* writefln("'"); // writes 'abcc'
|
|
||||||
* ---
|
|
||||||
*/
|
|
||||||
public RegExp opNext()
|
|
||||||
{
|
{
|
||||||
return test(input, pmatch[0].rm_eo) ? this : null;
|
int result;
|
||||||
|
RegExp r = this;
|
||||||
|
|
||||||
|
while (test())
|
||||||
|
{
|
||||||
|
result = dg(r);
|
||||||
|
if (result)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
|
@ -725,7 +751,7 @@ public int find(rchar[] string)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
deprecated alias find search;
|
//deprecated alias find search;
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
|
@ -2090,7 +2116,7 @@ class Range
|
||||||
uint maxb;
|
uint maxb;
|
||||||
OutBuffer buf;
|
OutBuffer buf;
|
||||||
ubyte* base;
|
ubyte* base;
|
||||||
bit[] bits;
|
BitArray bits;
|
||||||
|
|
||||||
this(OutBuffer buf)
|
this(OutBuffer buf)
|
||||||
{
|
{
|
||||||
|
@ -2102,6 +2128,7 @@ class Range
|
||||||
void setbitmax(uint u)
|
void setbitmax(uint u)
|
||||||
{ uint b;
|
{ uint b;
|
||||||
|
|
||||||
|
//printf("setbitmax(x%x), maxc = x%x\n", u, maxc);
|
||||||
if (u > maxc)
|
if (u > maxc)
|
||||||
{
|
{
|
||||||
maxc = u;
|
maxc = u;
|
||||||
|
@ -2113,8 +2140,10 @@ class Range
|
||||||
buf.fill0(b - maxb + 1);
|
buf.fill0(b - maxb + 1);
|
||||||
base = &buf.data[u];
|
base = &buf.data[u];
|
||||||
maxb = b + 1;
|
maxb = b + 1;
|
||||||
bits = (cast(bit*)this.base)[0 .. maxc + 1];
|
//bits = (cast(bit*)this.base)[0 .. maxc + 1];
|
||||||
|
bits.ptr = cast(uint*)this.base;
|
||||||
}
|
}
|
||||||
|
bits.len = maxc + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
std/socket.d
28
std/socket.d
|
@ -197,7 +197,7 @@ class Protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bit getProtocolByName(char[] name)
|
bool getProtocolByName(char[] name)
|
||||||
{
|
{
|
||||||
protoent* proto;
|
protoent* proto;
|
||||||
proto = getprotobyname(toStringz(name));
|
proto = getprotobyname(toStringz(name));
|
||||||
|
@ -209,7 +209,7 @@ class Protocol
|
||||||
|
|
||||||
|
|
||||||
// Same as getprotobynumber().
|
// Same as getprotobynumber().
|
||||||
bit getProtocolByType(ProtocolType type)
|
bool getProtocolByType(ProtocolType type)
|
||||||
{
|
{
|
||||||
protoent* proto;
|
protoent* proto;
|
||||||
proto = getprotobynumber(type);
|
proto = getprotobynumber(type);
|
||||||
|
@ -269,7 +269,7 @@ class Service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bit getServiceByName(char[] name, char[] protocolName)
|
bool getServiceByName(char[] name, char[] protocolName)
|
||||||
{
|
{
|
||||||
servent* serv;
|
servent* serv;
|
||||||
serv = getservbyname(toStringz(name), toStringz(protocolName));
|
serv = getservbyname(toStringz(name), toStringz(protocolName));
|
||||||
|
@ -281,7 +281,7 @@ class Service
|
||||||
|
|
||||||
|
|
||||||
// Any protocol name will be matched.
|
// Any protocol name will be matched.
|
||||||
bit getServiceByName(char[] name)
|
bool getServiceByName(char[] name)
|
||||||
{
|
{
|
||||||
servent* serv;
|
servent* serv;
|
||||||
serv = getservbyname(toStringz(name), null);
|
serv = getservbyname(toStringz(name), null);
|
||||||
|
@ -292,7 +292,7 @@ class Service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bit getServiceByPort(ushort port, char[] protocolName)
|
bool getServiceByPort(ushort port, char[] protocolName)
|
||||||
{
|
{
|
||||||
servent* serv;
|
servent* serv;
|
||||||
serv = getservbyport(port, toStringz(protocolName));
|
serv = getservbyport(port, toStringz(protocolName));
|
||||||
|
@ -304,7 +304,7 @@ class Service
|
||||||
|
|
||||||
|
|
||||||
// Any protocol name will be matched.
|
// Any protocol name will be matched.
|
||||||
bit getServiceByPort(ushort port)
|
bool getServiceByPort(ushort port)
|
||||||
{
|
{
|
||||||
servent* serv;
|
servent* serv;
|
||||||
serv = getservbyport(port, null);
|
serv = getservbyport(port, null);
|
||||||
|
@ -411,7 +411,7 @@ class InternetHost
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bit getHostByName(char[] name)
|
bool getHostByName(char[] name)
|
||||||
{
|
{
|
||||||
hostent* he = gethostbyname(toStringz(name));
|
hostent* he = gethostbyname(toStringz(name));
|
||||||
if(!he)
|
if(!he)
|
||||||
|
@ -422,7 +422,7 @@ class InternetHost
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bit getHostByAddr(uint addr)
|
bool getHostByAddr(uint addr)
|
||||||
{
|
{
|
||||||
uint x = htonl(addr);
|
uint x = htonl(addr);
|
||||||
hostent* he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
hostent* he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||||
|
@ -435,7 +435,7 @@ class InternetHost
|
||||||
|
|
||||||
|
|
||||||
//shortcut
|
//shortcut
|
||||||
bit getHostByAddr(char[] addr)
|
bool getHostByAddr(char[] addr)
|
||||||
{
|
{
|
||||||
uint x = inet_addr(std.string.toStringz(addr));
|
uint x = inet_addr(std.string.toStringz(addr));
|
||||||
hostent* he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
hostent* he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);
|
||||||
|
@ -922,7 +922,7 @@ class Socket
|
||||||
AddressFamily _family;
|
AddressFamily _family;
|
||||||
|
|
||||||
version(Win32)
|
version(Win32)
|
||||||
bit _blocking = false;
|
bool _blocking = false;
|
||||||
|
|
||||||
|
|
||||||
// For use with accepting().
|
// For use with accepting().
|
||||||
|
@ -972,7 +972,7 @@ class Socket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bit blocking() // getter
|
bool blocking() // getter
|
||||||
{
|
{
|
||||||
version(Win32)
|
version(Win32)
|
||||||
{
|
{
|
||||||
|
@ -985,7 +985,7 @@ class Socket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void blocking(bit byes) // setter
|
void blocking(bool byes) // setter
|
||||||
{
|
{
|
||||||
version(Win32)
|
version(Win32)
|
||||||
{
|
{
|
||||||
|
@ -1019,7 +1019,7 @@ class Socket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bit isAlive() // getter
|
bool isAlive() // getter
|
||||||
{
|
{
|
||||||
int type, typesize = type.sizeof;
|
int type, typesize = type.sizeof;
|
||||||
return !getsockopt(sock, SOL_SOCKET, SO_TYPE, cast(char*)&type, &typesize);
|
return !getsockopt(sock, SOL_SOCKET, SO_TYPE, cast(char*)&type, &typesize);
|
||||||
|
@ -1439,7 +1439,7 @@ class Socket
|
||||||
|
|
||||||
|
|
||||||
/+
|
/+
|
||||||
bit poll(events)
|
bool poll(events)
|
||||||
{
|
{
|
||||||
int WSAEventSelect(socket_t s, WSAEVENT hEventObject, int lNetworkEvents); // Winsock 2 ?
|
int WSAEventSelect(socket_t s, WSAEVENT hEventObject, int lNetworkEvents); // Winsock 2 ?
|
||||||
int poll(pollfd* fds, int nfds, int timeout); // Unix ?
|
int poll(pollfd* fds, int nfds, int timeout); // Unix ?
|
||||||
|
|
|
@ -62,7 +62,7 @@ class SocketStream: Stream
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
len = sock.receive(buffer[0 .. size]);
|
len = sock.receive(buffer[0 .. size]);
|
||||||
readEOF = cast(bit)(len == 0);
|
readEOF = cast(bool)(len == 0);
|
||||||
if(len < 0)
|
if(len < 0)
|
||||||
len = 0;
|
len = 0;
|
||||||
return len;
|
return len;
|
||||||
|
@ -78,7 +78,7 @@ class SocketStream: Stream
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
len = sock.send(buffer[0 .. size]);
|
len = sock.send(buffer[0 .. size]);
|
||||||
readEOF = cast(bit)(len == 0);
|
readEOF = cast(bool)(len == 0);
|
||||||
if(len < 0)
|
if(len < 0)
|
||||||
len = 0;
|
len = 0;
|
||||||
return len;
|
return len;
|
||||||
|
|
44
std/stream.d
44
std/stream.d
|
@ -380,15 +380,15 @@ class Stream : InputStream, OutputStream {
|
||||||
private import std.string, crc32, std.c.stdlib, std.c.stdio;
|
private import std.string, crc32, std.c.stdlib, std.c.stdio;
|
||||||
|
|
||||||
// stream abilities
|
// stream abilities
|
||||||
bit readable = false; /// Indicates whether this stream can be read from.
|
bool readable = false; /// Indicates whether this stream can be read from.
|
||||||
bit writeable = false; /// Indicates whether this stream can be written to.
|
bool writeable = false; /// Indicates whether this stream can be written to.
|
||||||
bit seekable = false; /// Indicates whether this stream can be seeked within.
|
bool seekable = false; /// Indicates whether this stream can be seeked within.
|
||||||
protected bit isopen = true; /// Indicates whether this stream is open.
|
protected bool isopen = true; /// Indicates whether this stream is open.
|
||||||
|
|
||||||
protected bit readEOF = false; /// Indicates whether this stream is at eof
|
protected bool readEOF = false; /// Indicates whether this stream is at eof
|
||||||
/// after the last read attempt.
|
/// after the last read attempt.
|
||||||
|
|
||||||
protected bit prevCr = false; /// For a non-seekable stream indicates that
|
protected bool prevCr = false; /// For a non-seekable stream indicates that
|
||||||
/// the last readLine or readLineW ended on a
|
/// the last readLine or readLineW ended on a
|
||||||
/// '\r' character.
|
/// '\r' character.
|
||||||
|
|
||||||
|
@ -712,7 +712,7 @@ class Stream : InputStream, OutputStream {
|
||||||
}
|
}
|
||||||
if (fmt[i] == '%') { // a field
|
if (fmt[i] == '%') { // a field
|
||||||
i++;
|
i++;
|
||||||
bit suppress = false;
|
bool suppress = false;
|
||||||
if (fmt[i] == '*') { // suppress assignment
|
if (fmt[i] == '*') { // suppress assignment
|
||||||
suppress = true;
|
suppress = true;
|
||||||
i++;
|
i++;
|
||||||
|
@ -745,7 +745,7 @@ class Stream : InputStream, OutputStream {
|
||||||
c = getc();
|
c = getc();
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
bit neg = false;
|
bool neg = false;
|
||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
neg = true;
|
neg = true;
|
||||||
c = getc();
|
c = getc();
|
||||||
|
@ -846,7 +846,7 @@ class Stream : InputStream, OutputStream {
|
||||||
c = getc();
|
c = getc();
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
bit neg = false;
|
bool neg = false;
|
||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
neg = true;
|
neg = true;
|
||||||
c = getc();
|
c = getc();
|
||||||
|
@ -881,7 +881,7 @@ class Stream : InputStream, OutputStream {
|
||||||
c = getc();
|
c = getc();
|
||||||
count++;
|
count++;
|
||||||
if (width) {
|
if (width) {
|
||||||
bit expneg = false;
|
bool expneg = false;
|
||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
expneg = true;
|
expneg = true;
|
||||||
width--;
|
width--;
|
||||||
|
@ -1249,7 +1249,7 @@ class Stream : InputStream, OutputStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if end of stream is reached, false otherwise
|
// returns true if end of stream is reached, false otherwise
|
||||||
bit eof() {
|
bool eof() {
|
||||||
// for unseekable streams we only know the end when we read it
|
// for unseekable streams we only know the end when we read it
|
||||||
if (readEOF && !ungetAvailable())
|
if (readEOF && !ungetAvailable())
|
||||||
return true;
|
return true;
|
||||||
|
@ -1366,7 +1366,7 @@ class FilterStream : Stream {
|
||||||
/// Property indicating when this stream closes to close the source stream as
|
/// Property indicating when this stream closes to close the source stream as
|
||||||
/// well.
|
/// well.
|
||||||
/// Defaults to true.
|
/// Defaults to true.
|
||||||
bit nestClose = true;
|
bool nestClose = true;
|
||||||
|
|
||||||
/// Construct a FilterStream for the given source.
|
/// Construct a FilterStream for the given source.
|
||||||
this(Stream source) {
|
this(Stream source) {
|
||||||
|
@ -1455,7 +1455,7 @@ class BufferedStream : FilterStream {
|
||||||
ubyte[] buffer; // buffer, if any
|
ubyte[] buffer; // buffer, if any
|
||||||
uint bufferCurPos; // current position in buffer
|
uint bufferCurPos; // current position in buffer
|
||||||
uint bufferLen; // amount of data in buffer
|
uint bufferLen; // amount of data in buffer
|
||||||
bit bufferDirty = false;
|
bool bufferDirty = false;
|
||||||
uint bufferSourcePos; // position in buffer of source stream position
|
uint bufferSourcePos; // position in buffer of source stream position
|
||||||
ulong streamPos; // absolute position in source stream
|
ulong streamPos; // absolute position in source stream
|
||||||
|
|
||||||
|
@ -1796,8 +1796,8 @@ class File: Stream {
|
||||||
this(HANDLE hFile, FileMode mode) {
|
this(HANDLE hFile, FileMode mode) {
|
||||||
super();
|
super();
|
||||||
this.hFile = hFile;
|
this.hFile = hFile;
|
||||||
readable = cast(bit)(mode & FileMode.In);
|
readable = cast(bool)(mode & FileMode.In);
|
||||||
writeable = cast(bit)(mode & FileMode.Out);
|
writeable = cast(bool)(mode & FileMode.Out);
|
||||||
version(Windows) {
|
version(Windows) {
|
||||||
seekable = GetFileType(hFile) == 1; // FILE_TYPE_DISK
|
seekable = GetFileType(hFile) == 1; // FILE_TYPE_DISK
|
||||||
} else {
|
} else {
|
||||||
|
@ -1831,8 +1831,8 @@ class File: Stream {
|
||||||
int access, share, createMode;
|
int access, share, createMode;
|
||||||
parseMode(mode, access, share, createMode);
|
parseMode(mode, access, share, createMode);
|
||||||
seekable = true;
|
seekable = true;
|
||||||
readable = cast(bit)(mode & FileMode.In);
|
readable = cast(bool)(mode & FileMode.In);
|
||||||
writeable = cast(bit)(mode & FileMode.Out);
|
writeable = cast(bool)(mode & FileMode.Out);
|
||||||
version (Win32) {
|
version (Win32) {
|
||||||
if (std.file.useWfuncs) {
|
if (std.file.useWfuncs) {
|
||||||
hFile = CreateFileW(std.utf.toUTF16z(filename), access, share,
|
hFile = CreateFileW(std.utf.toUTF16z(filename), access, share,
|
||||||
|
@ -2737,7 +2737,7 @@ class SliceStream : FilterStream {
|
||||||
ulong pos; // our position relative to low
|
ulong pos; // our position relative to low
|
||||||
ulong low; // low stream offset.
|
ulong low; // low stream offset.
|
||||||
ulong high; // high stream offset.
|
ulong high; // high stream offset.
|
||||||
bit bounded; // upper-bounded by high.
|
bool bounded; // upper-bounded by high.
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -2905,18 +2905,18 @@ class SliceStream : FilterStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper functions
|
// helper functions
|
||||||
private bit iswhite(char c) {
|
private bool iswhite(char c) {
|
||||||
return c == ' ' || c == '\t' || c == '\r' || c == '\n';
|
return c == ' ' || c == '\t' || c == '\r' || c == '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
private bit isdigit(char c) {
|
private bool isdigit(char c) {
|
||||||
return c >= '0' && c <= '9';
|
return c >= '0' && c <= '9';
|
||||||
}
|
}
|
||||||
|
|
||||||
private bit isoctdigit(char c) {
|
private bool isoctdigit(char c) {
|
||||||
return c >= '0' && c <= '7';
|
return c >= '0' && c <= '7';
|
||||||
}
|
}
|
||||||
|
|
||||||
private bit ishexdigit(char c) {
|
private bool ishexdigit(char c) {
|
||||||
return isdigit(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');
|
return isdigit(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');
|
||||||
}
|
}
|
||||||
|
|
10
std/string.d
10
std/string.d
|
@ -1730,6 +1730,8 @@ char[] replace(char[] s, char[] from, char[] to)
|
||||||
int istart;
|
int istart;
|
||||||
|
|
||||||
//printf("replace('%.*s','%.*s','%.*s')\n", s, from, to);
|
//printf("replace('%.*s','%.*s','%.*s')\n", s, from, to);
|
||||||
|
if (from.length == 0)
|
||||||
|
return s;
|
||||||
istart = 0;
|
istart = 0;
|
||||||
while (istart < s.length)
|
while (istart < s.length)
|
||||||
{
|
{
|
||||||
|
@ -1759,6 +1761,10 @@ unittest
|
||||||
r = replace(s, from, to);
|
r = replace(s, from, to);
|
||||||
i = cmp(r, "This is a silly silly list");
|
i = cmp(r, "This is a silly silly list");
|
||||||
assert(i == 0);
|
assert(i == 0);
|
||||||
|
|
||||||
|
r = replace(s, "", to);
|
||||||
|
i = cmp(r, "This is a foo foo list");
|
||||||
|
assert(i == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************
|
/*****************************
|
||||||
|
@ -2168,7 +2174,7 @@ char[] translate(char[] s, char[] transtab, char[] delchars)
|
||||||
{
|
{
|
||||||
char[] r;
|
char[] r;
|
||||||
int count;
|
int count;
|
||||||
bit[256] deltab;
|
bool[256] deltab;
|
||||||
|
|
||||||
deltab[] = false;
|
deltab[] = false;
|
||||||
foreach (char c; delchars)
|
foreach (char c; delchars)
|
||||||
|
@ -2220,7 +2226,7 @@ unittest
|
||||||
* Convert to char[].
|
* Convert to char[].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char[] toString(bit b)
|
char[] toString(bool b)
|
||||||
{
|
{
|
||||||
return b ? "true" : "false";
|
return b ? "true" : "false";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
|
|
||||||
module std.typeinfo.ti_Abit;
|
|
||||||
|
|
||||||
private import std.string;
|
|
||||||
|
|
||||||
// bit[]
|
|
||||||
|
|
||||||
class TypeInfo_Ab : TypeInfo
|
|
||||||
{
|
|
||||||
char[] toString() { return "bit[]"; }
|
|
||||||
|
|
||||||
uint getHash(void *p)
|
|
||||||
{ ubyte[] s = *cast(ubyte[]*)p;
|
|
||||||
size_t len = (s.length + 7) / 8;
|
|
||||||
ubyte *str = s;
|
|
||||||
uint hash = 0;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
switch (len)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
return hash;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
hash *= 9;
|
|
||||||
hash += *cast(ubyte *)str;
|
|
||||||
return hash;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
hash *= 9;
|
|
||||||
hash += *cast(ushort *)str;
|
|
||||||
return hash;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
hash *= 9;
|
|
||||||
hash += (*cast(ushort *)str << 8) +
|
|
||||||
(cast(ubyte *)str)[2];
|
|
||||||
return hash;
|
|
||||||
|
|
||||||
default:
|
|
||||||
hash *= 9;
|
|
||||||
hash += *cast(uint *)str;
|
|
||||||
str += 4;
|
|
||||||
len -= 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
int equals(void *p1, void *p2)
|
|
||||||
{
|
|
||||||
bit[] s1 = *cast(bit[]*)p1;
|
|
||||||
bit[] s2 = *cast(bit[]*)p2;
|
|
||||||
|
|
||||||
size_t len = s1.length;
|
|
||||||
|
|
||||||
if (s2.length != len)
|
|
||||||
return 0;;
|
|
||||||
|
|
||||||
// Woefully inefficient bit-by-bit comparison
|
|
||||||
for (size_t u = 0; u < len; u++)
|
|
||||||
{
|
|
||||||
if (s1[u] != s2[u])
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int compare(void *p1, void *p2)
|
|
||||||
{
|
|
||||||
bit[] s1 = *cast(bit[]*)p1;
|
|
||||||
bit[] s2 = *cast(bit[]*)p2;
|
|
||||||
|
|
||||||
size_t len = s1.length;
|
|
||||||
|
|
||||||
if (s2.length < len)
|
|
||||||
len = s2.length;
|
|
||||||
|
|
||||||
// Woefully inefficient bit-by-bit comparison
|
|
||||||
for (size_t u = 0; u < len; u++)
|
|
||||||
{
|
|
||||||
int result = s1[u] - s2[u];
|
|
||||||
if (result)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return cast(int)s1.length - cast(int)s2.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t tsize()
|
|
||||||
{
|
|
||||||
return (bit[]).sizeof;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -79,3 +79,10 @@ class TypeInfo_Av : TypeInfo_Ah
|
||||||
{
|
{
|
||||||
char[] toString() { return "void[]"; }
|
char[] toString() { return "void[]"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bool[]
|
||||||
|
|
||||||
|
class TypeInfo_Ax : TypeInfo_Ah
|
||||||
|
{
|
||||||
|
char[] toString() { return "bool[]"; }
|
||||||
|
}
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
|
|
||||||
// bit
|
|
||||||
|
|
||||||
module std.typeinfo.ti_bit;
|
|
||||||
|
|
||||||
class TypeInfo_b : TypeInfo
|
|
||||||
{
|
|
||||||
char[] toString() { return "bit"; }
|
|
||||||
|
|
||||||
uint getHash(void *p)
|
|
||||||
{
|
|
||||||
return *cast(bit *)p;
|
|
||||||
}
|
|
||||||
|
|
||||||
int equals(void *p1, void *p2)
|
|
||||||
{
|
|
||||||
return *cast(bit *)p1 == *cast(bit *)p2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int compare(void *p1, void *p2)
|
|
||||||
{
|
|
||||||
if (*cast(bit*) p1 < *cast(bit*) p2)
|
|
||||||
return -1;
|
|
||||||
else if (*cast(bit*) p1 > *cast(bit*) p2)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t tsize()
|
|
||||||
{
|
|
||||||
return bit.sizeof;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap(void *p1, void *p2)
|
|
||||||
{
|
|
||||||
bit t;
|
|
||||||
|
|
||||||
t = *cast(bit *)p1;
|
|
||||||
*cast(bit *)p1 = *cast(bit *)p2;
|
|
||||||
*cast(bit *)p2 = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -37,3 +37,7 @@ class TypeInfo_h : TypeInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TypeInfo_x : TypeInfo_h
|
||||||
|
{
|
||||||
|
char[] toString() { return "bool"; }
|
||||||
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ class UtfException : Exception
|
||||||
* Returns: true if it is, false if not.
|
* Returns: true if it is, false if not.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bit isValidDchar(dchar c)
|
bool isValidDchar(dchar c)
|
||||||
{
|
{
|
||||||
/* Note: FFFE and FFFF are specifically permitted by the
|
/* Note: FFFE and FFFF are specifically permitted by the
|
||||||
* Unicode standard for application internal use, but are not
|
* Unicode standard for application internal use, but are not
|
||||||
|
|
|
@ -47,6 +47,7 @@ import std.md5;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
import std.boxer;
|
import std.boxer;
|
||||||
|
import std.bitarray;
|
||||||
|
|
||||||
int main(char[][] args)
|
int main(char[][] args)
|
||||||
{
|
{
|
||||||
|
@ -103,6 +104,10 @@ printf("test2\n");
|
||||||
|
|
||||||
std.demangle.demangle("hello");
|
std.demangle.demangle("hello");
|
||||||
|
|
||||||
|
BitArray ba; // std.bitarray
|
||||||
|
ba.length = 3;
|
||||||
|
ba[0] = true;
|
||||||
|
|
||||||
printf("Success\n!");
|
printf("Success\n!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ OBJS= asserterror.obj deh.obj switch.obj complex.obj gcstats.obj \
|
||||||
socket.obj socketstream.obj loader.obj stdarg.obj format.obj stdio.obj \
|
socket.obj socketstream.obj loader.obj stdarg.obj format.obj stdio.obj \
|
||||||
perf.obj openrj.obj uni.obj winsock.obj oldsyserror.obj \
|
perf.obj openrj.obj uni.obj winsock.obj oldsyserror.obj \
|
||||||
errno.obj boxer.obj cstream.obj charset.obj \
|
errno.obj boxer.obj cstream.obj charset.obj \
|
||||||
realtest.obj gamma.obj demangle.obj cover.obj match.obj \
|
realtest.obj gamma.obj demangle.obj cover.obj \
|
||||||
ti_Aa.obj ti_Ag.obj ti_C.obj ti_int.obj ti_char.obj \
|
ti_Aa.obj ti_Ag.obj ti_C.obj ti_int.obj ti_char.obj \
|
||||||
ti_wchar.obj ti_uint.obj ti_short.obj ti_ushort.obj \
|
ti_wchar.obj ti_uint.obj ti_short.obj ti_ushort.obj \
|
||||||
ti_byte.obj ti_ubyte.obj ti_long.obj ti_ulong.obj ti_ptr.obj \
|
ti_byte.obj ti_ubyte.obj ti_long.obj ti_ulong.obj ti_ptr.obj \
|
||||||
|
@ -148,7 +148,7 @@ SRC_INT= \
|
||||||
internal\memset.d internal\arraycast.d internal\aaA.d internal\adi.d \
|
internal\memset.d internal\arraycast.d internal\aaA.d internal\adi.d \
|
||||||
internal\dmain2.d internal\cast.d internal\qsort.d internal\deh2.d \
|
internal\dmain2.d internal\cast.d internal\qsort.d internal\deh2.d \
|
||||||
internal\cmath2.d internal\obj.d internal\mars.h internal\aApply.d \
|
internal\cmath2.d internal\obj.d internal\mars.h internal\aApply.d \
|
||||||
internal\object.d internal\trace.d internal\qsort2.d internal\match.d
|
internal\object.d internal\trace.d internal\qsort2.d
|
||||||
|
|
||||||
SRC_STD_WIN= std\windows\registry.d \
|
SRC_STD_WIN= std\windows\registry.d \
|
||||||
std\windows\iunknown.d std\windows\syserror.d std\windows\charset.d
|
std\windows\iunknown.d std\windows\syserror.d std\windows\charset.d
|
||||||
|
@ -427,9 +427,6 @@ gcstub.obj : internal\gc\gcstub.d
|
||||||
invariant.obj : internal\invariant.d
|
invariant.obj : internal\invariant.d
|
||||||
$(DMD) -c $(DFLAGS) internal\invariant.d
|
$(DMD) -c $(DFLAGS) internal\invariant.d
|
||||||
|
|
||||||
match.obj : internal\match.d
|
|
||||||
$(DMD) -c $(DFLAGS) internal\match.d
|
|
||||||
|
|
||||||
memset.obj : internal\memset.d
|
memset.obj : internal\memset.d
|
||||||
$(DMD) -c $(DFLAGS) internal\memset.d
|
$(DMD) -c $(DFLAGS) internal\memset.d
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue