This commit is contained in:
Eugen Wissner 2017-01-07 17:53:57 +01:00
parent 976eb4bfbc
commit d6514cb515
7 changed files with 57 additions and 43 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
.dub .dub
__test__*__ __test__*__
__test__*__.core __test__*__.core
/docs/

View File

@ -632,7 +632,7 @@ struct WriteBuffer(T = ubyte)
* written. * written.
* *
* $(D_PSYMBOL opIndex) may return only part of the data. You may need * $(D_PSYMBOL opIndex) may return only part of the data. You may need
* to call it (and set $(D_KEYWORD +=) several times until * to call it and set $(D_KEYWORD +=) several times until
* $(D_PSYMBOL length) is 0. If all the data can be written, * $(D_PSYMBOL length) is 0. If all the data can be written,
* maximally 3 calls are required. * maximally 3 calls are required.
* *
@ -677,7 +677,7 @@ struct WriteBuffer(T = ubyte)
* written. * written.
* *
* $(D_PSYMBOL opIndex) may return only part of the data. You may need * $(D_PSYMBOL opIndex) may return only part of the data. You may need
* to call it (and set $(D_KEYWORD +=) several times until * to call it and set $(D_KEYWORD +=) several times until
* $(D_PSYMBOL length) is 0. If all the data can be written, * $(D_PSYMBOL length) is 0. If all the data can be written,
* maximally 3 calls are required. * maximally 3 calls are required.
* *

View File

@ -353,7 +353,6 @@ struct Vector(T)
* *
* Params: * Params:
* len = Initial length of the vector. * len = Initial length of the vector.
* init = Initial value to fill the vector with.
* allocator = Allocator. * allocator = Allocator.
*/ */
this(size_t len, shared Allocator allocator = defaultAllocator) @trusted this(size_t len, shared Allocator allocator = defaultAllocator) @trusted
@ -369,7 +368,14 @@ struct Vector(T)
capacity_ = length_ = len; capacity_ = length_ = len;
} }
/// Ditto. /**
* Creates a new $(D_PSYMBOL Vector).
*
* Params:
* len = Initial length of the vector.
* init = Initial value to fill the vector with.
* allocator = Allocator.
*/
this(size_t len, T init, shared Allocator allocator = defaultAllocator) @trusted this(size_t len, T init, shared Allocator allocator = defaultAllocator) @trusted
{ {
this(allocator); this(allocator);
@ -892,7 +898,6 @@ struct Vector(T)
* Comparison for equality. * Comparison for equality.
* *
* Params: * Params:
* R = Right hand side type.
* v = The vector to compare with. * v = The vector to compare with.
* *
* Returns: $(D_KEYWORD true) if the vectors are equal, $(D_KEYWORD false) * Returns: $(D_KEYWORD true) if the vectors are equal, $(D_KEYWORD false)
@ -952,7 +957,16 @@ struct Vector(T)
return true; return true;
} }
/// Ditto. /**
* Comparison for equality.
*
* Params:
* R = Right hand side type.
* v = The vector to compare with.
*
* Returns: $(D_KEYWORD true) if the vectors are equal, $(D_KEYWORD false)
* otherwise.
*/
bool opEquals(R)(Range!R v) const @trusted bool opEquals(R)(Range!R v) const @trusted
if (is(Unqual!R == T)) if (is(Unqual!R == T))
{ {

View File

@ -36,7 +36,7 @@ else version (Windows)
* block as free and only if all blocks in the region are free, the complete * block as free and only if all blocks in the region are free, the complete
* region is deallocated. * region is deallocated.
* *
* ---------------------------------------------------------------------------- * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* | | | | | || | | | * | | | | | || | | |
* | |prev <----------- | || | | | * | |prev <----------- | || | | |
* | R | B | | B | || R | B | | * | R | B | | B | || R | B | |
@ -46,7 +46,7 @@ else version (Windows)
* | O | K | | K | prev O | K | | * | O | K | | K | prev O | K | |
* | N | -----------> next| || N | | | * | N | -----------> next| || N | | |
* | | | | | || | | | * | | | | | || | | |
* --------------------------------------------------- ------------------------ * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/ */
final class MmapPool : Allocator final class MmapPool : Allocator
{ {

View File

@ -374,9 +374,10 @@ private unittest
* object). * object).
* *
* Params: * Params:
* T = Type of the constructed object. * T = Type of the constructed object.
* A = Types of the arguments to the constructor of $(D_PARAM T). * A = Types of the arguments to the constructor of $(D_PARAM T).
* args = Constructor arguments of $(D_PARAM T). * allocator = Allocator.
* args = Constructor arguments of $(D_PARAM T).
* *
* Returns: Newly created $(D_PSYMBOL RefCounted!T). * Returns: Newly created $(D_PSYMBOL RefCounted!T).
*/ */

View File

@ -812,7 +812,7 @@ abstract class Socket
* Params: * Params:
* level = Protocol level at that the option exists. * level = Protocol level at that the option exists.
* option = Option. * option = Option.
* result = Option value. * value = Option value.
* *
* Throws: $(D_PSYMBOL SocketException) on error. * Throws: $(D_PSYMBOL SocketException) on error.
*/ */

View File

@ -630,32 +630,31 @@ static this()
/** /**
* A Unique Resource Locator. * A Unique Resource Locator.
*/ */
struct URL(U = string) struct URL
if (isSomeString!U)
{ {
/** The URL scheme. */ /** The URL scheme. */
U scheme; const(char)[] scheme;
/** The username. */ /** The username. */
U user; const(char)[] user;
/** The password. */ /** The password. */
U pass; const(char)[] pass;
/** The hostname. */ /** The hostname. */
U host; const(char)[] host;
/** The port number. */ /** The port number. */
ushort port; ushort port;
/** The path. */ /** The path. */
U path; const(char)[] path;
/** The query string. */ /** The query string. */
U query; const(char)[] query;
/** The anchor. */ /** The anchor. */
U fragment; const(char)[] fragment;
/** /**
* Attempts to parse an URL from a string. * Attempts to parse an URL from a string.
@ -666,7 +665,7 @@ struct URL(U = string)
* *
* Throws: $(D_PSYMBOL URIException) if the URL is malformed. * Throws: $(D_PSYMBOL URIException) if the URL is malformed.
*/ */
this(U source) this(in char[] source)
{ {
auto value = source; auto value = source;
ptrdiff_t pos = -1, endPos = value.length, start; ptrdiff_t pos = -1, endPos = value.length, start;
@ -954,7 +953,7 @@ struct URL(U = string)
* *
* Returns: Whether the port could be found. * Returns: Whether the port could be found.
*/ */
private bool parsePort(U port) pure nothrow @safe @nogc private bool parsePort(in char[] port) pure nothrow @safe @nogc
{ {
ptrdiff_t i = 1; ptrdiff_t i = 1;
float lPort = 0; float lPort = 0;
@ -984,14 +983,14 @@ struct URL(U = string)
/// ///
unittest unittest
{ {
auto u = URL!()("example.org"); auto u = URL("example.org");
assert(u.path == "example.org"); assert(u.path == "example.org");
u = URL!()("relative/path"); u = URL("relative/path");
assert(u.path == "relative/path"); assert(u.path == "relative/path");
// Host and scheme // Host and scheme
u = URL!()("https://example.org"); u = URL("https://example.org");
assert(u.scheme == "https"); assert(u.scheme == "https");
assert(u.host == "example.org"); assert(u.host == "example.org");
assert(u.path is null); assert(u.path is null);
@ -999,7 +998,7 @@ unittest
assert(u.fragment is null); assert(u.fragment is null);
// With user and port and path // With user and port and path
u = URL!()("https://hilary:putnam@example.org:443/foo/bar"); u = URL("https://hilary:putnam@example.org:443/foo/bar");
assert(u.scheme == "https"); assert(u.scheme == "https");
assert(u.host == "example.org"); assert(u.host == "example.org");
assert(u.path == "/foo/bar"); assert(u.path == "/foo/bar");
@ -1009,7 +1008,7 @@ unittest
assert(u.fragment is null); assert(u.fragment is null);
// With query string // With query string
u = URL!()("https://example.org/?login=true"); u = URL("https://example.org/?login=true");
assert(u.scheme == "https"); assert(u.scheme == "https");
assert(u.host == "example.org"); assert(u.host == "example.org");
assert(u.path == "/"); assert(u.path == "/");
@ -1017,14 +1016,14 @@ unittest
assert(u.fragment is null); assert(u.fragment is null);
// With query string and fragment // With query string and fragment
u = URL!()("https://example.org/?login=false#label"); u = URL("https://example.org/?login=false#label");
assert(u.scheme == "https"); assert(u.scheme == "https");
assert(u.host == "example.org"); assert(u.host == "example.org");
assert(u.path == "/"); assert(u.path == "/");
assert(u.query == "login=false"); assert(u.query == "login=false");
assert(u.fragment == "label"); assert(u.fragment == "label");
u = URL!()("redis://root:password@localhost:2201/path?query=value#fragment"); u = URL("redis://root:password@localhost:2201/path?query=value#fragment");
assert(u.scheme == "redis"); assert(u.scheme == "redis");
assert(u.user == "root"); assert(u.user == "root");
assert(u.pass == "password"); assert(u.pass == "password");
@ -1043,7 +1042,7 @@ private unittest
{ {
try try
{ {
URL!()(t[0]); URL(t[0]);
assert(0); assert(0);
} }
catch (URIException e) catch (URIException e)
@ -1053,7 +1052,7 @@ private unittest
} }
else else
{ {
auto u = URL!()(t[0]); auto u = URL(t[0]);
assert("scheme" in t[1] ? u.scheme == t[1]["scheme"] : u.scheme is null, assert("scheme" in t[1] ? u.scheme == t[1]["scheme"] : u.scheme is null,
t[0]); t[0]);
assert("user" in t[1] ? u.user == t[1]["user"] : u.user is null, t[0]); assert("user" in t[1] ? u.user == t[1]["user"] : u.user is null, t[0]);
@ -1100,31 +1099,30 @@ enum Component : string
* *
* Returns: Requested URL components. * Returns: Requested URL components.
*/ */
URL parseURL(U)(in U source) URL parseURL(typeof(null) T)(in char[] source)
if (isSomeString!U)
{ {
return URL!U(source); return URL(source);
} }
/// Ditto. /// Ditto.
string parseURL(string T, U)(in U source) const(char)[] parseURL(immutable(char)[] T)(in char[] source)
if ((T == "scheme" if (T == "scheme"
|| T =="host" || T =="host"
|| T == "user" || T == "user"
|| T == "pass" || T == "pass"
|| T == "path" || T == "path"
|| T == "query" || T == "query"
|| T == "fragment") && isSomeString!U) || T == "fragment")
{ {
auto ret = URL!U(source); auto ret = URL(source);
return mixin("ret." ~ T); return mixin("ret." ~ T);
} }
/// Ditto. /// Ditto.
ushort parseURL(string T, U)(in U source) ushort parseURL(immutable(char)[] T)(in char[] source)
if (T == "port" && isSomeString!U) if (T == "port")
{ {
auto ret = URL!U(source); auto ret = URL(source);
return ret.port; return ret.port;
} }
@ -1158,7 +1156,7 @@ private unittest
else else
{ {
ushort port = parseURL!(Component.port)(t[0]); ushort port = parseURL!(Component.port)(t[0]);
string component = parseURL!(Component.scheme)(t[0]); auto component = parseURL!(Component.scheme)(t[0]);
assert("scheme" in t[1] ? component == t[1]["scheme"] : component is null, assert("scheme" in t[1] ? component == t[1]["scheme"] : component is null,
t[0]); t[0]);
component = parseURL!(Component.user)(t[0]); component = parseURL!(Component.user)(t[0]);