comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/mozilla/nsEmbedString.d @ 38:2e09b0e6857a

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