Mercurial > projects > dwt2
comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/mozilla/nsEmbedString.d @ 0:6dd524f61e62
add dwt win and basic java stuff
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 02 Mar 2009 14:44:16 +0100 |
parents | |
children | 950d84783eac |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6dd524f61e62 |
---|---|
1 module org.eclipse.swt.internal.mozilla.nsEmbedString; | |
2 | |
3 import Utf = tango.text.convert.Utf; | |
4 | |
5 import org.eclipse.swt.internal.mozilla.Common; | |
6 import org.eclipse.swt.internal.mozilla.nsStringAPI; | |
7 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM; | |
8 | |
9 scope class nsEmbedString | |
10 { | |
11 this(wchar[] s) | |
12 { | |
13 nsresult result; | |
14 result = NS_StringContainerInit2(&str, s.ptr, s.length, 0); | |
15 if (XPCOM.NS_FAILED(result)) | |
16 throw new Exception("Init string container fail"); | |
17 } | |
18 | |
19 this() | |
20 { | |
21 nsresult result; | |
22 result = NS_StringContainerInit(&str); | |
23 if (XPCOM.NS_FAILED(result)) | |
24 throw new Exception("Init string container fail"); | |
25 } | |
26 | |
27 nsAString* opCast() | |
28 { | |
29 return cast(nsAString*)&str; | |
30 } | |
31 | |
32 wchar[] toString16() | |
33 { | |
34 wchar* buffer = null; | |
35 PRBool terminated; | |
36 uint len = NS_StringGetData(cast(nsAString*)&str, &buffer, &terminated); | |
37 return buffer[0 .. len].dup; | |
38 } | |
39 | |
40 char[] toString() | |
41 { | |
42 return Utf.toString(this.toString16()); | |
43 } | |
44 ~this() | |
45 { | |
46 NS_StringContainerFinish(&str); | |
47 } | |
48 private: | |
49 nsStringContainer str; | |
50 } | |
51 | |
52 | |
53 scope class nsEmbedCString | |
54 { | |
55 this(char[] s) | |
56 { | |
57 nsresult result; | |
58 result = NS_CStringContainerInit2(&str, s.ptr, s.length, 0); | |
59 if (XPCOM.NS_FAILED(result)) | |
60 throw new Exception("Init string container fail"); | |
61 } | |
62 | |
63 this() | |
64 { | |
65 nsresult result; | |
66 result = NS_CStringContainerInit(&str); | |
67 if (XPCOM.NS_FAILED(result)) | |
68 throw new Exception("Init string container fail"); | |
69 } | |
70 | |
71 nsACString* opCast() | |
72 { | |
73 return cast(nsACString*)&str; | |
74 } | |
75 | |
76 char[] toString() | |
77 { | |
78 char* buffer = null; | |
79 PRBool terminated; | |
80 uint len = NS_CStringGetData(cast(nsACString*)&str, &buffer, &terminated); | |
81 return buffer[0 .. len].dup; | |
82 } | |
83 | |
84 ~this() | |
85 { | |
86 NS_CStringContainerFinish(&str); | |
87 } | |
88 private: | |
89 nsCStringContainer str; | |
90 } | |
91 |