comparison dwt/internal/mozilla/nsEmbedString2.d @ 278:93409d9838c5

Commit more browser/xpcom updates, including still uncoverted source.
author John Reimer<terminal.node@gmail.com>
date Thu, 31 Jul 2008 19:17:51 -0700
parents
children 44258e0b6687 3dfa75c74ed2
comparison
equal deleted inserted replaced
277:687f261028b8 278:93409d9838c5
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 wchar[] result = buffer[0 .. len].dup;
35 return result;
36 }
37
38 ~this()
39 {
40 NS_StringContainerFinish(&str);
41 }
42 private:
43 nsStringContainer str;
44 }
45
46
47 class nsEmbedCString
48 {
49 this(char[] s)
50 {
51 nsresult result;
52 result = NS_CStringContainerInit2(&str, s.ptr, s.length, 0);
53 if (result != 0) // TODO: convert to XPCOM fail macro
54 throw new Exception("Init string container fail");
55 }
56
57 this()
58 {
59 nsresult result;
60 result = NS_CStringContainerInit(&str);
61 if (result != 0) // TODO: convert to XPCOM fail macro
62 throw new Exception("Init string container fail");
63 }
64
65 nsACString* opCast()
66 {
67 return cast(nsACString*)&str;
68 }
69
70 char[] toString()
71 {
72 char* buffer = null;
73 PRBool terminated;
74 uint len = NS_CStringGetData(cast(nsACString*)&str, &buffer, &terminated);
75 char[] result = buffer[0 .. len].dup;
76 return result;
77 }
78
79 ~this()
80 {
81 NS_CStringContainerFinish(&str);
82 }
83 private:
84 nsCStringContainer str;
85 }
86