25
|
1 module org.eclipse.swt.internal.mozilla.nsEmbedString;
|
|
2
|
|
3 import java.lang.all;
|
|
4
|
48
|
5 version(Tango){
|
25
|
6 import Utf = tango.text.convert.Utf;
|
48
|
7 } else { // Phobos
|
|
8 }
|
25
|
9
|
|
10 import org.eclipse.swt.internal.mozilla.Common;
|
|
11 import org.eclipse.swt.internal.mozilla.nsStringAPI;
|
|
12 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM;
|
|
13
|
|
14 scope class nsEmbedString
|
|
15 {
|
48
|
16 this(wchar[] s)
|
|
17 {
|
|
18 nsresult result;
|
|
19 result = NS_StringContainerInit2(&str, s.ptr, s.length, 0);
|
|
20 if (XPCOM.NS_FAILED(result))
|
|
21 throw new Exception("Init string container fail");
|
|
22 }
|
25
|
23
|
48
|
24 this()
|
|
25 {
|
|
26 nsresult result;
|
|
27 result = NS_StringContainerInit(&str);
|
|
28 if (XPCOM.NS_FAILED(result))
|
|
29 throw new Exception("Init string container fail");
|
|
30 }
|
25
|
31
|
48
|
32 nsAString* opCast()
|
|
33 {
|
|
34 return cast(nsAString*)&str;
|
|
35 }
|
25
|
36
|
48
|
37 wchar[] toString16()
|
|
38 {
|
|
39 wchar* buffer = null;
|
|
40 PRBool terminated;
|
|
41 uint len = NS_StringGetData(cast(nsAString*)&str, &buffer, &terminated);
|
|
42 return buffer[0 .. len].dup;
|
|
43 }
|
25
|
44
|
|
45 char[] toString()
|
|
46 {
|
|
47 return Utf.toString(this.toString16());
|
|
48 }
|
|
49 ~this()
|
48
|
50 {
|
|
51 NS_StringContainerFinish(&str);
|
|
52 }
|
25
|
53 private:
|
48
|
54 nsStringContainer str;
|
25
|
55 }
|
|
56
|
|
57
|
|
58 scope class nsEmbedCString
|
|
59 {
|
48
|
60 this(char[] s)
|
|
61 {
|
|
62 nsresult result;
|
|
63 result = NS_CStringContainerInit2(&str, s.ptr, s.length, 0);
|
|
64 if (XPCOM.NS_FAILED(result))
|
|
65 throw new Exception("Init string container fail");
|
|
66 }
|
25
|
67
|
48
|
68 this()
|
|
69 {
|
|
70 nsresult result;
|
|
71 result = NS_CStringContainerInit(&str);
|
|
72 if (XPCOM.NS_FAILED(result))
|
|
73 throw new Exception("Init string container fail");
|
|
74 }
|
25
|
75
|
48
|
76 nsACString* opCast()
|
|
77 {
|
|
78 return cast(nsACString*)&str;
|
|
79 }
|
25
|
80
|
48
|
81 char[] toString()
|
|
82 {
|
|
83 char* buffer = null;
|
|
84 PRBool terminated;
|
|
85 uint len = NS_CStringGetData(cast(nsACString*)&str, &buffer, &terminated);
|
25
|
86 return buffer[0 .. len].dup;
|
48
|
87 }
|
25
|
88
|
48
|
89 ~this()
|
|
90 {
|
|
91 NS_CStringContainerFinish(&str);
|
|
92 }
|
25
|
93 private:
|
48
|
94 nsCStringContainer str;
|
25
|
95 }
|
|
96
|