root/dwt/internal/mozilla/nsEmbedString.d

Revision 327:b0d7eb5bd76c, 1.7 kB (checked in by John Reimer <terminal.node@gmail.com>, 3 years ago)

Adding Mozilla XPCOM interfaces from dwt-linux to dwt-win

Line 
1 module dwt.internal.mozilla.nsEmbedString;
2
3 import Utf = tango.text.convert.Utf;
4
5 import dwt.internal.mozilla.Common;
6 import dwt.internal.mozilla.nsStringAPI;
7 import XPCOM = dwt.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 }
Note: See TracBrowser for help on using the browser.