summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2017-10-08 15:53:29 +0200
committerEugen Wissner <belka@caraus.de>2017-10-08 15:53:29 +0200
commit87bfd77373d6d4f16528e7d7c14a33e751f88fab (patch)
tree8d003bb2c2bea7bee2612da873b8db1be75d01c6
parent17005e4ac9bbd151ffb779c48e11c4b53d32c78f (diff)
downloadtanya-87bfd77373d6d4f16528e7d7c14a33e751f88fab.tar.gz
container.string: Add missing postblit
-rw-r--r--source/tanya/container/string.d57
1 files 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 == 'В');
- cp.popFront();
- assert(cp.front == 'ы');
+ 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"));
+}