comparison d2/qtd/String.d @ 356:12cec2d14e1c

a better name for qtd.Str
author Max Samukha <maxter@spambox.com>
date Tue, 25 May 2010 20:14:04 +0300
parents d2/qtd/Str.d@31520b2c0b3c
children 9784459f0750
comparison
equal deleted inserted replaced
355:08c1ca7975ab 356:12cec2d14e1c
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 core.stdc.string;
15 import std.utf : toUTF8;
16
17 alias immutable(char)* stringz;
18 alias const(char)* cstringz;
19
20 /**
21 */
22 static char** toStringzArray(string[] args)
23 {
24 if ( args is null )
25 {
26 return null;
27 }
28 char** argv = (new char*[args.length]).ptr;
29 int argc = 0;
30 foreach (string p; args)
31 {
32 argv[argc++] = cast(char*)(p.dup~'\0');
33 }
34 argv[argc] = null;
35
36 return argv;
37 }
38
39 /**
40 */
41 bool isDigit(char s)
42 {
43 return (s >= '0' && s <= '9');
44 }
45
46 /**
47 */
48 bool isOctalChar(char s)
49 {
50 return (s >= '0' && s <= '7');
51 }
52
53 /**
54 */
55 bool isHexChar(char s)
56 {
57 return ((s >= 'a' && s <= 'f')
58 || (s >= 'A' && s <= 'F')
59 || (s >= '0' && s <= '9')
60 );
61 }
62
63 /**
64 */
65 string fromStringz(const (char) *s)
66 {
67 return s ? s[0 .. strlen(s)].idup : cast(string)null;
68 }
69
70 extern(C) void qtd_toUtf8(wchar* arr, uint size, string* str)
71 {
72 *str = toUTF8(arr[0..size]);
73 }
74
75
76