Mercurial > projects > qtd
comparison d2/qtd/String.d @ 317:0554382bdf7e lifetime
String.d
author | maxter <spambox@d-coding.com> |
---|---|
date | Thu, 24 Dec 2009 00:13:00 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
316:f04e6d82d3d4 | 317:0554382bdf7e |
---|---|
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 qtd.String; | |
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 |