changeset 317:0554382bdf7e lifetime

String.d
author maxter <spambox@d-coding.com>
date Thu, 24 Dec 2009 00:13:00 +0200
parents f04e6d82d3d4
children
files d2/qtd/String.d
diffstat 1 files changed, 55 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/d2/qtd/String.d	Thu Dec 24 00:13:00 2009 +0200
@@ -0,0 +1,55 @@
+/**
+ *
+ *  Copyright: Copyright QtD Team, 2008-2009
+ *  License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>
+ *
+ *  Copyright QtD Team, 2008-2009
+ *  Distributed under the Boost Software License, Version 1.0.
+ *  (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+module qtd.String;
+
+import std.utf : toUTF8;
+
+version(D_Version2) {
+//    private import core.sys.posix.stdio;
+    private import core.stdc.string;
+
+    version = druntime;
+}
+
+alias immutable(char)* stringz;
+alias const(char)* cstringz;
+
+public static char** toStringzArray(string[] args)
+{
+    if ( args is null )
+    {
+        return null;
+    }
+    char** argv = (new char*[args.length]).ptr;
+    int argc = 0;
+    foreach (string p; args)
+    {
+        argv[argc++] = cast(char*)(p.dup~'\0');
+    }
+    argv[argc] = null;
+
+    return argv;
+}
+
+public string fromStringz(const (char) *s)
+{
+    return s ? s[0 .. strlen(s)].idup : cast(string)null;
+}
+
+
+extern(C) void qtd_toUtf8(wchar* arr, uint size, string* str)
+{
+    *str = toUTF8(arr[0..size]);
+}
+
+
+