1 module org.eclipse.swt.internal.mozilla.nsEmbedString; 2 3 import java.lang.all; 4 5 import org.eclipse.swt.internal.mozilla.Common; 6 import org.eclipse.swt.internal.mozilla.nsStringAPI; 7 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM; 8 9 scope class nsEmbedString 10 { 11 this(String16 s) 12 { 13 nsresult result; 14 result = NS_StringContainerInit2(&str, cast(wchar*)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 String16 toString16() 33 { 34 wchar* buffer = null; 35 PRBool terminated; 36 uint len = NS_StringGetData(cast(nsAString*)&str, &buffer, &terminated); 37 return buffer[0 .. len]._idup(); 38 } 39 40 override String toString() 41 { 42 return String_valueOf(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(String 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 String toString() 77 { 78 char* buffer = null; 79 PRBool terminated; 80 uint len = NS_CStringGetData(cast(nsACString*)&str, &buffer, &terminated); 81 return buffer[0 .. len]._idup(); 82 } 83 84 ~this() 85 { 86 NS_CStringContainerFinish(&str); 87 } 88 private: 89 nsCStringContainer str; 90 } 91