comparison qt/d2/qt/qtd/Str.d @ 188:7dd099050621

initial commit for D2 support
author eldar
date Sun, 12 Jul 2009 18:58:03 +0000
parents
children 438877e90dbe
comparison
equal deleted inserted replaced
187:34fe79a9915b 188:7dd099050621
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 version (Tango)
15 {
16 public import tango.text.convert.Utf : toUTF8 = toString;
17 alias char[] string;
18 }
19 else
20 {
21 import std.utf : toUTF8;
22 }
23
24 version(D_Version2) {
25 private import core.sys.posix.stdio;
26 private import core.stdc.string;
27
28 version = druntime;
29 }
30
31 public static char** toStringzArray(string[] args)
32 {
33 if ( args is null )
34 {
35 return null;
36 }
37 char** argv = (new char*[args.length]).ptr;
38 int argc = 0;
39 foreach (string p; args)
40 {
41 argv[argc++] = cast(char*)(p.dup~'\0');
42 }
43 argv[argc] = null;
44
45 return argv;
46 }
47
48 version(Tango) {
49 import tango.stdc.stringz : toStringz, fromStringz;
50 }
51
52
53 public string fromStringz(const (char) *s)
54 {
55 return s ? s[0 .. strlen(s)].idup : cast(string)null;
56 }
57
58 version(Windows)
59 {
60 export extern(C) void _d_toUtf8(wchar* arr, uint size, string* str)
61 {
62 *str = toUTF8(arr[0..size]);
63 }
64 }
65 else
66 {
67 extern(C) void _d_toUtf8(wchar* arr, uint size, string* str)
68 {
69 *str = toUTF8(arr[0..size]);
70 }
71 }
72
73