Mercurial > projects > dwt-linux
annotate dwt/internal/mozilla/nsEmbedString.d @ 340:3f4a5c7d138f
Fixes
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Sun, 26 Oct 2008 08:09:00 -0700 |
parents | 93409d9838c5 |
children | 9a4d7706df52 |
rev | line source |
---|---|
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
1 module dwt.internal.mozilla.nsEmbedString; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
2 |
340 | 3 import Utf = tango.text.convert.Utf; |
4 | |
5 import dwt.internal.mozilla.Common; | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
6 import dwt.internal.mozilla.nsStringAPI; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
7 |
340 | 8 scope class nsEmbedString |
9 { | |
10 this(wchar[] s) | |
11 { | |
12 nsresult result; | |
13 result = NS_StringContainerInit2(&str, s.ptr, s.length, 0); | |
14 if (result != 0) // TODO: convert to XPCOM fail macro | |
15 throw new Exception("Init string container fail"); | |
16 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
17 |
340 | 18 this() |
19 { | |
20 nsresult result; | |
21 result = NS_StringContainerInit(&str); | |
22 if (result != 0) // TODO: convert to XPCOM fail macro | |
23 throw new Exception("Init string container fail"); | |
24 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
25 |
340 | 26 nsAString* opCast() |
27 { | |
28 return cast(nsAString*)&str; | |
29 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
30 |
340 | 31 wchar[] toString16() |
32 { | |
33 wchar* buffer = null; | |
34 PRBool terminated; | |
35 uint len = NS_StringGetData(cast(nsAString*)&str, &buffer, &terminated); | |
36 return buffer[0 .. len].dup; | |
37 } | |
38 | |
39 char[] toString() | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
40 { |
340 | 41 return Utf.toString(this.toString16()); |
42 } | |
43 ~this() | |
44 { | |
45 NS_StringContainerFinish(&str); | |
46 } | |
47 private: | |
48 nsStringContainer str; | |
49 } | |
50 | |
51 | |
52 scope class nsEmbedCString | |
53 { | |
54 this(char[] s) | |
55 { | |
56 nsresult result; | |
57 result = NS_CStringContainerInit2(&str, s.ptr, s.length, 0); | |
58 if (result != 0) // TODO: convert to XPCOM fail macro | |
59 throw new Exception("Init string container fail"); | |
60 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
61 |
340 | 62 this() |
63 { | |
64 nsresult result; | |
65 result = NS_CStringContainerInit(&str); | |
66 if (result != 0) // TODO: convert to XPCOM fail macro | |
67 throw new Exception("Init string container fail"); | |
68 } | |
69 | |
70 nsACString* opCast() | |
71 { | |
72 return cast(nsACString*)&str; | |
73 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
74 |
340 | 75 char[] toString() |
76 { | |
77 char* buffer = null; | |
78 PRBool terminated; | |
79 uint len = NS_CStringGetData(cast(nsACString*)&str, &buffer, &terminated); | |
80 return buffer[0 .. len].dup; | |
81 } | |
82 | |
83 ~this() | |
84 { | |
85 NS_CStringContainerFinish(&str); | |
86 } | |
87 private: | |
88 nsCStringContainer str; | |
89 } | |
90 |