comparison d2/qtd/Str.d @ 311:8674fd5f34f4 lifetime

Added d1/d2 top directories
author maxter <spambox@d-coding.com>
date Wed, 23 Dec 2009 16:17:22 +0200
parents
children
comparison
equal deleted inserted replaced
310:5bcfe9e7db7f 311:8674fd5f34f4
1 /**
2 *
3 * Copyright: Copyright QtD Team, 2008-2009
4 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>
5 *
6 * Copyright QtD Team, 2008-2009
7 * Distributed under the Boost Software License, Version 1.0.
8 * (See accompanying file boost-license-1.0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 *
10 */
11
12 module qt.qtd.Str;
13
14 import std.utf : toUTF8;
15
16 version(D_Version2) {
17 // private import core.sys.posix.stdio;
18 private import core.stdc.string;
19
20 version = druntime;
21 }
22
23 alias immutable(char)* stringz;
24 alias const(char)* cstringz;
25
26 public static char** toStringzArray(string[] args)
27 {
28 if ( args is null )
29 {
30 return null;
31 }
32 char** argv = (new char*[args.length]).ptr;
33 int argc = 0;
34 foreach (string p; args)
35 {
36 argv[argc++] = cast(char*)(p.dup~'\0');
37 }
38 argv[argc] = null;
39
40 return argv;
41 }
42
43 public string fromStringz(const (char) *s)
44 {
45 return s ? s[0 .. strlen(s)].idup : cast(string)null;
46 }
47
48
49 extern(C) void qtd_toUtf8(wchar* arr, uint size, string* str)
50 {
51 *str = toUTF8(arr[0..size]);
52 }
53
54
55