diff --git a/LICENSE_1_0.txt b/LICENSE_1_0.txt new file mode 100644 index 000000000..36b7cd93c --- /dev/null +++ b/LICENSE_1_0.txt @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/osx.mak b/osx.mak index 0d2bd17b0..22b352a77 100644 --- a/osx.mak +++ b/osx.mak @@ -118,13 +118,13 @@ $$(OBJDIR)/$1/$2/unittest/std/% : std/%.d \ @touch $$@ $(PRODUCTIONLIBDIR)/libphobos2tmp_$2$$(LIBSUFFIX_$1) : $$(LIB_$1_$2) - ln -sf $$(realpath $$<) $$@ + sudo ln -sf $$(realpath $$<) $$@ PRODUCTIONLIB_$1 = $(PRODUCTIONLIBDIR)/libphobos2$(LIBSUFFIX_$1) ifeq ($2,release) $1/$2 : $$(PRODUCTIONLIB_$1) $$(PRODUCTIONLIB_$1) : $$(LIB_$1_$2) - ln -sf $$(realpath $$<) $$@ + sudo ln -sf $$(realpath $$<) $$@ else $1/$2 : $$(LIB_$1_$2) endif diff --git a/phobos.d b/phobos.d index a690f3643..d8b2b01b6 100644 --- a/phobos.d +++ b/phobos.d @@ -169,9 +169,6 @@ D language compiler. Also, check out the
object
The root class of the inheritance hierarchy -
std.openrj -
Basic database. -
std.outbuffer
Assemble data into an array of bytes diff --git a/phoboslicense.txt b/phoboslicense.txt deleted file mode 100644 index c75d03d2c..000000000 --- a/phoboslicense.txt +++ /dev/null @@ -1,31 +0,0 @@ -Unless otherwise marked within the file, each file in the source -to the Phobos library is under the following license: - -/* - * Copyright (C) 2004-2005 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. - */ - - -By plainly marking modifications, something along the lines of adding to each -file that has been changed a "Modified by Foo Bar" line -underneath the "Written by" line would be adequate. - diff --git a/std/__fileinit.d b/std/__fileinit.d index c7e889e6e..64c4fce20 100644 --- a/std/__fileinit.d +++ b/std/__fileinit.d @@ -1,13 +1,18 @@ -/* - * Placed in the Public Domain - * Written by Walter Bright +// Written in the D programming language. + +/** + * The only purpose of this module is to do the static construction for + * std.file, to eliminate cyclic construction errors. + * + * Copyright: Copyright Digital Mars 2008 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2008 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - -/* The only purpose of this module is to do the static construction - * for std.file, to eliminate cyclic construction errors. - */ - - module std.__fileinit; version (Win32) diff --git a/std/algorithm.d b/std/algorithm.d index d04dc33e9..6105d8345 100644 --- a/std/algorithm.d +++ b/std/algorithm.d @@ -7,9 +7,6 @@ those found in the $(D $(LESS)_algorithm$(GREATER)) header in $(WEB sgi.com/tech/stl/, Alexander Stepanov's Standard Template Library) for C++. -Author: -$(WEB erdani.org, Andrei Alexandrescu) - Note: Many functions in this module are parameterized with a function or a @@ -39,9 +36,18 @@ sort(a); // no predicate, "a < b" is implicit Macros: WIKI = Phobos/StdAlgorithm -*/ +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.algorithm; + import std.c.string; import std.array; import std.contracts; @@ -5771,25 +5777,3 @@ unittest //writeln(b[0]); assert(b[0] == tuple(4.0, 2u)); } - -/* - * Copyright (C) 2004-2006 by Digital Mars, www.digitalmars.com - * Written by Andrei Alexandrescu, www.erdani.org - * - * 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, 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. - */ diff --git a/std/array.d b/std/array.d index 199b6a3c7..fc9795870 100644 --- a/std/array.d +++ b/std/array.d @@ -1,5 +1,15 @@ -// Written in the D programming language +// Written in the D programming language. +/** +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.array; import std.c.stdio; @@ -820,25 +830,3 @@ unittest // s.length = 7; // assert(equal(s, [10, 10, 6, 5, 9, 0, 0][])); } - -/* - * Copyright (C) 2004-2009 by Digital Mars, www.digitalmars.com - * Written by Andrei Alexandrescu, www.erdani.org - * - * 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, 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. - */ diff --git a/std/atomics.d b/std/atomics.d index 3ab3ff226..0872309dc 100644 --- a/std/atomics.d +++ b/std/atomics.d @@ -1,13 +1,19 @@ -// Written in the D programming language -// Put in the public domain by Bartosz Milewski +// Written in the D programming language. /** Implements processor dependent parts of the atomics library. - -Author: Bartosz Milewski Macros: WIKI = Phobos/Atomics + +Copyright: Copyright Bartosz Milewski 2008 - 2009. +License: Boost License 1.0. +Authors: Bartosz Milewski + + Copyright Bartosz Milewski 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ version (D_InlineAsm_X86) @@ -65,11 +71,11 @@ asm { unittest { uint x = 1; - bool success = CAS(&x, 1, 2); - assert(success); - assert(x == 2); - - success = CAS(&x, 1, 3); - assert(!success); - assert(x == 2); + bool success = CAS(&x, 1, 2); + assert(success); + assert(x == 2); + + success = CAS(&x, 1, 3); + assert(!success); + assert(x == 2); } diff --git a/std/base64.d b/std/base64.d index 025cabcc1..842d4be0f 100644 --- a/std/base64.d +++ b/std/base64.d @@ -1,4 +1,4 @@ -// Written in the D programming language +// Written in the D programming language. /** * Encodes/decodes MIME base64 data. diff --git a/std/bigint.d b/std/bigint.d index 204d0da08..6e26140f6 100644 --- a/std/bigint.d +++ b/std/bigint.d @@ -34,18 +34,19 @@ Example: assert(i == e); ---------------------------------------------------- -Authors: Janice Caron - -Date: 2008.05.18 - -License: Public Domain - - Macros: WIKI=Phobos/StdBigint -*/ -module bigint; +Copyright: Copyright Janice Caron 2008 - 2009. +License: Boost License 1.0. +Authors: Janice Caron + + Copyright Janice Caron 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ +module std.bigint; import std.string : format; import std.stdio : writef, writefln; @@ -1591,7 +1592,7 @@ debug unittest auto z = makeBig( 0x00012345, 0x6789ABCD, 0xEFEDCBA9, 0x87654321 ); auto r = mul(x,y); assert(r.digits == z.digits, hex(r)); - // Bugzilla 2987 + // Bugzilla 2987 BigInt a = "871782912000"; BigInt b = "760005445655199744000000"; assert(a * a == b); diff --git a/std/bind.d b/std/bind.d index 5df99fb0b..5d8c80222 100644 --- a/std/bind.d +++ b/std/bind.d @@ -1,291 +1,295 @@ -// Written in the D programming language +// Written in the D programming language. /** * Bind function arguments to functions. * * References: - * $(LINK2 http://www.boost.org/libs/bind/bind.html, boost::bind) - * Authors: Tomasz Stachowiak - * Date: November 28, 2006 + * $(LINK2 http://www.boost.org/libs/bind/bind.html, boost::bind) * Macros: - * WIKI = Phobos/StdBind - * Copyright: - * Public Domain + * WIKI = Phobos/StdBind + * + * Copyright: Copyright Tomasz Stachowiak 2006 - 2009. + * License: Boost License 1.0. + * Authors: Tomasz Stachowiak + * + * Copyright Tomasz Stachowiak 2006 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ module std.bind; - import std.string : stdFormat = format; import std.traits; import std.typetuple; struct DynArg(int i) { - static assert (i >= 0); - - alias i argNr; + static assert (i >= 0); + + alias i argNr; } /** - When passed to the 'bind' function, they will mark dynamic params - ones that aren't statically bound - In boost, they're called __1, __2, __3, etc.. here __0, __1, __2, ... + When passed to the 'bind' function, they will mark dynamic params - ones that aren't statically bound + In boost, they're called __1, __2, __3, etc.. here __0, __1, __2, ... */ const DynArg!(0) _0; -const DynArg!(1) _1; /// ditto -const DynArg!(2) _2; /// ditto -const DynArg!(3) _3; /// ditto -const DynArg!(4) _4; /// ditto -const DynArg!(5) _5; /// ditto -const DynArg!(6) _6; /// ditto -const DynArg!(7) _7; /// ditto -const DynArg!(8) _8; /// ditto -const DynArg!(9) _9; /// ditto +const DynArg!(1) _1; /// ditto +const DynArg!(2) _2; /// ditto +const DynArg!(3) _3; /// ditto +const DynArg!(4) _4; /// ditto +const DynArg!(5) _5; /// ditto +const DynArg!(6) _6; /// ditto +const DynArg!(7) _7; /// ditto +const DynArg!(8) _8; /// ditto +const DynArg!(9) _9; /// ditto /* - Detect if a given type is a DynArg of any index + Detect if a given type is a DynArg of any index */ template isDynArg(T) { - static if (is(typeof(T.argNr))) { // must have the argNr field - static if(is(T : DynArg!(T.argNr))) { // now check the exact type - static const bool isDynArg = true; - } else static const bool isDynArg = false; - } else static const bool isDynArg = false; + static if (is(typeof(T.argNr))) { // must have the argNr field + static if(is(T : DynArg!(T.argNr))) { // now check the exact type + static const bool isDynArg = true; + } else static const bool isDynArg = false; + } else static const bool isDynArg = false; } /* - Detect if a given type is a DynArg of the specified index + Detect if a given type is a DynArg of the specified index */ template isDynArg(T, int i) { - static const bool isDynArg = is(T : DynArg!(i)); + static const bool isDynArg = is(T : DynArg!(i)); } /* - Converts a static array type to a dynamic array type + Converts a static array type to a dynamic array type */ template DynamicArrayType(T) { - alias typeof(T[0])[] DynamicArrayType; + alias typeof(T[0])[] DynamicArrayType; } /* - Assigns one entity to another. As static arrays don't like normal assignment, slice assignment is used for them. - - Params: - a = destination - b = source + Assigns one entity to another. As static arrays don't like normal assignment, slice assignment is used for them. + + Params: + a = destination + b = source */ template _assign(T) { - static if (isStaticArray!(T)) { - void _assign(DynamicArrayType!(T) a, DynamicArrayType!(T) b) { - a[] = b[]; - } - } else { - void _assign(inout T a, inout T b) { - a = b; - } - } + static if (isStaticArray!(T)) { + void _assign(DynamicArrayType!(T) a, DynamicArrayType!(T) b) { + a[] = b[]; + } + } else { + void _assign(inout T a, inout T b) { + a = b; + } + } } /* - Assigns and potentially converts one entity to another - - Normally, only implicit conversion is used, but when both operands are numeric types, an explicit cast is performed on them. - - Params: - T = destination type - a = destination - Y = source type - b = source - copyStaticArrays = when a static array is assigned to a dynamic one, it sometimes has to be .dup'ed as the storage may exist in volatile locations + Assigns and potentially converts one entity to another + + Normally, only implicit conversion is used, but when both operands are numeric types, an explicit cast is performed on them. + + Params: + T = destination type + a = destination + Y = source type + b = source + copyStaticArrays = when a static array is assigned to a dynamic one, it sometimes has to be .dup'ed as the storage may exist in volatile locations */ template _assign(T, Y, bool copyStaticArrays = true) { - static if (isStaticArray!(T)) { - - // if the destination is a static array, copy each element from the source to the destination by a foreach - void _assign(DynamicArrayType!(T) a, DynamicArrayType!(Y) b) { - foreach (i, x; b) { - _assign!(typeof(a[i]), typeof(x))(a[i], x); - } - } - } else static if (!isStaticArray!(T) && isStaticArray!(Y)) { - - // the destination is a dynamic array and the source is a static array. this sometimes needs a .dup - void _assign(inout T a, DynamicArrayType!(Y) b) { - static if (copyStaticArrays) { - a = b.dup; - } else { - a = b; - } - } - } else { - - // none of the items is a static array - void _assign(inout T a, inout Y b) { - static if (IndexOf!(T, NumericTypes.type) != -1 && IndexOf!(Y, NumericTypes.type) != -1) { - a = cast(T)b; - } else { - a = b; - } - } - } + static if (isStaticArray!(T)) { + + // if the destination is a static array, copy each element from the source to the destination by a foreach + void _assign(DynamicArrayType!(T) a, DynamicArrayType!(Y) b) { + foreach (i, x; b) { + _assign!(typeof(a[i]), typeof(x))(a[i], x); + } + } + } else static if (!isStaticArray!(T) && isStaticArray!(Y)) { + + // the destination is a dynamic array and the source is a static array. this sometimes needs a .dup + void _assign(inout T a, DynamicArrayType!(Y) b) { + static if (copyStaticArrays) { + a = b.dup; + } else { + a = b; + } + } + } else { + + // none of the items is a static array + void _assign(inout T a, inout Y b) { + static if (IndexOf!(T, NumericTypes.type) != -1 && IndexOf!(Y, NumericTypes.type) != -1) { + a = cast(T)b; + } else { + a = b; + } + } + } } /** - A simple tuple struct with some basic operations + A simple tuple struct with some basic operations */ struct Tuple(T ...) { - alias Tuple meta; - const bool expressionTuple = isExpressionTuple!(T); - - static if (!expressionTuple) { - alias T type; // a built-in tuple - T value; // a built-in tuple instance - } else { - alias T value; - } - - - const int length = value.length; - + alias Tuple meta; + const bool expressionTuple = isExpressionTuple!(T); + + static if (!expressionTuple) { + alias T type; // a built-in tuple + T value; // a built-in tuple instance + } else { + alias T value; + } + + + const int length = value.length; + - /** - Statically yields a tuple type with an extra element added at its end - */ - template appendT(X) { - alias .Tuple!(T, X) appendT; - } + /** + Statically yields a tuple type with an extra element added at its end + */ + template appendT(X) { + alias .Tuple!(T, X) appendT; + } - /** - Yields a tuple with an extra element added at its end - */ - appendT!(X) append(X)(X x) { - appendT!(X) res; - foreach (i, y; value) { - _assign!(typeof(y))(res.value[i], y); - } - _assign!(typeof(x))(res.value[$-1], x); - return res; - } - - - /** - Statically yields a tuple type with an extra element added at its beginning - */ - template prependT(X) { - alias .Tuple!(X, T) prependT; - } + /** + Yields a tuple with an extra element added at its end + */ + appendT!(X) append(X)(X x) { + appendT!(X) res; + foreach (i, y; value) { + _assign!(typeof(y))(res.value[i], y); + } + _assign!(typeof(x))(res.value[$-1], x); + return res; + } + + + /** + Statically yields a tuple type with an extra element added at its beginning + */ + template prependT(X) { + alias .Tuple!(X, T) prependT; + } - /** - Yields a tuple with an extra element added at its beginning - */ - prependT!(X) prepend(X)(X x) { - prependT!(X) res; - foreach (i, y; value) { - _assign!(typeof(y))(res.value[i+1], y); - } - _assign!(typeof(x))(res.value[0], x); - return res; - } - - - /** - Statically concatenates this tuple type with another tuple type - */ - template concatT(T ...) { - static if (expressionTuple) { - alias .Tuple!(value, T) concatT; - } else { - alias .Tuple!(type, T) concatT; - } - } - - - string toString() { - auto res = "(" ~ stdFormat(value[0]); - foreach (x; value[1..$]) { - res ~= stdFormat(", ", x); - } - return res ~ ")"; - } + /** + Yields a tuple with an extra element added at its beginning + */ + prependT!(X) prepend(X)(X x) { + prependT!(X) res; + foreach (i, y; value) { + _assign!(typeof(y))(res.value[i+1], y); + } + _assign!(typeof(x))(res.value[0], x); + return res; + } + + + /** + Statically concatenates this tuple type with another tuple type + */ + template concatT(T ...) { + static if (expressionTuple) { + alias .Tuple!(value, T) concatT; + } else { + alias .Tuple!(type, T) concatT; + } + } + + + string toString() { + auto res = "(" ~ stdFormat(value[0]); + foreach (x; value[1..$]) { + res ~= stdFormat(", ", x); + } + return res ~ ")"; + } } /** - An empty tuple struct + An empty tuple struct */ struct Tuple() { - alias Tuple meta; + alias Tuple meta; - template EmptyTuple_(T ...) { - alias T EmptyTuple_; - } - + template EmptyTuple_(T ...) { + alias T EmptyTuple_; + } + - alias EmptyTuple_!() type; /// an empty built-in tuple - alias EmptyTuple_!() value; /// an empty built-in tuple - - const bool expressionTuple = false; - const int length = 0; + alias EmptyTuple_!() type; /// an empty built-in tuple + alias EmptyTuple_!() value; /// an empty built-in tuple + + const bool expressionTuple = false; + const int length = 0; - template appendT(X) { - alias .Tuple!(X) appendT; - } - alias appendT prependT; + template appendT(X) { + alias .Tuple!(X) appendT; + } + alias appendT prependT; - appendT!(X) append(X)(X x) { - appendT!(X) res; - foreach (i, y; value) { - _assign!(typeof(y))(res.value[i], y); - } - return res; - } - alias append prepend; - - - // T - other tuple - template concatT(T ...) { - alias .Tuple!(T) concatT; - } - - - char[] toString() { - return "()"; - } + appendT!(X) append(X)(X x) { + appendT!(X) res; + foreach (i, y; value) { + _assign!(typeof(y))(res.value[i], y); + } + return res; + } + alias append prepend; + + + // T - other tuple + template concatT(T ...) { + alias .Tuple!(T) concatT; + } + + + char[] toString() { + return "()"; + } } /** - Dynamically create a tuple from the given items + Dynamically create a tuple from the given items */ Tuple!(T) tuple(T ...)(T t) { - Tuple!(T) res; - foreach (i, x; t) { - _assign!(typeof(x))(res.value[i], x); - } - return res; + Tuple!(T) res; + foreach (i, x; t) { + _assign!(typeof(x))(res.value[i], x); + } + return res; } /** - Checks whether a given type is the Tuple struct of any length + Checks whether a given type is the Tuple struct of any length */ template isTypeTuple(T) { - static if (is(T.type)) { - static if (is(T == Tuple!(T.type))) { - const bool isTypeTuple = true; - } else const bool isTypeTuple = false; - } else const bool isTypeTuple = false; + static if (is(T.type)) { + static if (is(T == Tuple!(T.type))) { + const bool isTypeTuple = true; + } else const bool isTypeTuple = false; + } else const bool isTypeTuple = false; } static assert(isTypeTuple!(Tuple!(int))); @@ -299,354 +303,354 @@ static assert(!isTypeTuple!(int)); template minNumArgs_impl(alias fn, fnT) { - alias ParameterTypeTuple!(fnT) Params; - Params params = void; - - template loop(int i = 0) { - static assert (i <= Params.length); - - static if (is(typeof(fn(params[0..i])))) { - const int res = i; - } else { - alias loop!(i+1).res res; - } - } - - alias loop!().res res; + alias ParameterTypeTuple!(fnT) Params; + Params params = void; + + template loop(int i = 0) { + static assert (i <= Params.length); + + static if (is(typeof(fn(params[0..i])))) { + const int res = i; + } else { + alias loop!(i+1).res res; + } + } + + alias loop!().res res; } /** - Finds the minimal number of arguments a given function needs to be provided + Finds the minimal number of arguments a given function needs to be provided */ template minNumArgs(alias fn, fnT = typeof(&fn)) { - const int minNumArgs = minNumArgs_impl!(fn, fnT).res; + const int minNumArgs = minNumArgs_impl!(fn, fnT).res; } // mixed into BoundFunc struct/class template MBoundFunc() { - // meta - alias FAlias_ FAlias; - alias FT FuncType; - alias AllBoundArgs_ AllBoundArgs; // all arguments given to bind() or bindAlias() - - static if (!is(typeof(FAlias) == EmptySlot)) { - alias Tuple!(ParameterTypeTuple!(FT)) RealFuncParams; // the parameters of the bound function - alias FuncReferenceParamsAsPointers!(FAlias) FuncParams; // references converted to pointers - } else { - alias Tuple!(ParameterTypeTuple!(FT)) FuncParams; // the parameters of the bound function - } - - alias ReturnType!(FT) RetType; // the return type of the bound function - alias ExtractedBoundArgs!(AllBoundArgs.type) BoundArgs; // 'saved' arguments. this includes nested/composed functions - - - // if bindAlias was used, we can detect default arguments and only demand the non-default arguments to be specified - static if (!is(typeof(FAlias) == EmptySlot)) { - const int minFuncArgs = minNumArgs!(FAlias); - - alias ParamsPassMethodTuple!(FAlias) ParamPassingMethods; // find out whether the function expects parameters by value or reference - } else { - const int minFuncArgs = FuncParams.length; - } - - // the parameters that our wrapper function must get - alias getDynArgTypes!(FuncParams, AllBoundArgs, minFuncArgs).res.type DynParams; - - // data - FuncType fp; - BoundArgs boundArgs; + // meta + alias FAlias_ FAlias; + alias FT FuncType; + alias AllBoundArgs_ AllBoundArgs; // all arguments given to bind() or bindAlias() + + static if (!is(typeof(FAlias) == EmptySlot)) { + alias Tuple!(ParameterTypeTuple!(FT)) RealFuncParams; // the parameters of the bound function + alias FuncReferenceParamsAsPointers!(FAlias) FuncParams; // references converted to pointers + } else { + alias Tuple!(ParameterTypeTuple!(FT)) FuncParams; // the parameters of the bound function + } + + alias ReturnType!(FT) RetType; // the return type of the bound function + alias ExtractedBoundArgs!(AllBoundArgs.type) BoundArgs; // 'saved' arguments. this includes nested/composed functions + + + // if bindAlias was used, we can detect default arguments and only demand the non-default arguments to be specified + static if (!is(typeof(FAlias) == EmptySlot)) { + const int minFuncArgs = minNumArgs!(FAlias); + + alias ParamsPassMethodTuple!(FAlias) ParamPassingMethods; // find out whether the function expects parameters by value or reference + } else { + const int minFuncArgs = FuncParams.length; + } + + // the parameters that our wrapper function must get + alias getDynArgTypes!(FuncParams, AllBoundArgs, minFuncArgs).res.type DynParams; + + // data + FuncType fp; + BoundArgs boundArgs; - // yields the number of bound-function parameters that are covered by the binding. takes tuple expansion into account - template numFuncArgsReallyBound(int argI = 0, int fargI = 0, int bargI = 0) { - - // walk though all of AllBoundArgs - static if (argI < AllBoundArgs.length) { - - // the argI-th arg is a composed/nested function - static if (isBoundFunc!(AllBoundArgs.type[argI])) { - alias DerefFunc!(AllBoundArgs.type[argI]).RetType FuncRetType; - const int argLen = getArgLen!(FuncParams.type[fargI], FuncRetType); - const int bargInc = 1; - } - - // the argI-th arg is a dynamic argument whose value we will get in the call to func() - else static if (isDynArg!(AllBoundArgs.type[argI])) { - const int argLen = getArgLen!(FuncParams.type[fargI], DynParams[AllBoundArgs.type[argI].argNr]); - const int bargInc = 0; - } - - // the argI-th arg is a statically bound argument - else { - const int argLen = getArgLen!(FuncParams.type[fargI], BoundArgs.type[bargI]); - const int bargInc = 1; - } - - // iterate - const int res = numFuncArgsReallyBound!(argI+1, fargI+argLen, bargI+bargInc).res; - } else { - // last iteration - - // the number of bound args is the number of arguments we've detected in this template loop - const int res = fargI; + // yields the number of bound-function parameters that are covered by the binding. takes tuple expansion into account + template numFuncArgsReallyBound(int argI = 0, int fargI = 0, int bargI = 0) { + + // walk though all of AllBoundArgs + static if (argI < AllBoundArgs.length) { + + // the argI-th arg is a composed/nested function + static if (isBoundFunc!(AllBoundArgs.type[argI])) { + alias DerefFunc!(AllBoundArgs.type[argI]).RetType FuncRetType; + const int argLen = getArgLen!(FuncParams.type[fargI], FuncRetType); + const int bargInc = 1; + } + + // the argI-th arg is a dynamic argument whose value we will get in the call to func() + else static if (isDynArg!(AllBoundArgs.type[argI])) { + const int argLen = getArgLen!(FuncParams.type[fargI], DynParams[AllBoundArgs.type[argI].argNr]); + const int bargInc = 0; + } + + // the argI-th arg is a statically bound argument + else { + const int argLen = getArgLen!(FuncParams.type[fargI], BoundArgs.type[bargI]); + const int bargInc = 1; + } + + // iterate + const int res = numFuncArgsReallyBound!(argI+1, fargI+argLen, bargI+bargInc).res; + } else { + // last iteration + + // the number of bound args is the number of arguments we've detected in this template loop + const int res = fargI; - // make sure we'll copy all args the function is going to need - static assert (res >= minFuncArgs); - } - } - - const int numSpecifiedParams = numFuncArgsReallyBound!().res; - - // it's a tuple type whose instance will be applied to the bound function - alias Tuple!(FuncParams.type[0 .. numSpecifiedParams]) SpecifiedParams; - + // make sure we'll copy all args the function is going to need + static assert (res >= minFuncArgs); + } + } + + const int numSpecifiedParams = numFuncArgsReallyBound!().res; + + // it's a tuple type whose instance will be applied to the bound function + alias Tuple!(FuncParams.type[0 .. numSpecifiedParams]) SpecifiedParams; + - // argI = indexes AllBoundArgs - // fargI = indexes funcArgs - // bargI = indexes boundArgs - void copyArgs(int argI = 0, int fargI = 0, int bargI = 0)(inout SpecifiedParams funcArgs, DynParams dynArgs) { - static if (argI < AllBoundArgs.length) { + // argI = indexes AllBoundArgs + // fargI = indexes funcArgs + // bargI = indexes boundArgs + void copyArgs(int argI = 0, int fargI = 0, int bargI = 0)(inout SpecifiedParams funcArgs, DynParams dynArgs) { + static if (argI < AllBoundArgs.length) { - // the argI-th arg is a composed/nested function - static if (isBoundFunc!(AllBoundArgs.type[argI])) { - alias DerefFunc!(AllBoundArgs.type[argI]).RetType FuncRetType; - alias DerefFunc!(AllBoundArgs.type[argI]).DynParams FuncDynParams; - - // if FuncDynParams contains an empty slot, e.g. as in the case bind(&f, bind(&g, _1), _0) - // then we cannot just apply the dynArgs tuple to the nested/composed function because it will have EmptySlot params - // while our dynArgs tuple will contain ordinary types - static if (ContainsEmptySlotType!(FuncDynParams)) { - - FuncDynParams funcParams; // we'll fill it with values in a bit - - foreach (i, dummy_; dynArgs) { - static if (!is(typeof(FuncDynParams[i] == EmptySlot))) { - - // 3rd param is false because there is no need to .dup static arrays just for the function below this foreach - // the storage exists in the whole copyArgs function - // dynArgs[i] is used instead of dummy_ so that loop-local data isn't referenced in any dynamic arrays after the loop - _assign!(typeof(funcParams[i]), typeof(dummy_), false)(funcParams[i], dynArgs[i]); - } - } - - FuncRetType funcRet = boundArgs.value[bargI].func(funcParams); - } else { - FuncRetType funcRet = boundArgs.value[bargI].func(dynArgs[0..FuncDynParams.length]); // only give it as many dynParams as it needs - } - - // we'll take data from the returned value - auto srcItem = &funcRet; - - const int bargInc = 1; // nested/composed functions belong to the boundArgs tuple - const bool dupStaticArrays = true; // because the function's return value is stored locally - } + // the argI-th arg is a composed/nested function + static if (isBoundFunc!(AllBoundArgs.type[argI])) { + alias DerefFunc!(AllBoundArgs.type[argI]).RetType FuncRetType; + alias DerefFunc!(AllBoundArgs.type[argI]).DynParams FuncDynParams; + + // if FuncDynParams contains an empty slot, e.g. as in the case bind(&f, bind(&g, _1), _0) + // then we cannot just apply the dynArgs tuple to the nested/composed function because it will have EmptySlot params + // while our dynArgs tuple will contain ordinary types + static if (ContainsEmptySlotType!(FuncDynParams)) { + + FuncDynParams funcParams; // we'll fill it with values in a bit + + foreach (i, dummy_; dynArgs) { + static if (!is(typeof(FuncDynParams[i] == EmptySlot))) { + + // 3rd param is false because there is no need to .dup static arrays just for the function below this foreach + // the storage exists in the whole copyArgs function + // dynArgs[i] is used instead of dummy_ so that loop-local data isn't referenced in any dynamic arrays after the loop + _assign!(typeof(funcParams[i]), typeof(dummy_), false)(funcParams[i], dynArgs[i]); + } + } + + FuncRetType funcRet = boundArgs.value[bargI].func(funcParams); + } else { + FuncRetType funcRet = boundArgs.value[bargI].func(dynArgs[0..FuncDynParams.length]); // only give it as many dynParams as it needs + } + + // we'll take data from the returned value + auto srcItem = &funcRet; + + const int bargInc = 1; // nested/composed functions belong to the boundArgs tuple + const bool dupStaticArrays = true; // because the function's return value is stored locally + } - // the argI-th arg is a dynamic argument whose value we will get in the call to func() - else static if (isDynArg!(AllBoundArgs.type[argI])) { - - // we'll take data from dynArgs - auto srcItem = &dynArgs[AllBoundArgs.type[argI].argNr]; - - const int bargInc = 0; // dynamic args don't belond to the boundArgs tuple - const bool dupStaticArrays = true; // because we get dynArgs on stack - } - - // the argI-th arg is a statically bound argument - else { - - // we'll take data directly from boundArgs - auto srcItem = &boundArgs.value[bargI]; - - const int bargInc = 1; // statically bound args belong to the boundArgs tuple - const bool dupStaticArrays = false; // because the storage exists in boundArgs - } + // the argI-th arg is a dynamic argument whose value we will get in the call to func() + else static if (isDynArg!(AllBoundArgs.type[argI])) { + + // we'll take data from dynArgs + auto srcItem = &dynArgs[AllBoundArgs.type[argI].argNr]; + + const int bargInc = 0; // dynamic args don't belond to the boundArgs tuple + const bool dupStaticArrays = true; // because we get dynArgs on stack + } + + // the argI-th arg is a statically bound argument + else { + + // we'll take data directly from boundArgs + auto srcItem = &boundArgs.value[bargI]; + + const int bargInc = 1; // statically bound args belong to the boundArgs tuple + const bool dupStaticArrays = false; // because the storage exists in boundArgs + } - // the number of bound-function parameters this argument will cover after tuple expansion - const int argLen = getArgLen!(funcArgs.type[fargI], typeof(*srcItem)); + // the number of bound-function parameters this argument will cover after tuple expansion + const int argLen = getArgLen!(funcArgs.type[fargI], typeof(*srcItem)); - static if (isTypeTuple!(typeof(*srcItem)) && !isTypeTuple!(funcArgs.type[fargI])) { - foreach (i, x; srcItem.value) { - _assign!(funcArgs.type[fargI + i], typeof(x), dupStaticArrays)(funcArgs.value[fargI + i], x); - } - } else { - static assert (1 == argLen); - _assign!(funcArgs.type[fargI], typeof(*srcItem), dupStaticArrays)(funcArgs.value[fargI], *srcItem); - } + static if (isTypeTuple!(typeof(*srcItem)) && !isTypeTuple!(funcArgs.type[fargI])) { + foreach (i, x; srcItem.value) { + _assign!(funcArgs.type[fargI + i], typeof(x), dupStaticArrays)(funcArgs.value[fargI + i], x); + } + } else { + static assert (1 == argLen); + _assign!(funcArgs.type[fargI], typeof(*srcItem), dupStaticArrays)(funcArgs.value[fargI], *srcItem); + } - // because we might've just expended a tuple, this may be larger than one - static assert (argLen >= 1); - - // we could've just used a dynamic arg (0) or a statically bound arg(1) - static assert (bargInc == 0 || bargInc == 1); - - - return copyArgs!(argI+1, fargI+argLen, bargI+bargInc)(funcArgs, dynArgs); - } else { - // last iteration - - // make sure we've copied all args the function will need - static assert (fargI >= minFuncArgs); - } - } + // because we might've just expended a tuple, this may be larger than one + static assert (argLen >= 1); + + // we could've just used a dynamic arg (0) or a statically bound arg(1) + static assert (bargInc == 0 || bargInc == 1); + + + return copyArgs!(argI+1, fargI+argLen, bargI+bargInc)(funcArgs, dynArgs); + } else { + // last iteration + + // make sure we've copied all args the function will need + static assert (fargI >= minFuncArgs); + } + } - static if (SpecifiedParams.length > 0) { - /// The final wrapped function - RetType func(DynParams dynArgs) { - SpecifiedParams funcArgs; - copyArgs!()(funcArgs, dynArgs); - - // if the function expects any parameters passed by reference, we'll have to use the ptrApply template - // and convert pointers back to references by hand - static if (!is(typeof(FAlias) == EmptySlot) && IndexOf!(PassByRef, ParamPassingMethods.type) != -1) { - - // function parameter type pointers (int, float*, inout char) -> (int*, float*, char*) - PointerTuple!(Tuple!(RealFuncParams.type[0 .. SpecifiedParams.length])) ptrs; - - // initialize the 'ptrs' tuple instance - foreach (i, dummy_; funcArgs.value) { - static if (is(ParamPassingMethods.type[i] == PassByRef)) { - - version (BindNoNullCheck) {} - else { - assert (funcArgs.value[i], "references cannot be null"); - } - - ptrs.value[i] = funcArgs.value[i]; - } else { - ptrs.value[i] = &funcArgs.value[i]; - } - } - - // and call the function :) - ptrApply!(RetType, FuncType, ptrs.type)(fp, ptrs.value); - } else { - - // ordinary call-by-tuple - return fp(funcArgs.value); - } - } - } else { - /// The final wrapped function - RetType func() { - return fp(); - } - } - - /// The final wrapped function - alias func call; - - - /// The final wrapped function - alias func opCall; - - - /** - The type of the delegate that may be returned from this object - */ - template PtrType() { - alias typeof(&(new BoundFunc).call) PtrType; - } - - /** - Get a delegate. Equivalent to getting it thru &foo.call - */ - PtrType!() ptr() { - return &this.func; - } + static if (SpecifiedParams.length > 0) { + /// The final wrapped function + RetType func(DynParams dynArgs) { + SpecifiedParams funcArgs; + copyArgs!()(funcArgs, dynArgs); + + // if the function expects any parameters passed by reference, we'll have to use the ptrApply template + // and convert pointers back to references by hand + static if (!is(typeof(FAlias) == EmptySlot) && IndexOf!(PassByRef, ParamPassingMethods.type) != -1) { + + // function parameter type pointers (int, float*, inout char) -> (int*, float*, char*) + PointerTuple!(Tuple!(RealFuncParams.type[0 .. SpecifiedParams.length])) ptrs; + + // initialize the 'ptrs' tuple instance + foreach (i, dummy_; funcArgs.value) { + static if (is(ParamPassingMethods.type[i] == PassByRef)) { + + version (BindNoNullCheck) {} + else { + assert (funcArgs.value[i], "references cannot be null"); + } + + ptrs.value[i] = funcArgs.value[i]; + } else { + ptrs.value[i] = &funcArgs.value[i]; + } + } + + // and call the function :) + ptrApply!(RetType, FuncType, ptrs.type)(fp, ptrs.value); + } else { + + // ordinary call-by-tuple + return fp(funcArgs.value); + } + } + } else { + /// The final wrapped function + RetType func() { + return fp(); + } + } + + /// The final wrapped function + alias func call; + + + /// The final wrapped function + alias func opCall; + + + /** + The type of the delegate that may be returned from this object + */ + template PtrType() { + alias typeof(&(new BoundFunc).call) PtrType; + } + + /** + Get a delegate. Equivalent to getting it thru &foo.call + */ + PtrType!() ptr() { + return &this.func; + } } version (BindUseStruct) { - template DerefFunc(T) { - alias typeof(*T) DerefFunc; - } + template DerefFunc(T) { + alias typeof(*T) DerefFunc; + } - /** - A context for bound/curried functions - */ - struct BoundFunc(FT, alias FAlias_, AllBoundArgs_) { - mixin MBoundFunc; - } + /** + A context for bound/curried functions + */ + struct BoundFunc(FT, alias FAlias_, AllBoundArgs_) { + mixin MBoundFunc; + } } else { - template DerefFunc(T) { - alias T DerefFunc; - } + template DerefFunc(T) { + alias T DerefFunc; + } - /** - A context for bound/curried functions - */ - class BoundFunc(FT, alias FAlias_, AllBoundArgs_) { - mixin MBoundFunc; - } + /** + A context for bound/curried functions + */ + class BoundFunc(FT, alias FAlias_, AllBoundArgs_) { + mixin MBoundFunc; + } } /** - bind() can curry or "bind" arguments of a function, producing a different function which requires less parameters, - or a different order of parameters. It also allows function composition. - - The syntax of a bind() call is: - - bind(function or delegate pointer { , argument }); - - argument can be one of: - - - The result is a function object, which can be called using call(), func() or opCall(). - There also exists a convenience function, ptr() which returns a delegate to call/func/opCall - - The resulting delegate accepts exactly as many parameters as many distinct dynamic arguments were used. + bind() can curry or "bind" arguments of a function, producing a different function which requires less parameters, + or a different order of parameters. It also allows function composition. + + The syntax of a bind() call is: + + bind(function or delegate pointer { , argument }); + + argument can be one of: + + + The result is a function object, which can be called using call(), func() or opCall(). + There also exists a convenience function, ptr() which returns a delegate to call/func/opCall + + The resulting delegate accepts exactly as many parameters as many distinct dynamic arguments were used. --- - bind(&foo, _0, _1) // will yield a delegate accepting two parameters - bind(&foo, _1, _0) // will yield a delegate accepting two parameters - bind(&bar, _0, _1, _2, _0) // will yield a delegate accepting three parameters --- - -
-
- The types of dynamic parameters are extracted from the bound function itself and when necessary, type negotiation - is performed. For example, binding a function + +
+
+ The types of dynamic parameters are extracted from the bound function itself and when necessary, type negotiation + is performed. For example, binding a function --- void foo(int a, long b) // with: bind(&foo, _0, _0) --- - will result in a delegate accepting a single, optimal parameter type. The best type is computed - using std.typetuple.DerivedToFront, so in case of an int and a long, long will be selected. Generally, bind will try to find - a type that can be implicitly converted to all the other types a given dynamic parameter uses. - Note: in case of numeric types, an explicit, but transparent (to the user) cast will be performed - -
- Function composition works intuitively: + will result in a delegate accepting a single, optimal parameter type. The best type is computed + using std.typetuple.DerivedToFront, so in case of an int and a long, long will be selected. Generally, bind will try to find + a type that can be implicitly converted to all the other types a given dynamic parameter uses. + Note: in case of numeric types, an explicit, but transparent (to the user) cast will be performed + +
+ Function composition works intuitively: --- bind(&f1, bind(&f2, _0)) --- - - which will yield a delegate, that takes the argument, calls f2, then uses the return value of f2 to call f1. Mathematically - speaking, it will yield a function composition: + + which will yield a delegate, that takes the argument, calls f2, then uses the return value of f2 to call f1. Mathematically + speaking, it will yield a function composition: --- f1(f2(_0)) --- - - When one function is composed multiple times, it will be called multiple times - Bind does no lazy evaluation, so + + When one function is composed multiple times, it will be called multiple times - Bind does no lazy evaluation, so --- bind(&f3, bind(&f4, _0), bind(&f4, _0)) --- - will produce a delegate, which, upon calling, will invoke f4 two times to evaluate the arguments for f3 and then call f3 - - - One another feature that bind() supports is automatic tuple expansion. It means that having functions: + will produce a delegate, which, upon calling, will invoke f4 two times to evaluate the arguments for f3 and then call f3 + + + One another feature that bind() supports is automatic tuple expansion. It means that having functions: --- void foo(int a, int b) Tuple!(int, int) bar() --- - - Allows them to be bound by writing: + + Allows them to be bound by writing: --- bind(&foo, bind(&bar)) // or @@ -654,45 +658,45 @@ bind(&foo, tuple(23, 45)) --- */ typeof(new BoundFunc!(FT, NullAlias, Tuple!(ArgList))) bind(FT, ArgList...)(FT fp, ArgList args) { - auto res = new DerefFunc!(ReturnType!(bind)); - res.fp = fp; - extractBoundArgs!(0, 0, ArgList)(res.boundArgs, args); - return res; + auto res = new DerefFunc!(ReturnType!(bind)); + res.fp = fp; + extractBoundArgs!(0, 0, ArgList)(res.boundArgs, args); + return res; } /** - bindAlias() is similar to bind(), but it's more powerful. Use bindAlias() rather than bind() where possible.
+ bindAlias() is similar to bind(), but it's more powerful. Use bindAlias() rather than bind() where possible.
- The syntax is: - - bindAlias!(Function)(argument, argument, argument, argument, ...); - - bindAlias takes advantage of using aliases directly, thus being able to extract default values from functions and not forcing the user - to bind them. It doesn't, however mean that the resulting delegate can be called, omitting some of its parameters. It only means that these - arguments that have default values in the function provided to bindAlias don't have to be bound explicitly. - - Additionally, bindAlias takes care of functions with out/inout parameters, by converting them to pointers internally. A function like: + The syntax is: + + bindAlias!(Function)(argument, argument, argument, argument, ...); + + bindAlias takes advantage of using aliases directly, thus being able to extract default values from functions and not forcing the user + to bind them. It doesn't, however mean that the resulting delegate can be called, omitting some of its parameters. It only means that these + arguments that have default values in the function provided to bindAlias don't have to be bound explicitly. + + Additionally, bindAlias takes care of functions with out/inout parameters, by converting them to pointers internally. A function like: --- void foo(inout a) ---- - can be bound using: +--- + can be bound using: --- int x; bindAlias!(foo)(&x); --- - - Note: there is no bind-time check for reference nullness, there is however a call-time check on all references which can be disabled - by using version=BindNoNullCheck or compiling in release mode. + + Note: there is no bind-time check for reference nullness, there is however a call-time check on all references which can be disabled + by using version=BindNoNullCheck or compiling in release mode. */ template bindAlias(alias FT) { - typeof(new BoundFunc!(typeof(&FT), FT, Tuple!(ArgList))) bindAlias(ArgList...)(ArgList args) { - auto res = new DerefFunc!(ReturnType!(bindAlias)); - res.fp = &FT; - extractBoundArgs!(0, 0, ArgList)(res.boundArgs, args); - return res; - } + typeof(new BoundFunc!(typeof(&FT), FT, Tuple!(ArgList))) bindAlias(ArgList...)(ArgList args) { + auto res = new DerefFunc!(ReturnType!(bindAlias)); + res.fp = &FT; + extractBoundArgs!(0, 0, ArgList)(res.boundArgs, args); + return res; + } } @@ -700,18 +704,18 @@ template bindAlias(alias FT) { /* - Tells whether the specified type is a bound function + Tells whether the specified type is a bound function */ template isBoundFunc(T) { - static if (is(DerefFunc!(T).FuncType)) { - static if (is(DerefFunc!(T).BoundArgs)) { - static if (is(typeof(DerefFunc!(T).FAlias))) { - static if (is(DerefFunc!(T) : BoundFunc!(DerefFunc!(T).FuncType, DerefFunc!(T).FAlias, DerefFunc!(T).AllBoundArgs))) { - static const bool isBoundFunc = true; - } else static const bool isBoundFunc = false; - } else static const bool isBoundFunc = false; - } else static const bool isBoundFunc = false; - } else static const bool isBoundFunc = false; + static if (is(DerefFunc!(T).FuncType)) { + static if (is(DerefFunc!(T).BoundArgs)) { + static if (is(typeof(DerefFunc!(T).FAlias))) { + static if (is(DerefFunc!(T) : BoundFunc!(DerefFunc!(T).FuncType, DerefFunc!(T).FAlias, DerefFunc!(T).AllBoundArgs))) { + static const bool isBoundFunc = true; + } else static const bool isBoundFunc = false; + } else static const bool isBoundFunc = false; + } else static const bool isBoundFunc = false; + } else static const bool isBoundFunc = false; } @@ -721,216 +725,216 @@ alias Tuple!(byte, ubyte, short, ushort, int, uint, long, ulong, /+cent, ucent, /* - Gather all types that a given (i-th) dynamic arg uses. - The types will be inserted into a tuple + Gather all types that a given (i-th) dynamic arg uses. + The types will be inserted into a tuple */ template dynArgTypes(int i, FuncParams, BoundArgs, int minParamsLeft) { - - // performs slicing on the tuple ... tuple[i .. length] - template sliceOffTuple(T, int i) { - alias Tuple!(T.type[i..length]) res; - } - - // prepends a T to the resulting tuple - // SkipType - the type in BoundArgs that we're just processing - template prependType(T, SkipType) { - static if (isTypeTuple!(SkipType) && !isTypeTuple!(FuncParams.type[0])) { - // perform tuple decomposition - // e.g. if a function being bound is accepting (int, int) and the current type is a Tuple!(int, int), - // then skip just one tuple in the bound args and the length of the tuple in func args - // - skips two ints and one tuple in the example - alias dynArgTypes!( - i, - sliceOffTuple!(FuncParams, SkipType.length).res, - Tuple!(BoundArgs.type[1..$]), - minParamsLeft - SkipType.length - ).res tmp; - - } else { - // just advance by one type - alias dynArgTypes!( - i, - sliceOffTuple!(FuncParams, 1).res, - Tuple!(BoundArgs.type[1..$]), - minParamsLeft-1 - ).res tmp; - } - - static if (is(T == void)) { // void means that we aren't adding anything - alias tmp res; - } else { - alias tmp.meta.prependT!(T) res; - } - } - - // iteration end detector - static if (is(BoundArgs == Tuple!())) { - static assert (minParamsLeft <= 0, "there are still unbound function parameters"); - alias Tuple!() res; - } - else { - - // w00t, detected a regular dynamic arg - static if (isDynArg!(BoundArgs.type[0], i)) { - alias prependType!(FuncParams.type[0], BoundArgs.type[0]).res res; - } - - // the arg is a bound function, extract info from it. we will be evaluating it later - else static if (isBoundFunc!(BoundArgs.type[0])) { - alias DerefFunc!(BoundArgs.type[0]) BoundFunc; // the bound function is a struct pointer, we have to derefernce its type - - // does that function even have any dynamic params ? - static if (BoundFunc.DynParams.length > i) { - alias prependType!(BoundFunc.DynParams[i], BoundFunc.RetType).res res; - } - // it doesn't - else { - alias prependType!(void, BoundFunc.RetType).res res; - } - } - - // a static arg, just skip it since we want to find all types a given DynArg uses. static args <> dyn args - else alias prependType!(void, BoundArgs.type[0]).res res; - } + + // performs slicing on the tuple ... tuple[i .. length] + template sliceOffTuple(T, int i) { + alias Tuple!(T.type[i..length]) res; + } + + // prepends a T to the resulting tuple + // SkipType - the type in BoundArgs that we're just processing + template prependType(T, SkipType) { + static if (isTypeTuple!(SkipType) && !isTypeTuple!(FuncParams.type[0])) { + // perform tuple decomposition + // e.g. if a function being bound is accepting (int, int) and the current type is a Tuple!(int, int), + // then skip just one tuple in the bound args and the length of the tuple in func args + // - skips two ints and one tuple in the example + alias dynArgTypes!( + i, + sliceOffTuple!(FuncParams, SkipType.length).res, + Tuple!(BoundArgs.type[1..$]), + minParamsLeft - SkipType.length + ).res tmp; + + } else { + // just advance by one type + alias dynArgTypes!( + i, + sliceOffTuple!(FuncParams, 1).res, + Tuple!(BoundArgs.type[1..$]), + minParamsLeft-1 + ).res tmp; + } + + static if (is(T == void)) { // void means that we aren't adding anything + alias tmp res; + } else { + alias tmp.meta.prependT!(T) res; + } + } + + // iteration end detector + static if (is(BoundArgs == Tuple!())) { + static assert (minParamsLeft <= 0, "there are still unbound function parameters"); + alias Tuple!() res; + } + else { + + // w00t, detected a regular dynamic arg + static if (isDynArg!(BoundArgs.type[0], i)) { + alias prependType!(FuncParams.type[0], BoundArgs.type[0]).res res; + } + + // the arg is a bound function, extract info from it. we will be evaluating it later + else static if (isBoundFunc!(BoundArgs.type[0])) { + alias DerefFunc!(BoundArgs.type[0]) BoundFunc; // the bound function is a struct pointer, we have to derefernce its type + + // does that function even have any dynamic params ? + static if (BoundFunc.DynParams.length > i) { + alias prependType!(BoundFunc.DynParams[i], BoundFunc.RetType).res res; + } + // it doesn't + else { + alias prependType!(void, BoundFunc.RetType).res res; + } + } + + // a static arg, just skip it since we want to find all types a given DynArg uses. static args <> dyn args + else alias prependType!(void, BoundArgs.type[0]).res res; + } } // just a simple util private template maxInt(int a, int b) { - static if (a > b) static const int maxInt = a; - else static const int maxInt = b; + static if (a > b) static const int maxInt = a; + else static const int maxInt = b; } /* - Given a list of BoundArgs, it returns the nuber of args that should be specified dynamically + Given a list of BoundArgs, it returns the nuber of args that should be specified dynamically */ template numDynArgs(BoundArgs) { - static if (BoundArgs.length == 0) { - // received an EmptyTuple - static const int res = 0; - } else { - // ordinary dynamic arg - static if (isDynArg!(BoundArgs.type[0])) { - static const int res = maxInt!(BoundArgs.type[0].argNr+1, numDynArgs!(Tuple!(BoundArgs.type[1..$])).res); - } - - // count the args in nested / composed functions - else static if (isBoundFunc!(BoundArgs.type[0])) { - static const int res = maxInt!(DerefFunc!(BoundArgs.type[0]).DynParams.length, numDynArgs!(Tuple!(BoundArgs.type[1..$])).res); - } - - // statically bound arg, skip it - else { - static const int res = numDynArgs!(Tuple!(BoundArgs.type[1..$])).res; - } - } + static if (BoundArgs.length == 0) { + // received an EmptyTuple + static const int res = 0; + } else { + // ordinary dynamic arg + static if (isDynArg!(BoundArgs.type[0])) { + static const int res = maxInt!(BoundArgs.type[0].argNr+1, numDynArgs!(Tuple!(BoundArgs.type[1..$])).res); + } + + // count the args in nested / composed functions + else static if (isBoundFunc!(BoundArgs.type[0])) { + static const int res = maxInt!(DerefFunc!(BoundArgs.type[0]).DynParams.length, numDynArgs!(Tuple!(BoundArgs.type[1..$])).res); + } + + // statically bound arg, skip it + else { + static const int res = numDynArgs!(Tuple!(BoundArgs.type[1..$])).res; + } + } } /* - Used internally to mark a parameter which is a dummy placeholder - E.g. when using bind(&f, bind(&g, _1), _0), then the inner bound function will use an EmptySlot for its 0-th parameter + Used internally to mark a parameter which is a dummy placeholder + E.g. when using bind(&f, bind(&g, _1), _0), then the inner bound function will use an EmptySlot for its 0-th parameter */ struct EmptySlot { - string toString( ) { - return "_"; - } + string toString( ) { + return "_"; + } } /* - Get a tuple of all dynamic args a function binding will need - take nested/composed functions as well as tuple decomposition into account + Get a tuple of all dynamic args a function binding will need + take nested/composed functions as well as tuple decomposition into account */ template getDynArgTypes(FuncParams, BoundArgs, int minFuncArgs) { - template loop(int i) { - static if (i < numDynArgs!(BoundArgs).res) { - alias dynArgTypes!(i, FuncParams, BoundArgs, minFuncArgs).res.type dirtyArgTypeList; - - // 'clean' the type list, erasing all NoTypes from it that could've been added there from composed functions - // if the arg is not used, we'll mark it as NoType anyway, but for now, we only want 'real' types so the most derived one can be found - alias Tuple!(EraseAll!(EmptySlot, dirtyArgTypeList)) argTypeList; - - - // make sure the arg is used - static if(!is(argTypeList == Tuple!())) { - alias DerivedToFront!(argTypeList.type)[0] argType; - } else { - //static assert(false, i); - alias EmptySlot argType; - } + template loop(int i) { + static if (i < numDynArgs!(BoundArgs).res) { + alias dynArgTypes!(i, FuncParams, BoundArgs, minFuncArgs).res.type dirtyArgTypeList; + + // 'clean' the type list, erasing all NoTypes from it that could've been added there from composed functions + // if the arg is not used, we'll mark it as NoType anyway, but for now, we only want 'real' types so the most derived one can be found + alias Tuple!(EraseAll!(EmptySlot, dirtyArgTypeList)) argTypeList; + + + // make sure the arg is used + static if(!is(argTypeList == Tuple!())) { + alias DerivedToFront!(argTypeList.type)[0] argType; + } else { + //static assert(false, i); + alias EmptySlot argType; + } - alias loop!(i+1).res.meta.prependT!(argType) res; - } else { - alias Tuple!() res; - } - } - - alias loop!(0).res res; + alias loop!(i+1).res.meta.prependT!(argType) res; + } else { + alias Tuple!() res; + } + } + + alias loop!(0).res res; } /* - Given a tuple that bind() was called with, it will detect which types need to be stored in a BoundFunc object + Given a tuple that bind() was called with, it will detect which types need to be stored in a BoundFunc object */ template ExtractedBoundArgs(BoundArgs ...) { - static if (BoundArgs.length == 0) { - alias Tuple!() ExtractedBoundArgs; - } - - // we'll store all non-dynamic arguments... - else static if (!isDynArg!(BoundArgs[0])) { - alias ExtractedBoundArgs!(BoundArgs[1..$]).meta.prependT!(BoundArgs[0]) ExtractedBoundArgs; - } - - // ... and we're going to leave the dynamic ones for later - else { - alias ExtractedBoundArgs!(BoundArgs[1..$]) ExtractedBoundArgs; - } + static if (BoundArgs.length == 0) { + alias Tuple!() ExtractedBoundArgs; + } + + // we'll store all non-dynamic arguments... + else static if (!isDynArg!(BoundArgs[0])) { + alias ExtractedBoundArgs!(BoundArgs[1..$]).meta.prependT!(BoundArgs[0]) ExtractedBoundArgs; + } + + // ... and we're going to leave the dynamic ones for later + else { + alias ExtractedBoundArgs!(BoundArgs[1..$]) ExtractedBoundArgs; + } } /* - Given a tuple that bind() was called with, it will copy all data that a BoundFunc object will store into an ExtractedBoundArgs tuple + Given a tuple that bind() was called with, it will copy all data that a BoundFunc object will store into an ExtractedBoundArgs tuple */ void extractBoundArgs(int dst, int src, BoundArgs ...)(inout ExtractedBoundArgs!(BoundArgs) result, BoundArgs boundArgs) { - static if (dst < result.length) { - // again, we only want non-dynamic arguments here - static if (!isDynArg!(BoundArgs[src])) { - _assign!(typeof(result.value[dst]), typeof(boundArgs[src]))(result.value[dst], boundArgs[src]); - return extractBoundArgs!(dst+1, src+1, BoundArgs)(result, boundArgs); - } - - // the dynamic ones will be specified at the time BoundFunc.call() is invoked - else { - return extractBoundArgs!(dst, src+1, BoundArgs)(result, boundArgs); - } - } + static if (dst < result.length) { + // again, we only want non-dynamic arguments here + static if (!isDynArg!(BoundArgs[src])) { + _assign!(typeof(result.value[dst]), typeof(boundArgs[src]))(result.value[dst], boundArgs[src]); + return extractBoundArgs!(dst+1, src+1, BoundArgs)(result, boundArgs); + } + + // the dynamic ones will be specified at the time BoundFunc.call() is invoked + else { + return extractBoundArgs!(dst, src+1, BoundArgs)(result, boundArgs); + } + } } /* - Number of args in the bound function that this Src arg will cover + Number of args in the bound function that this Src arg will cover */ template getArgLen(Dst, Src) { - // if the arg is a tuple and the target isn't one, it will be expanded/decomposed to the tuple's length - static if (isTypeTuple!(Src) && !isTypeTuple!(Dst)) { - static const int getArgLen = Src.length; - } - - // plain arg - it will use 1:1 mapping of functioni params to bound params - else { - static const int getArgLen = 1; - } + // if the arg is a tuple and the target isn't one, it will be expanded/decomposed to the tuple's length + static if (isTypeTuple!(Src) && !isTypeTuple!(Dst)) { + static const int getArgLen = Src.length; + } + + // plain arg - it will use 1:1 mapping of functioni params to bound params + else { + static const int getArgLen = 1; + } } /* - Tell whether a parameter type tuple contains an EmptySlot struct + Tell whether a parameter type tuple contains an EmptySlot struct */ template ContainsEmptySlotType(ParamList ...) { - const bool ContainsEmptySlotType = -1 != IndexOf!(EmptySlot, ParamList); + const bool ContainsEmptySlotType = -1 != IndexOf!(EmptySlot, ParamList); } @@ -940,112 +944,112 @@ const EmptySlot NullAlias; -struct PassByCopy {} -struct PassByRef {} +struct PassByCopy {} +struct PassByRef {} template ParamsPassMethodTuple_impl(alias Func, int i = 0) { - alias Tuple!(ParameterTypeTuple!(typeof(&Func))) Params; - - static if (Params.length == i) { - alias Tuple!() res; - } else { - Params params = void; - const params.type[i] constParam; - - // if the function expects references, it won't like our const. - static if (is(typeof(Func(params.value[0..i], constParam, params.value[i+1..$])))) { - alias ParamsPassMethodTuple_impl!(Func, i+1).res.meta.prependT!(PassByCopy) res; - } else { - alias ParamsPassMethodTuple_impl!(Func, i+1).res.meta.prependT!(PassByRef) res; - } - } + alias Tuple!(ParameterTypeTuple!(typeof(&Func))) Params; + + static if (Params.length == i) { + alias Tuple!() res; + } else { + Params params = void; + const params.type[i] constParam; + + // if the function expects references, it won't like our const. + static if (is(typeof(Func(params.value[0..i], constParam, params.value[i+1..$])))) { + alias ParamsPassMethodTuple_impl!(Func, i+1).res.meta.prependT!(PassByCopy) res; + } else { + alias ParamsPassMethodTuple_impl!(Func, i+1).res.meta.prependT!(PassByRef) res; + } + } } /* - Detect parameter passing methods: PassByCopy or PassByRef[erence] + Detect parameter passing methods: PassByCopy or PassByRef[erence] */ template ParamsPassMethodTuple(alias Func) { - alias ParamsPassMethodTuple_impl!(Func).res ParamsPassMethodTuple; + alias ParamsPassMethodTuple_impl!(Func).res ParamsPassMethodTuple; } template FuncReferenceParamsAsPointers_impl(alias Func) { - alias Tuple!(ParameterTypeTuple!(typeof(&Func))) Params; - alias ParamsPassMethodTuple!(Func) PassMethods; - - template loop(int i) { - static if (i == Params.length) { - alias Tuple!() res; - } else { - static if (is(PassMethods.type[i] == PassByRef)) { - alias Params.type[i]* type; - } else { - alias Params.type[i] type; - } - - alias loop!(i+1).res.meta.prependT!(type) res; - } - } - - alias loop!(0).res res; + alias Tuple!(ParameterTypeTuple!(typeof(&Func))) Params; + alias ParamsPassMethodTuple!(Func) PassMethods; + + template loop(int i) { + static if (i == Params.length) { + alias Tuple!() res; + } else { + static if (is(PassMethods.type[i] == PassByRef)) { + alias Params.type[i]* type; + } else { + alias Params.type[i] type; + } + + alias loop!(i+1).res.meta.prependT!(type) res; + } + } + + alias loop!(0).res res; } /* - Takes a function/delegate alias and converts its refence parameters to pointers. E.g. - - void function(int, inout char, float*) -> (int, char*, float*) + Takes a function/delegate alias and converts its refence parameters to pointers. E.g. + + void function(int, inout char, float*) -> (int, char*, float*) */ template FuncReferenceParamsAsPointers(alias Func) { - alias FuncReferenceParamsAsPointers_impl!(Func).res FuncReferenceParamsAsPointers; + alias FuncReferenceParamsAsPointers_impl!(Func).res FuncReferenceParamsAsPointers; } /* - Converts a tuple of types to a tuple containing pointer types of the original types + Converts a tuple of types to a tuple containing pointer types of the original types */ template PointerTuple(T) { - static if (T.length > 0) { - alias PointerTuple!(Tuple!(T.type[1..$])).meta.prependT!(T.type[0]*) PointerTuple; - } else { - alias Tuple!() PointerTuple; - } + static if (T.length > 0) { + alias PointerTuple!(Tuple!(T.type[1..$])).meta.prependT!(T.type[0]*) PointerTuple; + } else { + alias Tuple!() PointerTuple; + } } /* - Calls a function, dereferencing a pointer tuple for each argument + Calls a function, dereferencing a pointer tuple for each argument */ RetType ptrApply(RetType, FN, T ...)(FN fn, T t) { - static if (1 == T.length) { - return fn(*t[0]); - } - else static if (2 == T.length) { - return fn(*t[0], *t[1]); - } - else static if (3 == T.length) { - return fn(*t[0], *t[1], *t[2]); - } - else static if (4 == T.length) { - return fn(*t[0], *t[1], *t[2], *t[3]); - } - else static if (5 == T.length) { - return fn(*t[0], *t[1], *t[2], *t[3], *t[4]); - } - else static if (6 == T.length) { - return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5]); - } - else static if (7 == T.length) { - return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5], *t[6]); - } - else static if (8 == T.length) { - return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5], *t[6], *t[7]); - } - else static if (9 == T.length) { - return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5], *t[6], *t[7], *t[8]); - } - else static if (10 == T.length) { - return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5], *t[6], *t[7], *t[8], *t[9]); - } + static if (1 == T.length) { + return fn(*t[0]); + } + else static if (2 == T.length) { + return fn(*t[0], *t[1]); + } + else static if (3 == T.length) { + return fn(*t[0], *t[1], *t[2]); + } + else static if (4 == T.length) { + return fn(*t[0], *t[1], *t[2], *t[3]); + } + else static if (5 == T.length) { + return fn(*t[0], *t[1], *t[2], *t[3], *t[4]); + } + else static if (6 == T.length) { + return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5]); + } + else static if (7 == T.length) { + return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5], *t[6]); + } + else static if (8 == T.length) { + return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5], *t[6], *t[7]); + } + else static if (9 == T.length) { + return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5], *t[6], *t[7], *t[8]); + } + else static if (10 == T.length) { + return fn(*t[0], *t[1], *t[2], *t[3], *t[4], *t[5], *t[6], *t[7], *t[8], *t[9]); + } } diff --git a/std/bitmanip.d b/std/bitmanip.d index 4c5ef7e46..4d2c8c477 100644 --- a/std/bitmanip.d +++ b/std/bitmanip.d @@ -1,17 +1,22 @@ -// Written in the D programming language +// Written in the D programming language. /** Bit-level manipulation facilities. - -Authors: - -$(WEB digitalmars.com, Walter Bright), $(WEB erdani.org, Andrei -Alexandrescu) Macros: -WIKI = StdBitarray -*/ +WIKI = StdBitarray + +Copyright: Copyright Digital Mars 2007 - 2009. +License: Boost License 1.0. +Authors: $(WEB digitalmars.com, Walter Bright), + $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Digital Mars 2007 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.bitmanip; //debug = bitarray; // uncomment to turn on debugging printf's diff --git a/std/boxer.d b/std/boxer.d index 9b91e5319..66be327a6 100644 --- a/std/boxer.d +++ b/std/boxer.d @@ -1,4 +1,4 @@ -// Written in the D programming language +// Written in the D programming language. /** * This module is a set of types and functions for converting any object (value @@ -56,19 +56,23 @@ a = boxArray(arg_types, arg_data); * simply call "boxArray(_arguments, _argptr)", then do whatever you need to do * with the array. * - * Authors: - * Burton Radons - * License: - * Public Domain * Bugs: - * $(UL - * $(LI $(BUGZILLA 309)) - * $(LI $(BUGZILLA 1968)) - * ) + * $(UL + * $(LI $(BUGZILLA 309)) + * $(LI $(BUGZILLA 1968)) + * ) * Macros: - * WIKI=Phobos/StdBoxer + * WIKI=Phobos/StdBoxer + * + * Copyright: Copyright Burton Radons 2007 - 2009. + * License: Boost License 1.0. + * Authors: Burton Radons + * + * Copyright Burton Radons 2007 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.boxer; private import std.format; @@ -135,7 +139,7 @@ private bool isArrayTypeInfo(TypeInfo type) private enum TypeClass { Bool, /**< bool */ - Bit = Bool, // for backwards compatibility + Bit = Bool, // for backwards compatibility Integer, /**< byte, ubyte, short, ushort, int, uint, long, ulong */ Float, /**< float, double, real */ Complex, /**< cfloat, cdouble, creal */ @@ -498,7 +502,7 @@ void boxArrayToArguments(Box[] arguments, out TypeInfo[] types, out void* data) */ class UnboxException : Exception { - Box object; /// This is the box that the user attempted to unbox. + Box object; /// This is the box that the user attempted to unbox. TypeInfo outputType; /// This is the type that the user attempted to unbox the value as. diff --git a/std/compiler.d b/std/compiler.d index 9e6a9e85d..22c5e6621 100644 --- a/std/compiler.d +++ b/std/compiler.d @@ -1,17 +1,20 @@ -// Written in the D programming language - -/** - * Macros: - * WIKI = Phobos/StdCompiler - */ +// Written in the D programming language. /** * Identify the compiler used and its various features. - * Authors: Walter Bright, www.digitalmars.com - * License: Public Domain + * + * Macros: + * WIKI = Phobos/StdCompiler + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - - module std.compiler; const @@ -22,7 +25,7 @@ const /// Master list of D compiler vendors. enum Vendor { - DigitalMars = 1, /// Digital Mars + DigitalMars = 1, /// Digital Mars } /// Which vendor produced this compiler. @@ -34,7 +37,7 @@ const * version_major.version_minor */ uint version_major = __VERSION__ / 1000; - uint version_minor = __VERSION__ % 1000; /// ditto + uint version_minor = __VERSION__ % 1000; /// ditto /** diff --git a/std/complex.d b/std/complex.d index 57c7cea15..4a38af5d0 100644 --- a/std/complex.d +++ b/std/complex.d @@ -4,11 +4,15 @@ Module that will replace the built-in types $(D cfloat), $(D cdouble), $(D creal), $(D ifloat), $(D idouble), and $(D ireal). -Author: -$(WEB erdani.org, Andrei Alexandrescu) -
-*/ +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu) + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.complex; import std.conv, std.math, std.stdio; diff --git a/std/contracts.d b/std/contracts.d index 8235c833a..386161410 100644 --- a/std/contracts.d +++ b/std/contracts.d @@ -5,7 +5,7 @@ * predicates (a la $(D_PARAM assert)). * * Macros: - * WIKI = Phobos/StdContracts + * WIKI = Phobos/StdContracts * * Synopsis: * @@ -27,16 +27,18 @@ * } * ---- * - * Author: + * Copyright: Copyright Andrei Alexandrescu 2008 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB erdani.org, Andrei Alexandrescu) + * Credits: Brad Roberts came up with the name $(D_PARAM contracts). * - * $(WEB erdani.org, Andrei Alexandrescu) - * - * Credits: - * - * Brad Roberts came up with the name $(D_PARAM contracts). + * Copyright Andrei Alexandrescu 2008 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.contracts; + import std.array, std.c.string, std.conv, std.range, std.string, std.traits; import core.stdc.errno; version(unittest) @@ -439,7 +441,7 @@ unittest */ class ErrnoException : Exception { - uint errno; // operating system error code + uint errno; // operating system error code this(string msg, string file = null, uint line = 0) { errno = getErrno; diff --git a/std/conv.d b/std/conv.d index 2e500103f..4017b4ebc 100644 --- a/std/conv.d +++ b/std/conv.d @@ -1,13 +1,19 @@ // Written in the D programming language. + /** A one-stop shop for converting values from one type to another. -Authors: +Copyright: Copyright Digital Mars 2007 - 2009. +License: Boost License 1.0. +Authors: $(WEB digitalmars.com, Walter Bright), + $(WEB erdani.org, Andrei Alexandrescu), + Shin Fujishiro -$(WEB digitalmars.com, Walter Bright), $(WEB erdani.org, Andrei -Alexandrescu), Shin Fujishiro + Copyright Digital Mars 2007 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - module std.conv; import core.memory, core.stdc.errno, core.stdc.string, core.stdc.stdlib, @@ -15,7 +21,7 @@ import core.memory, core.stdc.errno, core.stdc.string, core.stdc.stdlib, std.ctype, std.math, std.range, std.stdio, std.string, std.traits, std.typecons, std.typetuple, std.utf; -//debug=conv; // uncomment to turn on debugging printf's +//debug=conv; // uncomment to turn on debugging printf's /* ************* Exceptions *************** */ @@ -1093,7 +1099,7 @@ if (isSomeString!Source && isFloatingPoint!Target) //writefln("toFloat('%s')", s); auto sz = toStringz(to!(const char[])(s)); if (std.ctype.isspace(*sz)) - goto Lerr; + goto Lerr; // issue 1589 version (Windows) @@ -1269,36 +1275,36 @@ unittest invariant string[] errors = [ - "", - "-", - "+", - "-+", - " ", - " 0", - "0 ", - "- 0", - "1-", - "xx", - "123h", - "2147483648", - "-2147483649", - "5656566565", + "", + "-", + "+", + "-+", + " ", + " 0", + "0 ", + "- 0", + "1-", + "xx", + "123h", + "2147483648", + "-2147483649", + "5656566565", ]; for (int j = 0; j < errors.length; j++) { - i = 47; - try - { - i = to!int(errors[j]); - //printf("i = %d\n", i); - } - catch (Error e) - { - debug(conv) e.print(); - i = 3; - } - assert(i == 3); + i = 47; + try + { + i = to!int(errors[j]); + //printf("i = %d\n", i); + } + catch (Error e) + { + debug(conv) e.print(); + i = 3; + } + assert(i == 3); } } @@ -1332,36 +1338,36 @@ unittest static string[] errors = [ - "", - "-", - "+", - "-+", - " ", - " 0", - "0 ", - "- 0", - "1-", - "+5", - "-78", - "xx", - "123h", - "4294967296", + "", + "-", + "+", + "-+", + " ", + " 0", + "0 ", + "- 0", + "1-", + "+5", + "-78", + "xx", + "123h", + "4294967296", ]; for (int j = 0; j < errors.length; j++) { - i = 47; - try - { - i = to!uint(errors[j]); - //printf("i = %d\n", i); - } - catch (Error e) - { - debug(conv) e.print(); - i = 3; - } - assert(i == 3); + i = 47; + try + { + i = to!uint(errors[j]); + //printf("i = %d\n", i); + } + catch (Error e) + { + debug(conv) e.print(); + i = 3; + } + assert(i == 3); } } @@ -1407,35 +1413,35 @@ unittest static string[] errors = [ - "", - "-", - "+", - "-+", - " ", - " 0", - "0 ", - "- 0", - "1-", - "xx", - "123h", - "9223372036854775808", - "-9223372036854775809", + "", + "-", + "+", + "-+", + " ", + " 0", + "0 ", + "- 0", + "1-", + "xx", + "123h", + "9223372036854775808", + "-9223372036854775809", ]; for (int j = 0; j < errors.length; j++) { - i = 47; - try - { - i = to!long(errors[j]); - //printf("l = %d\n", i); - } - catch (Error e) - { - debug(conv) e.print(); - i = 3; - } - assert(i == 3); + i = 47; + try + { + i = to!long(errors[j]); + //printf("l = %d\n", i); + } + catch (Error e) + { + debug(conv) e.print(); + i = 3; + } + assert(i == 3); } } @@ -1477,36 +1483,36 @@ unittest static string[] errors = [ - "", - "-", - "+", - "-+", - " ", - " 0", - "0 ", - "- 0", - "1-", - "+5", - "-78", - "xx", - "123h", - "18446744073709551616", + "", + "-", + "+", + "-+", + " ", + " 0", + "0 ", + "- 0", + "1-", + "+5", + "-78", + "xx", + "123h", + "18446744073709551616", ]; for (int j = 0; j < errors.length; j++) { - i = 47; - try - { - i = to!ulong(errors[j]); - //printf("i = %d\n", i); - } - catch (Error e) - { - debug(conv) e.print(); - i = 3; - } - assert(i == 3); + i = 47; + try + { + i = to!ulong(errors[j]); + //printf("i = %d\n", i); + } + catch (Error e) + { + debug(conv) e.print(); + i = 3; + } + assert(i == 3); } } @@ -1546,35 +1552,35 @@ unittest static string[] errors = [ - "", - "-", - "+", - "-+", - " ", - " 0", - "0 ", - "- 0", - "1-", - "xx", - "123h", - "32768", - "-32769", + "", + "-", + "+", + "-+", + " ", + " 0", + "0 ", + "- 0", + "1-", + "xx", + "123h", + "32768", + "-32769", ]; for (int j = 0; j < errors.length; j++) { - i = 47; - try - { - i = to!short(errors[j]); - printf("i = %d\n", i); - } - catch (Error e) - { - debug(conv) e.print(); - i = 3; - } - assert(i == 3); + i = 47; + try + { + i = to!short(errors[j]); + printf("i = %d\n", i); + } + catch (Error e) + { + debug(conv) e.print(); + i = 3; + } + assert(i == 3); } } @@ -1609,36 +1615,36 @@ unittest static string[] errors = [ - "", - "-", - "+", - "-+", - " ", - " 0", - "0 ", - "- 0", - "1-", - "+5", - "-78", - "xx", - "123h", - "65536", + "", + "-", + "+", + "-+", + " ", + " 0", + "0 ", + "- 0", + "1-", + "+5", + "-78", + "xx", + "123h", + "65536", ]; for (int j = 0; j < errors.length; j++) { - i = 47; - try - { - i = to!ushort(errors[j]); - printf("i = %d\n", i); - } - catch (Error e) - { - debug(conv) e.print(); - i = 3; - } - assert(i == 3); + i = 47; + try + { + i = to!ushort(errors[j]); + printf("i = %d\n", i); + } + catch (Error e) + { + debug(conv) e.print(); + i = 3; + } + assert(i == 3); } } @@ -1679,35 +1685,35 @@ unittest static string[] errors = [ - "", - "-", - "+", - "-+", - " ", - " 0", - "0 ", - "- 0", - "1-", - "xx", - "123h", - "128", - "-129", + "", + "-", + "+", + "-+", + " ", + " 0", + "0 ", + "- 0", + "1-", + "xx", + "123h", + "128", + "-129", ]; for (int j = 0; j < errors.length; j++) { - i = 47; - try - { - i = to!byte(errors[j]); - printf("i = %d\n", i); - } - catch (Error e) - { - debug(conv) e.print(); - i = 3; - } - assert(i == 3); + i = 47; + try + { + i = to!byte(errors[j]); + printf("i = %d\n", i); + } + catch (Error e) + { + debug(conv) e.print(); + i = 3; + } + assert(i == 3); } } @@ -1742,36 +1748,36 @@ unittest static string[] errors = [ - "", - "-", - "+", - "-+", - " ", - " 0", - "0 ", - "- 0", - "1-", - "+5", - "-78", - "xx", - "123h", - "256", + "", + "-", + "+", + "-+", + " ", + " 0", + "0 ", + "- 0", + "1-", + "+5", + "-78", + "xx", + "123h", + "256", ]; for (int j = 0; j < errors.length; j++) { - i = 47; - try - { - i = to!ubyte(errors[j]); - printf("i = %d\n", i); - } - catch (Error e) - { - debug(conv) e.print(); - i = 3; - } - assert(i == 3); + i = 47; + try + { + i = to!ubyte(errors[j]); + printf("i = %d\n", i); + } + catch (Error e) + { + debug(conv) e.print(); + i = 3; + } + assert(i == 3); } } @@ -1783,7 +1789,7 @@ unittest // //writefln("toFloat('%s')", s); // auto sz = toStringz(to!(const char[])(s)); // if (std.ctype.isspace(*sz)) -// goto Lerr; +// goto Lerr; // // issue 1589 // version (Windows) @@ -1859,11 +1865,11 @@ unittest bool ok = false; try { - to!float("\x00"); + to!float("\x00"); } catch (ConvError e) { - ok = true; + ok = true; } assert(ok); } @@ -1910,11 +1916,11 @@ unittest bool ok = false; try { - to!double("\x00"); + to!double("\x00"); } catch (ConvError e) { - ok = true; + ok = true; } assert(ok); } @@ -1965,11 +1971,11 @@ unittest bool ok = false; try { - to!real("\x00"); + to!real("\x00"); } catch (ConvError e) { - ok = true; + ok = true; } assert(ok); } @@ -3024,28 +3030,3 @@ unittest auto t = parse!Testing(s); assert(t == cast(Testing) 123); } - -/* - * Copyright (C) 2002-2007 by Digital Mars, www.digitalmars.com - * Written by Walter Bright - * Some parts contributed by David L. Davis - * Major rewrite by Andrei Alexandrescu - * - * 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, 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. - */ - diff --git a/std/cpuid.d b/std/cpuid.d index 796ab2395..671ad2400 100644 --- a/std/cpuid.d +++ b/std/cpuid.d @@ -1,4 +1,4 @@ -// Written in the D programming language +// Written in the D programming language. /** * Identify the characteristics of the host CPU. @@ -6,13 +6,13 @@ * Implemented according to: - AP-485 Intel(C) Processor Identification and the CPUID Instruction - $(LINK http://www.intel.com/design/xeon/applnots/241618.htm) + $(LINK http://www.intel.com/design/xeon/applnots/241618.htm) - Intel(R) 64 and IA-32 Architectures Software Developer's Manual, Volume 2A: Instruction Set Reference, A-M - $(LINK http://developer.intel.com/design/pentium4/manuals/index_new.htm) + $(LINK http://developer.intel.com/design/pentium4/manuals/index_new.htm) - AMD CPUID Specification Publication # 25481 - $(LINK http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25481.pdf) + $(LINK http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25481.pdf) Example: --- @@ -25,17 +25,20 @@ void main() } --- -AUTHORS: Tomas Lindquist Olsen <tomas@famolsen.dk> - (slightly altered by Walter Bright) -COPYRIGHT: Public Domain +BUGS: Only works on x86 CPUs - * BUGS: Only works on x86 CPUs - * - * Macros: - * WIKI = Phobos/StdCpuid - * COPYRIGHT = Public Domain +Macros: + WIKI = Phobos/StdCpuid + +Copyright: Copyright Tomas Lindquist Olsen 2007 - 2009. +License: Boost License 1.0. +Authors: Tomas Lindquist Olsen <tomas@famolsen.dk> + + Copyright Tomas Lindquist Olsen 2007 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - module std.cpuid; import std.string; @@ -46,166 +49,166 @@ version(D_InlineAsm_X86) /// Returns everything as a printable string string toString() { - string feats; - if (mmx) feats ~= "MMX "; - if (fxsr) feats ~= "FXSR "; - if (sse) feats ~= "SSE "; - if (sse2) feats ~= "SSE2 "; - if (sse3) feats ~= "SSE3 "; - if (ssse3) feats ~= "SSSE3 "; - if (amd3dnow) feats ~= "3DNow! "; - if (amd3dnowExt) feats ~= "3DNow!+ "; - if (amdMmx) feats ~= "MMX+ "; - if (ia64) feats ~= "IA-64 "; - if (amd64) feats ~= "AMD64 "; - if (hyperThreading) feats ~= "HTT"; + string feats; + if (mmx) feats ~= "MMX "; + if (fxsr) feats ~= "FXSR "; + if (sse) feats ~= "SSE "; + if (sse2) feats ~= "SSE2 "; + if (sse3) feats ~= "SSE3 "; + if (ssse3) feats ~= "SSSE3 "; + if (amd3dnow) feats ~= "3DNow! "; + if (amd3dnowExt) feats ~= "3DNow!+ "; + if (amdMmx) feats ~= "MMX+ "; + if (ia64) feats ~= "IA-64 "; + if (amd64) feats ~= "AMD64 "; + if (hyperThreading) feats ~= "HTT"; - return format( - "Vendor string: %s\n", vendor, - "Processor string: %s\n", processor, - "Signature: Family=%d Model=%d Stepping=%d\n", family, model, stepping, - "Features: %s\n", feats, - "Multithreading: %d threads / %d cores\n", threadsPerCPU, coresPerCPU); + return format( + "Vendor string: %s\n", vendor, + "Processor string: %s\n", processor, + "Signature: Family=%d Model=%d Stepping=%d\n", family, model, stepping, + "Features: %s\n", feats, + "Multithreading: %d threads / %d cores\n", threadsPerCPU, coresPerCPU); } /// Returns vendor string - string vendor() {return vendorStr.idup;} // todo: optimize + string vendor() {return vendorStr.idup;} // todo: optimize /// Returns processor string - string processor() {return processorStr;} + string processor() {return processorStr;} /// Is MMX supported? - bool mmx() {return (flags&MMX_BIT)!=0;} + bool mmx() {return (flags&MMX_BIT)!=0;} /// Is FXSR supported? - bool fxsr() {return (flags&FXSR_BIT)!=0;} + bool fxsr() {return (flags&FXSR_BIT)!=0;} /// Is SSE supported? - bool sse() {return (flags&SSE_BIT)!=0;} + bool sse() {return (flags&SSE_BIT)!=0;} /// Is SSE2 supported? - bool sse2() {return (flags&SSE2_BIT)!=0;} + bool sse2() {return (flags&SSE2_BIT)!=0;} /// Is SSE3 supported? - bool sse3() {return (misc&SSE3_BIT)!=0;} + bool sse3() {return (misc&SSE3_BIT)!=0;} /// Is SSSE3 supported? - bool ssse3() {return (misc&SSSE3_BIT)!=0;} + bool ssse3() {return (misc&SSSE3_BIT)!=0;} /// Is AMD 3DNOW supported? - bool amd3dnow() {return (exflags&AMD_3DNOW_BIT)!=0;} + bool amd3dnow() {return (exflags&AMD_3DNOW_BIT)!=0;} /// Is AMD 3DNOW Ext supported? - bool amd3dnowExt() {return (exflags&AMD_3DNOW_EXT_BIT)!=0;} + bool amd3dnowExt() {return (exflags&AMD_3DNOW_EXT_BIT)!=0;} /// Is AMD MMX supported? - bool amdMmx() {return (exflags&AMD_MMX_BIT)!=0;} + bool amdMmx() {return (exflags&AMD_MMX_BIT)!=0;} /// Is this an Intel Architecture IA64? - bool ia64() {return (flags&IA64_BIT)!=0;} + bool ia64() {return (flags&IA64_BIT)!=0;} /// Is this an AMD 64? - bool amd64() {return (exflags&AMD64_BIT)!=0;} + bool amd64() {return (exflags&AMD64_BIT)!=0;} /// Is hyperthreading supported? - bool hyperThreading() {return (flags&HTT_BIT)!=0;} + bool hyperThreading() {return (flags&HTT_BIT)!=0;} /// Returns number of threads per CPU - uint threadsPerCPU() {return maxThreads;} + uint threadsPerCPU() {return maxThreads;} /// Returns number of cores in CPU - uint coresPerCPU() {return maxCores;} + uint coresPerCPU() {return maxCores;} /// Is this an Intel processor? - bool intel() {return manufac==INTEL;} + bool intel() {return manufac==INTEL;} /// Is this an AMD processor? - bool amd() {return manufac==AMD;} + bool amd() {return manufac==AMD;} /// Returns stepping - uint stepping() {return _stepping;} + uint stepping() {return _stepping;} /// Returns model - uint model() {return _model;} + uint model() {return _model;} /// Returns family - uint family() {return _family;} - //uint processorType() {return (signature>>>12)&0x3;} + uint family() {return _family;} + //uint processorType() {return (signature>>>12)&0x3;} static this() { - getVendorString(); - getProcessorString(); - getFeatureFlags(); + getVendorString(); + getProcessorString(); + getFeatureFlags(); - // stepping / family / model - _stepping = signature&0xF; - uint fbase = (signature>>>8)&0xF; - uint fex = (signature>>>20)&0xFF; - uint mbase = (signature>>>4)&0xF; - uint mex = (signature>>>16)&0xF; + // stepping / family / model + _stepping = signature&0xF; + uint fbase = (signature>>>8)&0xF; + uint fex = (signature>>>20)&0xFF; + uint mbase = (signature>>>4)&0xF; + uint mex = (signature>>>16)&0xF; - // vendor specific - void function() threadFn; - switch(vendorStr) - { - case "GenuineIntel": - manufac = INTEL; - threadFn = &getThreadingIntel; - if (fbase == 0xF) - _family = fbase+fex; - else - _family = fbase; - if (_family == 0x6 || _family == 0xF) - _model = mbase+(mex<<4); - else - _model = mbase; - break; + // vendor specific + void function() threadFn; + switch(vendorStr) + { + case "GenuineIntel": + manufac = INTEL; + threadFn = &getThreadingIntel; + if (fbase == 0xF) + _family = fbase+fex; + else + _family = fbase; + if (_family == 0x6 || _family == 0xF) + _model = mbase+(mex<<4); + else + _model = mbase; + break; - case "AuthenticAMD": - manufac = AMD; - threadFn = &getThreadingAMD; - if (fbase < 0xF) - { - _family = fbase; - _model = mbase; - } - else - { - _family = fbase+fex; - _model = mbase+(mex<<4); - } - break; + case "AuthenticAMD": + manufac = AMD; + threadFn = &getThreadingAMD; + if (fbase < 0xF) + { + _family = fbase; + _model = mbase; + } + else + { + _family = fbase+fex; + _model = mbase+(mex<<4); + } + break; - default: - manufac = OTHER; - } + default: + manufac = OTHER; + } - // threading details - if (hyperThreading && threadFn !is null) - { - threadFn(); - } + // threading details + if (hyperThreading && threadFn !is null) + { + threadFn(); + } } private: // feature flags enum : uint { - MMX_BIT = 1<<23, - FXSR_BIT = 1<<24, - SSE_BIT = 1<<25, - SSE2_BIT = 1<<26, - HTT_BIT = 1<<28, - IA64_BIT = 1<<30 + MMX_BIT = 1<<23, + FXSR_BIT = 1<<24, + SSE_BIT = 1<<25, + SSE2_BIT = 1<<26, + HTT_BIT = 1<<28, + IA64_BIT = 1<<30 } // feature flags misc enum : uint { - SSE3_BIT = 1, - SSSE3_BIT = 1<<9 + SSE3_BIT = 1, + SSSE3_BIT = 1<<9 } // extended feature flags enum : uint { - AMD_MMX_BIT = 1<<22, - AMD64_BIT = 1<<29, - AMD_3DNOW_EXT_BIT = 1<<30, - AMD_3DNOW_BIT = 1<<31 + AMD_MMX_BIT = 1<<22, + AMD64_BIT = 1<<29, + AMD_3DNOW_EXT_BIT = 1<<30, + AMD_3DNOW_BIT = 1<<31 } // manufacturer enum { - OTHER, - INTEL, - AMD + OTHER, + INTEL, + AMD } __gshared @@ -226,180 +229,180 @@ private: */ private void getVendorString() { - char* dst = vendorStr.ptr; - // puts the vendor string into dst - asm - { - mov EAX, 0 ; - cpuid ; - mov EAX, dst ; - mov [EAX], EBX ; - mov [EAX+4], EDX ; - mov [EAX+8], ECX ; - } + char* dst = vendorStr.ptr; + // puts the vendor string into dst + asm + { + mov EAX, 0 ; + cpuid ; + mov EAX, dst ; + mov [EAX], EBX ; + mov [EAX+4], EDX ; + mov [EAX+8], ECX ; + } } private void getProcessorString() { - char[48] buffer; - char* dst = buffer.ptr; - // puts the processor string into dst - asm - { - mov EAX, 0x8000_0000 ; - cpuid ; - cmp EAX, 0x8000_0004 ; - jb PSLabel ; // no support - push EDI ; - mov EDI, dst ; - mov EAX, 0x8000_0002 ; - cpuid ; - mov [EDI], EAX ; - mov [EDI+4], EBX ; - mov [EDI+8], ECX ; - mov [EDI+12], EDX ; - mov EAX, 0x8000_0003 ; - cpuid ; - mov [EDI+16], EAX ; - mov [EDI+20], EBX ; - mov [EDI+24], ECX ; - mov [EDI+28], EDX ; - mov EAX, 0x8000_0004 ; - cpuid ; - mov [EDI+32], EAX ; - mov [EDI+36], EBX ; - mov [EDI+40], ECX ; - mov [EDI+44], EDX ; - pop EDI ; - PSLabel: ; - } + char[48] buffer; + char* dst = buffer.ptr; + // puts the processor string into dst + asm + { + mov EAX, 0x8000_0000 ; + cpuid ; + cmp EAX, 0x8000_0004 ; + jb PSLabel ; // no support + push EDI ; + mov EDI, dst ; + mov EAX, 0x8000_0002 ; + cpuid ; + mov [EDI], EAX ; + mov [EDI+4], EBX ; + mov [EDI+8], ECX ; + mov [EDI+12], EDX ; + mov EAX, 0x8000_0003 ; + cpuid ; + mov [EDI+16], EAX ; + mov [EDI+20], EBX ; + mov [EDI+24], ECX ; + mov [EDI+28], EDX ; + mov EAX, 0x8000_0004 ; + cpuid ; + mov [EDI+32], EAX ; + mov [EDI+36], EBX ; + mov [EDI+40], ECX ; + mov [EDI+44], EDX ; + pop EDI ; + PSLabel: ; + } - if (buffer[0] == char.init) // no support - return; + if (buffer[0] == char.init) // no support + return; - // seems many intel processors prepend whitespace - processorStr = std.string.strip(to!string(dst)).idup; + // seems many intel processors prepend whitespace + processorStr = std.string.strip(to!string(dst)).idup; } private void getFeatureFlags() { - uint f,m,e,a,s; - asm - { - mov EAX, 0 ; - cpuid ; - cmp EAX, 1 ; - jb FeatLabel ; // no support - mov EAX, 1 ; - cpuid ; - mov f, EDX ; - mov m, ECX ; - mov a, EBX ; - mov s, EAX ; + uint f,m,e,a,s; + asm + { + mov EAX, 0 ; + cpuid ; + cmp EAX, 1 ; + jb FeatLabel ; // no support + mov EAX, 1 ; + cpuid ; + mov f, EDX ; + mov m, ECX ; + mov a, EBX ; + mov s, EAX ; - FeatLabel: ; - mov EAX, 0x8000_0000 ; - cpuid ; - cmp EAX, 0x8000_0001 ; - jb FeatLabel2 ; // no support - mov EAX, 0x8000_0001 ; - cpuid ; - mov e, EDX ; + FeatLabel: ; + mov EAX, 0x8000_0000 ; + cpuid ; + cmp EAX, 0x8000_0001 ; + jb FeatLabel2 ; // no support + mov EAX, 0x8000_0001 ; + cpuid ; + mov e, EDX ; - FeatLabel2: - ; - } - flags = f; - misc = m; - exflags = e; - apic = a; - signature = s; + FeatLabel2: + ; + } + flags = f; + misc = m; + exflags = e; + apic = a; + signature = s; } private void getThreadingIntel() { - uint n; - ubyte b = 0; - asm - { - mov EAX, 0 ; - cpuid ; - cmp EAX, 4 ; - jb IntelSingle ; - mov EAX, 4 ; - mov ECX, 0 ; - cpuid ; - mov n, EAX ; - mov b, 1 ; - IntelSingle: ; - } - if (b != 0) - { - maxCores = ((n>>>26)&0x3F)+1; - maxThreads = (apic>>>16)&0xFF; - } - else - { - maxCores = maxThreads = 1; - } + uint n; + ubyte b = 0; + asm + { + mov EAX, 0 ; + cpuid ; + cmp EAX, 4 ; + jb IntelSingle ; + mov EAX, 4 ; + mov ECX, 0 ; + cpuid ; + mov n, EAX ; + mov b, 1 ; + IntelSingle: ; + } + if (b != 0) + { + maxCores = ((n>>>26)&0x3F)+1; + maxThreads = (apic>>>16)&0xFF; + } + else + { + maxCores = maxThreads = 1; + } } private void getThreadingAMD() { - ubyte n; - ubyte b = 0; - asm - { - mov EAX, 0x8000_0000 ; - cpuid ; - cmp EAX, 0x8000_0008 ; - jb AMDSingle ; - mov EAX, 0x8000_0008 ; - cpuid ; - mov n, CL ; - mov b, 1 ; - AMDSingle: ; - } - if (b != 0) - { - maxCores = n+1; - maxThreads = (apic>>>16)&0xFF; - } - else - { - maxCores = maxThreads = 1; - } + ubyte n; + ubyte b = 0; + asm + { + mov EAX, 0x8000_0000 ; + cpuid ; + cmp EAX, 0x8000_0008 ; + jb AMDSingle ; + mov EAX, 0x8000_0008 ; + cpuid ; + mov n, CL ; + mov b, 1 ; + AMDSingle: ; + } + if (b != 0) + { + maxCores = n+1; + maxThreads = (apic>>>16)&0xFF; + } + else + { + maxCores = maxThreads = 1; + } } } else { char[] toString() { return "unknown CPU\n"; } - char[] vendor() {return "unknown vendor"; } - char[] processor() {return "unknown processor"; } + char[] vendor() {return "unknown vendor"; } + char[] processor() {return "unknown processor"; } - bool mmx() {return false; } - bool fxsr() {return false; } - bool sse() {return false; } - bool sse2() {return false; } - bool sse3() {return false; } - bool ssse3() {return false; } + bool mmx() {return false; } + bool fxsr() {return false; } + bool sse() {return false; } + bool sse2() {return false; } + bool sse3() {return false; } + bool ssse3() {return false; } - bool amd3dnow() {return false; } - bool amd3dnowExt() {return false; } - bool amdMmx() {return false; } + bool amd3dnow() {return false; } + bool amd3dnowExt() {return false; } + bool amdMmx() {return false; } - bool ia64() {return false; } - bool amd64() {return false; } + bool ia64() {return false; } + bool amd64() {return false; } - bool hyperThreading() {return false; } - uint threadsPerCPU() {return 0; } - uint coresPerCPU() {return 0; } + bool hyperThreading() {return false; } + uint threadsPerCPU() {return 0; } + uint coresPerCPU() {return 0; } - bool intel() {return false; } - bool amd() {return false; } + bool intel() {return false; } + bool amd() {return false; } - uint stepping() {return 0; } - uint model() {return 0; } - uint family() {return 0; } + uint stepping() {return 0; } + uint model() {return 0; } + uint family() {return 0; } } diff --git a/std/cstream.d b/std/cstream.d index e0257b318..87530dbd5 100644 --- a/std/cstream.d +++ b/std/cstream.d @@ -1,14 +1,21 @@ -// Written in the D programming language +// Written in the D programming language. /** * The std.cstream module bridges std.c.stdio (or std.stdio) and std.stream. * Both std.c.stdio and std.stream are publicly imported by std.cstream. - * Authors: Ben Hinkle - * License: Public Domain + * * Macros: - * WIKI=Phobos/StdCstream + * WIKI=Phobos/StdCstream + * + * Copyright: Copyright Ben Hinkle 2007 - 2009. + * License: Boost License 1.0. + * Authors: Ben Hinkle + * + * Copyright Ben Hinkle 2007 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.cstream; import std.stream; diff --git a/std/ctype.d b/std/ctype.d index 897f79c49..83569aaae 100644 --- a/std/ctype.d +++ b/std/ctype.d @@ -1,20 +1,23 @@ -/* - * Written in the D programming language. - * Placed into the Public Domain. - * Digital Mars, www.digitalmars.com - * Written by Walter Bright - */ +// Written in the D programming language. /** * Simple ASCII character classification functions. * For Unicode classification, see $(LINK2 std_uni.html, std.uni). * References: - * $(LINK2 http://www.digitalmars.com/d/ascii-table.html, ASCII Table), - * $(LINK2 http://en.wikipedia.org/wiki/Ascii, Wikipedia) + * $(LINK2 http://www.digitalmars.com/d/ascii-table.html, ASCII Table), + * $(LINK2 http://en.wikipedia.org/wiki/Ascii, Wikipedia) * Macros: - * WIKI=Phobos/StdCtype + * WIKI=Phobos/StdCtype + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.ctype; /** @@ -86,11 +89,11 @@ int isascii(dchar c) { return c <= 0x7F; } pure dchar tolower(dchar c) out (result) { - assert(!isupper(result)); + assert(!isupper(result)); } body { - return isupper(c) ? c + (cast(dchar)'a' - 'A') : c; + return isupper(c) ? c + (cast(dchar)'a' - 'A') : c; } @@ -101,47 +104,47 @@ pure dchar tolower(dchar c) dchar toupper(dchar c) out (result) { - assert(!islower(result)); + assert(!islower(result)); } body { - return islower(c) ? c - (cast(dchar)'a' - 'A') : c; + return islower(c) ? c - (cast(dchar)'a' - 'A') : c; } private: enum { - _SPC = 8, - _CTL = 0x20, - _BLK = 0x40, - _HEX = 0x80, - _UC = 1, - _LC = 2, - _PNC = 0x10, - _DIG = 4, - _ALP = _UC|_LC, + _SPC = 8, + _CTL = 0x20, + _BLK = 0x40, + _HEX = 0x80, + _UC = 1, + _LC = 2, + _PNC = 0x10, + _DIG = 4, + _ALP = _UC|_LC, } immutable ubyte _ctype[128] = [ - _CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL, - _CTL,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL,_CTL, - _CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL, - _CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL, - _SPC|_BLK,_PNC,_PNC,_PNC,_PNC,_PNC,_PNC,_PNC, - _PNC,_PNC,_PNC,_PNC,_PNC,_PNC,_PNC,_PNC, - _DIG|_HEX,_DIG|_HEX,_DIG|_HEX,_DIG|_HEX,_DIG|_HEX, - _DIG|_HEX,_DIG|_HEX,_DIG|_HEX,_DIG|_HEX,_DIG|_HEX, - _PNC,_PNC,_PNC,_PNC,_PNC,_PNC, - _PNC,_UC|_HEX,_UC|_HEX,_UC|_HEX,_UC|_HEX,_UC|_HEX,_UC|_HEX,_UC, - _UC,_UC,_UC,_UC,_UC,_UC,_UC,_UC, - _UC,_UC,_UC,_UC,_UC,_UC,_UC,_UC, - _UC,_UC,_UC,_PNC,_PNC,_PNC,_PNC,_PNC, - _PNC,_LC|_HEX,_LC|_HEX,_LC|_HEX,_LC|_HEX,_LC|_HEX,_LC|_HEX,_LC, - _LC,_LC,_LC,_LC,_LC,_LC,_LC,_LC, - _LC,_LC,_LC,_LC,_LC,_LC,_LC,_LC, - _LC,_LC,_LC,_PNC,_PNC,_PNC,_PNC,_CTL + _CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL, + _CTL,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL|_SPC,_CTL,_CTL, + _CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL, + _CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL,_CTL, + _SPC|_BLK,_PNC,_PNC,_PNC,_PNC,_PNC,_PNC,_PNC, + _PNC,_PNC,_PNC,_PNC,_PNC,_PNC,_PNC,_PNC, + _DIG|_HEX,_DIG|_HEX,_DIG|_HEX,_DIG|_HEX,_DIG|_HEX, + _DIG|_HEX,_DIG|_HEX,_DIG|_HEX,_DIG|_HEX,_DIG|_HEX, + _PNC,_PNC,_PNC,_PNC,_PNC,_PNC, + _PNC,_UC|_HEX,_UC|_HEX,_UC|_HEX,_UC|_HEX,_UC|_HEX,_UC|_HEX,_UC, + _UC,_UC,_UC,_UC,_UC,_UC,_UC,_UC, + _UC,_UC,_UC,_UC,_UC,_UC,_UC,_UC, + _UC,_UC,_UC,_PNC,_PNC,_PNC,_PNC,_PNC, + _PNC,_LC|_HEX,_LC|_HEX,_LC|_HEX,_LC|_HEX,_LC|_HEX,_LC|_HEX,_LC, + _LC,_LC,_LC,_LC,_LC,_LC,_LC,_LC, + _LC,_LC,_LC,_LC,_LC,_LC,_LC,_LC, + _LC,_LC,_LC,_PNC,_PNC,_PNC,_PNC,_CTL ]; diff --git a/std/date.d b/std/date.d index 725813674..d866be919 100644 --- a/std/date.d +++ b/std/date.d @@ -10,13 +10,16 @@ * calendar (Wikipedia)) * * Macros: WIKI = Phobos/StdDate + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - -// Copyright (c) 1999-2008 by Digital Mars -// All Rights Reserved -// written by Walter Bright -// http://www.digitalmars.com - module std.date; private import std.stdio; diff --git a/std/datebase.d b/std/datebase.d index 29495b4d6..980a8d8e7 100644 --- a/std/datebase.d +++ b/std/datebase.d @@ -1,3 +1,18 @@ +// Written in the D programming language. + +/** + * The only purpose of this module is to do the static construction for + * std.date, to eliminate cyclic construction errors. + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ module std.datebase; extern(C) void std_date_static_this(); @@ -6,25 +21,3 @@ static this() { std_date_static_this; } - -/* - * Copyright (C) 1999-2004 by Digital Mars, http://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, 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. - */ diff --git a/std/dateparse.d b/std/dateparse.d index c880b8751..a32d2fffa 100644 --- a/std/dateparse.d +++ b/std/dateparse.d @@ -1,5 +1,17 @@ -// Written in the D programming language +// Written in the D programming language. +/** + * dateparse module. + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ module std.dateparse; private @@ -15,7 +27,7 @@ class DateParseError : Error { this(string s) { - super("Invalid date string: " ~ s); + super("Invalid date string: " ~ s); } } @@ -23,90 +35,90 @@ struct DateParse { void parse(string s, out Date date) { - this = DateParse.init; + this = DateParse.init; - //version (Win32) - buffer = (cast(char *)alloca(s.length))[0 .. s.length]; - //else - //buffer = new char[s.length]; + //version (Win32) + buffer = (cast(char *)alloca(s.length))[0 .. s.length]; + //else + //buffer = new char[s.length]; - debug(dateparse) printf("DateParse.parse('%.*s')\n", s); - if (!parseString(s)) - { - goto Lerror; - } + debug(dateparse) printf("DateParse.parse('%.*s')\n", s); + if (!parseString(s)) + { + goto Lerror; + } /+ - if (year == year.init) - year = 0; - else + if (year == year.init) + year = 0; + else +/ - debug(dateparse) - printf("year = %d, month = %d, day = %d\n%02d:%02d:%02d.%03d\nweekday = %d, tzcorrection = %d\n", - year, month, day, - hours, minutes, seconds, ms, - weekday, tzcorrection); - if ( - year == year.init || - (month < 1 || month > 12) || - (day < 1 || day > 31) || - (hours < 0 || hours > 23) || - (minutes < 0 || minutes > 59) || - (seconds < 0 || seconds > 59) || - (tzcorrection != int.min && - ((tzcorrection < -2300 || tzcorrection > 2300) || - (tzcorrection % 10))) - ) - { - Lerror: - throw new DateParseError(s); - } + debug(dateparse) + printf("year = %d, month = %d, day = %d\n%02d:%02d:%02d.%03d\nweekday = %d, tzcorrection = %d\n", + year, month, day, + hours, minutes, seconds, ms, + weekday, tzcorrection); + if ( + year == year.init || + (month < 1 || month > 12) || + (day < 1 || day > 31) || + (hours < 0 || hours > 23) || + (minutes < 0 || minutes > 59) || + (seconds < 0 || seconds > 59) || + (tzcorrection != int.min && + ((tzcorrection < -2300 || tzcorrection > 2300) || + (tzcorrection % 10))) + ) + { + Lerror: + throw new DateParseError(s); + } - if (ampm) - { if (hours > 12) - goto Lerror; - if (hours < 12) - { - if (ampm == 2) // if P.M. - hours += 12; - } - else if (ampm == 1) // if 12am - { - hours = 0; // which is midnight - } - } + if (ampm) + { if (hours > 12) + goto Lerror; + if (hours < 12) + { + if (ampm == 2) // if P.M. + hours += 12; + } + else if (ampm == 1) // if 12am + { + hours = 0; // which is midnight + } + } -// if (tzcorrection != tzcorrection.init) -// tzcorrection /= 100; +// if (tzcorrection != tzcorrection.init) +// tzcorrection /= 100; - if (year >= 0 && year <= 99) - year += 1900; + if (year >= 0 && year <= 99) + year += 1900; - date.year = year; - date.month = month; - date.day = day; - date.hour = hours; - date.minute = minutes; - date.second = seconds; - date.ms = ms; - date.weekday = weekday; - date.tzcorrection = tzcorrection; + date.year = year; + date.month = month; + date.day = day; + date.hour = hours; + date.minute = minutes; + date.second = seconds; + date.ms = ms; + date.weekday = weekday; + date.tzcorrection = tzcorrection; } private: - int year = int.min; // our "nan" Date value - int month; // 1..12 - int day; // 1..31 - int hours; // 0..23 - int minutes; // 0..59 - int seconds; // 0..59 - int ms; // 0..999 - int weekday; // 1..7 - int ampm; // 0: not specified - // 1: AM - // 2: PM - int tzcorrection = int.min; // -1200..1200 correction in hours + int year = int.min; // our "nan" Date value + int month; // 1..12 + int day; // 1..31 + int hours; // 0..23 + int minutes; // 0..59 + int seconds; // 0..59 + int ms; // 0..999 + int weekday; // 1..7 + int ampm; // 0: not specified + // 1: AM + // 2: PM + int tzcorrection = int.min; // -1200..1200 correction in hours string s; int si; @@ -115,287 +127,287 @@ private: enum DP : byte { - err, - weekday, - month, - number, - end, - colon, - minus, - slash, - ampm, - plus, - tz, - dst, - dsttz, + err, + weekday, + month, + number, + end, + colon, + minus, + slash, + ampm, + plus, + tz, + dst, + dsttz, } DP nextToken() { int nest; - uint c; - int bi; - DP result = DP.err; + uint c; + int bi; + DP result = DP.err; - //printf("DateParse::nextToken()\n"); - for (;;) - { - assert(si <= s.length); - if (si == s.length) - { result = DP.end; - goto Lret; - } - //printf("\ts[%d] = '%c'\n", si, s[si]); - switch (s[si]) - { - case ':': result = DP.colon; goto ret_inc; - case '+': result = DP.plus; goto ret_inc; - case '-': result = DP.minus; goto ret_inc; - case '/': result = DP.slash; goto ret_inc; - case '.': - version(DATE_DOT_DELIM) - { - result = DP.slash; - goto ret_inc; - } - else - { - si++; - break; - } + //printf("DateParse::nextToken()\n"); + for (;;) + { + assert(si <= s.length); + if (si == s.length) + { result = DP.end; + goto Lret; + } + //printf("\ts[%d] = '%c'\n", si, s[si]); + switch (s[si]) + { + case ':': result = DP.colon; goto ret_inc; + case '+': result = DP.plus; goto ret_inc; + case '-': result = DP.minus; goto ret_inc; + case '/': result = DP.slash; goto ret_inc; + case '.': + version(DATE_DOT_DELIM) + { + result = DP.slash; + goto ret_inc; + } + else + { + si++; + break; + } - ret_inc: - si++; - goto Lret; + ret_inc: + si++; + goto Lret; - case ' ': - case '\n': - case '\r': - case '\t': - case ',': - si++; - break; + case ' ': + case '\n': + case '\r': + case '\t': + case ',': + si++; + break; - case '(': // comment - nest = 1; - for (;;) - { - si++; - if (si == s.length) - goto Lret; // error - switch (s[si]) - { - case '(': - nest++; - break; + case '(': // comment + nest = 1; + for (;;) + { + si++; + if (si == s.length) + goto Lret; // error + switch (s[si]) + { + case '(': + nest++; + break; - case ')': - if (--nest == 0) - goto Lendofcomment; - break; + case ')': + if (--nest == 0) + goto Lendofcomment; + break; - default: - break; - } - } - Lendofcomment: - si++; - break; + default: + break; + } + } + Lendofcomment: + si++; + break; - default: - number = 0; - for (;;) - { - if (si == s.length) - // c cannot be undefined here - break; - c = s[si]; - if (!(c >= '0' && c <= '9')) - break; - result = DP.number; - number = number * 10 + (c - '0'); - si++; - } - if (result == DP.number) - goto Lret; + default: + number = 0; + for (;;) + { + if (si == s.length) + // c cannot be undefined here + break; + c = s[si]; + if (!(c >= '0' && c <= '9')) + break; + result = DP.number; + number = number * 10 + (c - '0'); + si++; + } + if (result == DP.number) + goto Lret; - bi = 0; - bufloop: - while (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') - { - if (c < 'a') // if upper case - c += cast(uint)'a' - cast(uint)'A'; // to lower case - buffer[bi] = cast(char)c; - bi++; - do - { - si++; - if (si == s.length) - break bufloop; - c = s[si]; - } while (c == '.'); // ignore embedded '.'s - } - result = classify(buffer[0 .. bi].idup); - goto Lret; - } - } + bi = 0; + bufloop: + while (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') + { + if (c < 'a') // if upper case + c += cast(uint)'a' - cast(uint)'A'; // to lower case + buffer[bi] = cast(char)c; + bi++; + do + { + si++; + if (si == s.length) + break bufloop; + c = s[si]; + } while (c == '.'); // ignore embedded '.'s + } + result = classify(buffer[0 .. bi].idup); + goto Lret; + } + } Lret: - //printf("-DateParse::nextToken()\n"); - return result; + //printf("-DateParse::nextToken()\n"); + return result; } DP classify(string buf) { - struct DateID - { - string name; - DP tok; - short value; - } + struct DateID + { + string name; + DP tok; + short value; + } - static immutable DateID dateidtab[] = - [ - { "january", DP.month, 1}, - { "february", DP.month, 2}, - { "march", DP.month, 3}, - { "april", DP.month, 4}, - { "may", DP.month, 5}, - { "june", DP.month, 6}, - { "july", DP.month, 7}, - { "august", DP.month, 8}, - { "september", DP.month, 9}, - { "october", DP.month, 10}, - { "november", DP.month, 11}, - { "december", DP.month, 12}, - { "jan", DP.month, 1}, - { "feb", DP.month, 2}, - { "mar", DP.month, 3}, - { "apr", DP.month, 4}, - { "jun", DP.month, 6}, - { "jul", DP.month, 7}, - { "aug", DP.month, 8}, - { "sep", DP.month, 9}, - { "sept", DP.month, 9}, - { "oct", DP.month, 10}, - { "nov", DP.month, 11}, - { "dec", DP.month, 12}, + static immutable DateID dateidtab[] = + [ + { "january", DP.month, 1}, + { "february", DP.month, 2}, + { "march", DP.month, 3}, + { "april", DP.month, 4}, + { "may", DP.month, 5}, + { "june", DP.month, 6}, + { "july", DP.month, 7}, + { "august", DP.month, 8}, + { "september", DP.month, 9}, + { "october", DP.month, 10}, + { "november", DP.month, 11}, + { "december", DP.month, 12}, + { "jan", DP.month, 1}, + { "feb", DP.month, 2}, + { "mar", DP.month, 3}, + { "apr", DP.month, 4}, + { "jun", DP.month, 6}, + { "jul", DP.month, 7}, + { "aug", DP.month, 8}, + { "sep", DP.month, 9}, + { "sept", DP.month, 9}, + { "oct", DP.month, 10}, + { "nov", DP.month, 11}, + { "dec", DP.month, 12}, - { "sunday", DP.weekday, 1}, - { "monday", DP.weekday, 2}, - { "tuesday", DP.weekday, 3}, - { "tues", DP.weekday, 3}, - { "wednesday", DP.weekday, 4}, - { "wednes", DP.weekday, 4}, - { "thursday", DP.weekday, 5}, - { "thur", DP.weekday, 5}, - { "thurs", DP.weekday, 5}, - { "friday", DP.weekday, 6}, - { "saturday", DP.weekday, 7}, + { "sunday", DP.weekday, 1}, + { "monday", DP.weekday, 2}, + { "tuesday", DP.weekday, 3}, + { "tues", DP.weekday, 3}, + { "wednesday", DP.weekday, 4}, + { "wednes", DP.weekday, 4}, + { "thursday", DP.weekday, 5}, + { "thur", DP.weekday, 5}, + { "thurs", DP.weekday, 5}, + { "friday", DP.weekday, 6}, + { "saturday", DP.weekday, 7}, - { "sun", DP.weekday, 1}, - { "mon", DP.weekday, 2}, - { "tue", DP.weekday, 3}, - { "wed", DP.weekday, 4}, - { "thu", DP.weekday, 5}, - { "fri", DP.weekday, 6}, - { "sat", DP.weekday, 7}, + { "sun", DP.weekday, 1}, + { "mon", DP.weekday, 2}, + { "tue", DP.weekday, 3}, + { "wed", DP.weekday, 4}, + { "thu", DP.weekday, 5}, + { "fri", DP.weekday, 6}, + { "sat", DP.weekday, 7}, - { "am", DP.ampm, 1}, - { "pm", DP.ampm, 2}, + { "am", DP.ampm, 1}, + { "pm", DP.ampm, 2}, - { "gmt", DP.tz, +000}, - { "ut", DP.tz, +000}, - { "utc", DP.tz, +000}, - { "wet", DP.tz, +000}, - { "z", DP.tz, +000}, - { "wat", DP.tz, +100}, - { "a", DP.tz, +100}, - { "at", DP.tz, +200}, - { "b", DP.tz, +200}, - { "c", DP.tz, +300}, - { "ast", DP.tz, +400}, - { "d", DP.tz, +400}, - { "est", DP.tz, +500}, - { "e", DP.tz, +500}, - { "cst", DP.tz, +600}, - { "f", DP.tz, +600}, - { "mst", DP.tz, +700}, - { "g", DP.tz, +700}, - { "pst", DP.tz, +800}, - { "h", DP.tz, +800}, - { "yst", DP.tz, +900}, - { "i", DP.tz, +900}, - { "ahst", DP.tz, +1000}, - { "cat", DP.tz, +1000}, - { "hst", DP.tz, +1000}, - { "k", DP.tz, +1000}, - { "nt", DP.tz, +1100}, - { "l", DP.tz, +1100}, - { "idlw", DP.tz, +1200}, - { "m", DP.tz, +1200}, + { "gmt", DP.tz, +000}, + { "ut", DP.tz, +000}, + { "utc", DP.tz, +000}, + { "wet", DP.tz, +000}, + { "z", DP.tz, +000}, + { "wat", DP.tz, +100}, + { "a", DP.tz, +100}, + { "at", DP.tz, +200}, + { "b", DP.tz, +200}, + { "c", DP.tz, +300}, + { "ast", DP.tz, +400}, + { "d", DP.tz, +400}, + { "est", DP.tz, +500}, + { "e", DP.tz, +500}, + { "cst", DP.tz, +600}, + { "f", DP.tz, +600}, + { "mst", DP.tz, +700}, + { "g", DP.tz, +700}, + { "pst", DP.tz, +800}, + { "h", DP.tz, +800}, + { "yst", DP.tz, +900}, + { "i", DP.tz, +900}, + { "ahst", DP.tz, +1000}, + { "cat", DP.tz, +1000}, + { "hst", DP.tz, +1000}, + { "k", DP.tz, +1000}, + { "nt", DP.tz, +1100}, + { "l", DP.tz, +1100}, + { "idlw", DP.tz, +1200}, + { "m", DP.tz, +1200}, - { "cet", DP.tz, -100}, - { "fwt", DP.tz, -100}, - { "met", DP.tz, -100}, - { "mewt", DP.tz, -100}, - { "swt", DP.tz, -100}, - { "n", DP.tz, -100}, - { "eet", DP.tz, -200}, - { "o", DP.tz, -200}, - { "bt", DP.tz, -300}, - { "p", DP.tz, -300}, - { "zp4", DP.tz, -400}, - { "q", DP.tz, -400}, - { "zp5", DP.tz, -500}, - { "r", DP.tz, -500}, - { "zp6", DP.tz, -600}, - { "s", DP.tz, -600}, - { "wast", DP.tz, -700}, - { "t", DP.tz, -700}, - { "cct", DP.tz, -800}, - { "u", DP.tz, -800}, - { "jst", DP.tz, -900}, - { "v", DP.tz, -900}, - { "east", DP.tz, -1000}, - { "gst", DP.tz, -1000}, - { "w", DP.tz, -1000}, - { "x", DP.tz, -1100}, - { "idle", DP.tz, -1200}, - { "nzst", DP.tz, -1200}, - { "nzt", DP.tz, -1200}, - { "y", DP.tz, -1200}, + { "cet", DP.tz, -100}, + { "fwt", DP.tz, -100}, + { "met", DP.tz, -100}, + { "mewt", DP.tz, -100}, + { "swt", DP.tz, -100}, + { "n", DP.tz, -100}, + { "eet", DP.tz, -200}, + { "o", DP.tz, -200}, + { "bt", DP.tz, -300}, + { "p", DP.tz, -300}, + { "zp4", DP.tz, -400}, + { "q", DP.tz, -400}, + { "zp5", DP.tz, -500}, + { "r", DP.tz, -500}, + { "zp6", DP.tz, -600}, + { "s", DP.tz, -600}, + { "wast", DP.tz, -700}, + { "t", DP.tz, -700}, + { "cct", DP.tz, -800}, + { "u", DP.tz, -800}, + { "jst", DP.tz, -900}, + { "v", DP.tz, -900}, + { "east", DP.tz, -1000}, + { "gst", DP.tz, -1000}, + { "w", DP.tz, -1000}, + { "x", DP.tz, -1100}, + { "idle", DP.tz, -1200}, + { "nzst", DP.tz, -1200}, + { "nzt", DP.tz, -1200}, + { "y", DP.tz, -1200}, - { "bst", DP.dsttz, 000}, - { "adt", DP.dsttz, +400}, - { "edt", DP.dsttz, +500}, - { "cdt", DP.dsttz, +600}, - { "mdt", DP.dsttz, +700}, - { "pdt", DP.dsttz, +800}, - { "ydt", DP.dsttz, +900}, - { "hdt", DP.dsttz, +1000}, - { "mest", DP.dsttz, -100}, - { "mesz", DP.dsttz, -100}, - { "sst", DP.dsttz, -100}, - { "fst", DP.dsttz, -100}, - { "wadt", DP.dsttz, -700}, - { "eadt", DP.dsttz, -1000}, - { "nzdt", DP.dsttz, -1200}, + { "bst", DP.dsttz, 000}, + { "adt", DP.dsttz, +400}, + { "edt", DP.dsttz, +500}, + { "cdt", DP.dsttz, +600}, + { "mdt", DP.dsttz, +700}, + { "pdt", DP.dsttz, +800}, + { "ydt", DP.dsttz, +900}, + { "hdt", DP.dsttz, +1000}, + { "mest", DP.dsttz, -100}, + { "mesz", DP.dsttz, -100}, + { "sst", DP.dsttz, -100}, + { "fst", DP.dsttz, -100}, + { "wadt", DP.dsttz, -700}, + { "eadt", DP.dsttz, -1000}, + { "nzdt", DP.dsttz, -1200}, - { "dst", DP.dst, 0}, - ]; + { "dst", DP.dst, 0}, + ]; - //message(DTEXT("DateParse::classify('%s')\n"), buf); + //message(DTEXT("DateParse::classify('%s')\n"), buf); - // Do a linear search. Yes, it would be faster with a binary - // one. - for (uint i = 0; i < dateidtab.length; i++) - { - if (std.string.cmp(dateidtab[i].name, buf) == 0) - { - number = dateidtab[i].value; - return dateidtab[i].tok; - } - } - return DP.err; + // Do a linear search. Yes, it would be faster with a binary + // one. + for (uint i = 0; i < dateidtab.length; i++) + { + if (std.string.cmp(dateidtab[i].name, buf) == 0) + { + number = dateidtab[i].value; + return dateidtab[i].tok; + } + } + return DP.err; } int parseString(string s) @@ -427,13 +439,13 @@ private: goto Lret; case DP.minus: - break; // ignore spurious '-' + break; // ignore spurious '-' case DP.weekday: weekday = number; break; - case DP.month: // month day, [year] + case DP.month: // month day, [year] month = number; dp = nextToken(); if (dp == DP.number) @@ -468,13 +480,13 @@ private: break; case DP.minus: - case DP.slash: // n1/ ? ? ? + case DP.slash: // n1/ ? ? ? dp = parseCalendarDate(n1); if (dp == DP.err) goto case_error; break; - case DP.colon: // hh:mm [:ss] [am | pm] + case DP.colon: // hh:mm [:ss] [am | pm] dp = parseTimeOfDay(n1); if (dp == DP.err) goto case_error; @@ -512,144 +524,144 @@ private: int parseCalendarDate(int n1) { - int n2; - int n3; - int dp; + int n2; + int n3; + int dp; - debug(dateparse) printf("DateParse.parseCalendarDate(%d)\n", n1); - dp = nextToken(); - if (dp == DP.month) // day/month - { - day = n1; - month = number; - dp = nextToken(); - if (dp == DP.number) - { // day/month year - year = number; - dp = nextToken(); - } - else if (dp == DP.minus || dp == DP.slash) - { // day/month/year - dp = nextToken(); - if (dp != DP.number) - goto case_error; - year = number; - dp = nextToken(); - } - return dp; - } - if (dp != DP.number) - goto case_error; - n2 = number; - //message(DTEXT("\tn2 = %d\n"), n2); - dp = nextToken(); - if (dp == DP.minus || dp == DP.slash) - { - dp = nextToken(); - if (dp != DP.number) - goto case_error; - n3 = number; - //message(DTEXT("\tn3 = %d\n"), n3); - dp = nextToken(); + debug(dateparse) printf("DateParse.parseCalendarDate(%d)\n", n1); + dp = nextToken(); + if (dp == DP.month) // day/month + { + day = n1; + month = number; + dp = nextToken(); + if (dp == DP.number) + { // day/month year + year = number; + dp = nextToken(); + } + else if (dp == DP.minus || dp == DP.slash) + { // day/month/year + dp = nextToken(); + if (dp != DP.number) + goto case_error; + year = number; + dp = nextToken(); + } + return dp; + } + if (dp != DP.number) + goto case_error; + n2 = number; + //message(DTEXT("\tn2 = %d\n"), n2); + dp = nextToken(); + if (dp == DP.minus || dp == DP.slash) + { + dp = nextToken(); + if (dp != DP.number) + goto case_error; + n3 = number; + //message(DTEXT("\tn3 = %d\n"), n3); + dp = nextToken(); - // case1: year/month/day - // case2: month/day/year - int case1, case2; + // case1: year/month/day + // case2: month/day/year + int case1, case2; - case1 = (n1 > 12 || - (n2 >= 1 && n2 <= 12) && - (n3 >= 1 && n3 <= 31)); - case2 = ((n1 >= 1 && n1 <= 12) && - (n2 >= 1 && n2 <= 31) || - n3 > 31); - if (case1 == case2) - goto case_error; - if (case1) - { - year = n1; - month = n2; - day = n3; - } - else - { - month = n1; - day = n2; - year = n3; - } - } - else - { // must be month/day - month = n1; - day = n2; - } - return dp; + case1 = (n1 > 12 || + (n2 >= 1 && n2 <= 12) && + (n3 >= 1 && n3 <= 31)); + case2 = ((n1 >= 1 && n1 <= 12) && + (n2 >= 1 && n2 <= 31) || + n3 > 31); + if (case1 == case2) + goto case_error; + if (case1) + { + year = n1; + month = n2; + day = n3; + } + else + { + month = n1; + day = n2; + year = n3; + } + } + else + { // must be month/day + month = n1; + day = n2; + } + return dp; case_error: - return DP.err; + return DP.err; } int parseTimeOfDay(int n1) { - int dp; - int sign; + int dp; + int sign; - // 12am is midnight - // 12pm is noon + // 12am is midnight + // 12pm is noon - //message(DTEXT("DateParse::parseTimeOfDay(%d)\n"), n1); - hours = n1; - dp = nextToken(); - if (dp != DP.number) - goto case_error; - minutes = number; - dp = nextToken(); - if (dp == DP.colon) - { - dp = nextToken(); - if (dp != DP.number) - goto case_error; - seconds = number; - dp = nextToken(); - } - else - seconds = 0; + //message(DTEXT("DateParse::parseTimeOfDay(%d)\n"), n1); + hours = n1; + dp = nextToken(); + if (dp != DP.number) + goto case_error; + minutes = number; + dp = nextToken(); + if (dp == DP.colon) + { + dp = nextToken(); + if (dp != DP.number) + goto case_error; + seconds = number; + dp = nextToken(); + } + else + seconds = 0; - if (dp == DP.ampm) - { - ampm = number; - dp = nextToken(); - } - else if (dp == DP.plus || dp == DP.minus) - { - Loffset: - sign = (dp == DP.minus) ? -1 : 1; - dp = nextToken(); - if (dp != DP.number) - goto case_error; - tzcorrection = -sign * number; - dp = nextToken(); - } - else if (dp == DP.tz) - { - tzcorrection = number; - dp = nextToken(); - if (number == 0 && (dp == DP.plus || dp == DP.minus)) - goto Loffset; - if (dp == DP.dst) - { tzcorrection += 100; - dp = nextToken(); - } - } - else if (dp == DP.dsttz) - { - tzcorrection = number; - dp = nextToken(); - } + if (dp == DP.ampm) + { + ampm = number; + dp = nextToken(); + } + else if (dp == DP.plus || dp == DP.minus) + { + Loffset: + sign = (dp == DP.minus) ? -1 : 1; + dp = nextToken(); + if (dp != DP.number) + goto case_error; + tzcorrection = -sign * number; + dp = nextToken(); + } + else if (dp == DP.tz) + { + tzcorrection = number; + dp = nextToken(); + if (number == 0 && (dp == DP.plus || dp == DP.minus)) + goto Loffset; + if (dp == DP.dst) + { tzcorrection += 100; + dp = nextToken(); + } + } + else if (dp == DP.dsttz) + { + tzcorrection = number; + dp = nextToken(); + } - return dp; + return dp; case_error: - return DP.err; + return DP.err; } } @@ -759,29 +771,7 @@ unittest assert(d.tzcorrection == -530); debug(dateparse) printf("year = %d, month = %d, day = %d\n%02d:%02d:%02d.%03d\nweekday = %d, tzcorrection = %d\n", - d.year, d.month, d.day, - d.hour, d.minute, d.second, d.ms, - d.weekday, d.tzcorrection); + d.year, d.month, d.day, + d.hour, d.minute, d.second, d.ms, + d.weekday, d.tzcorrection); } - -/* - * Copyright (C) 1999-2004 by Digital Mars, http://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, 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. - */ diff --git a/std/demangle.d b/std/demangle.d index 5be5b16b3..d73a81be8 100644 --- a/std/demangle.d +++ b/std/demangle.d @@ -1,21 +1,21 @@ // Written in the D programming language. -/* - * Placed into the Public Domain. - */ - -/**** +/** * Demangle D mangled names. + * * Macros: - * WIKI = Phobos/StdDemangle + * WIKI = Phobos/StdDemangle + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright), + * Thomas Kuehne, Frits van Bommel + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - -/* Authors: - * Walter Bright, Digital Mars, www.digitalmars.com - * Thomas Kuehne - * Frits van Bommel - */ - module std.demangle; //debug=demangle; // uncomment to turn on debugging printf's diff --git a/std/encoding.d b/std/encoding.d index b044c23b8..9bc235939 100755 --- a/std/encoding.d +++ b/std/encoding.d @@ -35,17 +35,20 @@ architectures) UTF-16BE and UTF-32BE. This library provides a mechanism whereby other modules may add $(D EncodingScheme) subclasses for any other _encoding. -Authors: Janice Caron - -Date: 2008.02.27 - 2008.05.07 - -License: Public Domain - Macros: WIKI=Phobos/StdEncoding -*/ +Copyright: Copyright Janice Caron 2008 - 2009. +License: Boost License 1.0. +Authors: Janice Caron + + Copyright Janice Caron 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.encoding; + import std.string; import std.traits; import std.range; @@ -335,12 +338,12 @@ unittest // Make sure we can count properly { - assert(encodedLength!(char)('A') == 1); - assert(encodedLength!(char)('\u00E3') == 2); - assert(encodedLength!(char)('\u2028') == 3); - assert(encodedLength!(char)('\U0010FFF0') == 4); - assert(encodedLength!(wchar)('A') == 1); - assert(encodedLength!(wchar)('\U0010FFF0') == 2); + assert(encodedLength!(char)('A') == 1); + assert(encodedLength!(char)('\u00E3') == 2); + assert(encodedLength!(char)('\u2028') == 3); + assert(encodedLength!(char)('\U0010FFF0') == 4); + assert(encodedLength!(wchar)('A') == 1); + assert(encodedLength!(wchar)('\U0010FFF0') == 2); } // Make sure we can write into mutable arrays @@ -386,7 +389,7 @@ template EncoderFunctions() template WriteToArray() { - void write(E c) { array[0] = c; array = array[1..$]; } + void write(E c) { array[0] = c; array = array[1..$]; } } deprecated template WriteToBuffer() @@ -441,8 +444,8 @@ template EncoderFunctions() template EncodeToArray() { - mixin WriteToArray; - mixin EncodeViaWrite; + mixin WriteToArray; + mixin EncodeViaWrite; } deprecated template EncodeToBuffer() @@ -496,8 +499,8 @@ template EncoderFunctions() void encode(dchar c, ref E[] array) { - mixin EncodeToArray e; - e.encode(c); + mixin EncodeToArray e; + e.encode(c); } void encode(dchar c, void delegate(E) dg) @@ -682,7 +685,7 @@ template EncoderInstance(CharType : AsciiChar) uint encodedLength(dchar c) in { - assert(canEncode(c)); + assert(canEncode(c)); } body { @@ -765,11 +768,11 @@ template EncoderInstance(CharType : Latin1Char) uint encodedLength(dchar c) in { - assert(canEncode(c)); + assert(canEncode(c)); } body { - return 1; + return 1; } void encodeViaWrite()(dchar c) @@ -852,7 +855,7 @@ template EncoderInstance(CharType : Windows1252Char) uint encodedLength(dchar c) in { - assert(canEncode(c)); + assert(canEncode(c)); } body { @@ -960,7 +963,7 @@ template EncoderInstance(CharType : char) uint encodedLength(dchar c) in { - assert(canEncode(c)); + assert(canEncode(c)); } body { @@ -1104,11 +1107,11 @@ template EncoderInstance(CharType : wchar) uint encodedLength(dchar c) in { - assert(canEncode(c)); + assert(canEncode(c)); } body { - return (c < 0x10000) ? 1 : 2; + return (c < 0x10000) ? 1 : 2; } void encodeViaWrite()(dchar c) @@ -1201,11 +1204,11 @@ template EncoderInstance(CharType : dchar) uint encodedLength(dchar c) in { - assert(canEncode(c)); + assert(canEncode(c)); } body { - return 1; + return 1; } void encodeViaWrite()(dchar c) @@ -1735,7 +1738,7 @@ body c = the code point to be encoded Returns: - the number of code units written to the array + the number of code units written to the array */ uint encode(E)(dchar c, E[] array) in @@ -1744,7 +1747,7 @@ in } body { - E[] t = array; + E[] t = array; EncoderInstance!(E).encode(c,t); return array.length - t.length; } @@ -2284,41 +2287,41 @@ abstract class EncodingScheme */ immutable(ubyte)[] sanitize(immutable(ubyte)[] s) { - uint n = validLength(s); - if (n == s.length) return s; + uint n = validLength(s); + if (n == s.length) return s; - auto repSeq = replacementSequence; + auto repSeq = replacementSequence; - // Count how long the string needs to be. - // Overestimating is not a problem - uint len = s.length; - const(ubyte)[] t = s[n..$]; - while (t.length != 0) - { - dchar c = safeDecode(t); - assert(c == INVALID_SEQUENCE); - len += repSeq.length; - t = t[validLength(t)..$]; - } + // Count how long the string needs to be. + // Overestimating is not a problem + uint len = s.length; + const(ubyte)[] t = s[n..$]; + while (t.length != 0) + { + dchar c = safeDecode(t); + assert(c == INVALID_SEQUENCE); + len += repSeq.length; + t = t[validLength(t)..$]; + } - // Now do the write - ubyte[] array = new ubyte[len]; - array[0..n] = s[0..n]; - uint offset = n; + // Now do the write + ubyte[] array = new ubyte[len]; + array[0..n] = s[0..n]; + uint offset = n; - t = s[n..$]; - while (t.length != 0) - { - dchar c = safeDecode(t); - assert(c == INVALID_SEQUENCE); - array[offset..offset+repSeq.length] = repSeq[]; - offset += repSeq.length; - n = validLength(t); - array[offset..offset+n] = t[0..n]; - offset += n; - t = t[n..$]; - } - return cast(immutable(ubyte)[])array[0..offset]; + t = s[n..$]; + while (t.length != 0) + { + dchar c = safeDecode(t); + assert(c == INVALID_SEQUENCE); + array[offset..offset+repSeq.length] = repSeq[]; + offset += repSeq.length; + n = validLength(t); + array[offset..offset+n] = t[0..n]; + offset += n; + t = t[n..$]; + } + return cast(immutable(ubyte)[])array[0..offset]; } /** @@ -2450,12 +2453,12 @@ class EncodingSchemeASCII : EncodingScheme override uint encodedLength(dchar c) { - return std.encoding.encodedLength!(AsciiChar)(c); + return std.encoding.encodedLength!(AsciiChar)(c); } override uint encode(dchar c, ubyte[] buffer) { - auto r = cast(AsciiChar[])buffer; + auto r = cast(AsciiChar[])buffer; return std.encoding.encode(c,r); } @@ -2534,12 +2537,12 @@ class EncodingSchemeLatin1 : EncodingScheme override uint encodedLength(dchar c) { - return std.encoding.encodedLength!(Latin1Char)(c); + return std.encoding.encodedLength!(Latin1Char)(c); } override uint encode(dchar c, ubyte[] buffer) { - auto r = cast(Latin1Char[])buffer; + auto r = cast(Latin1Char[])buffer; return std.encoding.encode(c,r); } @@ -2602,12 +2605,12 @@ class EncodingSchemeWindows1252 : EncodingScheme override uint encodedLength(dchar c) { - return std.encoding.encodedLength!(Windows1252Char)(c); + return std.encoding.encodedLength!(Windows1252Char)(c); } override uint encode(dchar c, ubyte[] buffer) { - auto r = cast(Windows1252Char[])buffer; + auto r = cast(Windows1252Char[])buffer; return std.encoding.encode(c,r); } @@ -2670,12 +2673,12 @@ class EncodingSchemeUtf8 : EncodingScheme override uint encodedLength(dchar c) { - return std.encoding.encodedLength!(char)(c); + return std.encoding.encodedLength!(char)(c); } override uint encode(dchar c, ubyte[] buffer) { - auto r = cast(char[])buffer; + auto r = cast(char[])buffer; return std.encoding.encode(c,r); } @@ -2738,12 +2741,12 @@ class EncodingSchemeUtf16Native : EncodingScheme override uint encodedLength(dchar c) { - return std.encoding.encodedLength!(wchar)(c); + return std.encoding.encodedLength!(wchar)(c); } override uint encode(dchar c, ubyte[] buffer) { - auto r = cast(wchar[])buffer; + auto r = cast(wchar[])buffer; return wchar.sizeof * std.encoding.encode(c,r); } @@ -2816,12 +2819,12 @@ class EncodingSchemeUtf32Native : EncodingScheme override uint encodedLength(dchar c) { - return std.encoding.encodedLength!(dchar)(c); + return std.encoding.encodedLength!(dchar)(c); } override uint encode(dchar c, ubyte[] buffer) { - auto r = cast(dchar[])buffer; + auto r = cast(dchar[])buffer; return dchar.sizeof * std.encoding.encode(c,r); } diff --git a/std/file.d b/std/file.d index b952168f6..db16da232 100644 --- a/std/file.d +++ b/std/file.d @@ -3,16 +3,19 @@ /** Utilities for manipulating files and scanning directories. -Authors: - -$(WEB digitalmars.com, Walter Bright), $(WEB erdani.org, Andrei -Alexandrescu) - Macros: + WIKI = Phobos/StdFile -WIKI = Phobos/StdFile +Copyright: Copyright Digital Mars 2007 - 2009. +License: Boost License 1.0. +Authors: $(WEB digitalmars.com, Walter Bright), + $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Digital Mars 2007 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - module std.file; import core.memory; @@ -722,14 +725,14 @@ void mkdirRecurse(in char[] pathname) const left = dirname(pathname); if (!exists(left)) { - version (Windows) - { /* Prevent infinite recursion if left is "d:\" and - * drive d does not exist. - */ - if (left.length >= 3 && left[length - 2] == ':') - throw new FileException(left.idup); - } - mkdirRecurse(left); + version (Windows) + { /* Prevent infinite recursion if left is "d:\" and + * drive d does not exist. + */ + if (left.length >= 3 && left[length - 2] == ':') + throw new FileException(left.idup); + } + mkdirRecurse(left); } mkdir(pathname); } @@ -1573,26 +1576,3 @@ void listdir(in char[] pathname, bool delegate(string filename) callback) listdir(pathname, &listing); } - -/* - * Copyright (C) 2001-2004 by Digital Mars, www.digitalmars.com - * Written by Walter Bright, Christopher E. Miller, Andre Fornacon - * - * 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, 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. - */ - diff --git a/std/format.d b/std/format.d index 65afdacdf..ed50d0234 100644 --- a/std/format.d +++ b/std/format.d @@ -6,8 +6,16 @@ * * Macros: * WIKI = Phobos/StdFormat + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.format; //debug=format; // uncomment to turn on debugging printf's @@ -3018,25 +3026,3 @@ unittest formattedRead(line, "%s %*u %s", &t); assert(t.field[0] == 1 && t.field[1] == 2.125); } - -/* - * Copyright (C) 2004-2006 by Digital Mars, www.digitalmars.com - * Written by Walter Bright and Andrei Alexandrescu - * - * 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, 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. - */ diff --git a/std/functional.d b/std/functional.d index de601ade9..16090acab 100644 --- a/std/functional.d +++ b/std/functional.d @@ -7,33 +7,15 @@ Macros: WIKI = Phobos/StdFunctional -Author: +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu) -$(WEB erdani.org, Andrei Alexandrescu) + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - -/* - * Copyright (C) 2004-2006 by Digital Mars, www.digitalmars.com - * Written by Andrei Alexandrescu, www.erdani.org - * - * 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, 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 std.functional; import std.metastrings, std.stdio, std.traits, std.typecons, std.typetuple; diff --git a/std/getopt.d b/std/getopt.d index e01ce4c7d..2fb12fb39 100644 --- a/std/getopt.d +++ b/std/getopt.d @@ -1,4 +1,3 @@ - // Written in the D programming language. /** @@ -10,45 +9,27 @@ supported in the form of long options introduced by a double dash ("--"). Support for bundling of command line options, as was the case with the more traditional single-letter approach, is provided but not enabled by default. - -Author: - -$(WEB erdani.org, Andrei Alexandrescu) - -Credits: - -This module and its documentation are inspired by Perl's $(WEB -perldoc.perl.org/Getopt/Long.html, Getopt::Long) module. The syntax of -D's $(D getopt) is simpler than its Perl counterpart because $(D -getopt) infers the expected parameter types from the static types of -the passed-in pointers. - Macros: - WIKI = Phobos/StdGetopt +Macros: + +WIKI = Phobos/StdGetopt + +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu) +Credits: This module and its documentation are inspired by Perl's $(WEB + perldoc.perl.org/Getopt/Long.html, Getopt::Long) module. The syntax of + D's $(D getopt) is simpler than its Perl counterpart because $(D + getopt) infers the expected parameter types from the static types of + the passed-in pointers. + + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - -/* Author: - * Andrei Alexandrescu, www.erdani.org - * - * 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, 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 std.getopt; + private import std.string, std.conv, std.traits, std.contracts, std.bitmanip, std.algorithm, std.ctype; diff --git a/std/iterator.d b/std/iterator.d index ea23adbb7..c7d9b095c 100644 --- a/std/iterator.d +++ b/std/iterator.d @@ -5,10 +5,6 @@ This module is a port of a growing fragment of the $(D algorithm) header in Alexander Stepanov's $(LINK2 http://www.sgi.com/tech/stl/,Standard Template Library). -Author: - -$(WEB erdani.org, Andrei Alexandrescu) - Note: For now only iterators for built-in arrays are defined. Built-in @@ -17,31 +13,18 @@ built-in array $(D T[]) is a pointer of type $(D T*). This may change in the future. Macros: + WIKI = Phobos/StdIterator + +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - -/* - * Copyright (C) 2004-2008 by Digital Mars, www.digitalmars.com - * Written by Andrei Alexandrescu, www.erdani.org - * - * 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, 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 std.iterator; /* The iterator-related part below is undocumented and might diff --git a/std/math.d b/std/math.d index 3eb43e637..6a512d446 100644 --- a/std/math.d +++ b/std/math.d @@ -1,4 +1,5 @@ -// Written in the D programming language +// Written in the D programming language. + /** * Elementary mathematical functions. * @@ -9,9 +10,6 @@ * * Unlike C, there is no global 'errno' variable. Consequently, almost all of * these functions are pure nothrow. - * - * Authors: - * Walter Bright, Don Clugston * * Macros: * WIKI = Phobos/StdMath @@ -40,6 +38,16 @@ * GT = > * SQRT = &radix; * HALF = ½ + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright), + * Don Clugston + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ module(system) std.math; @@ -58,7 +66,7 @@ version(LDC) { } version(DigitalMars){ - version=INLINE_YL2X; // x87 has opcodes for these + version=INLINE_YL2X; // x87 has opcodes for these } @@ -1280,9 +1288,9 @@ unittest { pure nothrow real log(real x) { version (INLINE_YL2X) - return yl2x(x, LN2); + return yl2x(x, LN2); else - return core.stdc.math.logl(x); + return core.stdc.math.logl(x); } unittest @@ -1354,9 +1362,9 @@ pure nothrow real log1p(real x) { pure nothrow real log2(real x) { version (INLINE_YL2X) - return yl2x(x, 1); + return yl2x(x, 1); else - return core.stdc.math.log2l(x); + return core.stdc.math.log2l(x); } /***************************************** @@ -1785,7 +1793,7 @@ pure nothrow int isNormal(X)(X x) // doubledouble is normal if the least significant part is normal. return isNormal((cast(double*)&x)[MANTISSA_LSB]); } else { - ushort e = F.EXPMASK & (cast(ushort *)&x)[F.EXPPOS_SHORT]; + ushort e = F.EXPMASK & (cast(ushort *)&x)[F.EXPPOS_SHORT]; return (e != F.EXPMASK && e!=0); } } @@ -3018,10 +3026,10 @@ body ; } } - else - { - static assert(0); - } + else + { + static assert(0); + } } else { @@ -3129,43 +3137,14 @@ alias isInfinity isinf; * translate to a single x87 instruction. */ -pure nothrow real yl2x(real x, real y); // y * log2(x) -pure nothrow real yl2xp1(real x, real y); // y * log2(x + 1) +pure nothrow real yl2x(real x, real y); // y * log2(x) +pure nothrow real yl2xp1(real x, real y); // y * log2(x + 1) unittest { version (INLINE_YL2X) { - assert(yl2x(1024, 1) == 10); - assert(yl2xp1(1023, 1) == 10); + assert(yl2x(1024, 1) == 10); + assert(yl2xp1(1023, 1) == 10); } } - -/* - * Copyright: - * Copyright (c) 2001-2009 by Digital Mars, - * All Rights Reserved, - * http://www.digitalmars.com - * License: - * 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, subject to the following restrictions: - * - * - */ diff --git a/std/md5.d b/std/md5.d index b2eab9200..f50b0d808 100644 --- a/std/md5.d +++ b/std/md5.d @@ -1,4 +1,4 @@ -// Written in the D programming language +// Written in the D programming language. /* md5.d - RSA Data Security, Inc., MD5 message-digest algorithm * Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm. diff --git a/std/metastrings.d b/std/metastrings.d index 6306b0d42..5f6409a57 100644 --- a/std/metastrings.d +++ b/std/metastrings.d @@ -3,15 +3,19 @@ /** Templates with which to do compile-time manipulation of strings. -Authors: $(WEB digitalmars.com, Walter Bright, Digital Mars), Don -Clugston - Macros: - WIKI = Phobos/StdMetastrings -Copyright: - Public Domain - */ + WIKI = Phobos/StdMetastrings +Copyright: Copyright Digital Mars 2007 - 2009. +License: Boost License 1.0. +Authors: $(WEB digitalmars.com, Walter Bright), + Don Clugston + + Copyright Digital Mars 2007 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) + */ module std.metastrings; /** diff --git a/std/mmfile.d b/std/mmfile.d index 682a941c0..d03ef3c2e 100644 --- a/std/mmfile.d +++ b/std/mmfile.d @@ -1,34 +1,20 @@ -// Written in the D programming language - -/* Copyright 2004-2008 by Digital Mars - * Written by Walter Bright and Matthew Wilson - * - * 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: - * - * - 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. - * - Altered source versions must be plainly marked as such, and must not - * be misrepresented as being the original software. - * - This notice may not be removed or altered from any source - * distribution. - * - */ +// Written in the D programming language. /** * Read and write memory mapped files. * Macros: * WIKI=Phobos/StdMmfile + * + * Copyright: Copyright Digital Mars 2004 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright), + * Matthew Wilson + * + * Copyright Digital Mars 2004 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.mmfile; private import std.file; @@ -59,7 +45,7 @@ else version (Posix) { private import core.sys.posix.fcntl; private import core.sys.posix.unistd; - private import core.sys.posix.sys.mman; + private import core.sys.posix.sys.mman; private import core.sys.posix.sys.stat; } else diff --git a/std/numeric.d b/std/numeric.d index 80a99a5a2..f381bdc9d 100644 --- a/std/numeric.d +++ b/std/numeric.d @@ -9,12 +9,18 @@ Macros: WIKI = Phobos/StdNumeric -Authors: +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu), + Don Clugston -$(WEB erdani.org, Andrei Alexandrescu), Don Clugston + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - module std.numeric; + import std.algorithm; import std.array; import std.bitmanip; diff --git a/std/outbuffer.d b/std/outbuffer.d index 20ea9e649..b9a7da6ac 100644 --- a/std/outbuffer.d +++ b/std/outbuffer.d @@ -1,19 +1,20 @@ -// Written in the D programming language +// Written in the D programming language. /** * Boilerplate: - * $(std_boilerplate.html) + * $(std_boilerplate.html) * Macros: - * WIKI = Phobos/StdOutbuffer - * Copyright: - * Copyright (c) 2001-2005 by Digital Mars - * All Rights Reserved - * www.digitalmars.com + * WIKI = Phobos/StdOutbuffer + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - - -// Written by Walter Bright - module std.outbuffer; private @@ -41,13 +42,13 @@ class OutBuffer invariant() { - //printf("this = %p, offset = %x, data.length = %u\n", this, offset, data.length); + //printf("this = %p, offset = %x, data.length = %u\n", this, offset, data.length); assert(offset <= data.length); } this() { - //printf("in OutBuffer constructor\n"); + //printf("in OutBuffer constructor\n"); } /********************************* @@ -66,121 +67,121 @@ class OutBuffer void reserve(uint nbytes) - in - { - assert(offset + nbytes >= offset); - } - out - { - assert(offset + nbytes <= data.length); - } - body - { - //c.stdio.printf("OutBuffer.reserve: length = %d, offset = %d, nbytes = %d\n", data.length, offset, nbytes); - if (data.length < offset + nbytes) - { - data.length = (offset + nbytes) * 2; - GC.clrAttr(data.ptr, GC.BlkAttr.NO_SCAN); - } - } + in + { + assert(offset + nbytes >= offset); + } + out + { + assert(offset + nbytes <= data.length); + } + body + { + //c.stdio.printf("OutBuffer.reserve: length = %d, offset = %d, nbytes = %d\n", data.length, offset, nbytes); + if (data.length < offset + nbytes) + { + data.length = (offset + nbytes) * 2; + GC.clrAttr(data.ptr, GC.BlkAttr.NO_SCAN); + } + } /************************************* * Append data to the internal buffer. */ void write(const(ubyte)[] bytes) - { - reserve(bytes.length); - data[offset .. offset + bytes.length] = bytes; - offset += bytes.length; - } + { + reserve(bytes.length); + data[offset .. offset + bytes.length] = bytes; + offset += bytes.length; + } void write(in wchar[] chars) - { + { write(cast(ubyte[]) chars); - } + } void write(const(dchar)[] chars) - { + { write(cast(ubyte[]) chars); - } + } - void write(ubyte b) /// ditto - { - reserve(ubyte.sizeof); - this.data[offset] = b; - offset += ubyte.sizeof; - } + void write(ubyte b) /// ditto + { + reserve(ubyte.sizeof); + this.data[offset] = b; + offset += ubyte.sizeof; + } - void write(byte b) { write(cast(ubyte)b); } /// ditto - void write(char c) { write(cast(ubyte)c); } /// ditto - void write(dchar c) { write(cast(uint)c); } /// ditto + void write(byte b) { write(cast(ubyte)b); } /// ditto + void write(char c) { write(cast(ubyte)c); } /// ditto + void write(dchar c) { write(cast(uint)c); } /// ditto - void write(ushort w) /// ditto + void write(ushort w) /// ditto { reserve(ushort.sizeof); *cast(ushort *)&data[offset] = w; offset += ushort.sizeof; } - void write(short s) { write(cast(ushort)s); } /// ditto + void write(short s) { write(cast(ushort)s); } /// ditto - void write(wchar c) /// ditto + void write(wchar c) /// ditto { - reserve(wchar.sizeof); - *cast(wchar *)&data[offset] = c; - offset += wchar.sizeof; + reserve(wchar.sizeof); + *cast(wchar *)&data[offset] = c; + offset += wchar.sizeof; } - void write(uint w) /// ditto + void write(uint w) /// ditto { - reserve(uint.sizeof); - *cast(uint *)&data[offset] = w; - offset += uint.sizeof; + reserve(uint.sizeof); + *cast(uint *)&data[offset] = w; + offset += uint.sizeof; } - void write(int i) { write(cast(uint)i); } /// ditto + void write(int i) { write(cast(uint)i); } /// ditto - void write(ulong l) /// ditto + void write(ulong l) /// ditto { - reserve(ulong.sizeof); - *cast(ulong *)&data[offset] = l; - offset += ulong.sizeof; + reserve(ulong.sizeof); + *cast(ulong *)&data[offset] = l; + offset += ulong.sizeof; } - void write(long l) { write(cast(ulong)l); } /// ditto + void write(long l) { write(cast(ulong)l); } /// ditto - void write(float f) /// ditto + void write(float f) /// ditto { - reserve(float.sizeof); - *cast(float *)&data[offset] = f; - offset += float.sizeof; + reserve(float.sizeof); + *cast(float *)&data[offset] = f; + offset += float.sizeof; } - void write(double f) /// ditto + void write(double f) /// ditto { - reserve(double.sizeof); - *cast(double *)&data[offset] = f; - offset += double.sizeof; + reserve(double.sizeof); + *cast(double *)&data[offset] = f; + offset += double.sizeof; } - void write(real f) /// ditto + void write(real f) /// ditto { - reserve(real.sizeof); - *cast(real *)&data[offset] = f; - offset += real.sizeof; + reserve(real.sizeof); + *cast(real *)&data[offset] = f; + offset += real.sizeof; } - void write(in char[] s) /// ditto + void write(in char[] s) /// ditto { write(cast(ubyte[])s); } - // void write(immutable(char)[] s) /// ditto + // void write(immutable(char)[] s) /// ditto // { // write(cast(ubyte[])s); // } - void write(OutBuffer buf) /// ditto + void write(OutBuffer buf) /// ditto { write(buf.toBytes()); } @@ -191,9 +192,9 @@ class OutBuffer void fill0(uint nbytes) { - reserve(nbytes); - data[offset .. offset + nbytes] = 0; - offset += nbytes; + reserve(nbytes); + data[offset .. offset + nbytes] = 0; + offset += nbytes; } /********************************** @@ -203,18 +204,18 @@ class OutBuffer void alignSize(uint alignsize) in { - assert(alignsize && (alignsize & (alignsize - 1)) == 0); + assert(alignsize && (alignsize & (alignsize - 1)) == 0); } out { - assert((offset & (alignsize - 1)) == 0); + assert((offset & (alignsize - 1)) == 0); } body { uint nbytes; - nbytes = offset & (alignsize - 1); - if (nbytes) - fill0(alignsize - nbytes); + nbytes = offset & (alignsize - 1); + if (nbytes) + fill0(alignsize - nbytes); } /**************************************** @@ -223,8 +224,8 @@ class OutBuffer void align2() { - if (offset & 1) - write(cast(byte)0); + if (offset & 1) + write(cast(byte)0); } /**************************************** @@ -233,10 +234,10 @@ class OutBuffer void align4() { - if (offset & 3) - { uint nbytes = (4 - offset) & 3; - fill0(nbytes); - } + if (offset & 3) + { uint nbytes = (4 - offset) & 3; + fill0(nbytes); + } } /************************************** @@ -245,8 +246,8 @@ class OutBuffer override string toString() { - //printf("OutBuffer.toString()\n"); - return cast(string) data[0 .. offset].idup; + //printf("OutBuffer.toString()\n"); + return cast(string) data[0 .. offset].idup; } /***************************************** @@ -255,49 +256,49 @@ class OutBuffer void vprintf(string format, va_list args) { - char[128] buffer; - char* p; - uint psize; - int count; + char[128] buffer; + char* p; + uint psize; + int count; - auto f = toStringz(format); - p = buffer.ptr; - psize = buffer.length; - for (;;) - { - version(Win32) - { - count = _vsnprintf(p,psize,f,args); - if (count != -1) - break; - psize *= 2; - p = cast(char *) alloca(psize); // buffer too small, try again with larger size - } - version(Posix) - { - count = vsnprintf(p,psize,f,args); - if (count == -1) - psize *= 2; - else if (count >= psize) - psize = count + 1; - else - break; - /+ - if (p != buffer) - c.stdlib.free(p); - p = (char *) c.stdlib.malloc(psize); // buffer too small, try again with larger size - +/ - p = cast(char *) alloca(psize); // buffer too small, try again with larger size - } - } - write(cast(ubyte[]) p[0 .. count]); - /+ - version (Posix) - { - if (p != buffer) - c.stdlib.free(p); - } - +/ + auto f = toStringz(format); + p = buffer.ptr; + psize = buffer.length; + for (;;) + { + version(Win32) + { + count = _vsnprintf(p,psize,f,args); + if (count != -1) + break; + psize *= 2; + p = cast(char *) alloca(psize); // buffer too small, try again with larger size + } + version(Posix) + { + count = vsnprintf(p,psize,f,args); + if (count == -1) + psize *= 2; + else if (count >= psize) + psize = count + 1; + else + break; + /+ + if (p != buffer) + c.stdlib.free(p); + p = (char *) c.stdlib.malloc(psize); // buffer too small, try again with larger size + +/ + p = cast(char *) alloca(psize); // buffer too small, try again with larger size + } + } + write(cast(ubyte[]) p[0 .. count]); + /+ + version (Posix) + { + if (p != buffer) + c.stdlib.free(p); + } + +/ } /***************************************** @@ -306,10 +307,10 @@ class OutBuffer void printf(string format, ...) { - va_list ap; - ap = cast(va_list)&format; - ap += format.sizeof; - vprintf(format, ap); + va_list ap; + ap = cast(va_list)&format; + ap += format.sizeof; + vprintf(format, ap); } /***************************************** @@ -318,22 +319,22 @@ class OutBuffer */ void spread(uint index, uint nbytes) - in - { - assert(index <= offset); - } - body - { - reserve(nbytes); + in + { + assert(index <= offset); + } + body + { + reserve(nbytes); - // This is an overlapping copy - should use memmove() - for (uint i = offset; i > index; ) - { - --i; - data[i + nbytes] = data[i]; - } - offset += nbytes; - } + // This is an overlapping copy - should use memmove() + for (uint i = offset; i > index; ) + { + --i; + data[i + nbytes] = data[i]; + } + offset += nbytes; + } } unittest diff --git a/std/path.d b/std/path.d index 717f1bcd5..7fad735be 100644 --- a/std/path.d +++ b/std/path.d @@ -7,20 +7,21 @@ * with a dot, functions like $(D getExt()) will work with it just as * if it was a file. To differentiate these cases, use the std.file * module first (i.e. $(D std.file.isDir())). - * - * Authors: - * - * $(WEB digitalmars.com, Walter Bright), Grzegorz Adam Hankiewicz, -Thomas Kühne, $(WEB erdani.org, Andrei Alexandrescu) * * Macros: * WIKI = Phobos/StdPath - * Copyright: - * Placed into public domain. - * www.digitalmars.com * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright), + * Grzegorz Adam Hankiewicz, Thomas Kühne, + * $(WEB erdani.org, Andrei Alexandrescu) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.path; //debug=path; // uncomment to turn on debugging printf's diff --git a/std/process.d b/std/process.d index 7c53e2230..943278b28 100644 --- a/std/process.d +++ b/std/process.d @@ -1,30 +1,4 @@ -// Written in the D programming language - -/* - * Copyright (C) 2003-2009 by Digital Mars, http://www.digitalmars.com - * Written by Matthew Wilson and Walter Bright - * - * Incorporating idea (for execvpe() on Posix) from Russ Lewis - * - * Updated: 21st August 2004 - * - * 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, 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. - */ +// Written in the D programming language. /** Authors: @@ -35,8 +9,17 @@ Alexandrescu) Macros: WIKI=Phobos/StdProcess -*/ +Copyright: Copyright Digital Mars 2007 - 2009. +License: Boost License 1.0. +Authors: $(WEB digitalmars.com, Walter Bright), + $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Digital Mars 2007 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.process; private import std.c.stdlib; @@ -103,11 +86,11 @@ private void toAStringz(in string[] a, const(char)**az) //{ // int spawnvp(int mode, string pathname, string[] argv) // { -// char** argv_ = cast(char**)alloca((char*).sizeof * (1 + argv.length)); +// char** argv_ = cast(char**)alloca((char*).sizeof * (1 + argv.length)); // -// toAStringz(argv, argv_); +// toAStringz(argv, argv_); // -// return std.c.process.spawnvp(mode, toStringz(pathname), argv_); +// return std.c.process.spawnvp(mode, toStringz(pathname), argv_); // } //} diff --git a/std/random.d b/std/random.d index a15587c14..804be9575 100644 --- a/std/random.d +++ b/std/random.d @@ -1,4 +1,4 @@ -// Written in the D programming language +// Written in the D programming language. /** Facilities for random number generation. The old-style functions @@ -34,23 +34,24 @@ distributions, which skew a generator's output statistical distribution in various ways. So far the uniform distribution for integers and real numbers have been implemented. -Author: - -$(WEB erdani.org, Andrei Alexandrescu) - -Credits: - -The entire random number library architecture is derived from the -excellent $(WEB -open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2461.pdf, C++0X) random -number facility proposed by Jens Maurer and contributed to by -researchers at the Fermi laboratory. - Macros: WIKI = Phobos/StdRandom -*/ + +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu) +Credits: The entire random number library architecture is derived from the + excellent $(WEB open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2461.pdf, C++0X) + random number facility proposed by Jens Maurer and contributed to by + researchers at the Fermi laboratory. + + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.random; import std.algorithm, std.c.time, std.contracts, std.conv, std.date, std.math, @@ -974,8 +975,8 @@ unittest // seed and index are deliberately thread local -private uint seed; // starting seed -private uint index; // ith random number +private uint seed; // starting seed +private uint index; // ith random number /** The random number generator is seeded at program startup with a random @@ -1030,7 +1031,7 @@ deprecated uint rand() loword = seed; hiword = index++; - for (i = 0; i < 4; i++) // loop limit can be 2..20, we choose 4 + for (i = 0; i < 4; i++) // loop limit can be 2..20, we choose 4 { hihold = hiword; // save hiword for later temp = hihold ^ xormix1[i]; // mix up bits of hiword @@ -1075,16 +1076,16 @@ unittest { static uint results[10] = [ - 0x8c0188cb, - 0xb161200c, - 0xfc904ac5, - 0x2702e049, - 0x9705a923, - 0x1c139d89, - 0x346b6d1f, - 0xf8c33e32, - 0xdb9fef76, - 0xa97fcb3f + 0x8c0188cb, + 0xb161200c, + 0xfc904ac5, + 0x2702e049, + 0x9705a923, + 0x1c139d89, + 0x346b6d1f, + 0xf8c33e32, + 0xdb9fef76, + 0xa97fcb3f ]; int i; uint seedsave = seed; @@ -1092,9 +1093,9 @@ unittest rand_seed(1234, 5678); for (i = 0; i < 10; i++) - { uint r = rand(); - //printf("0x%x,\n", rand()); - assert(r == results[i]); + { uint r = rand(); + //printf("0x%x,\n", rand()); + assert(r == results[i]); } seed = seedsave; diff --git a/std/range.d b/std/range.d index f2c75bf0d..fb2eaecc2 100644 --- a/std/range.d +++ b/std/range.d @@ -1,18 +1,25 @@ // Written in the D programming language. + /** This module defines a few useful _range incarnations. Credit for ideas in building this module go to $(WEB fantascienza.net/leonardo/so/, Leonardo Maffi). -Author: - -$(WEB erdani.org, Andrei Alexandrescu) - Macros: -WIKI = Phobos/StdRange -*/ +WIKI = Phobos/StdRange + +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.range; + public import std.array; import std.contracts; import std.traits; @@ -2585,25 +2592,3 @@ version(none) unittest { } } - -/* - * Copyright (C) 2004-2009 by Digital Mars, www.digitalmars.com - * Written by Andrei Alexandrescu, www.erdani.org - * - * 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, 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. - */ diff --git a/std/regex.d b/std/regex.d index 9c2fccd5e..ffefe3ab1 100644 --- a/std/regex.d +++ b/std/regex.d @@ -1,8 +1,7 @@ // Written in the D programming language. +// Regular Expressions. -// Regular Expressions - -/********************************************** +/** $(WEB digitalmars.com/ctg/regular.html, Regular expressions) are a powerful method of string pattern matching. The regular expression language used in this library is the same as that commonly used, @@ -47,17 +46,24 @@ subexpressions, use the empty string instead.))) Any other $ are left as is. -Authors: $(WEB www.digitalmars.com, Walter Bright) and $(WEB -www.erdani.org, Andrei Alexandrescu). - References: $(WEB en.wikipedia.org/wiki/Regular_expressions, Wikipedia) Macros: + WIKI = StdRegex DOLLAR = $ - */ +Copyright: Copyright Digital Mars 2000 - 2009. +License: Boost License 1.0. +Authors: $(WEB digitalmars.com, Walter Bright), + $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Digital Mars 2000 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ /* Escape sequences: @@ -90,7 +96,7 @@ http://www.unicode.org/unicode/reports/tr18/ module std.regex; -//debug = regex; // uncomment to turn on debugging printf's +//debug = regex; // uncomment to turn on debugging printf's import core.stdc.stdio; import core.stdc.stdlib; @@ -178,47 +184,47 @@ private: alias Tuple!(uint, "startIdx", uint, "endIdx") regmatch_t; enum REA { - global = 1, // has the g attribute - ignoreCase = 2, // has the i attribute - multiline = 4, // if treat as multiple lines separated by + global = 1, // has the g attribute + ignoreCase = 2, // has the i attribute + multiline = 4, // if treat as multiple lines separated by // newlines, or as a single line - dotmatchlf = 8, // if . matches \n + dotmatchlf = 8, // if . matches \n } enum uint inf = ~0u; uint re_nsub; // number of parenthesized subexpression matches ubyte attributes; - immutable(ubyte)[] program; // pattern[] compiled into regular + immutable(ubyte)[] program; // pattern[] compiled into regular // expression program // Opcodes enum : ubyte { - REend, // end of program - REchar, // single character - REichar, // single character, case insensitive - REdchar, // single UCS character - REidchar, // single wide character, case insensitive - REanychar, // any character - REanystar, // ".*" - REstring, // string of characters - REistring, // string of characters, case insensitive - REtestbit, // any in bitmap, non-consuming - REbit, // any in the bit map - REnotbit, // any not in the bit map - RErange, // any in the string - REnotrange, // any not in the string - REor, // a | b - REplus, // 1 or more - REstar, // 0 or more - REquest, // 0 or 1 - REnm, // n..m - REnmq, // n..m, non-greedy version - REbol, // beginning of line - REeol, // end of line - REparen, // parenthesized subexpression - REgoto, // goto offset + REend, // end of program + REchar, // single character + REichar, // single character, case insensitive + REdchar, // single UCS character + REidchar, // single wide character, case insensitive + REanychar, // any character + REanystar, // ".*" + REstring, // string of characters + REistring, // string of characters, case insensitive + REtestbit, // any in bitmap, non-consuming + REbit, // any in the bit map + REnotbit, // any not in the bit map + RErange, // any in the string + REnotrange, // any not in the string + REor, // a | b + REplus, // 1 or more + REstar, // 0 or more + REquest, // 0 or 1 + REnm, // n..m + REnmq, // n..m, non-greedy version + REbol, // beginning of line + REeol, // end of line + REparen, // parenthesized subexpression + REgoto, // goto offset REwordboundary, REnotwordboundary, @@ -308,9 +314,9 @@ Returns the number of parenthesized captures switch (c) { - case 'g': att = REA.global; break; - case 'i': att = REA.ignoreCase; break; - case 'm': att = REA.multiline; break; + case 'g': att = REA.global; break; + case 'i': att = REA.ignoreCase; break; + case 'm': att = REA.multiline; break; default: error("unrecognized attribute"); return; @@ -330,7 +336,7 @@ Returns the number of parenthesized captures size_t p = 0; parseRegex(pattern, p, buf); if (p < pattern.length) - { error("unmatched ')'"); + { error("unmatched ')'"); } optimize(buf); program = cast(immutable(ubyte)[]) buf.data; @@ -496,7 +502,7 @@ Returns the number of parenthesized captures m = 1; goto Lnm; - case '{': // {n} {n,} {n,m} + case '{': // {n} {n,} {n,m} p++; if (p == plength || !isdigit(pattern[p])) goto Lerr; @@ -509,8 +515,8 @@ Returns the number of parenthesized captures if (p == plength) goto Lerr; } while (isdigit(pattern[p])); - if (pattern[p] == '}') // {n} - { m = n; + if (pattern[p] == '}') // {n} + { m = n; goto Lnm; } if (pattern[p] != ',') @@ -518,13 +524,13 @@ Returns the number of parenthesized captures p++; if (p == plength) goto Lerr; - if (pattern[p] == /*{*/ '}') // {n,} - { m = inf; + if (pattern[p] == /*{*/ '}') // {n,} + { m = inf; goto Lnm; } if (!isdigit(pattern[p])) goto Lerr; - m = 0; // {n,m} + m = 0; // {n,m} do { // BUG: handle overflow @@ -541,7 +547,7 @@ Returns the number of parenthesized captures p++; op = REnm; if (p < plength && pattern[p] == '?') - { op = REnmq; // minimal munch version + { op = REnmq; // minimal munch version p++; } len = buf.offset - offset; @@ -584,7 +590,7 @@ Returns the number of parenthesized captures p++; buf.write(REparen); offset = buf.offset; - buf.write(cast(uint)0); // reserve space for length + buf.write(cast(uint)0); // reserve space for length buf.write(re_nsub); re_nsub++; parseRegex(pattern, p, buf); @@ -627,14 +633,14 @@ Returns the number of parenthesized captures c = pattern[p]; switch (c) { - case 'b': op = REwordboundary; goto Lop; + case 'b': op = REwordboundary; goto Lop; case 'B': op = REnotwordboundary; goto Lop; - case 'd': op = REdigit; goto Lop; - case 'D': op = REnotdigit; goto Lop; - case 's': op = REspace; goto Lop; - case 'S': op = REnotspace; goto Lop; - case 'w': op = REword; goto Lop; - case 'W': op = REnotword; goto Lop; + case 'd': op = REdigit; goto Lop; + case 'D': op = REnotdigit; goto Lop; + case 's': op = REspace; goto Lop; + case 'S': op = REnotspace; goto Lop; + case 'w': op = REword; goto Lop; + case 'W': op = REnotword; goto Lop; Lop: buf.write(op); @@ -694,7 +700,7 @@ Returns the number of parenthesized captures int len; for (; q < pattern.length; ++q) - { auto qc = pattern[q]; + { auto qc = pattern[q]; switch (qc) { @@ -707,11 +713,11 @@ Returns the number of parenthesized captures q--; break; - case '(': case ')': + case '(': case ')': case '|': - case '[': case ']': - case '.': case '^': - case '$': case '\\': + case '[': case ']': + case '.': case '^': + case '$': case '\\': case '}': break; @@ -780,7 +786,7 @@ Returns the number of parenthesized captures maxc = u; uint b = u / 8; if (b >= maxb) - { uint u2; + { uint u2; u2 = base ? base - &buf.data[0] : 0; buf.fill0(b - maxb + 1); @@ -821,7 +827,7 @@ Returns the number of parenthesized captures } buf.write(op); offset = buf.offset; - buf.write(cast(uint)0); // reserve space for length + buf.write(cast(uint)0); // reserve space for length buf.reserve(128 / 8); auto r = new Range(buf); if (op == REnotbit) @@ -1030,7 +1036,7 @@ Returns the number of parenthesized captures return 1; case REanychar: - return 0; // no point + return 0; // no point case REstring: len = *cast(uint *)&prog[i + 1] / E.sizeof; @@ -1185,15 +1191,15 @@ Returns the number of parenthesized captures int i; E tc; - c = pattern[p]; // none of the cases are multibyte + c = pattern[p]; // none of the cases are multibyte switch (c) { - case 'b': c = '\b'; break; - case 'f': c = '\f'; break; - case 'n': c = '\n'; break; - case 'r': c = '\r'; break; - case 't': c = '\t'; break; - case 'v': c = '\v'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; // BUG: Perl does \a and \e too, should we? @@ -1232,7 +1238,7 @@ Returns the number of parenthesized captures // Treat overflow as if last // digit was not an octal digit if (c >= 0xFF) - { c >>= 3; + { c >>= 3; return c; } } @@ -1255,7 +1261,7 @@ Returns the number of parenthesized captures c = c * 16 + (tc - 'a' + 10); else if ('A' <= tc && tc <= 'F') c = c * 16 + (tc - 'A' + 10); - else if (i == 0) // if no hex digits after \x + else if (i == 0) // if no hex digits after \x { // Not a valid \xXX sequence return 'x'; @@ -1533,8 +1539,8 @@ Get or set the engine of the match. public Regex engine; // the string to search Range input; - size_t src; // current source index in input[] - size_t src_start; // starting index for match in input[] + size_t src; // current source index in input[] + size_t src_start; // starting index for match in input[] regmatch_t[] pmatch; // array [engine.re_nsub + 1] /* @@ -1781,13 +1787,13 @@ Returns $(D hit) (converted to $(D string) if necessary). /+ // Optimize by using std.string.replace if possible - Dave Fladebo auto slice = result[offset + so .. offset + eo]; - if (attributes & REA.global && // global, so replace all - !(attributes & REA.ignoreCase) && // not ignoring case - !(attributes & REA.multiline) && // not multiline - pattern == slice && // simple pattern + if (attributes & REA.global && // global, so replace all + !(attributes & REA.ignoreCase) && // not ignoring case + !(attributes & REA.multiline) && // not multiline + pattern == slice && // simple pattern // (exact match, no // special characters) - format == replacement) // simple format, not $ formats + format == replacement) // simple format, not $ formats { debug(regex) printf("pattern: %.*s, slice: %.*s, format: %.*s" @@ -1805,7 +1811,7 @@ Returns $(D hit) (converted to $(D string) if necessary). offset += replacement.length - (eo - so); if (lastindex == eo) - lastindex++; // always consume some source + lastindex++; // always consume some source else lastindex = eo; } @@ -1850,7 +1856,7 @@ Returns $(D hit) (converted to $(D string) if necessary). { pmatch[0].startIdx = pmatch[0].startIdx.max; pmatch[0].endIdx = pmatch[0].endIdx.max; - return 0; // fail + return 0; // fail } //engine.printProgram(engine.program); pmatch[0].startIdx = 0; @@ -1871,13 +1877,13 @@ Returns $(D hit) (converted to $(D string) if necessary). { if (startindex == input.length) { - break; // no match + break; // no match } if (input[startindex] != firstc) { startindex++; - if (!chr(startindex, firstc)) // 1st char not found - break; // no match + if (!chr(startindex, firstc)) // 1st char not found + break; // no match } } foreach (i; 0 .. engine.re_nsub + 1) @@ -1899,7 +1905,7 @@ Returns $(D hit) (converted to $(D string) if necessary). if (!(engine.attributes & engine.REA.multiline)) break; // Scan for the popFront \n if (!chr(startindex, '\n')) - break; // no match if '\n' not found + break; // no match if '\n' not found } if (startindex == input.length) break; @@ -1967,8 +1973,8 @@ Returns $(D hit) (converted to $(D string) if necessary). /* ************************************************* * Match input against a section of the program[]. * Returns: - * 1 if successful match - * 0 no match + * 1 if successful match + * 0 no match */ private bool trymatch(uint pc, uint pcend) @@ -1990,7 +1996,7 @@ Returns $(D hit) (converted to $(D string) if necessary). regmatch_t *psave = null; for (;;) { - if (pc == pcend) // if done matching + if (pc == pcend) // if done matching { debug(regex) printf("\tprogend\n"); return true; } @@ -2218,7 +2224,7 @@ Returns $(D hit) (converted to $(D string) if necessary). if (trymatch(pop, pcend)) { if (pcend != engine.program.length) - { int s; + { int s; s = src; if (trymatch(pcend, engine.program.length)) @@ -2242,11 +2248,11 @@ Returns $(D hit) (converted to $(D string) if necessary). src = ss; } else - { debug(regex) printf("\tfirst operand matched\n"); + { debug(regex) printf("\tfirst operand matched\n"); return 1; } } - pc = pop + len; // proceed with 2nd branch + pc = pop + len; // proceed with 2nd branch break; case engine.REgoto: @@ -2277,7 +2283,7 @@ Returns $(D hit) (converted to $(D string) if necessary). // BUG: should we save/restore pmatch[]? if (trymatch(pc, engine.program.length)) { - src = s1; // no match + src = s1; // no match break; } } @@ -2306,7 +2312,7 @@ Returns $(D hit) (converted to $(D string) if necessary). psave = cast(regmatch_t *)alloca( (engine.re_nsub + 1) * regmatch_t.sizeof); } - if (engine.program[pc] == engine.REnmq) // if minimal munch + if (engine.program[pc] == engine.REnmq) // if minimal munch { for (; count < m; count++) { int s1; @@ -2337,7 +2343,7 @@ Returns $(D hit) (converted to $(D string) if necessary). } } } - else // maximal munch + else // maximal munch { for (; count < m; count++) { @@ -2365,7 +2371,7 @@ Returns $(D hit) (converted to $(D string) if necessary). src = s1; if (trymatch(pop + len, engine.program.length)) { - src = s1; // no match + src = s1; // no match memcpy(pmatch.ptr, psave, (engine.re_nsub + 1) * regmatch_t.sizeof); break; @@ -2396,7 +2402,7 @@ Returns $(D hit) (converted to $(D string) if necessary). case engine.REend: debug(regex) printf("\tREend\n"); - return 1; // successful match + return 1; // successful match case engine.REwordboundary: debug(regex) printf("\tREwordboundary\n"); @@ -2628,22 +2634,22 @@ and, using the format string, generate and return a new string. /* *********************************** * Like replace(char[] format), but uses old style formatting: - - - - - - - -
Format - Description -
& - replace with the match -
\n - replace with the nth parenthesized match, n is 1..9 -
\c - replace with char c. -
+ + + + + + + +
Format + Description +
& + replace with the match +
\n + replace with the nth parenthesized match, n is 1..9 +
\c + replace with char c. +
*/ deprecated private string replaceOld(string format) @@ -2840,9 +2846,9 @@ Range replace(alias fun, Range, Regex) /+ // Optimize by using std.string.replace if possible - Dave Fladebo auto slice = result[offset + so .. offset + eo]; - if (rx.attributes & rx.REA.global && // global, so replace all - !(rx.attributes & rx.REA.ignoreCase) && // not ignoring case - !(rx.attributes & rx.REA.multiline) && // not multiline + if (rx.attributes & rx.REA.global && // global, so replace all + !(rx.attributes & rx.REA.ignoreCase) && // not ignoring case + !(rx.attributes & rx.REA.multiline) && // not multiline pattern == slice) // simple pattern (exact match, no // special characters) { @@ -2861,7 +2867,7 @@ Range replace(alias fun, Range, Regex) offset += replacement.length - (eo - so); if (lastindex == eo) - lastindex++; // always consume some source + lastindex++; // always consume some source else lastindex = eo; } @@ -3073,175 +3079,175 @@ unittest }; static TestVectors tv[] = [ - { "(a)\\1", "abaab","y", "&", "aa" }, - { "abc", "abc", "y", "&", "abc" }, - { "abc", "xbc", "n", "-", "-" }, - { "abc", "axc", "n", "-", "-" }, - { "abc", "abx", "n", "-", "-" }, - { "abc", "xabcy","y", "&", "abc" }, - { "abc", "ababc","y", "&", "abc" }, - { "ab*c", "abc", "y", "&", "abc" }, - { "ab*bc", "abc", "y", "&", "abc" }, - { "ab*bc", "abbc", "y", "&", "abbc" }, - { "ab*bc", "abbbbc","y", "&", "abbbbc" }, - { "ab+bc", "abbc", "y", "&", "abbc" }, - { "ab+bc", "abc", "n", "-", "-" }, - { "ab+bc", "abq", "n", "-", "-" }, - { "ab+bc", "abbbbc","y", "&", "abbbbc" }, - { "ab?bc", "abbc", "y", "&", "abbc" }, - { "ab?bc", "abc", "y", "&", "abc" }, - { "ab?bc", "abbbbc","n", "-", "-" }, - { "ab?c", "abc", "y", "&", "abc" }, - { "^abc$", "abc", "y", "&", "abc" }, - { "^abc$", "abcc", "n", "-", "-" }, - { "^abc", "abcc", "y", "&", "abc" }, - { "^abc$", "aabc", "n", "-", "-" }, - { "abc$", "aabc", "y", "&", "abc" }, - { "^", "abc", "y", "&", "" }, - { "$", "abc", "y", "&", "" }, - { "a.c", "abc", "y", "&", "abc" }, - { "a.c", "axc", "y", "&", "axc" }, - { "a.*c", "axyzc","y", "&", "axyzc" }, - { "a.*c", "axyzd","n", "-", "-" }, - { "a[bc]d", "abc", "n", "-", "-" }, - { "a[bc]d", "abd", "y", "&", "abd" }, - { "a[b-d]e", "abd", "n", "-", "-" }, - { "a[b-d]e", "ace", "y", "&", "ace" }, - { "a[b-d]", "aac", "y", "&", "ac" }, - { "a[-b]", "a-", "y", "&", "a-" }, - { "a[b-]", "a-", "y", "&", "a-" }, - { "a[b-a]", "-", "c", "-", "-" }, - { "a[]b", "-", "c", "-", "-" }, - { "a[", "-", "c", "-", "-" }, - { "a]", "a]", "y", "&", "a]" }, - { "a[]]b", "a]b", "y", "&", "a]b" }, - { "a[^bc]d", "aed", "y", "&", "aed" }, - { "a[^bc]d", "abd", "n", "-", "-" }, - { "a[^-b]c", "adc", "y", "&", "adc" }, - { "a[^-b]c", "a-c", "n", "-", "-" }, - { "a[^]b]c", "a]c", "n", "-", "-" }, - { "a[^]b]c", "adc", "y", "&", "adc" }, - { "ab|cd", "abc", "y", "&", "ab" }, - { "ab|cd", "abcd", "y", "&", "ab" }, - { "()ef", "def", "y", "&-\\1", "ef-" }, -//{ "()*", "-", "c", "-", "-" }, - { "()*", "-", "y", "-", "-" }, - { "*a", "-", "c", "-", "-" }, -//{ "^*", "-", "c", "-", "-" }, - { "^*", "-", "y", "-", "-" }, -//{ "$*", "-", "c", "-", "-" }, - { "$*", "-", "y", "-", "-" }, - { "(*)b", "-", "c", "-", "-" }, - { "$b", "b", "n", "-", "-" }, - { "a\\", "-", "c", "-", "-" }, - { "a\\(b", "a(b", "y", "&-\\1", "a(b-" }, - { "a\\(*b", "ab", "y", "&", "ab" }, - { "a\\(*b", "a((b", "y", "&", "a((b" }, - { "a\\\\b", "a\\b", "y", "&", "a\\b" }, - { "abc)", "-", "c", "-", "-" }, - { "(abc", "-", "c", "-", "-" }, - { "((a))", "abc", "y", "&-\\1-\\2", "a-a-a" }, - { "(a)b(c)", "abc", "y", "&-\\1-\\2", "abc-a-c" }, - { "a+b+c", "aabbabc","y", "&", "abc" }, - { "a**", "-", "c", "-", "-" }, -//{ "a*?", "-", "c", "-", "-" }, - { "a*?a", "aa", "y", "&", "a" }, -//{ "(a*)*", "-", "c", "-", "-" }, - { "(a*)*", "aaa", "y", "-", "-" }, -//{ "(a*)+", "-", "c", "-", "-" }, - { "(a*)+", "aaa", "y", "-", "-" }, -//{ "(a|)*", "-", "c", "-", "-" }, - { "(a|)*", "-", "y", "-", "-" }, -//{ "(a*|b)*", "-", "c", "-", "-" }, - { "(a*|b)*", "aabb", "y", "-", "-" }, - { "(a|b)*", "ab", "y", "&-\\1", "ab-b" }, - { "(a+|b)*", "ab", "y", "&-\\1", "ab-b" }, - { "(a+|b)+", "ab", "y", "&-\\1", "ab-b" }, - { "(a+|b)?", "ab", "y", "&-\\1", "a-a" }, - { "[^ab]*", "cde", "y", "&", "cde" }, -//{ "(^)*", "-", "c", "-", "-" }, - { "(^)*", "-", "y", "-", "-" }, -//{ "(ab|)*", "-", "c", "-", "-" }, - { "(ab|)*", "-", "y", "-", "-" }, - { ")(", "-", "c", "-", "-" }, - { "", "abc", "y", "&", "" }, - { "abc", "", "n", "-", "-" }, - { "a*", "", "y", "&", "" }, - { "([abc])*d", "abbbcd", "y", "&-\\1", "abbbcd-c" }, - { "([abc])*bcd", "abcd", "y", "&-\\1", "abcd-a" }, - { "a|b|c|d|e", "e", "y", "&", "e" }, - { "(a|b|c|d|e)f", "ef", "y", "&-\\1", "ef-e" }, -//{ "((a*|b))*", "-", "c", "-", "-" }, - { "((a*|b))*", "aabb", "y", "-", "-" }, - { "abcd*efg", "abcdefg", "y", "&", "abcdefg" }, - { "ab*", "xabyabbbz", "y", "&", "ab" }, - { "ab*", "xayabbbz", "y", "&", "a" }, - { "(ab|cd)e", "abcde", "y", "&-\\1", "cde-cd" }, - { "[abhgefdc]ij", "hij", "y", "&", "hij" }, - { "^(ab|cd)e", "abcde", "n", "x\\1y", "xy" }, - { "(abc|)ef", "abcdef", "y", "&-\\1", "ef-" }, - { "(a|b)c*d", "abcd", "y", "&-\\1", "bcd-b" }, - { "(ab|ab*)bc", "abc", "y", "&-\\1", "abc-a" }, - { "a([bc]*)c*", "abc", "y", "&-\\1", "abc-bc" }, - { "a([bc]*)(c*d)", "abcd", "y", "&-\\1-\\2", "abcd-bc-d" }, - { "a([bc]+)(c*d)", "abcd", "y", "&-\\1-\\2", "abcd-bc-d" }, - { "a([bc]*)(c+d)", "abcd", "y", "&-\\1-\\2", "abcd-b-cd" }, - { "a[bcd]*dcdcde", "adcdcde", "y", "&", "adcdcde" }, - { "a[bcd]+dcdcde", "adcdcde", "n", "-", "-" }, - { "(ab|a)b*c", "abc", "y", "&-\\1", "abc-ab" }, - { "((a)(b)c)(d)", "abcd", "y", "\\1-\\2-\\3-\\4", "abc-a-b-d" }, - { "[a-zA-Z_][a-zA-Z0-9_]*", "alpha", "y", "&", "alpha" }, - { "^a(bc+|b[eh])g|.h$", "abh", "y", "&-\\1", "bh-" }, - { "(bc+d$|ef*g.|h?i(j|k))", "effgz", "y", "&-\\1-\\2", "effgz-effgz-" }, - { "(bc+d$|ef*g.|h?i(j|k))", "ij", "y", "&-\\1-\\2", "ij-ij-j" }, - { "(bc+d$|ef*g.|h?i(j|k))", "effg", "n", "-", "-" }, - { "(bc+d$|ef*g.|h?i(j|k))", "bcdd", "n", "-", "-" }, - { "(bc+d$|ef*g.|h?i(j|k))", "reffgz", "y", "&-\\1-\\2", "effgz-effgz-" }, -//{ "((((((((((a))))))))))", "-", "c", "-", "-" }, - { "(((((((((a)))))))))", "a", "y", "&", "a" }, - { "multiple words of text", "uh-uh", "n", "-", "-" }, - { "multiple words", "multiple words, yeah", "y", "&", "multiple words" }, - { "(.*)c(.*)", "abcde", "y", "&-\\1-\\2", "abcde-ab-de" }, - { "\\((.*), (.*)\\)", "(a, b)", "y", "(\\2, \\1)", "(b, a)" }, - { "abcd", "abcd", "y", "&-\\&-\\\\&", "abcd-&-\\abcd" }, - { "a(bc)d", "abcd", "y", "\\1-\\\\1-\\\\\\1", "bc-\\1-\\bc" }, - { "[k]", "ab", "n", "-", "-" }, - { "[ -~]*", "abc", "y", "&", "abc" }, - { "[ -~ -~]*", "abc", "y", "&", "abc" }, - { "[ -~ -~ -~]*", "abc", "y", "&", "abc" }, - { "[ -~ -~ -~ -~]*", "abc", "y", "&", "abc" }, - { "[ -~ -~ -~ -~ -~]*", "abc", "y", "&", "abc" }, - { "[ -~ -~ -~ -~ -~ -~]*", "abc", "y", "&", "abc" }, - { "[ -~ -~ -~ -~ -~ -~ -~]*", "abc", "y", "&", "abc" }, - { "a{2}", "candy", "n", "", "" }, - { "a{2}", "caandy", "y", "&", "aa" }, - { "a{2}", "caaandy", "y", "&", "aa" }, - { "a{2,}", "candy", "n", "", "" }, - { "a{2,}", "caandy", "y", "&", "aa" }, - { "a{2,}", "caaaaaandy", "y", "&", "aaaaaa" }, - { "a{1,3}", "cndy", "n", "", "" }, - { "a{1,3}", "candy", "y", "&", "a" }, - { "a{1,3}", "caandy", "y", "&", "aa" }, - { "a{1,3}", "caaaaaandy", "y", "&", "aaa" }, - { "e?le?", "angel", "y", "&", "el" }, - { "e?le?", "angle", "y", "&", "le" }, - { "\\bn\\w", "noonday", "y", "&", "no" }, - { "\\wy\\b", "possibly yesterday", "y", "&", "ly" }, - { "\\w\\Bn", "noonday", "y", "&", "on" }, - { "y\\B\\w", "possibly yesterday", "y", "&", "ye" }, - { "\\cJ", "abc\ndef", "y", "&", "\n" }, - { "\\d", "B2 is", "y", "&", "2" }, - { "\\D", "B2 is", "y", "&", "B" }, - { "\\s\\w*", "foo bar", "y", "&", " bar" }, - { "\\S\\w*", "foo bar", "y", "&", "foo" }, - { "abc", "ababc", "y", "&", "abc" }, - { "apple(,)\\sorange\\1", "apple, orange, cherry, peach", "y", "&", "apple, orange," }, - { "(\\w+)\\s(\\w+)", "John Smith", "y", "\\2, \\1", "Smith, John" }, - { "\\n\\f\\r\\t\\v", "abc\n\f\r\t\vdef", "y", "&", "\n\f\r\t\v" }, - { ".*c", "abcde", "y", "&", "abc" }, + { "(a)\\1", "abaab","y", "&", "aa" }, + { "abc", "abc", "y", "&", "abc" }, + { "abc", "xbc", "n", "-", "-" }, + { "abc", "axc", "n", "-", "-" }, + { "abc", "abx", "n", "-", "-" }, + { "abc", "xabcy","y", "&", "abc" }, + { "abc", "ababc","y", "&", "abc" }, + { "ab*c", "abc", "y", "&", "abc" }, + { "ab*bc", "abc", "y", "&", "abc" }, + { "ab*bc", "abbc", "y", "&", "abbc" }, + { "ab*bc", "abbbbc","y", "&", "abbbbc" }, + { "ab+bc", "abbc", "y", "&", "abbc" }, + { "ab+bc", "abc", "n", "-", "-" }, + { "ab+bc", "abq", "n", "-", "-" }, + { "ab+bc", "abbbbc","y", "&", "abbbbc" }, + { "ab?bc", "abbc", "y", "&", "abbc" }, + { "ab?bc", "abc", "y", "&", "abc" }, + { "ab?bc", "abbbbc","n", "-", "-" }, + { "ab?c", "abc", "y", "&", "abc" }, + { "^abc$", "abc", "y", "&", "abc" }, + { "^abc$", "abcc", "n", "-", "-" }, + { "^abc", "abcc", "y", "&", "abc" }, + { "^abc$", "aabc", "n", "-", "-" }, + { "abc$", "aabc", "y", "&", "abc" }, + { "^", "abc", "y", "&", "" }, + { "$", "abc", "y", "&", "" }, + { "a.c", "abc", "y", "&", "abc" }, + { "a.c", "axc", "y", "&", "axc" }, + { "a.*c", "axyzc","y", "&", "axyzc" }, + { "a.*c", "axyzd","n", "-", "-" }, + { "a[bc]d", "abc", "n", "-", "-" }, + { "a[bc]d", "abd", "y", "&", "abd" }, + { "a[b-d]e", "abd", "n", "-", "-" }, + { "a[b-d]e", "ace", "y", "&", "ace" }, + { "a[b-d]", "aac", "y", "&", "ac" }, + { "a[-b]", "a-", "y", "&", "a-" }, + { "a[b-]", "a-", "y", "&", "a-" }, + { "a[b-a]", "-", "c", "-", "-" }, + { "a[]b", "-", "c", "-", "-" }, + { "a[", "-", "c", "-", "-" }, + { "a]", "a]", "y", "&", "a]" }, + { "a[]]b", "a]b", "y", "&", "a]b" }, + { "a[^bc]d", "aed", "y", "&", "aed" }, + { "a[^bc]d", "abd", "n", "-", "-" }, + { "a[^-b]c", "adc", "y", "&", "adc" }, + { "a[^-b]c", "a-c", "n", "-", "-" }, + { "a[^]b]c", "a]c", "n", "-", "-" }, + { "a[^]b]c", "adc", "y", "&", "adc" }, + { "ab|cd", "abc", "y", "&", "ab" }, + { "ab|cd", "abcd", "y", "&", "ab" }, + { "()ef", "def", "y", "&-\\1", "ef-" }, +//{ "()*", "-", "c", "-", "-" }, + { "()*", "-", "y", "-", "-" }, + { "*a", "-", "c", "-", "-" }, +//{ "^*", "-", "c", "-", "-" }, + { "^*", "-", "y", "-", "-" }, +//{ "$*", "-", "c", "-", "-" }, + { "$*", "-", "y", "-", "-" }, + { "(*)b", "-", "c", "-", "-" }, + { "$b", "b", "n", "-", "-" }, + { "a\\", "-", "c", "-", "-" }, + { "a\\(b", "a(b", "y", "&-\\1", "a(b-" }, + { "a\\(*b", "ab", "y", "&", "ab" }, + { "a\\(*b", "a((b", "y", "&", "a((b" }, + { "a\\\\b", "a\\b", "y", "&", "a\\b" }, + { "abc)", "-", "c", "-", "-" }, + { "(abc", "-", "c", "-", "-" }, + { "((a))", "abc", "y", "&-\\1-\\2", "a-a-a" }, + { "(a)b(c)", "abc", "y", "&-\\1-\\2", "abc-a-c" }, + { "a+b+c", "aabbabc","y", "&", "abc" }, + { "a**", "-", "c", "-", "-" }, +//{ "a*?", "-", "c", "-", "-" }, + { "a*?a", "aa", "y", "&", "a" }, +//{ "(a*)*", "-", "c", "-", "-" }, + { "(a*)*", "aaa", "y", "-", "-" }, +//{ "(a*)+", "-", "c", "-", "-" }, + { "(a*)+", "aaa", "y", "-", "-" }, +//{ "(a|)*", "-", "c", "-", "-" }, + { "(a|)*", "-", "y", "-", "-" }, +//{ "(a*|b)*", "-", "c", "-", "-" }, + { "(a*|b)*", "aabb", "y", "-", "-" }, + { "(a|b)*", "ab", "y", "&-\\1", "ab-b" }, + { "(a+|b)*", "ab", "y", "&-\\1", "ab-b" }, + { "(a+|b)+", "ab", "y", "&-\\1", "ab-b" }, + { "(a+|b)?", "ab", "y", "&-\\1", "a-a" }, + { "[^ab]*", "cde", "y", "&", "cde" }, +//{ "(^)*", "-", "c", "-", "-" }, + { "(^)*", "-", "y", "-", "-" }, +//{ "(ab|)*", "-", "c", "-", "-" }, + { "(ab|)*", "-", "y", "-", "-" }, + { ")(", "-", "c", "-", "-" }, + { "", "abc", "y", "&", "" }, + { "abc", "", "n", "-", "-" }, + { "a*", "", "y", "&", "" }, + { "([abc])*d", "abbbcd", "y", "&-\\1", "abbbcd-c" }, + { "([abc])*bcd", "abcd", "y", "&-\\1", "abcd-a" }, + { "a|b|c|d|e", "e", "y", "&", "e" }, + { "(a|b|c|d|e)f", "ef", "y", "&-\\1", "ef-e" }, +//{ "((a*|b))*", "-", "c", "-", "-" }, + { "((a*|b))*", "aabb", "y", "-", "-" }, + { "abcd*efg", "abcdefg", "y", "&", "abcdefg" }, + { "ab*", "xabyabbbz", "y", "&", "ab" }, + { "ab*", "xayabbbz", "y", "&", "a" }, + { "(ab|cd)e", "abcde", "y", "&-\\1", "cde-cd" }, + { "[abhgefdc]ij", "hij", "y", "&", "hij" }, + { "^(ab|cd)e", "abcde", "n", "x\\1y", "xy" }, + { "(abc|)ef", "abcdef", "y", "&-\\1", "ef-" }, + { "(a|b)c*d", "abcd", "y", "&-\\1", "bcd-b" }, + { "(ab|ab*)bc", "abc", "y", "&-\\1", "abc-a" }, + { "a([bc]*)c*", "abc", "y", "&-\\1", "abc-bc" }, + { "a([bc]*)(c*d)", "abcd", "y", "&-\\1-\\2", "abcd-bc-d" }, + { "a([bc]+)(c*d)", "abcd", "y", "&-\\1-\\2", "abcd-bc-d" }, + { "a([bc]*)(c+d)", "abcd", "y", "&-\\1-\\2", "abcd-b-cd" }, + { "a[bcd]*dcdcde", "adcdcde", "y", "&", "adcdcde" }, + { "a[bcd]+dcdcde", "adcdcde", "n", "-", "-" }, + { "(ab|a)b*c", "abc", "y", "&-\\1", "abc-ab" }, + { "((a)(b)c)(d)", "abcd", "y", "\\1-\\2-\\3-\\4", "abc-a-b-d" }, + { "[a-zA-Z_][a-zA-Z0-9_]*", "alpha", "y", "&", "alpha" }, + { "^a(bc+|b[eh])g|.h$", "abh", "y", "&-\\1", "bh-" }, + { "(bc+d$|ef*g.|h?i(j|k))", "effgz", "y", "&-\\1-\\2", "effgz-effgz-" }, + { "(bc+d$|ef*g.|h?i(j|k))", "ij", "y", "&-\\1-\\2", "ij-ij-j" }, + { "(bc+d$|ef*g.|h?i(j|k))", "effg", "n", "-", "-" }, + { "(bc+d$|ef*g.|h?i(j|k))", "bcdd", "n", "-", "-" }, + { "(bc+d$|ef*g.|h?i(j|k))", "reffgz", "y", "&-\\1-\\2", "effgz-effgz-" }, +//{ "((((((((((a))))))))))", "-", "c", "-", "-" }, + { "(((((((((a)))))))))", "a", "y", "&", "a" }, + { "multiple words of text", "uh-uh", "n", "-", "-" }, + { "multiple words", "multiple words, yeah", "y", "&", "multiple words" }, + { "(.*)c(.*)", "abcde", "y", "&-\\1-\\2", "abcde-ab-de" }, + { "\\((.*), (.*)\\)", "(a, b)", "y", "(\\2, \\1)", "(b, a)" }, + { "abcd", "abcd", "y", "&-\\&-\\\\&", "abcd-&-\\abcd" }, + { "a(bc)d", "abcd", "y", "\\1-\\\\1-\\\\\\1", "bc-\\1-\\bc" }, + { "[k]", "ab", "n", "-", "-" }, + { "[ -~]*", "abc", "y", "&", "abc" }, + { "[ -~ -~]*", "abc", "y", "&", "abc" }, + { "[ -~ -~ -~]*", "abc", "y", "&", "abc" }, + { "[ -~ -~ -~ -~]*", "abc", "y", "&", "abc" }, + { "[ -~ -~ -~ -~ -~]*", "abc", "y", "&", "abc" }, + { "[ -~ -~ -~ -~ -~ -~]*", "abc", "y", "&", "abc" }, + { "[ -~ -~ -~ -~ -~ -~ -~]*", "abc", "y", "&", "abc" }, + { "a{2}", "candy", "n", "", "" }, + { "a{2}", "caandy", "y", "&", "aa" }, + { "a{2}", "caaandy", "y", "&", "aa" }, + { "a{2,}", "candy", "n", "", "" }, + { "a{2,}", "caandy", "y", "&", "aa" }, + { "a{2,}", "caaaaaandy", "y", "&", "aaaaaa" }, + { "a{1,3}", "cndy", "n", "", "" }, + { "a{1,3}", "candy", "y", "&", "a" }, + { "a{1,3}", "caandy", "y", "&", "aa" }, + { "a{1,3}", "caaaaaandy", "y", "&", "aaa" }, + { "e?le?", "angel", "y", "&", "el" }, + { "e?le?", "angle", "y", "&", "le" }, + { "\\bn\\w", "noonday", "y", "&", "no" }, + { "\\wy\\b", "possibly yesterday", "y", "&", "ly" }, + { "\\w\\Bn", "noonday", "y", "&", "on" }, + { "y\\B\\w", "possibly yesterday", "y", "&", "ye" }, + { "\\cJ", "abc\ndef", "y", "&", "\n" }, + { "\\d", "B2 is", "y", "&", "2" }, + { "\\D", "B2 is", "y", "&", "B" }, + { "\\s\\w*", "foo bar", "y", "&", " bar" }, + { "\\S\\w*", "foo bar", "y", "&", "foo" }, + { "abc", "ababc", "y", "&", "abc" }, + { "apple(,)\\sorange\\1", "apple, orange, cherry, peach", "y", "&", "apple, orange," }, + { "(\\w+)\\s(\\w+)", "John Smith", "y", "\\2, \\1", "Smith, John" }, + { "\\n\\f\\r\\t\\v", "abc\n\f\r\t\vdef", "y", "&", "\n\f\r\t\v" }, + { ".*c", "abcde", "y", "&", "abc" }, { "^\\w+((;|=)\\w+)+$", "some=host=tld", "y", "&-\\1-\\2", "some=host=tld-=tld-=" }, { "^\\w+((\\.|-)\\w+)+$", "some.host.tld", "y", "&-\\1-\\2", "some.host.tld-.tld-." }, - { "q(a|b)*q", "xxqababqyy", "y", "&-\\1", "qababq-b" }, + { "q(a|b)*q", "xxqababqyy", "y", "&-\\1", "qababq-b" }, { "^(a)(b){0,1}(c*)", "abcc", "y", "\\1 \\2 \\3", "a b cc" }, { "^(a)((b){0,1})(c*)", "abcc", "y", "\\1 \\2 \\3", "a b b" }, diff --git a/std/regexp.d b/std/regexp.d index 6e244fa81..18d8c1f6b 100644 --- a/std/regexp.d +++ b/std/regexp.d @@ -1,30 +1,7 @@ // Written in the D programming language. +// Regular Expressions. -// Regular Expressions - -/* - * Copyright (C) 2000-2005 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, 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. - */ - -/********************************************** +/** * $(LINK2 http://www.digitalmars.com/ctg/regular.html, Regular * expressions) are a powerful method of string pattern matching. The * regular expression language used in this library is the same as @@ -39,68 +16,77 @@ * In the following guide, $(I pattern)[] refers to a * $(LINK2 http://www.digitalmars.com/ctg/regular.html, regular expression). * The $(I attributes)[] refers to - a string controlling the interpretation - of the regular expression. - It consists of a sequence of one or more - of the following characters: - - - - $(TR $(TH Attribute) $(TH Action)) - - $(TD $(B g)) - $(TD global; repeat over the whole input string) - - - $(TD $(B i)) - $(TD case insensitive) - - - $(TD $(B m)) - $(TD treat as multiple lines separated by newlines) - -
Attribute Characters
- * - * The $(I format)[] string has the formatting characters: - * - * - - $(TR $(TH Format) $(TH Replaced With)) - $(TR - $(TD $(B $$)) $(TD $) - ) - $(TR - $(TD $(B $&)) $(TD The matched substring.) - ) - $(TR - $(TD $(B $`)) $(TD The portion of string that precedes the matched substring.) - ) - $(TR - $(TD $(B $')) $(TD The portion of string that follows the matched substring.) - ) - $(TR - $(TD $(B $(DOLLAR))$(I n)) $(TD The $(I n)th capture, where $(I n) - is a single digit 1-9 - and $$(I n) is not followed by a decimal digit.) - ) - $(TR - $(TD $(B $(DOLLAR))$(I nn)) $(TD The $(I nn)th capture, where $(I nn) - is a two-digit decimal - number 01-99. - If $(I nn)th capture is undefined or more than the number - of parenthesized subexpressions, use the empty - string instead.) - ) -
Formatting Characters
- - * Any other $ are left as is. - * - * References: - * $(LINK2 http://en.wikipedia.org/wiki/Regular_expressions, Wikipedia) - * Macros: - * WIKI = StdRegexp - * DOLLAR = $ - */ + * a string controlling the interpretation + * of the regular expression. + * It consists of a sequence of one or more + * of the following characters: + * + * + * + * $(TR $(TH Attribute) $(TH Action)) + * + * $(TD $(B g)) + * $(TD global; repeat over the whole input string) + * + * + * $(TD $(B i)) + * $(TD case insensitive) + * + * + * $(TD $(B m)) + * $(TD treat as multiple lines separated by newlines) + * + *
Attribute Characters
+ * + * The $(I format)[] string has the formatting characters: + * + * + * + * $(TR $(TH Format) $(TH Replaced With)) + * $(TR + * $(TD $(B $$)) $(TD $) + * ) + * $(TR + * $(TD $(B $&)) $(TD The matched substring.) + * ) + * $(TR + * $(TD $(B $`)) $(TD The portion of string that precedes the matched substring.) + * ) + * $(TR + * $(TD $(B $')) $(TD The portion of string that follows the matched substring.) + * ) + * $(TR + * $(TD $(B $(DOLLAR))$(I n)) $(TD The $(I n)th capture, where $(I n) + * is a single digit 1-9 + * and $$(I n) is not followed by a decimal digit.) + * ) + * $(TR + * $(TD $(B $(DOLLAR))$(I nn)) $(TD The $(I nn)th capture, where $(I nn) + * is a two-digit decimal + * number 01-99. + * If $(I nn)th capture is undefined or more than the number + * of parenthesized subexpressions, use the empty + * string instead.) + * ) + *
Formatting Characters
+ * + * Any other $ are left as is. + * + * References: + * $(LINK2 http://en.wikipedia.org/wiki/Regular_expressions, Wikipedia) + * Macros: + * WIKI = StdRegexp + * DOLLAR = $ + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ /* Escape sequences: @@ -134,7 +120,7 @@ module std.regexp; -//debug = regexp; // uncomment to turn on debugging printf's +//debug = regexp; // uncomment to turn on debugging printf's private { @@ -154,8 +140,8 @@ private /** Regular expression to extract an _email address. * References: - * $(LINK2 http://www.regular-expressions.info/email.html, How to Find or Validate an Email Address)$(BR) - * $(LINK2 http://tools.ietf.org/html/rfc2822#section-3.4.1, RFC 2822 Internet Message Format) + * $(LINK2 http://www.regular-expressions.info/email.html, How to Find or Validate an Email Address)$(BR) + * $(LINK2 http://tools.ietf.org/html/rfc2822#section-3.4.1, RFC 2822 Internet Message Format) */ string email = r"[a-zA-Z]([.]?([[a-zA-Z0-9_]-]+)*)?@([[a-zA-Z0-9_]\-_]+\.)+[a-zA-Z]{2,6}"; @@ -177,32 +163,32 @@ class RegExpException : Exception struct regmatch_t { - int rm_so; // index of start of match - int rm_eo; // index past end of match + int rm_so; // index of start of match + int rm_eo; // index past end of match } -private alias char rchar; // so we can make a wchar version +private alias char rchar; // so we can make a wchar version /****************************************************** * Search string for matches with regular expression * pattern with attributes. * Replace each match with string generated from format. * Params: - * s = String to search. - * pattern = Regular expression pattern. - * format = Replacement string format. - * attributes = Regular expression attributes. + * s = String to search. + * pattern = Regular expression pattern. + * format = Replacement string format. + * attributes = Regular expression attributes. * Returns: - * the resulting string + * the resulting string * Example: - * Replace the letters 'a' with the letters 'ZZ'. + * Replace the letters 'a' with the letters 'ZZ'. * --- * s = "Strap a rocket engine on a chicken." * sub(s, "a", "ZZ") // result: StrZZp a rocket engine on a chicken. * sub(s, "a", "ZZ", "g") // result: StrZZp ZZ rocket engine on ZZ chicken. * --- - * The replacement format can reference the matches using - * the $&, $$, $', $`, $0 .. $99 notation: + * The replacement format can reference the matches using + * the $&, $$, $', $`, $0 .. $99 notation: * --- * sub(s, "[ar]", "[$&]", "g") // result: St[r][a]p [a] [r]ocket engine on [a] chi * --- @@ -230,10 +216,10 @@ unittest * Pass each match to delegate dg. * Replace each match with the return value from dg. * Params: - * s = String to search. - * pattern = Regular expression pattern. - * dg = Delegate - * attributes = Regular expression attributes. + * s = String to search. + * pattern = Regular expression pattern. + * dg = Delegate + * attributes = Regular expression attributes. * Returns: the resulting string. * Example: * Capitalize the letters 'a' and 'r': @@ -267,10 +253,10 @@ string sub(string s, string pattern, string delegate(RegExp) dg, string attribut // Optimize by using std.string.replace if possible - Dave Fladebo string slice = result[offset + so .. offset + eo]; - if (r.attributes & RegExp.REA.global && // global, so replace all - !(r.attributes & RegExp.REA.ignoreCase) && // not ignoring case - !(r.attributes & RegExp.REA.multiline) && // not multiline - pattern == slice) // simple pattern (exact match, no special characters) + if (r.attributes & RegExp.REA.global && // global, so replace all + !(r.attributes & RegExp.REA.ignoreCase) && // not ignoring case + !(r.attributes & RegExp.REA.multiline) && // not multiline + pattern == slice) // simple pattern (exact match, no special characters) { debug(regexp) printf("pattern: %.*s, slice: %.*s, replacement: %.*s\n",pattern,result[offset + so .. offset + eo],replacement); @@ -285,7 +271,7 @@ string sub(string s, string pattern, string delegate(RegExp) dg, string attribut offset += replacement.length - (eo - so); if (lastindex == eo) - lastindex++; // always consume some source + lastindex++; // always consume some source else lastindex = eo; } @@ -323,10 +309,10 @@ unittest /************************************************* * Search $(D_PARAM s[]) for first match with $(D_PARAM pattern). * Params: - * s = String to search. - * pattern = Regular expression pattern. + * s = String to search. + * pattern = Regular expression pattern. * Returns: - * index into s[] of match if found, -1 if no match. + * index into s[] of match if found, -1 if no match. * Example: * --- * auto s = "abcabcabab"; @@ -391,10 +377,10 @@ unittest /************************************************* * Search $(D_PARAM s[]) for last match with $(D_PARAM pattern). * Params: - * s = String to search. - * pattern = Regular expression pattern. + * s = String to search. + * pattern = Regular expression pattern. * Returns: - * index into s[] of match if found, -1 if no match. + * index into s[] of match if found, -1 if no match. * Example: * --- * auto s = "abcabcabab"; @@ -412,7 +398,7 @@ int rfind(string s, RegExp pattern) { int eo = pattern.pmatch[0].rm_eo; i = pattern.pmatch[0].rm_so; if (lastindex == eo) - lastindex++; // always consume some source + lastindex++; // always consume some source else lastindex = eo; } @@ -459,7 +445,7 @@ int rfind(string s, string pattern, string attributes = null) { int eo = r.pmatch[0].rm_eo; i = r.pmatch[0].rm_so; if (lastindex == eo) - lastindex++; // always consume some source + lastindex++; // always consume some source else lastindex = eo; } @@ -489,10 +475,10 @@ unittest * Split s[] into an array of strings, using the regular * expression $(D_PARAM pattern) as the separator. * Params: - * s = String to search. - * pattern = Regular expression pattern. + * s = String to search. + * pattern = Regular expression pattern. * Returns: - * array of slices into s[] + * array of slices into s[] * Example: * --- * foreach (s; split("abcabcabab", RegExp("C.", "i"))) @@ -533,7 +519,7 @@ unittest /******************************************** Returns: - Same as $(D_PARAM split(s, RegExp(pattern, attributes))). + Same as $(D_PARAM split(s, RegExp(pattern, attributes))). WARNING: @@ -574,11 +560,11 @@ unittest /**************************************************** * Search s[] for first match with pattern[] with attributes[]. * Params: - * s = String to search. - * pattern = Regular expression pattern. - * attributes = Regular expression attributes. + * s = String to search. + * pattern = Regular expression pattern. + * attributes = Regular expression attributes. * Returns: - * corresponding RegExp if found, null if not. + * corresponding RegExp if found, null if not. * Example: * --- * import std.stdio; @@ -600,7 +586,7 @@ RegExp search(string s, string pattern, string attributes = null) { auto r = new RegExp(pattern, attributes); if (!r.test(s)) - { delete r; + { delete r; assert(r is null); } return r; @@ -618,7 +604,7 @@ unittest assert(m[2] == null); } else - assert(0); + assert(0); if (auto n = std.regexp.search("abcdef", "g")) { @@ -641,7 +627,7 @@ class RegExp * with attributes into * an internal form for fast execution. * Params: - * pattern = regular expression + * pattern = regular expression * attributes = _attributes * Throws: RegExpException if there are any compilation errors. * Example: @@ -660,7 +646,7 @@ class RegExp /***** * Generate instance of RegExp. * Params: - * pattern = regular expression + * pattern = regular expression * attributes = _attributes * Throws: RegExpException if there are any compilation errors. * Example: @@ -696,7 +682,7 @@ class RegExp /************************************ * Set up for start of foreach loop. * Returns: - * search() returns instance of RegExp set up to _search string[]. + * search() returns instance of RegExp set up to _search string[]. * Example: * --- * import std.stdio; @@ -809,16 +795,16 @@ class RegExp return input[pmatch[0].rm_eo .. $]; } - uint re_nsub; // number of parenthesized subexpression matches - regmatch_t[] pmatch; // array [re_nsub + 1] + uint re_nsub; // number of parenthesized subexpression matches + regmatch_t[] pmatch; // array [re_nsub + 1] - string input; // the string to search + string input; // the string to search // per instance: - string pattern; // source text of the regular expression + string pattern; // source text of the regular expression - string flags; // source text of the attributes parameter + string flags; // source text of the attributes parameter int errors; @@ -826,22 +812,22 @@ class RegExp enum REA { - global = 1, // has the g attribute - ignoreCase = 2, // has the i attribute - multiline = 4, // if treat as multiple lines separated + global = 1, // has the g attribute + ignoreCase = 2, // has the i attribute + multiline = 4, // if treat as multiple lines separated // by newlines, or as a single line - dotmatchlf = 8, // if . matches \n + dotmatchlf = 8, // if . matches \n } private: - size_t src; // current source index in input[] - size_t src_start; // starting index for match in input[] - size_t p; // position of parser in pattern[] - regmatch_t gmatch; // match for the entire regular expression + size_t src; // current source index in input[] + size_t src_start; // starting index for match in input[] + size_t p; // position of parser in pattern[] + regmatch_t gmatch; // match for the entire regular expression // (serves as storage for pmatch[0]) - const(ubyte)[] program; // pattern[] compiled into regular expression program + const(ubyte)[] program; // pattern[] compiled into regular expression program OutBuffer buf; @@ -853,30 +839,30 @@ private: enum : ubyte { - REend, // end of program - REchar, // single character - REichar, // single character, case insensitive - REdchar, // single UCS character - REidchar, // single wide character, case insensitive - REanychar, // any character - REanystar, // ".*" - REstring, // string of characters - REistring, // string of characters, case insensitive - REtestbit, // any in bitmap, non-consuming - REbit, // any in the bit map - REnotbit, // any not in the bit map - RErange, // any in the string - REnotrange, // any not in the string - REor, // a | b - REplus, // 1 or more - REstar, // 0 or more - REquest, // 0 or 1 - REnm, // n..m - REnmq, // n..m, non-greedy version - REbol, // beginning of line - REeol, // end of line - REparen, // parenthesized subexpression - REgoto, // goto offset + REend, // end of program + REchar, // single character + REichar, // single character, case insensitive + REdchar, // single UCS character + REidchar, // single wide character, case insensitive + REanychar, // any character + REanystar, // ".*" + REstring, // string of characters + REistring, // string of characters, case insensitive + REtestbit, // any in bitmap, non-consuming + REbit, // any in the bit map + REnotbit, // any not in the bit map + RErange, // any in the string + REnotrange, // any not in the string + REor, // a | b + REplus, // 1 or more + REstar, // 0 or more + REquest, // 0 or 1 + REnm, // n..m + REnmq, // n..m, non-greedy version + REbol, // beginning of line + REeol, // end of line + REparen, // parenthesized subexpression + REgoto, // goto offset REwordboundary, REnotwordboundary, @@ -908,9 +894,9 @@ private: switch (c) { - case 'g': att = REA.global; break; - case 'i': att = REA.ignoreCase; break; - case 'm': att = REA.multiline; break; + case 'g': att = REA.global; break; + case 'i': att = REA.ignoreCase; break; + case 'm': att = REA.multiline; break; default: error("unrecognized attribute"); return; @@ -936,7 +922,7 @@ private: p = 0; parseRegexp(); if (p < pattern.length) - { error("unmatched ')'"); + { error("unmatched ')'"); } optimize(); program = buf.data; @@ -957,7 +943,7 @@ private: * Split s[] into an array of strings, using the regular * expression as the separator. * Returns: - * array of slices into s[] + * array of slices into s[] */ public string[] split(string s) @@ -973,7 +959,7 @@ private: for (q = p; q != s.length;) { if (test(s, q)) - { int e; + { int e; q = pmatch[0].rm_so; e = pmatch[0].rm_eo; @@ -985,7 +971,7 @@ private: int so = pmatch[i].rm_so; int eo = pmatch[i].rm_eo; if (so == eo) - { so = 0; // -1 gives array bounds error + { so = 0; // -1 gives array bounds error eo = 0; } result ~= s[so .. eo]; @@ -1056,7 +1042,7 @@ private: /************************************************* * Search string[] for match with regular expression. * Returns: - * index of match if successful, -1 if not found + * index of match if successful, -1 if not found */ public int find(string string) @@ -1067,7 +1053,7 @@ private: if (i) i = pmatch[0].rm_so; else - i = -1; // no match + i = -1; // no match return i; } @@ -1089,8 +1075,8 @@ private: /************************************************* * Search s[] for match. * Returns: - * If global attribute, return same value as exec(s). - * If not global attribute, return array of all matches. + * If global attribute, return same value as exec(s). + * If not global attribute, return array of all matches. */ public string[] match(string s) @@ -1106,7 +1092,7 @@ private: result ~= input[pmatch[0].rm_so .. eo]; if (lastindex == eo) - lastindex++; // always consume some source + lastindex++; // always consume some source else lastindex = eo; } @@ -1170,11 +1156,11 @@ private: // Optimize by using std.string.replace if possible - Dave Fladebo string slice = result[offset + so .. offset + eo]; - if (attributes & REA.global && // global, so replace all - !(attributes & REA.ignoreCase) && // not ignoring case - !(attributes & REA.multiline) && // not multiline - pattern == slice && // simple pattern (exact match, no special characters) - format == replacement) // simple format, not $ formats + if (attributes & REA.global && // global, so replace all + !(attributes & REA.ignoreCase) && // not ignoring case + !(attributes & REA.multiline) && // not multiline + pattern == slice && // simple pattern (exact match, no special characters) + format == replacement) // simple format, not $ formats { debug(regexp) printf("pattern: %.*s, slice: %.*s, format: %.*s, replacement: %.*s\n",pattern,result[offset + so .. offset + eo],format,replacement); @@ -1189,7 +1175,7 @@ private: offset += replacement.length - (eo - so); if (lastindex == eo) - lastindex++; // always consume some source + lastindex++; // always consume some source else lastindex = eo; } @@ -1223,7 +1209,7 @@ private: /************************************************* * Search string[] for match. * Returns: - * array of slices into string[] representing matches + * array of slices into string[] representing matches */ public string[] exec(string string) @@ -1239,7 +1225,7 @@ private: * Pick up where last exec(string) or exec() left off, * searching string[] for next match. * Returns: - * array of slices into string[] representing matches + * array of slices into string[] representing matches */ public string[] exec() @@ -1319,7 +1305,7 @@ public int test(string s) pmatch[0].rm_eo = 0; if (startindex < 0 || startindex > input.length) { - return 0; // fail + return 0; // fail } //debug(regexp) printProgram(program); @@ -1337,12 +1323,12 @@ public int test(string s) if (firstc) { if (si == input.length) - break; // no match + break; // no match if (input[si] != firstc) { si++; - if (!chr(si, firstc)) // if first character not found - break; // no match + if (!chr(si, firstc)) // if first character not found + break; // no match } } for (int i = 0; i < re_nsub + 1; i++) @@ -1365,7 +1351,7 @@ public int test(string s) { // Scan for the popFront \n if (!chr(si, '\n')) - break; // no match if '\n' not found + break; // no match if '\n' not found } else break; @@ -1374,7 +1360,7 @@ public int test(string s) break; //debug(regexp) printf("Starting new try: '%.*s'\n", input[si + 1 .. input.length]); } - return 0; // no match + return 0; // no match } /** @@ -1608,8 +1594,8 @@ public int test(string s) /************************************************** * Match input against a section of the program[]. * Returns: - * 1 if successful match - * 0 no match + * 1 if successful match + * 0 no match */ int trymatch(int pc, int pcend) @@ -1633,7 +1619,7 @@ public int test(string s) psave = null; for (;;) { - if (pc == pcend) // if done matching + if (pc == pcend) // if done matching { debug(regex) printf("\tprogend\n"); return 1; } @@ -1840,7 +1826,7 @@ public int test(string s) if (trymatch(pop, pcend)) { if (pcend != program.length) - { int s; + { int s; s = src; if (trymatch(pcend, program.length)) @@ -1862,11 +1848,11 @@ public int test(string s) src = ss; } else - { debug(regexp) printf("\tfirst operand matched\n"); + { debug(regexp) printf("\tfirst operand matched\n"); return 1; } } - pc = pop + len; // proceed with 2nd branch + pc = pop + len; // proceed with 2nd branch break; case REgoto: @@ -1898,7 +1884,7 @@ public int test(string s) // BUG: should we save/restore pmatch[]? if (trymatch(pc, program.length)) { - src = s1; // no match + src = s1; // no match break; } } @@ -1927,7 +1913,7 @@ public int test(string s) //else //psave = new regmatch_t[re_nsub + 1]; } - if (program[pc] == REnmq) // if minimal munch + if (program[pc] == REnmq) // if minimal munch { for (; count < m; count++) { int s1; @@ -1955,7 +1941,7 @@ public int test(string s) } } } - else // maximal munch + else // maximal munch { for (; count < m; count++) { int s1; @@ -1983,7 +1969,7 @@ public int test(string s) src = s1; if (trymatch(pop + len, program.length)) { - src = s1; // no match + src = s1; // no match memcpy(pmatch.ptr, psave, (re_nsub + 1) * regmatch_t.sizeof); break; } @@ -2012,7 +1998,7 @@ public int test(string s) case REend: debug(regexp) printf("\tREend\n"); - return 1; // successful match + return 1; // successful match case REwordboundary: debug(regexp) printf("\tREwordboundary\n"); @@ -2222,7 +2208,7 @@ public int test(string s) m = 1; goto Lnm; - case '{': // {n} {n,} {n,m} + case '{': // {n} {n,} {n,m} p++; if (p == plength || !isdigit(pattern[p])) goto Lerr; @@ -2235,8 +2221,8 @@ public int test(string s) if (p == plength) goto Lerr; } while (isdigit(pattern[p])); - if (pattern[p] == '}') // {n} - { m = n; + if (pattern[p] == '}') // {n} + { m = n; goto Lnm; } if (pattern[p] != ',') @@ -2244,13 +2230,13 @@ public int test(string s) p++; if (p == plength) goto Lerr; - if (pattern[p] == /*{*/ '}') // {n,} - { m = inf; + if (pattern[p] == /*{*/ '}') // {n,} + { m = inf; goto Lnm; } if (!isdigit(pattern[p])) goto Lerr; - m = 0; // {n,m} + m = 0; // {n,m} do { // BUG: handle overflow @@ -2267,7 +2253,7 @@ public int test(string s) p++; op = REnm; if (p < plength && pattern[p] == '?') - { op = REnmq; // minimal munch version + { op = REnmq; // minimal munch version p++; } len = buf.offset - offset; @@ -2311,7 +2297,7 @@ public int test(string s) p++; buf.write(REparen); offset = buf.offset; - buf.write(cast(uint)0); // reserve space for length + buf.write(cast(uint)0); // reserve space for length buf.write(re_nsub); re_nsub++; parseRegexp(); @@ -2354,14 +2340,14 @@ public int test(string s) c = pattern[p]; switch (c) { - case 'b': op = REwordboundary; goto Lop; + case 'b': op = REwordboundary; goto Lop; case 'B': op = REnotwordboundary; goto Lop; - case 'd': op = REdigit; goto Lop; - case 'D': op = REnotdigit; goto Lop; - case 's': op = REspace; goto Lop; - case 'S': op = REnotspace; goto Lop; - case 'w': op = REword; goto Lop; - case 'W': op = REnotword; goto Lop; + case 'd': op = REdigit; goto Lop; + case 'D': op = REnotdigit; goto Lop; + case 's': op = REspace; goto Lop; + case 'S': op = REnotspace; goto Lop; + case 'w': op = REword; goto Lop; + case 'W': op = REnotword; goto Lop; Lop: buf.write(op); @@ -2421,7 +2407,7 @@ public int test(string s) int len; for (q = p; q < pattern.length; ++q) - { rchar qc = pattern[q]; + { rchar qc = pattern[q]; switch (qc) { @@ -2434,11 +2420,11 @@ public int test(string s) q--; break; - case '(': case ')': + case '(': case ')': case '|': - case '[': case ']': - case '.': case '^': - case '$': case '\\': + case '[': case ']': + case '.': case '^': + case '$': case '\\': case '}': break; @@ -2505,7 +2491,7 @@ private: maxc = u; b = u / 8; if (b >= maxb) - { uint u2; + { uint u2; u2 = base ? base - &buf.data[0] : 0; buf.fill0(b - maxb + 1); @@ -2548,7 +2534,7 @@ private: } buf.write(op); offset = buf.offset; - buf.write(cast(uint)0); // reserve space for length + buf.write(cast(uint)0); // reserve space for length buf.reserve(128 / 8); auto r = new Range(buf); if (op == REnotbit) @@ -2740,15 +2726,15 @@ private: int i; rchar tc; - c = pattern[p]; // none of the cases are multibyte + c = pattern[p]; // none of the cases are multibyte switch (c) { - case 'b': c = '\b'; break; - case 'f': c = '\f'; break; - case 'n': c = '\n'; break; - case 'r': c = '\r'; break; - case 't': c = '\t'; break; - case 'v': c = '\v'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; // BUG: Perl does \a and \e too, should we? @@ -2787,7 +2773,7 @@ private: // Treat overflow as if last // digit was not an octal digit if (c >= 0xFF) - { c >>= 3; + { c >>= 3; return c; } } @@ -2810,7 +2796,7 @@ private: c = c * 16 + (tc - 'a' + 10); else if ('A' <= tc && tc <= 'F') c = c * 16 + (tc - 'A' + 10); - else if (i == 0) // if no hex digits after \x + else if (i == 0) // if no hex digits after \x { // Not a valid \xXX sequence return 'x'; @@ -2963,7 +2949,7 @@ private: return 1; case REanychar: - return 0; // no point + return 0; // no point case REstring: len = *cast(uint *)&prog[i + 1]; @@ -3215,22 +3201,22 @@ private: /************************************ * Like replace(char[] format), but uses old style formatting: - - - - - - - -
Format - Description -
& - replace with the match -
\n - replace with the nth parenthesized match, n is 1..9 -
\c - replace with char c. -
+ + + + + + + +
Format + Description +
& + replace with the match +
\n + replace with the nth parenthesized match, n is 1..9 +
\c + replace with char c. +
*/ public string replaceOld(string format) diff --git a/std/signals.d b/std/signals.d index f7ac6c6bd..4c9777383 100644 --- a/std/signals.d +++ b/std/signals.d @@ -1,7 +1,6 @@ -// Written in the D programming language -// This is part of the Phobos runtime libary for the D programming language. +// Written in the D programming language. -/******************************** +/** * Signals and Slots are an implementation of the Observer Pattern. * Essentially, when a Signal is emitted, a list of connected Observers * (called slots) are called. @@ -12,48 +11,53 @@ * longer necessary to instrument the slots. * * References: - * $(LINK2 http://scottcollins.net/articles/a-deeper-look-at-_signals-and-slots.html, A Deeper Look at Signals and Slots)$(BR) - * $(LINK2 http://en.wikipedia.org/wiki/Observer_pattern, Observer pattern)$(BR) - * $(LINK2 http://en.wikipedia.org/wiki/Signals_and_slots, Wikipedia)$(BR) - * $(LINK2 http://boost.org/doc/html/$(SIGNALS).html, Boost Signals)$(BR) - * $(LINK2 http://doc.trolltech.com/4.1/signalsandslots.html, Qt)$(BR) + * $(LINK2 http://scottcollins.net/articles/a-deeper-look-at-_signals-and-slots.html, A Deeper Look at Signals and Slots)$(BR) + * $(LINK2 http://en.wikipedia.org/wiki/Observer_pattern, Observer pattern)$(BR) + * $(LINK2 http://en.wikipedia.org/wiki/Signals_and_slots, Wikipedia)$(BR) + * $(LINK2 http://boost.org/doc/html/$(SIGNALS).html, Boost Signals)$(BR) + * $(LINK2 http://doc.trolltech.com/4.1/signalsandslots.html, Qt)$(BR) * - * There has been a great deal of discussion in the D newsgroups - * over this, and several implementations: + * There has been a great deal of discussion in the D newsgroups + * over this, and several implementations: * - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/announce/signal_slots_library_4825.html, signal slots library)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/Signals_and_Slots_in_D_42387.html, Signals and Slots in D)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/Dynamic_binding_--_Qt_s_Signals_and_Slots_vs_Objective-C_42260.html, Dynamic binding -- Qt's Signals and Slots vs Objective-C)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/Dissecting_the_SS_42377.html, Dissecting the SS)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/dwt/about_harmonia_454.html, about harmonia)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/announce/1502.html, Another event handling module)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/41825.html, Suggestion: signal/slot mechanism)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/13251.html, Signals and slots?)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/10714.html, Signals and slots ready for evaluation)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/1393.html, Signals & Slots for Walter)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/28456.html, Signal/Slot mechanism?)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/19470.html, Modern Features?)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/16592.html, Delegates vs interfaces)$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/16583.html, The importance of component programming (properties, signals and slots, etc))$(BR) - * $(LINK2 http://www.digitalmars.com/d/archives/16368.html, signals and slots)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/announce/signal_slots_library_4825.html, signal slots library)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/Signals_and_Slots_in_D_42387.html, Signals and Slots in D)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/Dynamic_binding_--_Qt_s_Signals_and_Slots_vs_Objective-C_42260.html, Dynamic binding -- Qt's Signals and Slots vs Objective-C)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/Dissecting_the_SS_42377.html, Dissecting the SS)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/dwt/about_harmonia_454.html, about harmonia)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/announce/1502.html, Another event handling module)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/41825.html, Suggestion: signal/slot mechanism)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/13251.html, Signals and slots?)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/10714.html, Signals and slots ready for evaluation)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/digitalmars/D/1393.html, Signals & Slots for Walter)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/28456.html, Signal/Slot mechanism?)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/19470.html, Modern Features?)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/16592.html, Delegates vs interfaces)$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/16583.html, The importance of component programming (properties, signals and slots, etc))$(BR) + * $(LINK2 http://www.digitalmars.com/d/archives/16368.html, signals and slots)$(BR) * * Bugs: - * Slots can only be delegates formed from class objects or - * interfaces to class objects. If a delegate to something else - * is passed to connect(), such as a struct member function, - * a nested function or a COM interface, undefined behavior - * will result. + * Slots can only be delegates formed from class objects or + * interfaces to class objects. If a delegate to something else + * is passed to connect(), such as a struct member function, + * a nested function or a COM interface, undefined behavior + * will result. * - * Not safe for multiple threads operating on the same signals - * or slots. + * Not safe for multiple threads operating on the same signals + * or slots. * Macros: - * WIKI = Phobos/StdSignals - * SIGNALS=signals - * Copyright: - * Public Domain - * Author: Walter Bright, Digital Mars, www.digitalmars.com + * WIKI = Phobos/StdSignals + * SIGNALS=signals + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.signals; import std.stdio; @@ -85,7 +89,7 @@ class Observer { // our slot void watch(string msg, int i) { - writefln("Observed msg '%s' and value %s", msg, i); + writefln("Observed msg '%s' and value %s", msg, i); } } @@ -95,12 +99,12 @@ class Foo int value(int v) { - if (v != _value) - { _value = v; - // call all the connected slots with the two parameters - emit("setting new value", v); - } - return v; + if (v != _value) + { _value = v; + // call all the connected slots with the two parameters + emit("setting new value", v); + } + return v; } // Mix in all the code we need to make Foo into a signal @@ -115,15 +119,15 @@ void main() Foo a = new Foo; Observer o = new Observer; - a.value = 3; // should not call o.watch() - a.connect(&o.watch); // o.watch is the slot - a.value = 4; // should call o.watch() - a.disconnect(&o.watch); // o.watch is no longer a slot - a.value = 5; // so should not call o.watch() - a.connect(&o.watch); // connect again - a.value = 6; // should call o.watch() - delete o; // destroying o should automatically disconnect it - a.value = 7; // should not call o.watch() + a.value = 3; // should not call o.watch() + a.connect(&o.watch); // o.watch is the slot + a.value = 4; // should call o.watch() + a.disconnect(&o.watch); // o.watch is no longer a slot + a.value = 5; // so should not call o.watch() + a.connect(&o.watch); // connect again + a.value = 6; // should call o.watch() + delete o; // destroying o should automatically disconnect it + a.value = 7; // should not call o.watch() } --- * which should print: @@ -152,9 +156,9 @@ template Signal(T1...) void emit( T1 i ) { foreach (slot; slots[0 .. slots_idx]) - { if (slot) - slot(i); - } + { if (slot) + slot(i); + } } /*** @@ -162,36 +166,36 @@ template Signal(T1...) */ void connect(slot_t slot) { - /* Do this: - * slots ~= slot; - * but use malloc() and friends instead - */ - auto len = slots.length; - if (slots_idx == len) - { - if (slots.length == 0) - { - len = 4; - auto p = std.signals.calloc(slot_t.sizeof, len); - if (!p) - onOutOfMemoryError(); - slots = (cast(slot_t*)p)[0 .. len]; - } - else - { - len = len * 2 + 4; - auto p = std.signals.realloc(slots.ptr, slot_t.sizeof * len); - if (!p) - onOutOfMemoryError(); - slots = (cast(slot_t*)p)[0 .. len]; - slots[slots_idx + 1 .. length] = null; - } - } - slots[slots_idx++] = slot; + /* Do this: + * slots ~= slot; + * but use malloc() and friends instead + */ + auto len = slots.length; + if (slots_idx == len) + { + if (slots.length == 0) + { + len = 4; + auto p = std.signals.calloc(slot_t.sizeof, len); + if (!p) + onOutOfMemoryError(); + slots = (cast(slot_t*)p)[0 .. len]; + } + else + { + len = len * 2 + 4; + auto p = std.signals.realloc(slots.ptr, slot_t.sizeof * len); + if (!p) + onOutOfMemoryError(); + slots = (cast(slot_t*)p)[0 .. len]; + slots[slots_idx + 1 .. length] = null; + } + } + slots[slots_idx++] = slot; L1: - Object o = _d_toObject(slot.ptr); - rt_attachDisposeEvent(o, &unhook); + Object o = _d_toObject(slot.ptr); + rt_attachDisposeEvent(o, &unhook); } /*** @@ -199,20 +203,20 @@ template Signal(T1...) */ void disconnect( slot_t slot) { - debug (signal) writefln("Signal.disconnect(slot)"); - for (size_t i = 0; i < slots_idx; ) - { - if (slots[i] == slot) - { slots_idx--; - slots[i] = slots[slots_idx]; - slots[slots_idx] = null; // not strictly necessary + debug (signal) writefln("Signal.disconnect(slot)"); + for (size_t i = 0; i < slots_idx; ) + { + if (slots[i] == slot) + { slots_idx--; + slots[i] = slots[slots_idx]; + slots[slots_idx] = null; // not strictly necessary - Object o = _d_toObject(slot.ptr); - rt_detachDisposeEvent(o, &unhook); - } - else - i++; - } + Object o = _d_toObject(slot.ptr); + rt_detachDisposeEvent(o, &unhook); + } + else + i++; + } } /* ** @@ -222,17 +226,17 @@ template Signal(T1...) */ void unhook(Object o) { - debug (signal) writefln("Signal.unhook(o = %s)", cast(void*)o); - for (size_t i = 0; i < slots_idx; ) - { - if (_d_toObject(slots[i].ptr) is o) - { slots_idx--; - slots[i] = slots[slots_idx]; - slots[slots_idx] = null; // not strictly necessary - } - else - i++; - } + debug (signal) writefln("Signal.unhook(o = %s)", cast(void*)o); + for (size_t i = 0; i < slots_idx; ) + { + if (_d_toObject(slots[i].ptr) is o) + { slots_idx--; + slots[i] = slots[slots_idx]; + slots[slots_idx] = null; // not strictly necessary + } + else + i++; + } } /* ** @@ -240,28 +244,28 @@ template Signal(T1...) */ ~this() { - /* ** - * When this object is destroyed, need to let every slot - * know that this object is destroyed so they are not left - * with dangling references to it. - */ - if (slots) - { - foreach (slot; slots[0 .. slots_idx]) - { - if (slot) - { Object o = _d_toObject(slot.ptr); - rt_detachDisposeEvent(o, &unhook); - } - } - std.signals.free(slots.ptr); - slots = null; - } + /* ** + * When this object is destroyed, need to let every slot + * know that this object is destroyed so they are not left + * with dangling references to it. + */ + if (slots) + { + foreach (slot; slots[0 .. slots_idx]) + { + if (slot) + { Object o = _d_toObject(slot.ptr); + rt_detachDisposeEvent(o, &unhook); + } + } + std.signals.free(slots.ptr); + slots = null; + } } private: - slot_t[] slots; // the slots to call from emit() - size_t slots_idx; // used length of slots[] + slot_t[] slots; // the slots to call from emit() + size_t slots_idx; // used length of slots[] } // A function whose sole purpose is to get this module linked in @@ -272,12 +276,12 @@ unittest { class Observer { - void watch(string msg, int i) - { - //writefln("Observed msg '%s' and value %s", msg, i); + void watch(string msg, int i) + { + //writefln("Observed msg '%s' and value %s", msg, i); captured_value = i; captured_msg = msg; - } + } void clear() { @@ -292,21 +296,21 @@ unittest class Foo { - int value() { return _value; } + int value() { return _value; } - int value(int v) - { - if (v != _value) - { _value = v; - emit("setting new value", v); - } - return v; - } + int value(int v) + { + if (v != _value) + { _value = v; + emit("setting new value", v); + } + return v; + } - mixin Signal!(string, int); + mixin Signal!(string, int); private: - int _value; + int _value; } Foo a = new Foo; diff --git a/std/stdarg.d b/std/stdarg.d index ecb1d473e..93378a094 100644 --- a/std/stdarg.d +++ b/std/stdarg.d @@ -1,12 +1,17 @@ +// Written in the D programming language. -/* - * Written in the D programming language. - * Placed in public domain. - * Written by Hauke Duden and Walter Bright +/** + * This is for use with variable argument lists with extern(D) linkage. + * + * Copyright: Copyright Hauke Duden 2004 - 2009. + * License: Boost License 1.0. + * Authors: Hauke Duden, $(WEB digitalmars.com, Walter Bright) + * + * Copyright Hauke Duden 2004 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - -/* This is for use with variable argument lists with extern(D) linkage. */ - module std.stdarg; alias void* va_list; @@ -15,9 +20,9 @@ template va_arg(T) { T va_arg(inout va_list _argptr) { - T arg = *cast(T*)_argptr; - _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)); - return arg; + T arg = *cast(T*)_argptr; + _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)); + return arg; } } diff --git a/std/stdint.d b/std/stdint.d index dcc0a5976..94d41580d 100644 --- a/std/stdint.d +++ b/std/stdint.d @@ -1,124 +1,129 @@ - -// Written in the D programming language +// Written in the D programming language. /** * - D constrains integral types to specific sizes. But efficiency - of different sizes varies from machine to machine, - pointer sizes vary, and the maximum integer size varies. - stdint offers a portable way of trading off size - vs efficiency, in a manner compatible with the stdint.h - definitions in C. + D constrains integral types to specific sizes. But efficiency + of different sizes varies from machine to machine, + pointer sizes vary, and the maximum integer size varies. + stdint offers a portable way of trading off size + vs efficiency, in a manner compatible with the stdint.h + definitions in C. - The exact aliases are types of exactly the specified number of bits. - The at least aliases are at least the specified number of bits - large, and can be larger. - The fast aliases are the fastest integral type supported by the - processor that is at least as wide as the specified number of bits. + The exact aliases are types of exactly the specified number of bits. + The at least aliases are at least the specified number of bits + large, and can be larger. + The fast aliases are the fastest integral type supported by the + processor that is at least as wide as the specified number of bits. - The aliases are: + The aliases are: - - - - + +
Exact Alias - Description - At Least Alias - Description - Fast Alias - Description -
int8_t - exactly 8 bits signed - int_least8_t - at least 8 bits signed - int_fast8_t - fast 8 bits signed -
uint8_t - exactly 8 bits unsigned - uint_least8_t - at least 8 bits unsigned - uint_fast8_t - fast 8 bits unsigned + + + + - - + + - - + + - -
Exact Alias + Description + At Least Alias + Description + Fast Alias + Description +
int8_t + exactly 8 bits signed + int_least8_t + at least 8 bits signed + int_fast8_t + fast 8 bits signed +
uint8_t + exactly 8 bits unsigned + uint_least8_t + at least 8 bits unsigned + uint_fast8_t + fast 8 bits unsigned -
int16_t - exactly 16 bits signed - int_least16_t - at least 16 bits signed - int_fast16_t - fast 16 bits signed -
uint16_t - exactly 16 bits unsigned - uint_least16_t - at least 16 bits unsigned - uint_fast16_t - fast 16 bits unsigned +
int16_t + exactly 16 bits signed + int_least16_t + at least 16 bits signed + int_fast16_t + fast 16 bits signed +
uint16_t + exactly 16 bits unsigned + uint_least16_t + at least 16 bits unsigned + uint_fast16_t + fast 16 bits unsigned -
int32_t - exactly 32 bits signed - int_least32_t - at least 32 bits signed - int_fast32_t - fast 32 bits signed -
uint32_t - exactly 32 bits unsigned - uint_least32_t - at least 32 bits unsigned - uint_fast32_t - fast 32 bits unsigned +
int32_t + exactly 32 bits signed + int_least32_t + at least 32 bits signed + int_fast32_t + fast 32 bits signed +
uint32_t + exactly 32 bits unsigned + uint_least32_t + at least 32 bits unsigned + uint_fast32_t + fast 32 bits unsigned -
int64_t - exactly 64 bits signed - int_least64_t - at least 64 bits signed - int_fast64_t - fast 64 bits signed -
uint64_t - exactly 64 bits unsigned - uint_least64_t - at least 64 bits unsigned - uint_fast64_t - fast 64 bits unsigned -
+
int64_t + exactly 64 bits signed + int_least64_t + at least 64 bits signed + int_fast64_t + fast 64 bits signed +
uint64_t + exactly 64 bits unsigned + uint_least64_t + at least 64 bits unsigned + uint_fast64_t + fast 64 bits unsigned +
- The ptr aliases are integral types guaranteed to be large enough - to hold a pointer without losing bits: + The ptr aliases are integral types guaranteed to be large enough + to hold a pointer without losing bits: - - - -
Alias - Description -
intptr_t - signed integral type large enough to hold a pointer -
uintptr_t - unsigned integral type large enough to hold a pointer -
+ + + +
Alias + Description +
intptr_t + signed integral type large enough to hold a pointer +
uintptr_t + unsigned integral type large enough to hold a pointer +
- The max aliases are the largest integral types: + The max aliases are the largest integral types: - - - -
Alias - Description -
intmax_t - the largest signed integral type -
uintmax_t - the largest unsigned integral type -
+ + + +
Alias + Description +
intmax_t + the largest signed integral type +
uintmax_t + the largest unsigned integral type +
- * Authors: Walter Bright, www.digitalmars.com - * License: Public Domain * Macros: - * WIKI=Phobos/StdStdint + * WIKI=Phobos/StdStdint + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.stdint; public import core.stdc.stdint; diff --git a/std/stdio.d b/std/stdio.d index 925af1b2c..e6abdef19 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -1,21 +1,22 @@ // Written in the D programming language. -/* Written by Walter Bright and Andrei Alexandrescu - * http://www.digitalmars.com/d - * Placed in the Public Domain. - */ - -/******************************** +/** Standard I/O functions that extend $(B std.c.stdio). $(B std.c.stdio) is $(D_PARAM public)ally imported when importing $(B std.stdio). - -Authors: $(WEB digitalmars.com, Walter Bright), $(WEB erdani.org, -Andrei Alexandrescu) Macros: WIKI=Phobos/StdStdio - */ +Copyright: Copyright Digital Mars 2007 - 2009. +License: Boost License 1.0. +Authors: $(WEB digitalmars.com, Walter Bright), + $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Digital Mars 2007 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) + */ module std.stdio; public import core.stdc.stdio; @@ -57,8 +58,8 @@ version (DIGITAL_MARS_STDIO) { /* ** * Digital Mars under-the-hood C I/O functions. - * Use _iobuf* for the unshared version of FILE*, - * usable when the FILE is locked. + * Use _iobuf* for the unshared version of FILE*, + * usable when the FILE is locked. */ int _fputc_nlock(int, _iobuf*); int _fputwc_nlock(int, _iobuf*); @@ -859,8 +860,8 @@ $(D Range) that locks the file and allows fast writing to it. { //@@@ Hacky implementation due to bugs, see the correct //implementation at the end of this struct - FILE* fps; // the shared file handle - _iobuf* handle; // the unshared version of fps + FILE* fps; // the shared file handle + _iobuf* handle; // the unshared version of fps int orientation; this(ref File f) @@ -1084,7 +1085,7 @@ unittest private void writefx(FILE* fps, TypeInfo[] arguments, void* argptr, int newline=false) { - int orientation = fwide(fps, 0); // move this inside the lock? + int orientation = fwide(fps, 0); // move this inside the lock? /* Do the file stream locking at the outermost level * rather than character by character. @@ -1092,7 +1093,7 @@ void writefx(FILE* fps, TypeInfo[] arguments, void* argptr, int newline=false) FLOCK(fps); scope(exit) FUNLOCK(fps); - auto fp = cast(_iobuf*)fps; // fp is locked version + auto fp = cast(_iobuf*)fps; // fp is locked version if (orientation <= 0) // byte orientation or no orientation { @@ -1902,10 +1903,10 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator = '\n') FLOCK(fps); scope(exit) FUNLOCK(fps); - /* Since fps is now locked, we can create an "unshared" version - * of fp. - */ - auto fp = cast(_iobuf*)fps; + /* Since fps is now locked, we can create an "unshared" version + * of fp. + */ + auto fp = cast(_iobuf*)fps; if (__fhnd_info[fp._file] & FHND_WCHAR) { /* Stream is in wide characters. @@ -1973,7 +1974,7 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator = '\n') buf = p[0 .. i]; { char[] buf2; - // This recursively does an unnecessary lock + // This recursively does an unnecessary lock readlnImpl(fps, buf2, terminator); buf ~= buf2; } @@ -2061,7 +2062,7 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator = '\n') */ FLOCK(fps); scope(exit) FUNLOCK(fps); - auto fp = cast(_iobuf*)fps; + auto fp = cast(_iobuf*)fps; version (Windows) { buf.length = 0; @@ -2138,9 +2139,9 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator = '\n') } else version (GENERIC_IO) { - FLOCK(fps); - scope(exit) FUNLOCK(fps); - auto fp = cast(_iobuf*)fps; + FLOCK(fps); + scope(exit) FUNLOCK(fps); + auto fp = cast(_iobuf*)fps; if (fwide(fps, 0) > 0) { /* Stream is in wide characters. * Read them and convert to chars. diff --git a/std/stdiobase.d b/std/stdiobase.d index 75731a182..1ae3a9a39 100644 --- a/std/stdiobase.d +++ b/std/stdiobase.d @@ -1,3 +1,18 @@ +// Written in the D programming language. + +/** + * The only purpose of this module is to do the static construction for + * std.stdio, to eliminate cyclic construction errors. + * + * Copyright: Copyright Andrei Alexandrescu 2008 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB erdani.org, Andrei Alexandrescu) + * + * Copyright Andrei Alexandrescu 2008 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ module std.stdiobase; extern(C) void std_stdio_static_this(); diff --git a/std/string.d b/std/string.d index 9761c73a7..65d6e9295 100644 --- a/std/string.d +++ b/std/string.d @@ -8,25 +8,19 @@ $(D char[]), $(D wchar[]), or $(D dchar[]). The $(D *_string) types are preferable because they don't exhibit undesired aliasing, thus making code more robust. -Authors: - -$(WEB digitalmars.com, Walter Bright), $(WEB erdani.org, Andrei -Alexandrescu) - Macros: - WIKI = Phobos/StdString +WIKI = Phobos/StdString -Copyright: - Public Domain +Copyright: Copyright Digital Mars 2007 - 2009. +License: Boost License 1.0. +Authors: $(WEB digitalmars.com, Walter Bright), + $(WEB erdani.org, Andrei Alexandrescu) + + Copyright Digital Mars 2007 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - -/* Author: - * Walter Bright, Digital Mars, www.digitalmars.com - */ - -// The code is not optimized for speed, that will have to wait -// until the design is solidified. - module std.string; //debug=string; // uncomment to turn on debugging printf's diff --git a/std/system.d b/std/system.d index 7a83588c9..a520e0d07 100644 --- a/std/system.d +++ b/std/system.d @@ -1,14 +1,20 @@ -// Written in the D programming language +// Written in the D programming language. /** * Information about the target operating system, environment, and CPU - * Authors: Walter Bright, http://www.digitalmars.com - * License: Public Domain + * * Macros: - * WIKI = Phobos/StdSystem + * WIKI = Phobos/StdSystem + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - - module std.system; const @@ -17,53 +23,53 @@ const // Operating system family enum Family { - Win32 = 1, // Microsoft 32 bit Windows systems - linux, // all linux systems - OSX, + Win32 = 1, // Microsoft 32 bit Windows systems + linux, // all linux systems + OSX, } version (Win32) { - Family family = Family.Win32; + Family family = Family.Win32; } else version (Posix) { - Family family = Family.linux; + Family family = Family.linux; } else version (OSX) { - Family family = Family.OSX; + Family family = Family.OSX; } else { - static assert(0); + static assert(0); } // More specific operating system name enum OS { - Windows95 = 1, - Windows98, - WindowsME, - WindowsNT, - Windows2000, - WindowsXP, + Windows95 = 1, + Windows98, + WindowsME, + WindowsNT, + Windows2000, + WindowsXP, - RedHatLinux, - OSX, + RedHatLinux, + OSX, } /// Byte order endianness enum Endian { - BigEndian, /// big endian byte order - LittleEndian /// little endian byte order + BigEndian, /// big endian byte order + LittleEndian /// little endian byte order } version(LittleEndian) { - /// Native system endianness + /// Native system endianness Endian endian = Endian.LittleEndian; } else diff --git a/std/traits.d b/std/traits.d index 9d59bc155..a6d8a561b 100644 --- a/std/traits.d +++ b/std/traits.d @@ -4,17 +4,20 @@ * Templates with which to extract information about * types at compile time. * - * Authors: - * - * $(WEB digitalmars.com, Walter Bright), Tomasz Stachowiak ($(D - * isExpressionTuple)), $(WEB erdani.org, Andrei Alexandrescu) - * * Macros: - * WIKI = Phobos/StdTraits - * Copyright: - * Public Domain + * WIKI = Phobos/StdTraits + * + * Copyright: Copyright Digital Mars 2005 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright), + * Tomasz Stachowiak ($(D isExpressionTuple)), + * $(WEB erdani.org, Andrei Alexandrescu) + * + * Copyright Digital Mars 2005 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.traits; import std.typetuple; diff --git a/std/typecons.d b/std/typecons.d index d9ab1cbab..1c41d144d 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -43,34 +43,17 @@ void bar() } ---- -Author: - -$(WEB erdani.org, Andrei Alexandrescu), Bartosz Milewski, Don Clugston +Copyright: Copyright Andrei Alexandrescu 2008 - 2009. +License: Boost License 1.0. +Authors: $(WEB erdani.org, Andrei Alexandrescu), + $(WEB bartoszmilewski.wordpress.com, Bartosz Milewski), + Don Clugston + Copyright Andrei Alexandrescu 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ - -/* - * Copyright (C) 2004-2006 by Digital Mars, www.digitalmars.com - * Written by Andrei Alexandrescu, www.erdani.org - * - * 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, 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 std.typecons; import std.array, std.contracts, std.conv, std.metastrings, std.traits; @@ -92,36 +75,36 @@ else alias T * RefT; public: /+ Doesn't work yet - /** - The safe constructor. It creates the resource and - guarantees unique ownership of it (unless the constructor - of $(D T) publishes aliases of $(D this)), - */ - this(A...)(A args) - { - _p = new T(args); - } + /** + The safe constructor. It creates the resource and + guarantees unique ownership of it (unless the constructor + of $(D T) publishes aliases of $(D this)), + */ + this(A...)(A args) + { + _p = new T(args); + } +/ - /** - Constructor that takes an rvalue. - It will ensure uniqueness, as long as the rvalue - isn't just a view on an lvalue (e.g., a cast) - Typical usage: - ---- - Unique!(Foo) f = new Foo; - ---- - */ + /** + Constructor that takes an rvalue. + It will ensure uniqueness, as long as the rvalue + isn't just a view on an lvalue (e.g., a cast) + Typical usage: + ---- + Unique!(Foo) f = new Foo; + ---- + */ this(RefT p) { writeln("Unique constructor with rvalue"); _p = p; } - /** - Constructor that takes an lvalue. It nulls its source. - The nulling will ensure uniqueness as long as there - are no previous aliases to the source. - */ + /** + Constructor that takes an lvalue. It nulls its source. + The nulling will ensure uniqueness as long as there + are no previous aliases to the source. + */ this(ref RefT p) { _p = p; @@ -130,29 +113,29 @@ public: assert(p is null); } /+ Doesn't work yet - /** - Constructor that takes a Unique of a type that is convertible to our type: - Disallow construction from lvalue (force the use of release on the source Unique) - If the source is an rvalue, null its content, so the destrutctor doesn't delete it + /** + Constructor that takes a Unique of a type that is convertible to our type: + Disallow construction from lvalue (force the use of release on the source Unique) + If the source is an rvalue, null its content, so the destrutctor doesn't delete it - Typically used by the compiler to return $(D Unique) of derived type as $(D Unique) - of base type. + Typically used by the compiler to return $(D Unique) of derived type as $(D Unique) + of base type. - Example: - ---- - Unique!(Base) create() - { - Unique!(Derived) d = new Derived; - return d; // Implicit Derived->Base conversion - } - ---- - */ - this(U)(ref Unique!(U) u) = null; - this(U)(Unique!(U) u) - { - _p = u._p; - u._p = null; - } + Example: + ---- + Unique!(Base) create() + { + Unique!(Derived) d = new Derived; + return d; // Implicit Derived->Base conversion + } + ---- + */ + this(U)(ref Unique!(U) u) = null; + this(U)(Unique!(U) u) + { + _p = u._p; + u._p = null; + } +/ ~this() @@ -165,7 +148,7 @@ public: { return _p is null; } - /** Returns a unique rvalue. Nullifies the current contents */ + /** Returns a unique rvalue. Nullifies the current contents */ Unique release() { writeln("Release"); @@ -174,13 +157,13 @@ public: writeln("return from Release"); return u; } - /** Forwards member access to contents */ + /** Forwards member access to contents */ RefT opDot() { return _p; } /+ doesn't work yet! - /** - Postblit operator is undefined to prevent the cloning of $(D Unique) objects - */ + /** + Postblit operator is undefined to prevent the cloning of $(D Unique) objects + */ this(this) = null; +/ diff --git a/std/typelist.d b/std/typelist.d index c81391ab3..dff02923c 100644 --- a/std/typelist.d +++ b/std/typelist.d @@ -30,14 +30,15 @@ * static assert(is (Synopsis!(char**, void***).StripPointers.toTuple == TypeTuple!(char, void))); * ---- * - * Author: + * Copyright: Copyright Bartosz Milewski 2008- 2009. + * License: Boost License 1.0. + * Authors: $(WEB bartoszmilewski.wordpress.com, Bartosz Milewski) * - * $(WEB bartoszmilewski.wordpress.com, Bartosz Milewski) - * - * Copyright: - * Public Domain -*/ - + * Copyright Burton Radons 2008 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ module std.typelist; version(unittest) { import std.typetuple; @@ -287,8 +288,8 @@ version(unittest) { } unittest { - // *** Compiler bugs - //static assert (snoC!(int, TypeList!(long)).toTuple == TypeTuple!(long, int)); + // *** Compiler bugs + //static assert (snoC!(int, TypeList!(long)).toTuple == TypeTuple!(long, int)); //static assert (FoldRight!(snoC, TypeList!(), TypeList!(int, long)).toTuple == TypeTuple!(long, int)); static assert (!FoldRight!(snoC, TypeList!(), TypeList!(int)).isEmpty); static assert (FoldRight!(Inc, 0, TypeList!(int, long)) == 2); diff --git a/std/typetuple.d b/std/typetuple.d index b04bfc470..dbe318051 100644 --- a/std/typetuple.d +++ b/std/typetuple.d @@ -1,4 +1,3 @@ - // Written in the D programming language. /** @@ -10,20 +9,22 @@ * list that is a slice of the old one. * * References: - * Based on ideas in Table 3.1 from - * $(LINK2 http://www.amazon.com/exec/obidos/ASIN/0201704315/ref=ase_classicempire/102-2957199-2585768, - * Modern C++ Design), - * Andrei Alexandrescu (Addison-Wesley Professional, 2001) + * Based on ideas in Table 3.1 from + * $(LINK2 http://www.amazon.com/exec/obidos/ASIN/0201704315/ref=ase_classicempire/102-2957199-2585768, + * Modern C++ Design), + * Andrei Alexandrescu (Addison-Wesley Professional, 2001) * Macros: - * WIKI = Phobos/StdTypeTuple - * Copyright: - * Public Domain + * WIKI = Phobos/StdTypeTuple + * + * Copyright: Copyright Digital Mars 2005 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2005 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - -/* Author: - * Walter Bright, Digital Mars, www.digitalmars.com - */ - module std.typetuple; /** @@ -145,11 +146,11 @@ alias staticIndexOf IndexOf; // template Erase(T, TList...) // { // static if (TList.length == 0) -// alias TList Erase; +// alias TList Erase; // else static if (is(T == TList[0])) -// alias TList[1 .. length] Erase; +// alias TList[1 .. length] Erase; // else -// alias TypeTuple!(TList[0], Erase!(T, TList[1 .. length])) Erase; +// alias TypeTuple!(TList[0], Erase!(T, TList[1 .. length])) Erase; // } template Erase(T, TList...) { @@ -271,9 +272,9 @@ unittest template NoDuplicates(TList...) { static if (TList.length == 0) - alias TList NoDuplicates; + alias TList NoDuplicates; else - alias TypeTuple!(TList[0], NoDuplicates!(EraseAll!(TList[0], TList[1 .. length]))) NoDuplicates; + alias TypeTuple!(TList[0], NoDuplicates!(EraseAll!(TList[0], TList[1 .. length]))) NoDuplicates; } unittest @@ -457,9 +458,9 @@ unittest template Reverse(TList...) { static if (TList.length == 0) - alias TList Reverse; + alias TList Reverse; else - alias TypeTuple!(Reverse!(TList[1 .. length]), TList[0]) Reverse; + alias TypeTuple!(Reverse!(TList[1 .. length]), TList[0]) Reverse; } /** @@ -478,11 +479,11 @@ template Reverse(TList...) template MostDerived(T, TList...) { static if (TList.length == 0) - alias T MostDerived; + alias T MostDerived; else static if (is(TList[0] : T)) - alias MostDerived!(TList[0], TList[1 .. length]) MostDerived; + alias MostDerived!(TList[0], TList[1 .. length]) MostDerived; else - alias MostDerived!(T, TList[1 .. length]) MostDerived; + alias MostDerived!(T, TList[1 .. length]) MostDerived; } /** @@ -503,12 +504,12 @@ template MostDerived(T, TList...) template DerivedToFront(TList...) { static if (TList.length == 0) - alias TList DerivedToFront; + alias TList DerivedToFront; else - alias TypeTuple!(MostDerived!(TList[0], TList[1 .. length]), - DerivedToFront!(ReplaceAll!(MostDerived!(TList[0], TList[1 .. length]), - TList[0], - TList[1 .. length]))) DerivedToFront; + alias TypeTuple!(MostDerived!(TList[0], TList[1 .. length]), + DerivedToFront!(ReplaceAll!(MostDerived!(TList[0], TList[1 .. length]), + TList[0], + TList[1 .. length]))) DerivedToFront; } diff --git a/std/uni.d b/std/uni.d index 9f440a983..5ea409402 100644 --- a/std/uni.d +++ b/std/uni.d @@ -1,26 +1,26 @@ - // Written in the D programming language. -/* - * Placed into the Public Domain. - * Digital Mars, www.digitalmars.com - * Written by Walter Bright - */ - /** * Simple Unicode character classification functions. * For ASCII classification, see $(LINK2 std_ctype.html, std.ctype). * Macros: - * WIKI=Phobos/StdUni + * WIKI=Phobos/StdUni * References: - * $(LINK2 http://www.digitalmars.com/d/ascii-table.html, ASCII Table), - * $(LINK2 http://en.wikipedia.org/wiki/Unicode, Wikipedia), - * $(LINK2 http://www.unicode.org, The Unicode Consortium) + * $(LINK2 http://www.digitalmars.com/d/ascii-table.html, ASCII Table), + * $(LINK2 http://en.wikipedia.org/wiki/Unicode, Wikipedia), + * $(LINK2 http://www.unicode.org, The Unicode Consortium) * Trademarks: - * Unicode(tm) is a trademark of Unicode, Inc. + * Unicode(tm) is a trademark of Unicode, Inc. + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - - module std.uni; /** @@ -40,7 +40,7 @@ int isUniLower(dchar c) int isUniUpper(dchar c) { if (c <= 0x7F) - return (c >= 'A' && c <= 'Z'); + return (c >= 'A' && c <= 'Z'); return isUniAlpha(c) && c == toUniUpper(c); } @@ -57,56 +57,56 @@ dchar toUniLower(dchar c) } else if (c >= 0x00C0) { - if ((c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE)) - { - c += 32; - } - else if ((c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178)) - { - if (c == 0x0130) - c = 0x0069; - else if ((c & 1) == 0) - c += 1; - } - else if (c == 0x0178) - { - c = 0x00FF; - } - else if ((c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F)) - { - if (c & 1) - c += 1; - } - else if (c >= 0x0200 && c <= 0x0217) - { - if ((c & 1) == 0) - c += 1; - } - else if ((c >= 0x0401 && c <= 0x040C) || (c>= 0x040E && c <= 0x040F)) - { - c += 80; - } - else if (c >= 0x0410 && c <= 0x042F) - { - c += 32; - } - else if (c >= 0x0460 && c <= 0x047F) - { - if ((c & 1) == 0) - c += 1; - } - else if (c >= 0x0531 && c <= 0x0556) - { - c += 48; - } - else if (c >= 0x10A0 && c <= 0x10C5) - { - c += 48; - } - else if (c >= 0xFF21 && c <= 0xFF3A) - { - c += 32; - } + if ((c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE)) + { + c += 32; + } + else if ((c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178)) + { + if (c == 0x0130) + c = 0x0069; + else if ((c & 1) == 0) + c += 1; + } + else if (c == 0x0178) + { + c = 0x00FF; + } + else if ((c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F)) + { + if (c & 1) + c += 1; + } + else if (c >= 0x0200 && c <= 0x0217) + { + if ((c & 1) == 0) + c += 1; + } + else if ((c >= 0x0401 && c <= 0x040C) || (c>= 0x040E && c <= 0x040F)) + { + c += 80; + } + else if (c >= 0x0410 && c <= 0x042F) + { + c += 32; + } + else if (c >= 0x0460 && c <= 0x047F) + { + if ((c & 1) == 0) + c += 1; + } + else if (c >= 0x0531 && c <= 0x0556) + { + c += 48; + } + else if (c >= 0x10A0 && c <= 0x10C5) + { + c += 48; + } + else if (c >= 0xFF21 && c <= 0xFF3A) + { + c += 32; + } } return c; } @@ -119,60 +119,60 @@ dchar toUniUpper(dchar c) { if (c >= 'a' && c <= 'z') { - c -= 32; + c -= 32; } else if (c >= 0x00E0) { - if ((c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE)) - { - c -= 32; - } - else if (c == 0x00FF) - { - c = 0x0178; - } - else if ((c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178)) - { - if (c == 0x0131) - c = 0x0049; - else if (c & 1) - c -= 1; - } - else if ((c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F)) - { - if ((c & 1) == 0) - c = c-1; - } - else if (c == 0x017F) - { - c = 0x0053; - } - else if (c >= 0x0200 && c <= 0x0217) - { - if (c & 1) - c = c-1; - } - else if (c >= 0x0430 && c<= 0x044F) - { - c -= 32; - } - else if ((c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F)) - { - c -= 80; - } - else if (c >= 0x0460 && c <= 0x047F) - { - if (c & 1) - c -= 1; - } - else if (c >= 0x0561 && c < 0x0587) - { - c -= 48; - } - else if (c >= 0xFF41 && c <= 0xFF5A) - { - c -= 32; - } + if ((c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE)) + { + c -= 32; + } + else if (c == 0x00FF) + { + c = 0x0178; + } + else if ((c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178)) + { + if (c == 0x0131) + c = 0x0049; + else if (c & 1) + c -= 1; + } + else if ((c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F)) + { + if ((c & 1) == 0) + c = c-1; + } + else if (c == 0x017F) + { + c = 0x0053; + } + else if (c >= 0x0200 && c <= 0x0217) + { + if (c & 1) + c = c-1; + } + else if (c >= 0x0430 && c<= 0x044F) + { + c -= 32; + } + else if ((c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F)) + { + c -= 80; + } + else if (c >= 0x0460 && c <= 0x047F) + { + if (c & 1) + c -= 1; + } + else if (c >= 0x0561 && c < 0x0587) + { + c -= 48; + } + else if (c >= 0xFF41 && c <= 0xFF5A) + { + c -= 32; + } } return c; } @@ -189,363 +189,363 @@ int isUniAlpha(dchar u) { static immutable dchar table[][2] = [ - [ 'A', 'Z' ], - [ 'a', 'z' ], - [ 0x00AA, 0x00AA ], - [ 0x00B5, 0x00B5 ], - [ 0x00BA, 0x00BA ], - [ 0x00C0, 0x00D6 ], - [ 0x00D8, 0x00F6 ], - [ 0x00F8, 0x02C1 ], - [ 0x02C6, 0x02D1 ], - [ 0x02E0, 0x02E4 ], - [ 0x02EE, 0x02EE ], - [ 0x037A, 0x037D ], - [ 0x0386, 0x0386 ], - [ 0x0388, 0x038A ], - [ 0x038C, 0x038C ], - [ 0x038E, 0x03A1 ], - [ 0x03A3, 0x03CE ], - [ 0x03D0, 0x03F5 ], - [ 0x03F7, 0x0481 ], - [ 0x048A, 0x0513 ], - [ 0x0531, 0x0556 ], - [ 0x0559, 0x0559 ], - [ 0x0561, 0x0587 ], - [ 0x05D0, 0x05EA ], - [ 0x05F0, 0x05F2 ], - [ 0x0621, 0x063A ], - [ 0x0640, 0x064A ], - [ 0x066E, 0x066F ], - [ 0x0671, 0x06D3 ], - [ 0x06D5, 0x06D5 ], - [ 0x06E5, 0x06E6 ], - [ 0x06EE, 0x06EF ], - [ 0x06FA, 0x06FC ], - [ 0x06FF, 0x06FF ], - [ 0x0710, 0x0710 ], - [ 0x0712, 0x072F ], - [ 0x074D, 0x076D ], - [ 0x0780, 0x07A5 ], - [ 0x07B1, 0x07B1 ], - [ 0x07CA, 0x07EA ], - [ 0x07F4, 0x07F5 ], - [ 0x07FA, 0x07FA ], - [ 0x0904, 0x0939 ], - [ 0x093D, 0x093D ], - [ 0x0950, 0x0950 ], - [ 0x0958, 0x0961 ], - [ 0x097B, 0x097F ], - [ 0x0985, 0x098C ], - [ 0x098F, 0x0990 ], - [ 0x0993, 0x09A8 ], - [ 0x09AA, 0x09B0 ], - [ 0x09B2, 0x09B2 ], - [ 0x09B6, 0x09B9 ], - [ 0x09BD, 0x09BD ], - [ 0x09CE, 0x09CE ], - [ 0x09DC, 0x09DD ], - [ 0x09DF, 0x09E1 ], - [ 0x09F0, 0x09F1 ], - [ 0x0A05, 0x0A0A ], - [ 0x0A0F, 0x0A10 ], - [ 0x0A13, 0x0A28 ], - [ 0x0A2A, 0x0A30 ], - [ 0x0A32, 0x0A33 ], - [ 0x0A35, 0x0A36 ], - [ 0x0A38, 0x0A39 ], - [ 0x0A59, 0x0A5C ], - [ 0x0A5E, 0x0A5E ], - [ 0x0A72, 0x0A74 ], - [ 0x0A85, 0x0A8D ], - [ 0x0A8F, 0x0A91 ], - [ 0x0A93, 0x0AA8 ], - [ 0x0AAA, 0x0AB0 ], - [ 0x0AB2, 0x0AB3 ], - [ 0x0AB5, 0x0AB9 ], - [ 0x0ABD, 0x0ABD ], - [ 0x0AD0, 0x0AD0 ], - [ 0x0AE0, 0x0AE1 ], - [ 0x0B05, 0x0B0C ], - [ 0x0B0F, 0x0B10 ], - [ 0x0B13, 0x0B28 ], - [ 0x0B2A, 0x0B30 ], - [ 0x0B32, 0x0B33 ], - [ 0x0B35, 0x0B39 ], - [ 0x0B3D, 0x0B3D ], - [ 0x0B5C, 0x0B5D ], - [ 0x0B5F, 0x0B61 ], - [ 0x0B71, 0x0B71 ], - [ 0x0B83, 0x0B83 ], - [ 0x0B85, 0x0B8A ], - [ 0x0B8E, 0x0B90 ], - [ 0x0B92, 0x0B95 ], - [ 0x0B99, 0x0B9A ], - [ 0x0B9C, 0x0B9C ], - [ 0x0B9E, 0x0B9F ], - [ 0x0BA3, 0x0BA4 ], - [ 0x0BA8, 0x0BAA ], - [ 0x0BAE, 0x0BB9 ], - [ 0x0C05, 0x0C0C ], - [ 0x0C0E, 0x0C10 ], - [ 0x0C12, 0x0C28 ], - [ 0x0C2A, 0x0C33 ], - [ 0x0C35, 0x0C39 ], - [ 0x0C60, 0x0C61 ], - [ 0x0C85, 0x0C8C ], - [ 0x0C8E, 0x0C90 ], - [ 0x0C92, 0x0CA8 ], - [ 0x0CAA, 0x0CB3 ], - [ 0x0CB5, 0x0CB9 ], - [ 0x0CBD, 0x0CBD ], - [ 0x0CDE, 0x0CDE ], - [ 0x0CE0, 0x0CE1 ], - [ 0x0D05, 0x0D0C ], - [ 0x0D0E, 0x0D10 ], - [ 0x0D12, 0x0D28 ], - [ 0x0D2A, 0x0D39 ], - [ 0x0D60, 0x0D61 ], - [ 0x0D85, 0x0D96 ], - [ 0x0D9A, 0x0DB1 ], - [ 0x0DB3, 0x0DBB ], - [ 0x0DBD, 0x0DBD ], - [ 0x0DC0, 0x0DC6 ], - [ 0x0E01, 0x0E30 ], - [ 0x0E32, 0x0E33 ], - [ 0x0E40, 0x0E46 ], - [ 0x0E81, 0x0E82 ], - [ 0x0E84, 0x0E84 ], - [ 0x0E87, 0x0E88 ], - [ 0x0E8A, 0x0E8A ], - [ 0x0E8D, 0x0E8D ], - [ 0x0E94, 0x0E97 ], - [ 0x0E99, 0x0E9F ], - [ 0x0EA1, 0x0EA3 ], - [ 0x0EA5, 0x0EA5 ], - [ 0x0EA7, 0x0EA7 ], - [ 0x0EAA, 0x0EAB ], - [ 0x0EAD, 0x0EB0 ], - [ 0x0EB2, 0x0EB3 ], - [ 0x0EBD, 0x0EBD ], - [ 0x0EC0, 0x0EC4 ], - [ 0x0EC6, 0x0EC6 ], - [ 0x0EDC, 0x0EDD ], - [ 0x0F00, 0x0F00 ], - [ 0x0F40, 0x0F47 ], - [ 0x0F49, 0x0F6A ], - [ 0x0F88, 0x0F8B ], - [ 0x1000, 0x1021 ], - [ 0x1023, 0x1027 ], - [ 0x1029, 0x102A ], - [ 0x1050, 0x1055 ], - [ 0x10A0, 0x10C5 ], - [ 0x10D0, 0x10FA ], - [ 0x10FC, 0x10FC ], - [ 0x1100, 0x1159 ], - [ 0x115F, 0x11A2 ], - [ 0x11A8, 0x11F9 ], - [ 0x1200, 0x1248 ], - [ 0x124A, 0x124D ], - [ 0x1250, 0x1256 ], - [ 0x1258, 0x1258 ], - [ 0x125A, 0x125D ], - [ 0x1260, 0x1288 ], - [ 0x128A, 0x128D ], - [ 0x1290, 0x12B0 ], - [ 0x12B2, 0x12B5 ], - [ 0x12B8, 0x12BE ], - [ 0x12C0, 0x12C0 ], - [ 0x12C2, 0x12C5 ], - [ 0x12C8, 0x12D6 ], - [ 0x12D8, 0x1310 ], - [ 0x1312, 0x1315 ], - [ 0x1318, 0x135A ], - [ 0x1380, 0x138F ], - [ 0x13A0, 0x13F4 ], - [ 0x1401, 0x166C ], - [ 0x166F, 0x1676 ], - [ 0x1681, 0x169A ], - [ 0x16A0, 0x16EA ], - [ 0x1700, 0x170C ], - [ 0x170E, 0x1711 ], - [ 0x1720, 0x1731 ], - [ 0x1740, 0x1751 ], - [ 0x1760, 0x176C ], - [ 0x176E, 0x1770 ], - [ 0x1780, 0x17B3 ], - [ 0x17D7, 0x17D7 ], - [ 0x17DC, 0x17DC ], - [ 0x1820, 0x1877 ], - [ 0x1880, 0x18A8 ], - [ 0x1900, 0x191C ], - [ 0x1950, 0x196D ], - [ 0x1970, 0x1974 ], - [ 0x1980, 0x19A9 ], - [ 0x19C1, 0x19C7 ], - [ 0x1A00, 0x1A16 ], - [ 0x1B05, 0x1B33 ], - [ 0x1B45, 0x1B4B ], - [ 0x1D00, 0x1DBF ], - [ 0x1E00, 0x1E9B ], - [ 0x1EA0, 0x1EF9 ], - [ 0x1F00, 0x1F15 ], - [ 0x1F18, 0x1F1D ], - [ 0x1F20, 0x1F45 ], - [ 0x1F48, 0x1F4D ], - [ 0x1F50, 0x1F57 ], - [ 0x1F59, 0x1F59 ], - [ 0x1F5B, 0x1F5B ], - [ 0x1F5D, 0x1F5D ], - [ 0x1F5F, 0x1F7D ], - [ 0x1F80, 0x1FB4 ], - [ 0x1FB6, 0x1FBC ], - [ 0x1FBE, 0x1FBE ], - [ 0x1FC2, 0x1FC4 ], - [ 0x1FC6, 0x1FCC ], - [ 0x1FD0, 0x1FD3 ], - [ 0x1FD6, 0x1FDB ], - [ 0x1FE0, 0x1FEC ], - [ 0x1FF2, 0x1FF4 ], - [ 0x1FF6, 0x1FFC ], - [ 0x2071, 0x2071 ], - [ 0x207F, 0x207F ], - [ 0x2090, 0x2094 ], - [ 0x2102, 0x2102 ], - [ 0x2107, 0x2107 ], - [ 0x210A, 0x2113 ], - [ 0x2115, 0x2115 ], - [ 0x2119, 0x211D ], - [ 0x2124, 0x2124 ], - [ 0x2126, 0x2126 ], - [ 0x2128, 0x2128 ], - [ 0x212A, 0x212D ], - [ 0x212F, 0x2139 ], - [ 0x213C, 0x213F ], - [ 0x2145, 0x2149 ], - [ 0x214E, 0x214E ], - [ 0x2183, 0x2184 ], - [ 0x2C00, 0x2C2E ], - [ 0x2C30, 0x2C5E ], - [ 0x2C60, 0x2C6C ], - [ 0x2C74, 0x2C77 ], - [ 0x2C80, 0x2CE4 ], - [ 0x2D00, 0x2D25 ], - [ 0x2D30, 0x2D65 ], - [ 0x2D6F, 0x2D6F ], - [ 0x2D80, 0x2D96 ], - [ 0x2DA0, 0x2DA6 ], - [ 0x2DA8, 0x2DAE ], - [ 0x2DB0, 0x2DB6 ], - [ 0x2DB8, 0x2DBE ], - [ 0x2DC0, 0x2DC6 ], - [ 0x2DC8, 0x2DCE ], - [ 0x2DD0, 0x2DD6 ], - [ 0x2DD8, 0x2DDE ], - [ 0x3005, 0x3006 ], - [ 0x3031, 0x3035 ], - [ 0x303B, 0x303C ], - [ 0x3041, 0x3096 ], - [ 0x309D, 0x309F ], - [ 0x30A1, 0x30FA ], - [ 0x30FC, 0x30FF ], - [ 0x3105, 0x312C ], - [ 0x3131, 0x318E ], - [ 0x31A0, 0x31B7 ], - [ 0x31F0, 0x31FF ], - [ 0x3400, 0x4DB5 ], - [ 0x4E00, 0x9FBB ], - [ 0xA000, 0xA48C ], - [ 0xA717, 0xA71A ], - [ 0xA800, 0xA801 ], - [ 0xA803, 0xA805 ], - [ 0xA807, 0xA80A ], - [ 0xA80C, 0xA822 ], - [ 0xA840, 0xA873 ], - [ 0xAC00, 0xD7A3 ], - [ 0xF900, 0xFA2D ], - [ 0xFA30, 0xFA6A ], - [ 0xFA70, 0xFAD9 ], - [ 0xFB00, 0xFB06 ], - [ 0xFB13, 0xFB17 ], - [ 0xFB1D, 0xFB1D ], - [ 0xFB1F, 0xFB28 ], - [ 0xFB2A, 0xFB36 ], - [ 0xFB38, 0xFB3C ], - [ 0xFB3E, 0xFB3E ], - [ 0xFB40, 0xFB41 ], - [ 0xFB43, 0xFB44 ], - [ 0xFB46, 0xFBB1 ], - [ 0xFBD3, 0xFD3D ], - [ 0xFD50, 0xFD8F ], - [ 0xFD92, 0xFDC7 ], - [ 0xFDF0, 0xFDFB ], - [ 0xFE70, 0xFE74 ], - [ 0xFE76, 0xFEFC ], - [ 0xFF21, 0xFF3A ], - [ 0xFF41, 0xFF5A ], - [ 0xFF66, 0xFFBE ], - [ 0xFFC2, 0xFFC7 ], - [ 0xFFCA, 0xFFCF ], - [ 0xFFD2, 0xFFD7 ], - [ 0xFFDA, 0xFFDC ], - [ 0x10000, 0x1000B ], - [ 0x1000D, 0x10026 ], - [ 0x10028, 0x1003A ], - [ 0x1003C, 0x1003D ], - [ 0x1003F, 0x1004D ], - [ 0x10050, 0x1005D ], - [ 0x10080, 0x100FA ], - [ 0x10300, 0x1031E ], - [ 0x10330, 0x10340 ], - [ 0x10342, 0x10349 ], - [ 0x10380, 0x1039D ], - [ 0x103A0, 0x103C3 ], - [ 0x103C8, 0x103CF ], - [ 0x10400, 0x1049D ], - [ 0x10800, 0x10805 ], - [ 0x10808, 0x10808 ], - [ 0x1080A, 0x10835 ], - [ 0x10837, 0x10838 ], - [ 0x1083C, 0x1083C ], - [ 0x1083F, 0x1083F ], - [ 0x10900, 0x10915 ], - [ 0x10A00, 0x10A00 ], - [ 0x10A10, 0x10A13 ], - [ 0x10A15, 0x10A17 ], - [ 0x10A19, 0x10A33 ], - [ 0x12000, 0x1236E ], - [ 0x1D400, 0x1D454 ], - [ 0x1D456, 0x1D49C ], - [ 0x1D49E, 0x1D49F ], - [ 0x1D4A2, 0x1D4A2 ], - [ 0x1D4A5, 0x1D4A6 ], - [ 0x1D4A9, 0x1D4AC ], - [ 0x1D4AE, 0x1D4B9 ], - [ 0x1D4BB, 0x1D4BB ], - [ 0x1D4BD, 0x1D4C3 ], - [ 0x1D4C5, 0x1D505 ], - [ 0x1D507, 0x1D50A ], - [ 0x1D50D, 0x1D514 ], - [ 0x1D516, 0x1D51C ], - [ 0x1D51E, 0x1D539 ], - [ 0x1D53B, 0x1D53E ], - [ 0x1D540, 0x1D544 ], - [ 0x1D546, 0x1D546 ], - [ 0x1D54A, 0x1D550 ], - [ 0x1D552, 0x1D6A5 ], - [ 0x1D6A8, 0x1D6C0 ], - [ 0x1D6C2, 0x1D6DA ], - [ 0x1D6DC, 0x1D6FA ], - [ 0x1D6FC, 0x1D714 ], - [ 0x1D716, 0x1D734 ], - [ 0x1D736, 0x1D74E ], - [ 0x1D750, 0x1D76E ], - [ 0x1D770, 0x1D788 ], - [ 0x1D78A, 0x1D7A8 ], - [ 0x1D7AA, 0x1D7C2 ], - [ 0x1D7C4, 0x1D7CB ], - [ 0x20000, 0x2A6D6 ], - [ 0x2F800, 0x2FA1D ], + [ 'A', 'Z' ], + [ 'a', 'z' ], + [ 0x00AA, 0x00AA ], + [ 0x00B5, 0x00B5 ], + [ 0x00BA, 0x00BA ], + [ 0x00C0, 0x00D6 ], + [ 0x00D8, 0x00F6 ], + [ 0x00F8, 0x02C1 ], + [ 0x02C6, 0x02D1 ], + [ 0x02E0, 0x02E4 ], + [ 0x02EE, 0x02EE ], + [ 0x037A, 0x037D ], + [ 0x0386, 0x0386 ], + [ 0x0388, 0x038A ], + [ 0x038C, 0x038C ], + [ 0x038E, 0x03A1 ], + [ 0x03A3, 0x03CE ], + [ 0x03D0, 0x03F5 ], + [ 0x03F7, 0x0481 ], + [ 0x048A, 0x0513 ], + [ 0x0531, 0x0556 ], + [ 0x0559, 0x0559 ], + [ 0x0561, 0x0587 ], + [ 0x05D0, 0x05EA ], + [ 0x05F0, 0x05F2 ], + [ 0x0621, 0x063A ], + [ 0x0640, 0x064A ], + [ 0x066E, 0x066F ], + [ 0x0671, 0x06D3 ], + [ 0x06D5, 0x06D5 ], + [ 0x06E5, 0x06E6 ], + [ 0x06EE, 0x06EF ], + [ 0x06FA, 0x06FC ], + [ 0x06FF, 0x06FF ], + [ 0x0710, 0x0710 ], + [ 0x0712, 0x072F ], + [ 0x074D, 0x076D ], + [ 0x0780, 0x07A5 ], + [ 0x07B1, 0x07B1 ], + [ 0x07CA, 0x07EA ], + [ 0x07F4, 0x07F5 ], + [ 0x07FA, 0x07FA ], + [ 0x0904, 0x0939 ], + [ 0x093D, 0x093D ], + [ 0x0950, 0x0950 ], + [ 0x0958, 0x0961 ], + [ 0x097B, 0x097F ], + [ 0x0985, 0x098C ], + [ 0x098F, 0x0990 ], + [ 0x0993, 0x09A8 ], + [ 0x09AA, 0x09B0 ], + [ 0x09B2, 0x09B2 ], + [ 0x09B6, 0x09B9 ], + [ 0x09BD, 0x09BD ], + [ 0x09CE, 0x09CE ], + [ 0x09DC, 0x09DD ], + [ 0x09DF, 0x09E1 ], + [ 0x09F0, 0x09F1 ], + [ 0x0A05, 0x0A0A ], + [ 0x0A0F, 0x0A10 ], + [ 0x0A13, 0x0A28 ], + [ 0x0A2A, 0x0A30 ], + [ 0x0A32, 0x0A33 ], + [ 0x0A35, 0x0A36 ], + [ 0x0A38, 0x0A39 ], + [ 0x0A59, 0x0A5C ], + [ 0x0A5E, 0x0A5E ], + [ 0x0A72, 0x0A74 ], + [ 0x0A85, 0x0A8D ], + [ 0x0A8F, 0x0A91 ], + [ 0x0A93, 0x0AA8 ], + [ 0x0AAA, 0x0AB0 ], + [ 0x0AB2, 0x0AB3 ], + [ 0x0AB5, 0x0AB9 ], + [ 0x0ABD, 0x0ABD ], + [ 0x0AD0, 0x0AD0 ], + [ 0x0AE0, 0x0AE1 ], + [ 0x0B05, 0x0B0C ], + [ 0x0B0F, 0x0B10 ], + [ 0x0B13, 0x0B28 ], + [ 0x0B2A, 0x0B30 ], + [ 0x0B32, 0x0B33 ], + [ 0x0B35, 0x0B39 ], + [ 0x0B3D, 0x0B3D ], + [ 0x0B5C, 0x0B5D ], + [ 0x0B5F, 0x0B61 ], + [ 0x0B71, 0x0B71 ], + [ 0x0B83, 0x0B83 ], + [ 0x0B85, 0x0B8A ], + [ 0x0B8E, 0x0B90 ], + [ 0x0B92, 0x0B95 ], + [ 0x0B99, 0x0B9A ], + [ 0x0B9C, 0x0B9C ], + [ 0x0B9E, 0x0B9F ], + [ 0x0BA3, 0x0BA4 ], + [ 0x0BA8, 0x0BAA ], + [ 0x0BAE, 0x0BB9 ], + [ 0x0C05, 0x0C0C ], + [ 0x0C0E, 0x0C10 ], + [ 0x0C12, 0x0C28 ], + [ 0x0C2A, 0x0C33 ], + [ 0x0C35, 0x0C39 ], + [ 0x0C60, 0x0C61 ], + [ 0x0C85, 0x0C8C ], + [ 0x0C8E, 0x0C90 ], + [ 0x0C92, 0x0CA8 ], + [ 0x0CAA, 0x0CB3 ], + [ 0x0CB5, 0x0CB9 ], + [ 0x0CBD, 0x0CBD ], + [ 0x0CDE, 0x0CDE ], + [ 0x0CE0, 0x0CE1 ], + [ 0x0D05, 0x0D0C ], + [ 0x0D0E, 0x0D10 ], + [ 0x0D12, 0x0D28 ], + [ 0x0D2A, 0x0D39 ], + [ 0x0D60, 0x0D61 ], + [ 0x0D85, 0x0D96 ], + [ 0x0D9A, 0x0DB1 ], + [ 0x0DB3, 0x0DBB ], + [ 0x0DBD, 0x0DBD ], + [ 0x0DC0, 0x0DC6 ], + [ 0x0E01, 0x0E30 ], + [ 0x0E32, 0x0E33 ], + [ 0x0E40, 0x0E46 ], + [ 0x0E81, 0x0E82 ], + [ 0x0E84, 0x0E84 ], + [ 0x0E87, 0x0E88 ], + [ 0x0E8A, 0x0E8A ], + [ 0x0E8D, 0x0E8D ], + [ 0x0E94, 0x0E97 ], + [ 0x0E99, 0x0E9F ], + [ 0x0EA1, 0x0EA3 ], + [ 0x0EA5, 0x0EA5 ], + [ 0x0EA7, 0x0EA7 ], + [ 0x0EAA, 0x0EAB ], + [ 0x0EAD, 0x0EB0 ], + [ 0x0EB2, 0x0EB3 ], + [ 0x0EBD, 0x0EBD ], + [ 0x0EC0, 0x0EC4 ], + [ 0x0EC6, 0x0EC6 ], + [ 0x0EDC, 0x0EDD ], + [ 0x0F00, 0x0F00 ], + [ 0x0F40, 0x0F47 ], + [ 0x0F49, 0x0F6A ], + [ 0x0F88, 0x0F8B ], + [ 0x1000, 0x1021 ], + [ 0x1023, 0x1027 ], + [ 0x1029, 0x102A ], + [ 0x1050, 0x1055 ], + [ 0x10A0, 0x10C5 ], + [ 0x10D0, 0x10FA ], + [ 0x10FC, 0x10FC ], + [ 0x1100, 0x1159 ], + [ 0x115F, 0x11A2 ], + [ 0x11A8, 0x11F9 ], + [ 0x1200, 0x1248 ], + [ 0x124A, 0x124D ], + [ 0x1250, 0x1256 ], + [ 0x1258, 0x1258 ], + [ 0x125A, 0x125D ], + [ 0x1260, 0x1288 ], + [ 0x128A, 0x128D ], + [ 0x1290, 0x12B0 ], + [ 0x12B2, 0x12B5 ], + [ 0x12B8, 0x12BE ], + [ 0x12C0, 0x12C0 ], + [ 0x12C2, 0x12C5 ], + [ 0x12C8, 0x12D6 ], + [ 0x12D8, 0x1310 ], + [ 0x1312, 0x1315 ], + [ 0x1318, 0x135A ], + [ 0x1380, 0x138F ], + [ 0x13A0, 0x13F4 ], + [ 0x1401, 0x166C ], + [ 0x166F, 0x1676 ], + [ 0x1681, 0x169A ], + [ 0x16A0, 0x16EA ], + [ 0x1700, 0x170C ], + [ 0x170E, 0x1711 ], + [ 0x1720, 0x1731 ], + [ 0x1740, 0x1751 ], + [ 0x1760, 0x176C ], + [ 0x176E, 0x1770 ], + [ 0x1780, 0x17B3 ], + [ 0x17D7, 0x17D7 ], + [ 0x17DC, 0x17DC ], + [ 0x1820, 0x1877 ], + [ 0x1880, 0x18A8 ], + [ 0x1900, 0x191C ], + [ 0x1950, 0x196D ], + [ 0x1970, 0x1974 ], + [ 0x1980, 0x19A9 ], + [ 0x19C1, 0x19C7 ], + [ 0x1A00, 0x1A16 ], + [ 0x1B05, 0x1B33 ], + [ 0x1B45, 0x1B4B ], + [ 0x1D00, 0x1DBF ], + [ 0x1E00, 0x1E9B ], + [ 0x1EA0, 0x1EF9 ], + [ 0x1F00, 0x1F15 ], + [ 0x1F18, 0x1F1D ], + [ 0x1F20, 0x1F45 ], + [ 0x1F48, 0x1F4D ], + [ 0x1F50, 0x1F57 ], + [ 0x1F59, 0x1F59 ], + [ 0x1F5B, 0x1F5B ], + [ 0x1F5D, 0x1F5D ], + [ 0x1F5F, 0x1F7D ], + [ 0x1F80, 0x1FB4 ], + [ 0x1FB6, 0x1FBC ], + [ 0x1FBE, 0x1FBE ], + [ 0x1FC2, 0x1FC4 ], + [ 0x1FC6, 0x1FCC ], + [ 0x1FD0, 0x1FD3 ], + [ 0x1FD6, 0x1FDB ], + [ 0x1FE0, 0x1FEC ], + [ 0x1FF2, 0x1FF4 ], + [ 0x1FF6, 0x1FFC ], + [ 0x2071, 0x2071 ], + [ 0x207F, 0x207F ], + [ 0x2090, 0x2094 ], + [ 0x2102, 0x2102 ], + [ 0x2107, 0x2107 ], + [ 0x210A, 0x2113 ], + [ 0x2115, 0x2115 ], + [ 0x2119, 0x211D ], + [ 0x2124, 0x2124 ], + [ 0x2126, 0x2126 ], + [ 0x2128, 0x2128 ], + [ 0x212A, 0x212D ], + [ 0x212F, 0x2139 ], + [ 0x213C, 0x213F ], + [ 0x2145, 0x2149 ], + [ 0x214E, 0x214E ], + [ 0x2183, 0x2184 ], + [ 0x2C00, 0x2C2E ], + [ 0x2C30, 0x2C5E ], + [ 0x2C60, 0x2C6C ], + [ 0x2C74, 0x2C77 ], + [ 0x2C80, 0x2CE4 ], + [ 0x2D00, 0x2D25 ], + [ 0x2D30, 0x2D65 ], + [ 0x2D6F, 0x2D6F ], + [ 0x2D80, 0x2D96 ], + [ 0x2DA0, 0x2DA6 ], + [ 0x2DA8, 0x2DAE ], + [ 0x2DB0, 0x2DB6 ], + [ 0x2DB8, 0x2DBE ], + [ 0x2DC0, 0x2DC6 ], + [ 0x2DC8, 0x2DCE ], + [ 0x2DD0, 0x2DD6 ], + [ 0x2DD8, 0x2DDE ], + [ 0x3005, 0x3006 ], + [ 0x3031, 0x3035 ], + [ 0x303B, 0x303C ], + [ 0x3041, 0x3096 ], + [ 0x309D, 0x309F ], + [ 0x30A1, 0x30FA ], + [ 0x30FC, 0x30FF ], + [ 0x3105, 0x312C ], + [ 0x3131, 0x318E ], + [ 0x31A0, 0x31B7 ], + [ 0x31F0, 0x31FF ], + [ 0x3400, 0x4DB5 ], + [ 0x4E00, 0x9FBB ], + [ 0xA000, 0xA48C ], + [ 0xA717, 0xA71A ], + [ 0xA800, 0xA801 ], + [ 0xA803, 0xA805 ], + [ 0xA807, 0xA80A ], + [ 0xA80C, 0xA822 ], + [ 0xA840, 0xA873 ], + [ 0xAC00, 0xD7A3 ], + [ 0xF900, 0xFA2D ], + [ 0xFA30, 0xFA6A ], + [ 0xFA70, 0xFAD9 ], + [ 0xFB00, 0xFB06 ], + [ 0xFB13, 0xFB17 ], + [ 0xFB1D, 0xFB1D ], + [ 0xFB1F, 0xFB28 ], + [ 0xFB2A, 0xFB36 ], + [ 0xFB38, 0xFB3C ], + [ 0xFB3E, 0xFB3E ], + [ 0xFB40, 0xFB41 ], + [ 0xFB43, 0xFB44 ], + [ 0xFB46, 0xFBB1 ], + [ 0xFBD3, 0xFD3D ], + [ 0xFD50, 0xFD8F ], + [ 0xFD92, 0xFDC7 ], + [ 0xFDF0, 0xFDFB ], + [ 0xFE70, 0xFE74 ], + [ 0xFE76, 0xFEFC ], + [ 0xFF21, 0xFF3A ], + [ 0xFF41, 0xFF5A ], + [ 0xFF66, 0xFFBE ], + [ 0xFFC2, 0xFFC7 ], + [ 0xFFCA, 0xFFCF ], + [ 0xFFD2, 0xFFD7 ], + [ 0xFFDA, 0xFFDC ], + [ 0x10000, 0x1000B ], + [ 0x1000D, 0x10026 ], + [ 0x10028, 0x1003A ], + [ 0x1003C, 0x1003D ], + [ 0x1003F, 0x1004D ], + [ 0x10050, 0x1005D ], + [ 0x10080, 0x100FA ], + [ 0x10300, 0x1031E ], + [ 0x10330, 0x10340 ], + [ 0x10342, 0x10349 ], + [ 0x10380, 0x1039D ], + [ 0x103A0, 0x103C3 ], + [ 0x103C8, 0x103CF ], + [ 0x10400, 0x1049D ], + [ 0x10800, 0x10805 ], + [ 0x10808, 0x10808 ], + [ 0x1080A, 0x10835 ], + [ 0x10837, 0x10838 ], + [ 0x1083C, 0x1083C ], + [ 0x1083F, 0x1083F ], + [ 0x10900, 0x10915 ], + [ 0x10A00, 0x10A00 ], + [ 0x10A10, 0x10A13 ], + [ 0x10A15, 0x10A17 ], + [ 0x10A19, 0x10A33 ], + [ 0x12000, 0x1236E ], + [ 0x1D400, 0x1D454 ], + [ 0x1D456, 0x1D49C ], + [ 0x1D49E, 0x1D49F ], + [ 0x1D4A2, 0x1D4A2 ], + [ 0x1D4A5, 0x1D4A6 ], + [ 0x1D4A9, 0x1D4AC ], + [ 0x1D4AE, 0x1D4B9 ], + [ 0x1D4BB, 0x1D4BB ], + [ 0x1D4BD, 0x1D4C3 ], + [ 0x1D4C5, 0x1D505 ], + [ 0x1D507, 0x1D50A ], + [ 0x1D50D, 0x1D514 ], + [ 0x1D516, 0x1D51C ], + [ 0x1D51E, 0x1D539 ], + [ 0x1D53B, 0x1D53E ], + [ 0x1D540, 0x1D544 ], + [ 0x1D546, 0x1D546 ], + [ 0x1D54A, 0x1D550 ], + [ 0x1D552, 0x1D6A5 ], + [ 0x1D6A8, 0x1D6C0 ], + [ 0x1D6C2, 0x1D6DA ], + [ 0x1D6DC, 0x1D6FA ], + [ 0x1D6FC, 0x1D714 ], + [ 0x1D716, 0x1D734 ], + [ 0x1D736, 0x1D74E ], + [ 0x1D750, 0x1D76E ], + [ 0x1D770, 0x1D788 ], + [ 0x1D78A, 0x1D7A8 ], + [ 0x1D7AA, 0x1D7C2 ], + [ 0x1D7C4, 0x1D7CB ], + [ 0x20000, 0x2A6D6 ], + [ 0x2F800, 0x2FA1D ], ]; debug @@ -584,48 +584,48 @@ int isUniAlpha(dchar u) high = table.length - 1; while (cast(int)low <= cast(int)high) { - mid = (low + high) >> 1; - if (u < table[mid][0]) - high = mid - 1; - else if (u > table[mid][1]) - low = mid + 1; - else - goto Lis; + mid = (low + high) >> 1; + if (u < table[mid][0]) + high = mid - 1; + else if (u > table[mid][1]) + low = mid + 1; + else + goto Lis; } Lisnot: debug { - for (int i = 0; i < table.length; i++) - { - assert(u < table[i][0] || u > table[i][1]); - } + for (int i = 0; i < table.length; i++) + { + assert(u < table[i][0] || u > table[i][1]); + } } return 0; Lis: debug { - for (int i = 0; i < table.length; i++) - { - if (u >= table[i][0] && u <= table[i][1]) - return 1; - } - assert(0); // should have been in table + for (int i = 0; i < table.length; i++) + { + if (u >= table[i][0] && u <= table[i][1]) + return 1; + } + assert(0); // should have been in table } else - return 1; + return 1; } unittest { for (uint i = 0; i < 0x80; i++) { - if (i >= 'A' && i <= 'Z') - assert(isUniAlpha(i)); - else if (i >= 'a' && i <= 'z') - assert(isUniAlpha(i)); - else - assert(!isUniAlpha(i)); + if (i >= 'A' && i <= 'Z') + assert(isUniAlpha(i)); + else if (i >= 'a' && i <= 'z') + assert(isUniAlpha(i)); + else + assert(!isUniAlpha(i)); } } diff --git a/std/uri.d b/std/uri.d index 74b8c430c..0dbeffe44 100644 --- a/std/uri.d +++ b/std/uri.d @@ -1,29 +1,6 @@ -// Written in the D programming language +// Written in the D programming language. -/* - * Copyright (C) 2004-2007 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. - */ - -/************************* +/** * Encode and decode Uniform Resource Identifiers (URIs). * URIs are used in internet transfer protocols. * Valid URI characters consist of letters, digits, @@ -36,8 +13,16 @@ * $(LINK2 http://en.wikipedia.org/wiki/Uniform_resource_identifier, Wikipedia) * Macros: * WIKI = Phobos/StdUri + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.uri; //debug=uri; // uncomment to turn on debugging printf's diff --git a/std/utf.d b/std/utf.d index 562f1cace..9fcf2f7e3 100644 --- a/std/utf.d +++ b/std/utf.d @@ -1,28 +1,6 @@ -// Written in the D programming language +// Written in the D programming language. -/* - * Copyright (C) 2003-2004 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, 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. - */ - -/******************************************** +/** * Encode and decode UTF-8, UTF-16 and UTF-32 strings. * * For Win32 systems, the C wchar_t type is UTF-16 and corresponds to the D @@ -33,23 +11,31 @@ * UTF character support is restricted to (\u0000 <= character <= \U0010FFFF). * * See_Also: - * $(LINK2 http://en.wikipedia.org/wiki/Unicode, Wikipedia)
- * $(LINK http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8)
- * $(LINK http://anubis.dkuug.dk/JTC1/SC2/WG2/docs/n1335) + * $(LINK2 http://en.wikipedia.org/wiki/Unicode, Wikipedia)
+ * $(LINK http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8)
+ * $(LINK http://anubis.dkuug.dk/JTC1/SC2/WG2/docs/n1335) * Macros: - * WIKI = Phobos/StdUtf + * WIKI = Phobos/StdUtf + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.utf; private import std.stdio; import std.contracts, std.conv, std.range, std.typecons; -//debug=utf; // uncomment to turn on debugging printf's +//debug=utf; // uncomment to turn on debugging printf's deprecated class UtfError : Error { - size_t idx; // index in string of where error occurred + size_t idx; // index in string of where error occurred this(string s, size_t i) { @@ -64,7 +50,7 @@ deprecated class UtfError : Error class UtfException : Exception { - //size_t idx; /// index in string of where error occurred + //size_t idx; /// index in string of where error occurred uint[4] sequence; size_t len; @@ -102,7 +88,7 @@ bool isValidDchar(dchar c) */ return c < 0xD800 || - (c > 0xDFFF && c <= 0x10FFFF /*&& c != 0xFFFE && c != 0xFFFF*/); + (c > 0xDFFF && c <= 0x10FFFF /*&& c != 0xFFFE && c != 0xFFFF*/); } unittest @@ -137,8 +123,8 @@ private invariant ubyte[256] UTF8stride = * stride() returns the length of a UTF-8 sequence starting at index i * in string s. * Returns: - * The number of bytes in the UTF-8 sequence or - * 0xFF meaning s[i] is not the start of of UTF-8 sequence. + * The number of bytes in the UTF-8 sequence or + * 0xFF meaning s[i] is not the start of of UTF-8 sequence. */ uint stride(in char[] s, size_t i) @@ -200,12 +186,12 @@ size_t toUCSindex(in wchar[] s, size_t i) for (j = 0; j < i; ) { - j += stride(s, j); - n++; + j += stride(s, j); + n++; } if (j > i) { - throw new UtfException("2invalid UTF-16 sequence"); + throw new UtfException("2invalid UTF-16 sequence"); } return n; } @@ -227,10 +213,10 @@ size_t toUTFindex(in char[] s, size_t n) while (n--) { - uint j = UTF8stride[s[i]]; - if (j == 0xFF) - throw new UtfException("3invalid UTF-8 sequence ", s[i]); - i += j; + uint j = UTF8stride[s[i]]; + if (j == 0xFF) + throw new UtfException("3invalid UTF-8 sequence ", s[i]); + i += j; } return i; } @@ -242,9 +228,9 @@ size_t toUTFindex(in wchar[] s, size_t n) size_t i; while (n--) - { wchar u = s[i]; + { wchar u = s[i]; - i += 1 + (u >= 0xD800 && u <= 0xDBFF); + i += 1 + (u >= 0xD800 && u <= 0xDBFF); } return i; } @@ -271,83 +257,83 @@ in } out (result) { - assert(isValidDchar(result)); + assert(isValidDchar(result)); } body { - size_t len = s.length; - dchar V; - size_t i = idx; - char u = s[i]; + size_t len = s.length; + dchar V; + size_t i = idx; + char u = s[i]; - if (u & 0x80) - { - /* The following encodings are valid, except for the 5 and 6 byte - * combinations: - * 0xxxxxxx - * 110xxxxx 10xxxxxx - * 1110xxxx 10xxxxxx 10xxxxxx - * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx - * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx - */ + if (u & 0x80) + { + /* The following encodings are valid, except for the 5 and 6 byte + * combinations: + * 0xxxxxxx + * 110xxxxx 10xxxxxx + * 1110xxxx 10xxxxxx 10xxxxxx + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + */ uint n = 1; for (; ; n++) - { + { if (n > 4) - goto Lerr; // only do the first 4 of 6 encodings + goto Lerr; // only do the first 4 of 6 encodings if (((u << n) & 0x80) == 0) { if (n == 1) goto Lerr; break; } - } + } - // Pick off (7 - n) significant bits of B from first byte of octet - V = cast(dchar)(u & ((1 << (7 - n)) - 1)); + // Pick off (7 - n) significant bits of B from first byte of octet + V = cast(dchar)(u & ((1 << (7 - n)) - 1)); - if (i + n > len) - goto Lerr; // off end of string + if (i + n > len) + goto Lerr; // off end of string - /* The following combinations are overlong, and illegal: - * 1100000x (10xxxxxx) - * 11100000 100xxxxx (10xxxxxx) - * 11110000 1000xxxx (10xxxxxx 10xxxxxx) - * 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) - * 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) - */ - auto u2 = s[i + 1]; - if ((u & 0xFE) == 0xC0 || + /* The following combinations are overlong, and illegal: + * 1100000x (10xxxxxx) + * 11100000 100xxxxx (10xxxxxx) + * 11110000 1000xxxx (10xxxxxx 10xxxxxx) + * 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) + * 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) + */ + auto u2 = s[i + 1]; + if ((u & 0xFE) == 0xC0 || (u == 0xE0 && (u2 & 0xE0) == 0x80) || (u == 0xF0 && (u2 & 0xF0) == 0x80) || (u == 0xF8 && (u2 & 0xF8) == 0x80) || (u == 0xFC && (u2 & 0xFC) == 0x80)) - goto Lerr; // overlong combination + goto Lerr; // overlong combination - foreach (j; 1 .. n) - { + foreach (j; 1 .. n) + { u = s[i + j]; if ((u & 0xC0) != 0x80) - goto Lerr; // trailing bytes are 10xxxxxx + goto Lerr; // trailing bytes are 10xxxxxx V = (V << 6) | (u & 0x3F); - } - if (!isValidDchar(V)) + } + if (!isValidDchar(V)) goto Lerr; - i += n; - } - else - { - V = cast(dchar) u; - i++; - } + i += n; + } + else + { + V = cast(dchar) u; + i++; + } - idx = i; - return V; + idx = i; + return V; Lerr: - //printf("\ndecode: idx = %d, i = %d, length = %d s = \n'%.*s'\n%x\n'%.*s'\n", idx, i, s.length, s, s[i], s[i .. length]); - throw new UtfException("4invalid UTF-8 sequence", s[i]); + //printf("\ndecode: idx = %d, i = %d, length = %d s = \n'%.*s'\n%x\n'%.*s'\n", idx, i, s.length, s, s[i], s[i .. length]); + throw new UtfException("4invalid UTF-8 sequence", s[i]); } unittest @@ -378,28 +364,28 @@ unittest assert(i == 3); static string[] s4 = - [ "\xE2\x89", // too short - "\xC0\x8A", - "\xE0\x80\x8A", - "\xF0\x80\x80\x8A", - "\xF8\x80\x80\x80\x8A", - "\xFC\x80\x80\x80\x80\x8A", + [ "\xE2\x89", // too short + "\xC0\x8A", + "\xE0\x80\x8A", + "\xF0\x80\x80\x8A", + "\xF8\x80\x80\x80\x8A", + "\xFC\x80\x80\x80\x80\x8A", ]; for (int j = 0; j < s4.length; j++) { - try - { - i = 0; - c = decode(s4[j], i); - assert(0); - } - catch (UtfException u) - { - i = 23; - delete u; - } - assert(i == 23); + try + { + i = 0; + c = decode(s4[j], i); + assert(0); + } + catch (UtfException u) + { + i = 23; + delete u; + } + assert(i == 23); } } @@ -408,22 +394,22 @@ unittest dchar decode(in wchar[] s, inout size_t idx) in { - assert(idx >= 0 && idx < s.length); + assert(idx >= 0 && idx < s.length); } out (result) { - assert(isValidDchar(result)); + assert(isValidDchar(result)); } body { - string msg; - dchar V; - size_t i = idx; - uint u = s[i]; + string msg; + dchar V; + size_t i = idx; + uint u = s[i]; - if (u & ~0x7F) - { if (u >= 0xD800 && u <= 0xDBFF) - { uint u2; + if (u & ~0x7F) + { if (u >= 0xD800 && u <= 0xDBFF) + { uint u2; if (i + 1 == s.length) { msg = "surrogate UTF-16 high value past end of string"; @@ -436,28 +422,28 @@ body } u = ((u - 0xD7C0) << 10) + (u2 - 0xDC00); i += 2; - } - else if (u >= 0xDC00 && u <= 0xDFFF) - { msg = "unpaired surrogate UTF-16 value"; + } + else if (u >= 0xDC00 && u <= 0xDFFF) + { msg = "unpaired surrogate UTF-16 value"; goto Lerr; - } - else if (u == 0xFFFE || u == 0xFFFF) - { msg = "illegal UTF-16 value"; + } + else if (u == 0xFFFE || u == 0xFFFF) + { msg = "illegal UTF-16 value"; goto Lerr; - } - else + } + else i++; - } - else - { - i++; - } + } + else + { + i++; + } - idx = i; - return cast(dchar)u; + idx = i; + return cast(dchar)u; Lerr: - throw new UtfException(msg, s[i]); + throw new UtfException(msg, s[i]); } /** ditto */ @@ -465,20 +451,20 @@ body dchar decode(in dchar[] s, inout size_t idx) in { - assert(idx >= 0 && idx < s.length); + assert(idx >= 0 && idx < s.length); } body { - size_t i = idx; - dchar c = s[i]; + size_t i = idx; + dchar c = s[i]; - if (!isValidDchar(c)) - goto Lerr; - idx = i + 1; - return c; + if (!isValidDchar(c)) + goto Lerr; + idx = i + 1; + return c; Lerr: - throw new UtfException("5invalid UTF-32 value", c); + throw new UtfException("5invalid UTF-32 value", c); } // Decodes one dchar from input range $(D r). Returns the decoded @@ -486,15 +472,15 @@ body dchar decodeFront(Range)(ref Range r) out (result) { - assert(isValidDchar(result)); + assert(isValidDchar(result)); } body { enforce(!r.empty); - char u = r.front; + char u = r.front; r.popFront; - if (!(u & 0x80)) + if (!(u & 0x80)) { // simplest case: one single character return u; @@ -508,12 +494,12 @@ body /* The following encodings are valid, except for the 5 and 6 byte * combinations: - * 0xxxxxxx - * 110xxxxx 10xxxxxx - * 1110xxxx 10xxxxxx 10xxxxxx - * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx - * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + * 0xxxxxxx + * 110xxxxx 10xxxxxx + * 1110xxxx 10xxxxxx 10xxxxxx + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ uint n = void; switch (u & 0b1111_0000) @@ -536,11 +522,11 @@ body auto result = cast(dchar) (u & ((1 << (7 - n)) - 1)); /* The following combinations are overlong, and illegal: - * 1100000x (10xxxxxx) - * 11100000 100xxxxx (10xxxxxx) - * 11110000 1000xxxx (10xxxxxx 10xxxxxx) - * 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) - * 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) + * 1100000x (10xxxxxx) + * 11100000 100xxxxx (10xxxxxx) + * 11110000 1000xxxx (10xxxxxx 10xxxxxx) + * 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) + * 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) */ char u2 = r.front; enforce(!((u & 0xFE) == 0xC0 || @@ -558,7 +544,7 @@ body result = (result << 6) | (u & 0x3F); } enforce(isValidDchar(result)); - return result; + return result; } unittest @@ -584,12 +570,12 @@ unittest assert(s3 == ""); static string[] s4 = - [ "\xE2\x89", // too short - "\xC0\x8A", - "\xE0\x80\x8A", - "\xF0\x80\x80\x8A", - "\xF8\x80\x80\x80\x8A", - "\xFC\x80\x80\x80\x80\x8A", + [ "\xE2\x89", // too short + "\xC0\x8A", + "\xE0\x80\x8A", + "\xF0\x80\x80\x8A", + "\xF8\x80\x80\x80\x8A", + "\xFC\x80\x80\x80\x80\x8A", ]; for (int j = 0; j < s4.length; j++) @@ -626,12 +612,12 @@ dchar decodeBack(Range)(ref Range r) r.popBack; /* The following encodings are valid, except for the 5 and 6 byte * combinations: - * 0xxxxxxx - * 110xxxxx 10xxxxxx - * 1110xxxx 10xxxxxx 10xxxxxx - * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx - * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + * 0xxxxxxx + * 110xxxxx 10xxxxxx + * 1110xxxx 10xxxxxx 10xxxxxx + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ if (! (chars[idx] & 0b0100_0000)) { chars[1] = r.back; r.popBack; idx = 1; } if (! (chars[idx] & 0b0100_0000)) { chars[0] = r.back; r.popBack; idx = 0; } @@ -664,12 +650,12 @@ unittest assert(s3 == ""); static string[] s4 = - [ "\xE2\x89", // too short - "\xC0\x8A", - "\xE0\x80\x8A", - "\xF0\x80\x80\x8A", - "\xF8\x80\x80\x80\x8A", - "\xFC\x80\x80\x80\x80\x8A", + [ "\xE2\x89", // too short + "\xC0\x8A", + "\xE0\x80\x8A", + "\xF0\x80\x80\x8A", + "\xF8\x80\x80\x80\x8A", + "\xFC\x80\x80\x80\x80\x8A", ]; for (int j = 0; j < s4.length; j++) @@ -704,11 +690,11 @@ in } body { - if (c <= 0x7F) - { - buf[0] = cast(char) c; + if (c <= 0x7F) + { + buf[0] = cast(char) c; return 1; - } + } if (c <= 0x7FF) { buf[0] = cast(char)(0xC0 | (c >> 6)); @@ -737,15 +723,15 @@ body void encode(/*ref*/ wchar[2] buf, dchar c) in { - assert(isValidDchar(c)); + assert(isValidDchar(c)); } body { - if (c <= 0xFFFF) - { - buf[0] = cast(wchar) c; + if (c <= 0xFFFF) + { + buf[0] = cast(wchar) c; return 1; - } + } buf[0] = cast(wchar) ((((c - 0x10000) >> 10) & 0x3FF) + 0xD800); buf[1] = cast(wchar) (((c - 0x10000) & 0x3FF) + 0xDC00); return 2; @@ -762,45 +748,45 @@ in } body { - char[] r = s; + char[] r = s; - if (c <= 0x7F) - { - r ~= cast(char) c; - } - else - { - char[4] buf; - uint L; + if (c <= 0x7F) + { + r ~= cast(char) c; + } + else + { + char[4] buf; + uint L; - if (c <= 0x7FF) - { + if (c <= 0x7FF) + { buf[0] = cast(char)(0xC0 | (c >> 6)); buf[1] = cast(char)(0x80 | (c & 0x3F)); L = 2; - } - else if (c <= 0xFFFF) - { + } + else if (c <= 0xFFFF) + { buf[0] = cast(char)(0xE0 | (c >> 12)); buf[1] = cast(char)(0x80 | ((c >> 6) & 0x3F)); buf[2] = cast(char)(0x80 | (c & 0x3F)); L = 3; - } - else if (c <= 0x10FFFF) - { + } + else if (c <= 0x10FFFF) + { buf[0] = cast(char)(0xF0 | (c >> 18)); buf[1] = cast(char)(0x80 | ((c >> 12) & 0x3F)); buf[2] = cast(char)(0x80 | ((c >> 6) & 0x3F)); buf[3] = cast(char)(0x80 | (c & 0x3F)); L = 4; - } - else - { + } + else + { assert(0); - } - r ~= buf[0 .. L]; - } - s = r; + } + r ~= buf[0 .. L]; + } + s = r; } unittest @@ -815,7 +801,7 @@ unittest encode(s, cast(dchar)'\u00A9'); assert(s.length == 7); assert(s == "abcda\xC2\xA9"); - //assert(s == "abcda\u00A9"); // BUG: fix compiler + //assert(s == "abcda\u00A9"); // BUG: fix compiler encode(s, cast(dchar)'\u2260'); assert(s.length == 10); @@ -827,25 +813,25 @@ unittest void encode(inout wchar[] s, dchar c) in { - assert(isValidDchar(c)); + assert(isValidDchar(c)); } body { - wchar[] r = s; + wchar[] r = s; - if (c <= 0xFFFF) - { - r ~= cast(wchar) c; - } - else - { - wchar[2] buf; + if (c <= 0xFFFF) + { + r ~= cast(wchar) c; + } + else + { + wchar[2] buf; - buf[0] = cast(wchar) ((((c - 0x10000) >> 10) & 0x3FF) + 0xD800); - buf[1] = cast(wchar) (((c - 0x10000) & 0x3FF) + 0xDC00); - r ~= buf; - } - s = r; + buf[0] = cast(wchar) ((((c - 0x10000) >> 10) & 0x3FF) + 0xD800); + buf[1] = cast(wchar) (((c - 0x10000) & 0x3FF) + 0xDC00); + r ~= buf; + } + s = r; } /** ditto */ @@ -853,11 +839,11 @@ void encode(inout wchar[] s, dchar c) void encode(inout dchar[] s, dchar c) in { - assert(isValidDchar(c)); + assert(isValidDchar(c)); } body { - s ~= c; + s ~= c; } /** @@ -878,7 +864,7 @@ ubyte codeLength(C)(dchar c) } else static if (C.sizeof == 2) { - return c <= 0xFFFF ? 1 : 2; + return c <= 0xFFFF ? 1 : 2; } else { @@ -900,7 +886,7 @@ void validate(S)(in S s) invariant len = s.length; for (size_t i = 0; i < len; ) { - decode(s, i); + decode(s, i); } } @@ -909,37 +895,37 @@ void validate(S)(in S s) char[] toUTF8(char[4] buf, dchar c) in { - assert(isValidDchar(c)); + assert(isValidDchar(c)); } body { - if (c <= 0x7F) - { - buf[0] = cast(char) c; - return buf[0 .. 1]; - } - else if (c <= 0x7FF) - { - buf[0] = cast(char)(0xC0 | (c >> 6)); - buf[1] = cast(char)(0x80 | (c & 0x3F)); - return buf[0 .. 2]; - } - else if (c <= 0xFFFF) - { - buf[0] = cast(char)(0xE0 | (c >> 12)); - buf[1] = cast(char)(0x80 | ((c >> 6) & 0x3F)); - buf[2] = cast(char)(0x80 | (c & 0x3F)); - return buf[0 .. 3]; - } - else if (c <= 0x10FFFF) - { - buf[0] = cast(char)(0xF0 | (c >> 18)); - buf[1] = cast(char)(0x80 | ((c >> 12) & 0x3F)); - buf[2] = cast(char)(0x80 | ((c >> 6) & 0x3F)); - buf[3] = cast(char)(0x80 | (c & 0x3F)); - return buf[0 .. 4]; - } - assert(0); + if (c <= 0x7F) + { + buf[0] = cast(char) c; + return buf[0 .. 1]; + } + else if (c <= 0x7FF) + { + buf[0] = cast(char)(0xC0 | (c >> 6)); + buf[1] = cast(char)(0x80 | (c & 0x3F)); + return buf[0 .. 2]; + } + else if (c <= 0xFFFF) + { + buf[0] = cast(char)(0xE0 | (c >> 12)); + buf[1] = cast(char)(0x80 | ((c >> 6) & 0x3F)); + buf[2] = cast(char)(0x80 | (c & 0x3F)); + return buf[0 .. 3]; + } + else if (c <= 0x10FFFF) + { + buf[0] = cast(char)(0xF0 | (c >> 18)); + buf[1] = cast(char)(0x80 | ((c >> 12) & 0x3F)); + buf[2] = cast(char)(0x80 | ((c >> 6) & 0x3F)); + buf[3] = cast(char)(0x80 | (c & 0x3F)); + return buf[0 .. 4]; + } + assert(0); } /******************* @@ -949,11 +935,11 @@ char[] toUTF8(char[4] buf, dchar c) string toUTF8(string s) in { - validate(s); + validate(s); } body { - return s; + return s; } /** ditto */ @@ -967,19 +953,19 @@ string toUTF8(const(wchar)[] s) r.length = slen; for (i = 0; i < slen; i++) - { wchar c = s[i]; + { wchar c = s[i]; - if (c <= 0x7F) - r[i] = cast(char)c; // fast path for ascii - else - { - r.length = i; - foreach (dchar c; s[i .. slen]) - { - encode(r, c); - } - break; - } + if (c <= 0x7F) + r[i] = cast(char)c; // fast path for ascii + else + { + r.length = i; + foreach (dchar c; s[i .. slen]) + { + encode(r, c); + } + break; + } } return assumeUnique(r); } @@ -995,19 +981,19 @@ string toUTF8(const(dchar)[] s) r.length = slen; for (i = 0; i < slen; i++) - { dchar c = s[i]; + { dchar c = s[i]; - if (c <= 0x7F) - r[i] = cast(char)c; // fast path for ascii - else - { - r.length = i; - foreach (dchar d; s[i .. slen]) - { - encode(r, d); - } - break; - } + if (c <= 0x7F) + r[i] = cast(char)c; // fast path for ascii + else + { + r.length = i; + foreach (dchar d; s[i .. slen]) + { + encode(r, d); + } + break; + } } return assumeUnique(r); } @@ -1017,21 +1003,21 @@ string toUTF8(const(dchar)[] s) wchar[] toUTF16(wchar[2] buf, dchar c) in { - assert(isValidDchar(c)); + assert(isValidDchar(c)); } body { - if (c <= 0xFFFF) - { - buf[0] = cast(wchar) c; - return buf[0 .. 1]; - } - else - { - buf[0] = cast(wchar) ((((c - 0x10000) >> 10) & 0x3FF) + 0xD800); - buf[1] = cast(wchar) (((c - 0x10000) & 0x3FF) + 0xDC00); - return buf[0 .. 2]; - } + if (c <= 0xFFFF) + { + buf[0] = cast(wchar) c; + return buf[0 .. 1]; + } + else + { + buf[0] = cast(wchar) ((((c - 0x10000) >> 10) & 0x3FF) + 0xD800); + buf[1] = cast(wchar) (((c - 0x10000) & 0x3FF) + 0xDC00); + return buf[0 .. 2]; + } } /**************** @@ -1075,17 +1061,17 @@ const(wchar*) toUTF16z(in char[] s) r.length = 0; for (size_t i = 0; i < slen; ) { - dchar c = s[i]; - if (c <= 0x7F) - { - i++; - r ~= cast(wchar)c; - } - else - { - c = decode(s, i); - encode(r, c); - } + dchar c = s[i]; + if (c <= 0x7F) + { + i++; + r ~= cast(wchar)c; + } + else + { + c = decode(s, i); + encode(r, c); + } } r ~= "\000"; return r.ptr; @@ -1096,11 +1082,11 @@ const(wchar*) toUTF16z(in char[] s) wstring toUTF16(wstring s) in { - validate(s); + validate(s); } body { - return s; + return s; } /** ditto */ @@ -1114,7 +1100,7 @@ wstring toUTF16(const(dchar)[] s) r.length = 0; for (size_t i = 0; i < slen; i++) { - encode(r, s[i]); + encode(r, s[i]); } return cast(wstring) r; // ok because r is unique } @@ -1131,15 +1117,15 @@ dstring toUTF32(const(char)[] s) size_t slen = s.length; size_t j = 0; - r.length = slen; // r[] will never be longer than s[] + r.length = slen; // r[] will never be longer than s[] for (size_t i = 0; i < slen; ) { - dchar c = s[i]; - if (c >= 0x80) - c = decode(s, i); - else - i++; // c is ascii, no need for decode - r[j++] = c; + dchar c = s[i]; + if (c >= 0x80) + c = decode(s, i); + else + i++; // c is ascii, no need for decode + r[j++] = c; } return cast(dstring) r[0 .. j]; // legit because it's unique } @@ -1152,15 +1138,15 @@ dstring toUTF32(const(wchar)[] s) size_t slen = s.length; size_t j = 0; - r.length = slen; // r[] will never be longer than s[] + r.length = slen; // r[] will never be longer than s[] for (size_t i = 0; i < slen; ) { - dchar c = s[i]; - if (c >= 0x80) - c = decode(s, i); - else - i++; // c is ascii, no need for decode - r[j++] = c; + dchar c = s[i]; + if (c >= 0x80) + c = decode(s, i); + else + i++; // c is ascii, no need for decode + r[j++] = c; } return cast(dstring) r[0 .. j]; // legit because it's unique } @@ -1170,11 +1156,11 @@ dstring toUTF32(const(wchar)[] s) dstring toUTF32(dstring s) in { - validate(s); + validate(s); } body { - return s; + return s; } /* ================================ tests ================================== */ diff --git a/std/variant.d b/std/variant.d index d5c61d8d1..e32e57827 100644 --- a/std/variant.d +++ b/std/variant.d @@ -11,7 +11,7 @@ * languages, and comfortable exploratory programming. * * Macros: - * WIKI = Phobos/StdVariant + * WIKI = Phobos/StdVariant * * Synopsis: * @@ -45,11 +45,6 @@ * a = foo; * assert(*a.peek!(Foo) == foo); // and full type information is preserved * ---- - * - * Author: - * - * $(WEB erdani.org, Andrei Alexandrescu) - * * Credits: * @@ -57,30 +52,17 @@ * review prompting the following improvements: (1) better support for * arrays; (2) support for associative arrays; (3) friendlier behavior * towards the garbage collector. + * + * Copyright: Copyright Andrei Alexandrescu 2007 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB erdani.org, Andrei Alexandrescu) + * Credits: Brad Roberts came up with the name $(D_PARAM contracts). + * + * Copyright Andrei Alexandrescu 2007 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - -/* - * Copyright (C) 2004-2006 by Digital Mars, www.digitalmars.com - * Written by Andrei Alexandrescu, www.erdani.org - * - * 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, 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 std.variant; import std.traits, std.c.string, std.typetuple, std.conv; @@ -440,7 +422,7 @@ private: // append a whole array to the array (*zis) ~= arg[0].get!(A); } - break; + break; } else { @@ -890,7 +872,7 @@ public: // temp ~= this; // return temp; // } - + ///ditto VariantN opAddAssign(T)(T rhs) { return this = this + rhs; } ///ditto @@ -1223,7 +1205,7 @@ version(none) unittest unittest { Variant v; - + assert(!v.hasValue); v = 42; assert( v.peek!(int) ); @@ -1239,7 +1221,7 @@ unittest assert( v.get!(string) == "Hello, World!" ); assert(!is(char[] : wchar[])); assert( !v.convertsTo!(wchar[]) ); - assert( v.get!(string) == "Hello, World!" ); + assert( v.get!(string) == "Hello, World!" ); v = [1,2,3,4,5]; assert( v.peek!(int[]) ); @@ -1254,7 +1236,7 @@ unittest auto u = Variant(v); assert( u.peek!(double) ); - assert( *u.peek!(double) == 3.1413 ); + assert( *u.peek!(double) == 3.1413 ); // operators v = 38; @@ -1280,7 +1262,7 @@ unittest assert( Variant(4) >> Variant(2) == 1 ); assert( Variant("abc") ~ "def" == "abcdef" ); assert( Variant("abc") ~ Variant("def") == "abcdef" ); - + v = 38; v += 4; assert( v == 42 ); @@ -1293,7 +1275,7 @@ unittest v = 38; v ^= 5; assert( v == 35 ); v = 38; v <<= 1; assert( v == 76 ); v = 38; v >>= 1; assert( v == 19 ); - + v = "abc"; v ~= "def"; assert( v == "abcdef", *v.peek!(char[]) ); @@ -1310,12 +1292,12 @@ unittest auto v1 = Variant(42); auto v2 = Variant("foo"); auto v3 = Variant(1+2.0i); - + int[Variant] hash; hash[v1] = 0; hash[v2] = 1; hash[v3] = 2; - + assert( hash[v1] == 0 ); assert( hash[v2] == 1 ); assert( hash[v3] == 2 ); @@ -1326,7 +1308,7 @@ unittest hash["b"] = 2; hash["c"] = 3; Variant vhash = hash; - + assert( vhash.get!(int[char[]])["a"] == 1 ); assert( vhash.get!(int[char[]])["b"] == 2 ); assert( vhash.get!(int[char[]])["c"] == 3 ); diff --git a/std/windows/charset.d b/std/windows/charset.d index 023ed1d13..f464ede6d 100644 --- a/std/windows/charset.d +++ b/std/windows/charset.d @@ -1,11 +1,20 @@ -/* Public Domain */ +// Written in the D programming language. /** * Support UTF-8 on Windows 95, 98 and ME systems. + * * Macros: * WIKI = Phobos/StdWindowsCharset + * + * Copyright: Copyright Digital Mars 2005 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2005 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.windows.charset; private import std.c.windows.windows; diff --git a/std/windows/iunknown.d b/std/windows/iunknown.d index be304d931..afcb9f3f6 100644 --- a/std/windows/iunknown.d +++ b/std/windows/iunknown.d @@ -1,4 +1,17 @@ +// Written in the D programming language. +/** + * Support COM on Windows systems. + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ module std.windows.iunknown; private import std.c.windows.windows; diff --git a/std/windows/syserror.d b/std/windows/syserror.d index 384a6c5bb..ae47010dd 100644 --- a/std/windows/syserror.d +++ b/std/windows/syserror.d @@ -1,8 +1,18 @@ +// Written in the D programming language. -// Placed in public domain -// Convert Win32 error code to string -// Based on code written by Regan Heath - +/** + * Convert Win32 error code to string. + * + * Copyright: Copyright Digital Mars 2006 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * Credits: Based on code written by Regan Heath + * + * Copyright Digital Mars 2006 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ module std.windows.syserror; private import std.windows.charset; diff --git a/std/xml.d b/std/xml.d index 9e6207a4b..e735e2134 100644 --- a/std/xml.d +++ b/std/xml.d @@ -11,12 +11,6 @@ Document, but that is not their primary purpose. The handling capabilities of DocumentParser and ElementParser are sufficiently customizable that you can make them do pretty much whatever you want. -Authors: Janice Caron - -Date: 2008.02.12 - 2008.05.07 - -License: Public Domain - Example: This example creates a DOM (Document Object Model) tree from an XML file. ------------------------------------------------------------------------------ @@ -113,11 +107,20 @@ void main() writefln(join(doc.pretty(3),"\n")); } ------------------------------------------------------------------------------- - * Macros: - * WIKI=Phobos/StdXml - */ +Macros: + WIKI=Phobos/StdXml +Copyright: Copyright Janice Caron 2008 - 2009. +License: Boost License 1.0. +Authors: Janice Caron + + Copyright Janice Caron 2008 - 2009. +Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ module std.xml; + import std.array; import std.string; import std.encoding; @@ -1653,9 +1656,9 @@ class ElementParser // Private constructor for empty tags this(Tag tag, string* t) { - s = t; - this(); - tag_ = tag; + s = t; + this(); + tag_ = tag; } } @@ -1940,10 +1943,10 @@ class ElementParser auto startTag = startTags[tag_.name]; string text; - invariant(char)* p = startTag.tagString.ptr - + startTag.tagString.length; - invariant(char)* q = tag_.tagString.ptr; - text = p[0..(q-p)]; + invariant(char)* p = startTag.tagString.ptr + + startTag.tagString.length; + invariant(char)* q = tag_.tagString.ptr; + text = p[0..(q-p)]; auto element = new Element(startTag); if (text.length != 0) element ~= new Text(text); @@ -1960,7 +1963,7 @@ class ElementParser } else if (tag_.isEmpty) { - Tag startTag = new Tag(tag_.name); + Tag startTag = new Tag(tag_.name); // FIX by hed010gy, for bug 2979 // http://d.puremagic.com/issues/show_bug.cgi?id=2979 @@ -1968,26 +1971,26 @@ class ElementParser foreach(tn,tv; tag_.attr) startTag.attr[tn]=tv; // END FIX - // Handle the pretend start tag - string s2; - auto parser = new ElementParser(startTag,&s2); - auto handler1 = startTag.name in onStartTag; - if (handler1 !is null) (*handler1)(parser); - else - { - handler1 = null in onStartTag; - if (handler1 !is null) (*handler1)(parser); - } - - // Handle the pretend end tag - auto element = new Element(startTag); - auto handler2 = tag_.name in onEndTag; - if (handler2 !is null) (*handler2)(element); - else - { - handler2 = null in onEndTag; - if (handler2 !is null) (*handler2)(element); - } + // Handle the pretend start tag + string s2; + auto parser = new ElementParser(startTag,&s2); + auto handler1 = startTag.name in onStartTag; + if (handler1 !is null) (*handler1)(parser); + else + { + handler1 = null in onStartTag; + if (handler1 !is null) (*handler1)(parser); + } + + // Handle the pretend end tag + auto element = new Element(startTag); + auto handler2 = tag_.name in onEndTag; + if (handler2 !is null) (*handler2)(element); + else + { + handler2 = null in onEndTag; + if (handler2 !is null) (*handler2)(element); + } } } else diff --git a/std/zip.d b/std/zip.d index 55aaa5371..73e1deb50 100644 --- a/std/zip.d +++ b/std/zip.d @@ -5,21 +5,29 @@ * Makes use of the etc.c.zlib compression library. * * Bugs: - * $(UL - * $(LI Multi-disk zips not supported.) - * $(LI Only Zip version 20 formats are supported.) - * $(LI Only supports compression modes 0 (no compression) and 8 (deflate).) - * $(LI Does not support encryption.) - * $(LI $(BUGZILLA 592)) - * $(LI $(BUGZILLA 1832)) - * $(LI $(BUGZILLA 2137)) - * $(LI $(BUGZILLA 2138)) - * ) + * $(UL + * $(LI Multi-disk zips not supported.) + * $(LI Only Zip version 20 formats are supported.) + * $(LI Only supports compression modes 0 (no compression) and 8 (deflate).) + * $(LI Does not support encryption.) + * $(LI $(BUGZILLA 592)) + * $(LI $(BUGZILLA 1832)) + * $(LI $(BUGZILLA 2137)) + * $(LI $(BUGZILLA 2138)) + * ) * * Macros: - * WIKI = Phobos/StdZip + * WIKI = Phobos/StdZip + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - module std.zip; private import std.zlib; @@ -34,7 +42,7 @@ class ZipException : Exception { this(string msg) { - super("ZipException: " ~ msg); + super("ZipException: " ~ msg); } } @@ -43,17 +51,17 @@ class ZipException : Exception */ class ArchiveMember { - ushort madeVersion = 20; /// Read Only - ushort extractVersion = 20; /// Read Only - ushort flags; /// Read/Write: normally set to 0 - ushort compressionMethod; /// Read/Write: 0 for compression, 8 for deflate - std.date.DosFileTime time; /// Read/Write: Last modified time of the member. It's in the DOS date/time format. - uint crc32; /// Read Only: cyclic redundancy check (CRC) value - uint compressedSize; /// Read Only: size of data of member in compressed form. - uint expandedSize; /// Read Only: size of data of member in expanded form. - ushort diskNumber; /// Read Only: should be 0. - ushort internalAttributes; /// Read/Write - uint externalAttributes; /// Read/Write + ushort madeVersion = 20; /// Read Only + ushort extractVersion = 20; /// Read Only + ushort flags; /// Read/Write: normally set to 0 + ushort compressionMethod; /// Read/Write: 0 for compression, 8 for deflate + std.date.DosFileTime time; /// Read/Write: Last modified time of the member. It's in the DOS date/time format. + uint crc32; /// Read Only: cyclic redundancy check (CRC) value + uint compressedSize; /// Read Only: size of data of member in compressed form. + uint expandedSize; /// Read Only: size of data of member in expanded form. + ushort diskNumber; /// Read Only: should be 0. + ushort internalAttributes; /// Read/Write + uint externalAttributes; /// Read/Write private uint offset; @@ -64,27 +72,27 @@ class ArchiveMember */ string name; - ubyte[] extra; /// Read/Write: extra data for this member. - string comment; /// Read/Write: comment associated with this member. - ubyte[] compressedData; /// Read Only: data of member in compressed form. - ubyte[] expandedData; /// Read/Write: data of member in uncompressed form. + ubyte[] extra; /// Read/Write: extra data for this member. + string comment; /// Read/Write: comment associated with this member. + ubyte[] compressedData; /// Read Only: data of member in compressed form. + ubyte[] expandedData; /// Read/Write: data of member in uncompressed form. debug(print) { void print() { - printf("name = '%.*s'\n", name); - printf("\tcomment = '%.*s'\n", comment); - printf("\tmadeVersion = x%04x\n", madeVersion); - printf("\textractVersion = x%04x\n", extractVersion); - printf("\tflags = x%04x\n", flags); - printf("\tcompressionMethod = %d\n", compressionMethod); - printf("\ttime = %d\n", time); - printf("\tcrc32 = x%08x\n", crc32); - printf("\texpandedSize = %d\n", expandedSize); - printf("\tcompressedSize = %d\n", compressedSize); - printf("\tinternalAttributes = x%04x\n", internalAttributes); - printf("\texternalAttributes = x%08x\n", externalAttributes); + printf("name = '%.*s'\n", name); + printf("\tcomment = '%.*s'\n", comment); + printf("\tmadeVersion = x%04x\n", madeVersion); + printf("\textractVersion = x%04x\n", extractVersion); + printf("\tflags = x%04x\n", flags); + printf("\tcompressionMethod = %d\n", compressionMethod); + printf("\ttime = %d\n", time); + printf("\tcrc32 = x%08x\n", crc32); + printf("\texpandedSize = %d\n", expandedSize); + printf("\tcompressedSize = %d\n", compressedSize); + printf("\tinternalAttributes = x%04x\n", internalAttributes); + printf("\texternalAttributes = x%08x\n", externalAttributes); } } } @@ -95,14 +103,14 @@ class ArchiveMember */ class ZipArchive { - ubyte[] data; /// Read Only: array representing the entire contents of the archive. + ubyte[] data; /// Read Only: array representing the entire contents of the archive. uint endrecOffset; - uint diskNumber; /// Read Only: 0 since multi-disk zip archives are not supported. - uint diskStartDir; /// Read Only: 0 since multi-disk zip archives are not supported. - uint numEntries; /// Read Only: number of ArchiveMembers in the directory. - uint totalEntries; /// Read Only: same as totalEntries. - string comment; /// Read/Write: the archive comment. Must be less than 65536 bytes in length. + uint diskNumber; /// Read Only: 0 since multi-disk zip archives are not supported. + uint diskStartDir; /// Read Only: 0 since multi-disk zip archives are not supported. + uint numEntries; /// Read Only: number of ArchiveMembers in the directory. + uint totalEntries; /// Read Only: same as totalEntries. + string comment; /// Read/Write: the archive comment. Must be less than 65536 bytes in length. /** * Read Only: array indexed by the name of each member of the archive. @@ -122,11 +130,11 @@ class ZipArchive { void print() { - printf("\tdiskNumber = %u\n", diskNumber); - printf("\tdiskStartDir = %u\n", diskStartDir); - printf("\tnumEntries = %u\n", numEntries); - printf("\ttotalEntries = %u\n", totalEntries); - printf("\tcomment = '%.*s'\n", comment); + printf("\tdiskNumber = %u\n", diskNumber); + printf("\tdiskStartDir = %u\n", diskStartDir); + printf("\tnumEntries = %u\n", numEntries); + printf("\ttotalEntries = %u\n", totalEntries); + printf("\tcomment = '%.*s'\n", comment); } } @@ -142,14 +150,14 @@ class ZipArchive */ void addMember(ArchiveMember de) { - directory[de.name] = de; + directory[de.name] = de; } /** Delete de from the archive. */ void deleteMember(ArchiveMember de) { - directory.remove(de.name); + directory.remove(de.name); } /** @@ -163,122 +171,122 @@ class ZipArchive * Returns: array representing the entire archive. */ void[] build() - { uint i; - uint directoryOffset; + { uint i; + uint directoryOffset; - if (comment.length > 0xFFFF) - throw new ZipException("archive comment longer than 65535"); + if (comment.length > 0xFFFF) + throw new ZipException("archive comment longer than 65535"); - // Compress each member; compute size - uint archiveSize = 0; - uint directorySize = 0; - foreach (ArchiveMember de; directory) - { - de.expandedSize = de.expandedData.length; - switch (de.compressionMethod) - { - case 0: - de.compressedData = de.expandedData; - break; + // Compress each member; compute size + uint archiveSize = 0; + uint directorySize = 0; + foreach (ArchiveMember de; directory) + { + de.expandedSize = de.expandedData.length; + switch (de.compressionMethod) + { + case 0: + de.compressedData = de.expandedData; + break; - case 8: - de.compressedData = cast(ubyte[])std.zlib.compress(cast(void[])de.expandedData); - de.compressedData = de.compressedData[2 .. de.compressedData.length - 4]; - break; + case 8: + de.compressedData = cast(ubyte[])std.zlib.compress(cast(void[])de.expandedData); + de.compressedData = de.compressedData[2 .. de.compressedData.length - 4]; + break; - default: - throw new ZipException("unsupported compression method"); - } - de.compressedSize = de.compressedData.length; - de.crc32 = std.zlib.crc32(0, cast(void[])de.expandedData); + default: + throw new ZipException("unsupported compression method"); + } + de.compressedSize = de.compressedData.length; + de.crc32 = std.zlib.crc32(0, cast(void[])de.expandedData); - archiveSize += 30 + de.name.length + - de.extra.length + - de.compressedSize; - directorySize += 46 + de.name.length + - de.extra.length + - de.comment.length; - } + archiveSize += 30 + de.name.length + + de.extra.length + + de.compressedSize; + directorySize += 46 + de.name.length + + de.extra.length + + de.comment.length; + } - data = new ubyte[archiveSize + directorySize + 22 + comment.length]; + data = new ubyte[archiveSize + directorySize + 22 + comment.length]; - // Populate the data[] + // Populate the data[] - // Store each archive member - i = 0; - foreach (ArchiveMember de; directory) - { - de.offset = i; - data[i .. i + 4] = cast(ubyte[])"PK\x03\x04"; - putUshort(i + 4, de.extractVersion); - putUshort(i + 6, de.flags); - putUshort(i + 8, de.compressionMethod); - putUint (i + 10, cast(uint)de.time); - putUint (i + 14, de.crc32); - putUint (i + 18, de.compressedSize); - putUint (i + 22, de.expandedData.length); - putUshort(i + 26, cast(ushort)de.name.length); - putUshort(i + 28, cast(ushort)de.extra.length); - i += 30; + // Store each archive member + i = 0; + foreach (ArchiveMember de; directory) + { + de.offset = i; + data[i .. i + 4] = cast(ubyte[])"PK\x03\x04"; + putUshort(i + 4, de.extractVersion); + putUshort(i + 6, de.flags); + putUshort(i + 8, de.compressionMethod); + putUint (i + 10, cast(uint)de.time); + putUint (i + 14, de.crc32); + putUint (i + 18, de.compressedSize); + putUint (i + 22, de.expandedData.length); + putUshort(i + 26, cast(ushort)de.name.length); + putUshort(i + 28, cast(ushort)de.extra.length); + i += 30; - data[i .. i + de.name.length] = cast(ubyte[])de.name[]; - i += de.name.length; - data[i .. i + de.extra.length] = cast(ubyte[])de.extra[]; - i += de.extra.length; - data[i .. i + de.compressedSize] = de.compressedData[]; - i += de.compressedSize; - } + data[i .. i + de.name.length] = cast(ubyte[])de.name[]; + i += de.name.length; + data[i .. i + de.extra.length] = cast(ubyte[])de.extra[]; + i += de.extra.length; + data[i .. i + de.compressedSize] = de.compressedData[]; + i += de.compressedSize; + } - // Write directory - directoryOffset = i; - numEntries = 0; - foreach (ArchiveMember de; directory) - { - data[i .. i + 4] = cast(ubyte[])"PK\x01\x02"; - putUshort(i + 4, de.madeVersion); - putUshort(i + 6, de.extractVersion); - putUshort(i + 8, de.flags); - putUshort(i + 10, de.compressionMethod); - putUint (i + 12, cast(uint)de.time); - putUint (i + 16, de.crc32); - putUint (i + 20, de.compressedSize); - putUint (i + 24, de.expandedSize); - putUshort(i + 28, cast(ushort)de.name.length); - putUshort(i + 30, cast(ushort)de.extra.length); - putUshort(i + 32, cast(ushort)de.comment.length); - putUshort(i + 34, de.diskNumber); - putUshort(i + 36, de.internalAttributes); - putUint (i + 38, de.externalAttributes); - putUint (i + 42, de.offset); - i += 46; + // Write directory + directoryOffset = i; + numEntries = 0; + foreach (ArchiveMember de; directory) + { + data[i .. i + 4] = cast(ubyte[])"PK\x01\x02"; + putUshort(i + 4, de.madeVersion); + putUshort(i + 6, de.extractVersion); + putUshort(i + 8, de.flags); + putUshort(i + 10, de.compressionMethod); + putUint (i + 12, cast(uint)de.time); + putUint (i + 16, de.crc32); + putUint (i + 20, de.compressedSize); + putUint (i + 24, de.expandedSize); + putUshort(i + 28, cast(ushort)de.name.length); + putUshort(i + 30, cast(ushort)de.extra.length); + putUshort(i + 32, cast(ushort)de.comment.length); + putUshort(i + 34, de.diskNumber); + putUshort(i + 36, de.internalAttributes); + putUint (i + 38, de.externalAttributes); + putUint (i + 42, de.offset); + i += 46; - data[i .. i + de.name.length] = cast(ubyte[])de.name[]; - i += de.name.length; - data[i .. i + de.extra.length] = cast(ubyte[])de.extra[]; - i += de.extra.length; - data[i .. i + de.comment.length] = cast(ubyte[])de.comment[]; - i += de.comment.length; - numEntries++; - } - totalEntries = numEntries; + data[i .. i + de.name.length] = cast(ubyte[])de.name[]; + i += de.name.length; + data[i .. i + de.extra.length] = cast(ubyte[])de.extra[]; + i += de.extra.length; + data[i .. i + de.comment.length] = cast(ubyte[])de.comment[]; + i += de.comment.length; + numEntries++; + } + totalEntries = numEntries; - // Write end record - endrecOffset = i; - data[i .. i + 4] = cast(ubyte[])"PK\x05\x06"; - putUshort(i + 4, cast(ushort)diskNumber); - putUshort(i + 6, cast(ushort)diskStartDir); - putUshort(i + 8, cast(ushort)numEntries); - putUshort(i + 10, cast(ushort)totalEntries); - putUint (i + 12, directorySize); - putUint (i + 16, directoryOffset); - putUshort(i + 20, cast(ushort)comment.length); - i += 22; + // Write end record + endrecOffset = i; + data[i .. i + 4] = cast(ubyte[])"PK\x05\x06"; + putUshort(i + 4, cast(ushort)diskNumber); + putUshort(i + 6, cast(ushort)diskStartDir); + putUshort(i + 8, cast(ushort)numEntries); + putUshort(i + 10, cast(ushort)totalEntries); + putUint (i + 12, directorySize); + putUint (i + 16, directoryOffset); + putUshort(i + 20, cast(ushort)comment.length); + i += 22; - // Write archive comment - assert(i + comment.length == data.length); - data[i .. data.length] = cast(ubyte[])comment[]; + // Write archive comment + assert(i + comment.length == data.length); + data[i .. data.length] = cast(ubyte[])comment[]; - return cast(void[])data; + return cast(void[])data; } /* ============ Reading an existing archive =================== */ @@ -295,104 +303,104 @@ class ZipArchive * Use expand() to get the expanded data for each ArchiveMember. * * Params: - * buffer = the entire contents of the archive. + * buffer = the entire contents of the archive. */ this(void[] buffer) - { int iend; - int i; - int endcommentlength; - uint directorySize; - uint directoryOffset; + { int iend; + int i; + int endcommentlength; + uint directorySize; + uint directoryOffset; - this.data = cast(ubyte[]) buffer; + this.data = cast(ubyte[]) buffer; - // Find 'end record index' by searching backwards for signature - iend = data.length - 66000; - if (iend < 0) - iend = 0; - for (i = data.length - 22; 1; i--) - { - if (i < iend) - throw new ZipException("no end record"); + // Find 'end record index' by searching backwards for signature + iend = data.length - 66000; + if (iend < 0) + iend = 0; + for (i = data.length - 22; 1; i--) + { + if (i < iend) + throw new ZipException("no end record"); - if (data[i .. i + 4] == cast(ubyte[])"PK\x05\x06") - { - endcommentlength = getUshort(i + 20); - if (i + 22 + endcommentlength > data.length) - continue; - comment = cast(string)(data[i + 22 .. i + 22 + endcommentlength]); - endrecOffset = i; - break; - } - } + if (data[i .. i + 4] == cast(ubyte[])"PK\x05\x06") + { + endcommentlength = getUshort(i + 20); + if (i + 22 + endcommentlength > data.length) + continue; + comment = cast(string)(data[i + 22 .. i + 22 + endcommentlength]); + endrecOffset = i; + break; + } + } - // Read end record data - diskNumber = getUshort(i + 4); - diskStartDir = getUshort(i + 6); + // Read end record data + diskNumber = getUshort(i + 4); + diskStartDir = getUshort(i + 6); - numEntries = getUshort(i + 8); - totalEntries = getUshort(i + 10); + numEntries = getUshort(i + 8); + totalEntries = getUshort(i + 10); - if (numEntries != totalEntries) - throw new ZipException("multiple disk zips not supported"); + if (numEntries != totalEntries) + throw new ZipException("multiple disk zips not supported"); - directorySize = getUint(i + 12); - directoryOffset = getUint(i + 16); + directorySize = getUint(i + 12); + directoryOffset = getUint(i + 16); - if (directoryOffset + directorySize > i) - throw new ZipException("corrupted directory"); + if (directoryOffset + directorySize > i) + throw new ZipException("corrupted directory"); - i = directoryOffset; - for (int n = 0; n < numEntries; n++) - { - /* The format of an entry is: - * 'PK' 1, 2 - * directory info - * path - * extra data - * comment - */ + i = directoryOffset; + for (int n = 0; n < numEntries; n++) + { + /* The format of an entry is: + * 'PK' 1, 2 + * directory info + * path + * extra data + * comment + */ - uint offset; - uint namelen; - uint extralen; - uint commentlen; + uint offset; + uint namelen; + uint extralen; + uint commentlen; - if (data[i .. i + 4] != cast(ubyte[])"PK\x01\x02") - throw new ZipException("invalid directory entry 1"); - ArchiveMember de = new ArchiveMember(); - de.madeVersion = getUshort(i + 4); - de.extractVersion = getUshort(i + 6); - de.flags = getUshort(i + 8); - de.compressionMethod = getUshort(i + 10); - de.time = cast(DosFileTime)getUint(i + 12); - de.crc32 = getUint(i + 16); - de.compressedSize = getUint(i + 20); - de.expandedSize = getUint(i + 24); - namelen = getUshort(i + 28); - extralen = getUshort(i + 30); - commentlen = getUshort(i + 32); - de.diskNumber = getUshort(i + 34); - de.internalAttributes = getUshort(i + 36); - de.externalAttributes = getUint(i + 38); - de.offset = getUint(i + 42); - i += 46; + if (data[i .. i + 4] != cast(ubyte[])"PK\x01\x02") + throw new ZipException("invalid directory entry 1"); + ArchiveMember de = new ArchiveMember(); + de.madeVersion = getUshort(i + 4); + de.extractVersion = getUshort(i + 6); + de.flags = getUshort(i + 8); + de.compressionMethod = getUshort(i + 10); + de.time = cast(DosFileTime)getUint(i + 12); + de.crc32 = getUint(i + 16); + de.compressedSize = getUint(i + 20); + de.expandedSize = getUint(i + 24); + namelen = getUshort(i + 28); + extralen = getUshort(i + 30); + commentlen = getUshort(i + 32); + de.diskNumber = getUshort(i + 34); + de.internalAttributes = getUshort(i + 36); + de.externalAttributes = getUint(i + 38); + de.offset = getUint(i + 42); + i += 46; - if (i + namelen + extralen + commentlen > directoryOffset + directorySize) - throw new ZipException("invalid directory entry 2"); + if (i + namelen + extralen + commentlen > directoryOffset + directorySize) + throw new ZipException("invalid directory entry 2"); - de.name = cast(string)(data[i .. i + namelen]); - i += namelen; - de.extra = data[i .. i + extralen]; - i += extralen; - de.comment = cast(string)(data[i .. i + commentlen]); - i += commentlen; + de.name = cast(string)(data[i .. i + namelen]); + i += namelen; + de.extra = data[i .. i + extralen]; + i += extralen; + de.comment = cast(string)(data[i .. i + commentlen]); + i += commentlen; - directory[de.name] = de; - } - if (i != directoryOffset + directorySize) - throw new ZipException("invalid directory entry 3"); + directory[de.name] = de; + } + if (i != directoryOffset + directorySize) + throw new ZipException("invalid directory entry 3"); } /***** @@ -403,108 +411,108 @@ class ZipArchive * crc32, compressedSize, expandedSize, expandedData[], name[], extra[]. */ ubyte[] expand(ArchiveMember de) - { uint namelen; - uint extralen; + { uint namelen; + uint extralen; - if (data[de.offset .. de.offset + 4] != cast(ubyte[])"PK\x03\x04") - throw new ZipException("invalid directory entry 4"); + if (data[de.offset .. de.offset + 4] != cast(ubyte[])"PK\x03\x04") + throw new ZipException("invalid directory entry 4"); - // These values should match what is in the main zip archive directory - de.extractVersion = getUshort(de.offset + 4); - de.flags = getUshort(de.offset + 6); - de.compressionMethod = getUshort(de.offset + 8); - de.time = cast(DosFileTime)getUint(de.offset + 10); - de.crc32 = getUint(de.offset + 14); - de.compressedSize = getUint(de.offset + 18); - de.expandedSize = getUint(de.offset + 22); - namelen = getUshort(de.offset + 26); - extralen = getUshort(de.offset + 28); + // These values should match what is in the main zip archive directory + de.extractVersion = getUshort(de.offset + 4); + de.flags = getUshort(de.offset + 6); + de.compressionMethod = getUshort(de.offset + 8); + de.time = cast(DosFileTime)getUint(de.offset + 10); + de.crc32 = getUint(de.offset + 14); + de.compressedSize = getUint(de.offset + 18); + de.expandedSize = getUint(de.offset + 22); + namelen = getUshort(de.offset + 26); + extralen = getUshort(de.offset + 28); - debug(print) - { - printf("\t\texpandedSize = %d\n", de.expandedSize); - printf("\t\tcompressedSize = %d\n", de.compressedSize); - printf("\t\tnamelen = %d\n", namelen); - printf("\t\textralen = %d\n", extralen); - } + debug(print) + { + printf("\t\texpandedSize = %d\n", de.expandedSize); + printf("\t\tcompressedSize = %d\n", de.compressedSize); + printf("\t\tnamelen = %d\n", namelen); + printf("\t\textralen = %d\n", extralen); + } - if (de.flags & 1) - throw new ZipException("encryption not supported"); + if (de.flags & 1) + throw new ZipException("encryption not supported"); - int i; - i = de.offset + 30 + namelen + extralen; - if (i + de.compressedSize > endrecOffset) - throw new ZipException("invalid directory entry 5"); + int i; + i = de.offset + 30 + namelen + extralen; + if (i + de.compressedSize > endrecOffset) + throw new ZipException("invalid directory entry 5"); - de.compressedData = data[i .. i + de.compressedSize]; - debug(print) arrayPrint(de.compressedData); + de.compressedData = data[i .. i + de.compressedSize]; + debug(print) arrayPrint(de.compressedData); - switch (de.compressionMethod) - { - case 0: - de.expandedData = de.compressedData; - return de.expandedData; + switch (de.compressionMethod) + { + case 0: + de.expandedData = de.compressedData; + return de.expandedData; - case 8: - // -15 is a magic value used to decompress zip files. - // It has the effect of not requiring the 2 byte header - // and 4 byte trailer. - de.expandedData = cast(ubyte[])std.zlib.uncompress(cast(void[])de.compressedData, de.expandedSize, -15); - return de.expandedData; + case 8: + // -15 is a magic value used to decompress zip files. + // It has the effect of not requiring the 2 byte header + // and 4 byte trailer. + de.expandedData = cast(ubyte[])std.zlib.uncompress(cast(void[])de.compressedData, de.expandedSize, -15); + return de.expandedData; - default: - throw new ZipException("unsupported compression method"); - } + default: + throw new ZipException("unsupported compression method"); + } } /* ============ Utility =================== */ ushort getUshort(int i) { - version (LittleEndian) - { - return *cast(ushort *)&data[i]; - } - else - { - ubyte b0 = data[i]; - ubyte b1 = data[i + 1]; - return (b1 << 8) | b0; - } + version (LittleEndian) + { + return *cast(ushort *)&data[i]; + } + else + { + ubyte b0 = data[i]; + ubyte b1 = data[i + 1]; + return (b1 << 8) | b0; + } } uint getUint(int i) { - version (LittleEndian) - { - return *cast(uint *)&data[i]; - } - else - { - return bswap(*cast(uint *)&data[i]); - } + version (LittleEndian) + { + return *cast(uint *)&data[i]; + } + else + { + return bswap(*cast(uint *)&data[i]); + } } void putUshort(int i, ushort us) { - version (LittleEndian) - { - *cast(ushort *)&data[i] = us; - } - else - { - data[i] = cast(ubyte)us; - data[i + 1] = cast(ubyte)(us >> 8); - } + version (LittleEndian) + { + *cast(ushort *)&data[i] = us; + } + else + { + data[i] = cast(ubyte)us; + data[i + 1] = cast(ubyte)(us >> 8); + } } void putUint(int i, uint ui) { - version (BigEndian) - { - ui = bswap(ui); - } - *cast(uint *)&data[i] = ui; + version (BigEndian) + { + ui = bswap(ui); + } + *cast(uint *)&data[i] = ui; } } @@ -512,13 +520,13 @@ debug(print) { void arrayPrint(ubyte[] array) { - printf("array %p,%d\n", cast(void*)array, array.length); - for (int i = 0; i < array.length; i++) - { - printf("%02x ", array[i]); - if (((i + 1) & 15) == 0) - printf("\n"); - } - printf("\n"); + printf("array %p,%d\n", cast(void*)array, array.length); + for (int i = 0; i < array.length; i++) + { + printf("%02x ", array[i]); + if (((i + 1) & 15) == 0) + printf("\n"); + } + printf("\n"); } } diff --git a/std/zlib.d b/std/zlib.d index 21a676f64..7d039bed4 100644 --- a/std/zlib.d +++ b/std/zlib.d @@ -1,21 +1,26 @@ -// Written in the D programming language +// Written in the D programming language. /** * Compress/decompress data using the $(LINK2 http://www._zlib.net, zlib library). * * References: - * $(LINK2 http://en.wikipedia.org/wiki/Zlib, Wikipedia) - * License: - * Public Domain + * $(LINK2 http://en.wikipedia.org/wiki/Zlib, Wikipedia) * * Macros: - * WIKI = Phobos/StdZlib + * WIKI = Phobos/StdZlib + * + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) + * + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - - module std.zlib; -//debug=zlib; // uncomment to turn on debugging printf's +//debug=zlib; // uncomment to turn on debugging printf's private import etc.c.zlib; @@ -23,10 +28,10 @@ private import etc.c.zlib; enum { - Z_NO_FLUSH = 0, - Z_SYNC_FLUSH = 2, - Z_FULL_FLUSH = 3, - Z_FINISH = 4, + Z_NO_FLUSH = 0, + Z_SYNC_FLUSH = 2, + Z_FULL_FLUSH = 3, + Z_FINISH = 4, } /************************************* @@ -36,21 +41,21 @@ enum class ZlibException : Exception { this(int errnum) - { string msg; + { string msg; - switch (errnum) - { - case Z_STREAM_END: msg = "stream end"; break; - case Z_NEED_DICT: msg = "need dict"; break; - case Z_ERRNO: msg = "errno"; break; - case Z_STREAM_ERROR: msg = "stream error"; break; - case Z_DATA_ERROR: msg = "data error"; break; - case Z_MEM_ERROR: msg = "mem error"; break; - case Z_BUF_ERROR: msg = "buf error"; break; - case Z_VERSION_ERROR: msg = "version error"; break; - default: msg = "unknown error"; break; - } - super(msg); + switch (errnum) + { + case Z_STREAM_END: msg = "stream end"; break; + case Z_NEED_DICT: msg = "need dict"; break; + case Z_ERRNO: msg = "errno"; break; + case Z_STREAM_ERROR: msg = "stream error"; break; + case Z_DATA_ERROR: msg = "data error"; break; + case Z_MEM_ERROR: msg = "mem error"; break; + case Z_BUF_ERROR: msg = "buf error"; break; + case Z_VERSION_ERROR: msg = "version error"; break; + default: msg = "unknown error"; break; + } + super(msg); } } @@ -121,8 +126,8 @@ body destbuf = new ubyte[destlen]; err = etc.c.zlib.compress2(destbuf.ptr, &destlen, cast(ubyte *)srcbuf, srcbuf.length, level); if (err) - { delete destbuf; - throw new ZlibException(err); + { delete destbuf; + throw new ZlibException(err); } destbuf.length = destlen; @@ -152,46 +157,46 @@ const(void)[] uncompress(const(void)[] srcbuf, uint destlen = 0u, int winbits = ubyte[] destbuf; if (!destlen) - destlen = srcbuf.length * 2 + 1; + destlen = srcbuf.length * 2 + 1; while (1) { - etc.c.zlib.z_stream zs; + etc.c.zlib.z_stream zs; - destbuf = new ubyte[destlen]; - - zs.next_in = cast(ubyte*) srcbuf; - zs.avail_in = srcbuf.length; + destbuf = new ubyte[destlen]; + + zs.next_in = cast(ubyte*) srcbuf; + zs.avail_in = srcbuf.length; - zs.next_out = destbuf.ptr; - zs.avail_out = destlen; + zs.next_out = destbuf.ptr; + zs.avail_out = destlen; - err = etc.c.zlib.inflateInit2(&zs, winbits); - if (err) - { delete destbuf; - throw new ZlibException(err); - } - err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH); - switch (err) - { - case Z_OK: - etc.c.zlib.inflateEnd(&zs); - destlen = destbuf.length * 2; - continue; + err = etc.c.zlib.inflateInit2(&zs, winbits); + if (err) + { delete destbuf; + throw new ZlibException(err); + } + err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH); + switch (err) + { + case Z_OK: + etc.c.zlib.inflateEnd(&zs); + destlen = destbuf.length * 2; + continue; - case Z_STREAM_END: - destbuf.length = zs.total_out; - err = etc.c.zlib.inflateEnd(&zs); - if (err != Z_OK) - goto Lerr; - return destbuf; + case Z_STREAM_END: + destbuf.length = zs.total_out; + err = etc.c.zlib.inflateEnd(&zs); + if (err != Z_OK) + goto Lerr; + return destbuf; - default: - etc.c.zlib.inflateEnd(&zs); - Lerr: - delete destbuf; - throw new ZlibException(err); - } + default: + etc.c.zlib.inflateEnd(&zs); + Lerr: + delete destbuf; + throw new ZlibException(err); + } } assert(0); } @@ -219,9 +224,9 @@ void arrayPrint(ubyte[] array) //printf("array %p,%d\n", (void*)array, array.length); for (int i = 0; i < array.length; i++) { - printf("%02x ", array[i]); - if (((i + 1) & 15) == 0) - printf("\n"); + printf("%02x ", array[i]); + if (((i + 1) & 15) == 0) + printf("\n"); } printf("\n\n"); } @@ -240,11 +245,11 @@ class Compress void error(int err) { - if (inited) - { deflateEnd(&zs); - inited = 0; - } - throw new ZlibException(err); + if (inited) + { deflateEnd(&zs); + inited = 0; + } + throw new ZlibException(err); } public: @@ -255,11 +260,11 @@ class Compress this(int level) in { - assert(1 <= level && level <= 9); + assert(1 <= level && level <= 9); } body { - this.level = level; + this.level = level; } /// ditto @@ -268,15 +273,15 @@ class Compress } ~this() - { int err; + { int err; - if (inited) - { - inited = 0; - err = deflateEnd(&zs); - if (err) - error(err); - } + if (inited) + { + inited = 0; + err = deflateEnd(&zs); + if (err) + error(err); + } } /** @@ -285,106 +290,106 @@ class Compress * returned from successive calls to this should be concatenated together. */ const(void)[] compress(const(void)[] buf) - { int err; - ubyte[] destbuf; + { int err; + ubyte[] destbuf; - if (buf.length == 0) - return null; + if (buf.length == 0) + return null; - if (!inited) - { - err = deflateInit(&zs, level); - if (err) - error(err); - inited = 1; - } + if (!inited) + { + err = deflateInit(&zs, level); + if (err) + error(err); + inited = 1; + } - destbuf = new ubyte[zs.avail_in + buf.length]; - zs.next_out = destbuf.ptr; - zs.avail_out = destbuf.length; + destbuf = new ubyte[zs.avail_in + buf.length]; + zs.next_out = destbuf.ptr; + zs.avail_out = destbuf.length; - if (zs.avail_in) - buf = cast(void[])zs.next_in[0 .. zs.avail_in] ~ buf; + if (zs.avail_in) + buf = cast(void[])zs.next_in[0 .. zs.avail_in] ~ buf; - zs.next_in = cast(ubyte*) buf.ptr; - zs.avail_in = buf.length; + zs.next_in = cast(ubyte*) buf.ptr; + zs.avail_in = buf.length; - err = deflate(&zs, Z_NO_FLUSH); - if (err != Z_STREAM_END && err != Z_OK) - { delete destbuf; - error(err); - } - destbuf.length = destbuf.length - zs.avail_out; - return destbuf; + err = deflate(&zs, Z_NO_FLUSH); + if (err != Z_STREAM_END && err != Z_OK) + { delete destbuf; + error(err); + } + destbuf.length = destbuf.length - zs.avail_out; + return destbuf; } /*** * Compress and return any remaining data. * The returned data should be appended to that returned by compress(). * Params: - * mode = one of the following: - * $(DL - $(DT Z_SYNC_FLUSH ) - $(DD Syncs up flushing to the next byte boundary. - Used when more data is to be compressed later on.) - $(DT Z_FULL_FLUSH ) - $(DD Syncs up flushing to the next byte boundary. - Used when more data is to be compressed later on, - and the decompressor needs to be restartable at this - point.) - $(DT Z_FINISH) - $(DD (default) Used when finished compressing the data. ) - ) + * mode = one of the following: + * $(DL + $(DT Z_SYNC_FLUSH ) + $(DD Syncs up flushing to the next byte boundary. + Used when more data is to be compressed later on.) + $(DT Z_FULL_FLUSH ) + $(DD Syncs up flushing to the next byte boundary. + Used when more data is to be compressed later on, + and the decompressor needs to be restartable at this + point.) + $(DT Z_FINISH) + $(DD (default) Used when finished compressing the data. ) + ) */ void[] flush(int mode = Z_FINISH) in { - assert(mode == Z_FINISH || mode == Z_SYNC_FLUSH || mode == Z_FULL_FLUSH); + assert(mode == Z_FINISH || mode == Z_SYNC_FLUSH || mode == Z_FULL_FLUSH); } body { - void[] destbuf; - ubyte[512] tmpbuf = void; - int err; + void[] destbuf; + ubyte[512] tmpbuf = void; + int err; - if (!inited) - return null; + if (!inited) + return null; - /* may be zs.avail_out+ - * zs.avail_out is set nonzero by deflate in previous compress() - */ - //tmpbuf = new void[zs.avail_out]; - zs.next_out = tmpbuf.ptr; - zs.avail_out = tmpbuf.length; + /* may be zs.avail_out+ + * zs.avail_out is set nonzero by deflate in previous compress() + */ + //tmpbuf = new void[zs.avail_out]; + zs.next_out = tmpbuf.ptr; + zs.avail_out = tmpbuf.length; - while( (err = deflate(&zs, mode)) != Z_STREAM_END) - { - if (err == Z_OK) - { - if (zs.avail_out != 0 && mode != Z_FINISH) - break; - else if(zs.avail_out == 0) - { - destbuf ~= tmpbuf; - zs.next_out = tmpbuf.ptr; - zs.avail_out = tmpbuf.length; - continue; - } - err = Z_BUF_ERROR; - } - delete destbuf; - error(err); - } - destbuf ~= tmpbuf[0 .. (tmpbuf.length - zs.avail_out)]; + while( (err = deflate(&zs, mode)) != Z_STREAM_END) + { + if (err == Z_OK) + { + if (zs.avail_out != 0 && mode != Z_FINISH) + break; + else if(zs.avail_out == 0) + { + destbuf ~= tmpbuf; + zs.next_out = tmpbuf.ptr; + zs.avail_out = tmpbuf.length; + continue; + } + err = Z_BUF_ERROR; + } + delete destbuf; + error(err); + } + destbuf ~= tmpbuf[0 .. (tmpbuf.length - zs.avail_out)]; - if (mode == Z_FINISH) - { - err = deflateEnd(&zs); - inited = 0; - if (err) - error(err); - } - return destbuf; + if (mode == Z_FINISH) + { + err = deflateEnd(&zs); + inited = 0; + if (err) + error(err); + } + return destbuf; } } @@ -402,11 +407,11 @@ class UnCompress void error(int err) { - if (inited) - { inflateEnd(&zs); - inited = 0; - } - throw new ZlibException(err); + if (inited) + { inflateEnd(&zs); + inited = 0; + } + throw new ZlibException(err); } public: @@ -416,7 +421,7 @@ class UnCompress */ this(uint destbufsize) { - this.destbufsize = destbufsize; + this.destbufsize = destbufsize; } /** ditto */ @@ -425,16 +430,16 @@ class UnCompress } ~this() - { int err; + { int err; - if (inited) - { - inited = 0; - err = inflateEnd(&zs); - if (err) - error(err); - } - done = 1; + if (inited) + { + inited = 0; + err = inflateEnd(&zs); + if (err) + error(err); + } + done = 1; } /** @@ -445,42 +450,42 @@ class UnCompress const(void)[] uncompress(const(void)[] buf) in { - assert(!done); + assert(!done); } body - { int err; - ubyte[] destbuf; + { int err; + ubyte[] destbuf; - if (buf.length == 0) - return null; + if (buf.length == 0) + return null; - if (!inited) - { - err = inflateInit(&zs); - if (err) - error(err); - inited = 1; - } + if (!inited) + { + err = inflateInit(&zs); + if (err) + error(err); + inited = 1; + } - if (!destbufsize) - destbufsize = buf.length * 2; - destbuf = new ubyte[zs.avail_in * 2 + destbufsize]; - zs.next_out = destbuf.ptr; - zs.avail_out = destbuf.length; + if (!destbufsize) + destbufsize = buf.length * 2; + destbuf = new ubyte[zs.avail_in * 2 + destbufsize]; + zs.next_out = destbuf.ptr; + zs.avail_out = destbuf.length; - if (zs.avail_in) - buf = cast(void[])zs.next_in[0 .. zs.avail_in] ~ buf; + if (zs.avail_in) + buf = cast(void[])zs.next_in[0 .. zs.avail_in] ~ buf; - zs.next_in = cast(ubyte*) buf; - zs.avail_in = buf.length; + zs.next_in = cast(ubyte*) buf; + zs.avail_in = buf.length; - err = inflate(&zs, Z_NO_FLUSH); - if (err != Z_STREAM_END && err != Z_OK) - { delete destbuf; - error(err); - } - destbuf.length = destbuf.length - zs.avail_out; - return destbuf; + err = inflate(&zs, Z_NO_FLUSH); + if (err != Z_STREAM_END && err != Z_OK) + { delete destbuf; + error(err); + } + destbuf.length = destbuf.length - zs.avail_out; + return destbuf; } /** @@ -491,48 +496,48 @@ class UnCompress void[] flush() in { - assert(!done); + assert(!done); } out { - assert(done); + assert(done); } body { - ubyte[] extra; - ubyte[] destbuf; - int err; + ubyte[] extra; + ubyte[] destbuf; + int err; - done = 1; - if (!inited) - return null; + done = 1; + if (!inited) + return null; L1: - destbuf = new ubyte[zs.avail_in * 2 + 100]; - zs.next_out = destbuf.ptr; - zs.avail_out = destbuf.length; + destbuf = new ubyte[zs.avail_in * 2 + 100]; + zs.next_out = destbuf.ptr; + zs.avail_out = destbuf.length; - err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH); - if (err == Z_OK && zs.avail_out == 0) - { - extra ~= destbuf; - goto L1; - } - if (err != Z_STREAM_END) - { - delete destbuf; - if (err == Z_OK) - err = Z_BUF_ERROR; - error(err); - } - destbuf = destbuf.ptr[0 .. zs.next_out - destbuf.ptr]; - err = etc.c.zlib.inflateEnd(&zs); - inited = 0; - if (err) - error(err); - if (extra.length) - destbuf = extra ~ destbuf; - return destbuf; + err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH); + if (err == Z_OK && zs.avail_out == 0) + { + extra ~= destbuf; + goto L1; + } + if (err != Z_STREAM_END) + { + delete destbuf; + if (err == Z_OK) + err = Z_BUF_ERROR; + error(err); + } + destbuf = destbuf.ptr[0 .. zs.next_out - destbuf.ptr]; + err = etc.c.zlib.inflateEnd(&zs); + inited = 0; + if (err) + error(err); + if (extra.length) + destbuf = extra ~ destbuf; + return destbuf; } } @@ -548,17 +553,17 @@ unittest // by Dave bool CompressThenUncompress (ubyte[] src) { try { - ubyte[] dst = cast(ubyte[])std.zlib.compress(cast(void[])src); - double ratio = (dst.length / cast(double)src.length); - debug(zlib) writef("src.length: ", src.length, ", dst: ", dst.length, ", Ratio = ", ratio); - ubyte[] uncompressedBuf; - uncompressedBuf = cast(ubyte[])std.zlib.uncompress(cast(void[])dst); - assert(src.length == uncompressedBuf.length); - assert(src == uncompressedBuf); + ubyte[] dst = cast(ubyte[])std.zlib.compress(cast(void[])src); + double ratio = (dst.length / cast(double)src.length); + debug(zlib) writef("src.length: ", src.length, ", dst: ", dst.length, ", Ratio = ", ratio); + ubyte[] uncompressedBuf; + uncompressedBuf = cast(ubyte[])std.zlib.uncompress(cast(void[])dst); + assert(src.length == uncompressedBuf.length); + assert(src == uncompressedBuf); } catch { - debug(zlib) writefln(" ... Exception thrown when src.length = ", src.length, "."); - return false; + debug(zlib) writefln(" ... Exception thrown when src.length = ", src.length, "."); + return false; } return true; } diff --git a/unittest.d b/unittest.d index ce3ba697a..a882bf4a8 100644 --- a/unittest.d +++ b/unittest.d @@ -1,30 +1,18 @@ -/* - * Copyright (C) 1999-2006 by Digital Mars, www.digitalmars.com - * Written by Walter Bright +// Written in the D programming language. + +/** + * This test program pulls in all the library modules in order to run the unit + * tests on them. Then, it prints out the arguments passed to main(). * - * 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. + * Copyright: Copyright Digital Mars 2000 - 2009. + * License: Boost License 1.0. + * Authors: $(WEB digitalmars.com, Walter Bright) * - * 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. + * Copyright Digital Mars 2000 - 2009. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) */ - -// This test program pulls in all the library modules in order -// to run the unit tests on them. -// Then, it prints out the arguments passed to main(). - public import std.base64; public import std.bind; public import std.boxer; @@ -46,7 +34,6 @@ public import std.math; public import std.md5; public import std.metastrings; public import std.mmfile; -public import std.openrj; public import std.outbuffer; public import std.path; public import std.perf; diff --git a/win32.mak b/win32.mak index 57d2ee2f3..b007ee946 100644 --- a/win32.mak +++ b/win32.mak @@ -105,7 +105,7 @@ SRCS= std\math.d std\stdio.d std\dateparse.d std\date.d std\uni.d std\string.d \ std\system.d \ std\iterator.d std\encoding.d std\variant.d \ std\stream.d std\socket.d std\socketstream.d \ - std\perf.d std\openrj.d std\conv.d \ + std\perf.d std\conv.d \ std\zip.d std\cstream.d std\loader.d \ std\__fileinit.d \ std\datebase.d \ @@ -155,7 +155,6 @@ DOCS= $(DOC)\object.html \ $(DOC)\std_metastrings.html \ $(DOC)\std_mmfile.html \ $(DOC)\std_numeric.html \ - $(DOC)\std_openrj.html \ $(DOC)\std_outbuffer.html \ $(DOC)\std_path.html \ $(DOC)\std_perf.html \ @@ -207,7 +206,7 @@ SRC_STD= std\zlib.d std\zip.d std\stdint.d std\conv.d std\utf.d std\uri.d \ std\intrinsic.d std\syserror.d \ std\regexp.d std\random.d std\stream.d std\process.d \ std\socket.d std\socketstream.d std\loader.d std\stdarg.d std\format.d \ - std\stdio.d std\perf.d std\openrj.d std\uni.d std\boxer.d \ + std\stdio.d std\perf.d std\uni.d std\boxer.d \ std\cstream.d std\demangle.d \ std\signals.d std\cpuid.d std\typetuple.d std\traits.d std\bind.d \ std\metastrings.d std\contracts.d std\getopt.d \ @@ -389,9 +388,6 @@ mmfile.obj : std\mmfile.d numeric.obj : std\numeric.d $(DMD) -c $(DFLAGS) std\numeric.d -openrj.obj : std\openrj.d - $(DMD) -c $(DFLAGS) std\openrj.d - outbuffer.obj : std\outbuffer.d $(DMD) -c $(DFLAGS) std\outbuffer.d @@ -605,9 +601,6 @@ $(DOC)\std_mmfile.html : std.ddoc std\mmfile.d $(DOC)\std_numeric.html : std.ddoc std\numeric.d $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_numeric.html std.ddoc std\numeric.d -$(DOC)\std_openrj.html : std.ddoc std\openrj.d - $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_openrj.html std.ddoc std\openrj.d - $(DOC)\std_outbuffer.html : std.ddoc std\outbuffer.d $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_outbuffer.html std.ddoc std\outbuffer.d