From 87bfd77373d6d4f16528e7d7c14a33e751f88fab Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 8 Oct 2017 15:53:29 +0200 Subject: [PATCH] container.string: Add missing postblit --- source/tanya/container/string.d | 57 +++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/source/tanya/container/string.d b/source/tanya/container/string.d index b0bbeec..4b2732b 100644 --- a/source/tanya/container/string.d +++ b/source/tanya/container/string.d @@ -26,7 +26,6 @@ */ module tanya.container.string; -import core.exception; import std.algorithm.comparison; import std.algorithm.mutation; import std.algorithm.searching; @@ -501,6 +500,14 @@ struct String assert(s.length == 0); } + this(this) @nogc nothrow @trusted + { + auto buf = this.data[0 .. this.length_]; + this.length_ = capacity_ = 0; + this.data = null; + insertBack(buf); + } + /** * Destroys the string. */ @@ -1112,15 +1119,13 @@ struct String } /// - @safe @nogc unittest + @nogc @safe unittest { - auto s = String("Высоцкий"); + auto s = String("Мне есть, что спеть, представ перед Всевышним."); auto cp = s.byCodePoint(); - assert(cp.front == 'В'); + assert(cp.front == 'М'); cp.popFront(); - assert(cp.front == 'ы'); - cp.popFront(); - assert(cp.front == 'с'); + assert(cp.front == 'н'); s = String("€"); cp = s.byCodePoint(); @@ -1133,6 +1138,24 @@ struct String assert(s.length == 4); } + /// + @nogc @safe unittest + { + auto s = const String("Высоцкий"); + auto cp1 = s.byCodePoint(); + assert(cp1.front == 'В'); + + auto cp2 = cp1[]; + cp1.popFront(); + assert(cp1.front == 'ы'); + assert(cp2.front == 'В'); + + cp2 = cp1.save(); + cp1.popFront(); + assert(cp1.front == 'с'); + assert(cp2.front == 'ы'); + } + /** * Returns: $(D_KEYWORD true) if the string is empty. */ @@ -1594,3 +1617,23 @@ struct String mixin DefaultAllocator; } + +// Postblit works. +@nogc @safe unittest +{ + void internFunc(String arg) + { + } + void middleFunc(S...)(S args) + { + foreach (arg; args) + { + internFunc(arg); + } + } + void topFunc(String args) + { + middleFunc(args); + } + topFunc(String("asdf")); +}