Mercurial > projects > dwt-linux
comparison dwt/internal/mozilla/nsEmbedString2.d @ 291:b0bd1789106b
fix: added wrong directory :(
author | John Reimer<terminal.node@gmail.com> |
---|---|
date | Wed, 06 Aug 2008 18:29:44 -0700 |
parents | |
children | 3dfa75c74ed2 |
comparison
equal
deleted
inserted
replaced
290:4c1340edee0d | 291:b0bd1789106b |
---|---|
1 module dwt.internal.mozilla.nsEmbedString; | |
2 | |
3 import dwt.internal.mozilla.Common; | |
4 import dwt.internal.mozilla.nsStringAPI; | |
5 | |
6 class nsEmbedString | |
7 { | |
8 this(wchar[] s) | |
9 { | |
10 nsresult result; | |
11 result = NS_StringContainerInit2(&str, s.ptr, s.length, 0); | |
12 if (result != 0) // TODO: convert to XPCOM fail macro | |
13 throw new Exception("Init string container fail"); | |
14 } | |
15 | |
16 this() | |
17 { | |
18 nsresult result; | |
19 result = NS_StringContainerInit(&str); | |
20 if (result != 0) // TODO: convert to XPCOM fail macro | |
21 throw new Exception("Init string container fail"); | |
22 } | |
23 | |
24 nsAString* opCast() | |
25 { | |
26 return cast(nsAString*)&str; | |
27 } | |
28 | |
29 wchar[] toString16() | |
30 { | |
31 wchar* buffer = null; | |
32 PRBool terminated; | |
33 uint len = NS_StringGetData(cast(nsAString*)&str, &buffer, &terminated); | |
34 return buffer[0 .. len].dup; | |
35 } | |
36 | |
37 ~this() | |
38 { | |
39 NS_StringContainerFinish(&str); | |
40 } | |
41 private: | |
42 nsStringContainer str; | |
43 } | |
44 | |
45 | |
46 class nsEmbedCString | |
47 { | |
48 this(char[] s) | |
49 { | |
50 nsresult result; | |
51 result = NS_CStringContainerInit2(&str, s.ptr, s.length, 0); | |
52 if (result != 0) // TODO: convert to XPCOM fail macro | |
53 throw new Exception("Init string container fail"); | |
54 } | |
55 | |
56 this() | |
57 { | |
58 nsresult result; | |
59 result = NS_CStringContainerInit(&str); | |
60 if (result != 0) // TODO: convert to XPCOM fail macro | |
61 throw new Exception("Init string container fail"); | |
62 } | |
63 | |
64 nsACString* opCast() | |
65 { | |
66 return cast(nsACString*)&str; | |
67 } | |
68 | |
69 char[] toString() | |
70 { | |
71 char* buffer = null; | |
72 PRBool terminated; | |
73 uint len = NS_CStringGetData(cast(nsACString*)&str, &buffer, &terminated); | |
74 return buffer[0 .. len].dup; | |
75 } | |
76 | |
77 ~this() | |
78 { | |
79 NS_CStringContainerFinish(&str); | |
80 } | |
81 private: | |
82 nsCStringContainer str; | |
83 } | |
84 |