summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2017-06-22 11:48:58 +0200
committerEugen Wissner <belka@caraus.de>2017-06-22 11:48:58 +0200
commita4de1cc754aa82544b95592269e3b391dbc46258 (patch)
treeeb3ea9b2408f8c63aa414bfaba9b80a3356ac1b6
parent8d3cdb88625e08f159f91d833206dedfda9ceca6 (diff)
downloadtanya-a4de1cc754aa82544b95592269e3b391dbc46258.tar.gz
toStringz returns a pointer
-rw-r--r--source/tanya/container/string.d45
1 files changed, 40 insertions, 5 deletions
diff --git a/source/tanya/container/string.d b/source/tanya/container/string.d
index 19f9d89..796ed45 100644
--- a/source/tanya/container/string.d
+++ b/source/tanya/container/string.d
@@ -500,6 +500,12 @@ struct String
}
}
+ @safe @nogc unittest
+ {
+ auto s = String(0, 'K');
+ assert(s.length == 0);
+ }
+
/**
* Destroys the string.
*/
@@ -854,6 +860,9 @@ struct String
s.shrink(18);
assert(s.capacity == 21);
+
+ s.shrink(22);
+ assert(s.capacity == 21);
}
/**
@@ -948,25 +957,32 @@ struct String
return this.data[0 .. this.length_];
}
+ ///
+ nothrow @safe @nogc unittest
+ {
+ auto s = String("Char array.");
+ assert(s.get().length == 11);
+ }
+
/**
* Returns null-terminated string. The returned string is managed by this
* object and shouldn't be freed.
*
* Returns: Null-terminated string.
*/
- const(char)[] toStringz() nothrow @trusted @nogc
+ const(char)* toStringz() nothrow @nogc
{
reserve(length + 1);
this.data[length] = '\0';
- return this.data[0 .. length + 1];
+ return this.data;
}
///
- @safe @nogc unittest
+ @nogc unittest
{
auto s = String("C string.");
- assert(s.toStringz().length == 10);
- assert(s.toStringz()[$ - 1] == '\0');
+ assert(s.toStringz()[0] == 'C');
+ assert(s.toStringz()[9] == '\0');
}
/**
@@ -1092,6 +1108,16 @@ struct String
return length == 0;
}
+ ///
+ @safe @nogc unittest
+ {
+ String s;
+ assert(s.empty);
+
+ s.insertBack('K');
+ assert(!s.empty);
+ }
+
/**
* Params:
* i = Slice start.
@@ -1350,6 +1376,15 @@ struct String
return opIndex(pos) = value;
}
+ ///
+ @safe @nogc unittest
+ {
+ auto s = String("alea iacta est.");
+
+ s[0] = 'A';
+ assert(s[0] == 'A');
+ }
+
/**
* Assigns a range or a string.
*