diff org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/mozilla/nsEmbedString.d @ 0:6dd524f61e62

add dwt win and basic java stuff
author Frank Benoit <benoit@tionex.de>
date Mon, 02 Mar 2009 14:44:16 +0100
parents
children 950d84783eac
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/mozilla/nsEmbedString.d	Mon Mar 02 14:44:16 2009 +0100
@@ -0,0 +1,91 @@
+module org.eclipse.swt.internal.mozilla.nsEmbedString;
+
+import Utf = tango.text.convert.Utf;
+
+import org.eclipse.swt.internal.mozilla.Common;
+import org.eclipse.swt.internal.mozilla.nsStringAPI;
+import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM;
+
+scope class nsEmbedString
+{    
+	this(wchar[] s)
+	{
+		nsresult result;
+		result = NS_StringContainerInit2(&str, s.ptr, s.length, 0);
+		if (XPCOM.NS_FAILED(result)) 
+			throw new Exception("Init string container fail");
+	}
+
+	this()
+	{
+		nsresult result;
+		result = NS_StringContainerInit(&str);
+		if (XPCOM.NS_FAILED(result)) 
+			throw new Exception("Init string container fail");
+	}
+
+	nsAString* opCast()
+	{
+		return cast(nsAString*)&str;
+	}
+
+	wchar[] toString16()
+	{
+		wchar* buffer = null;
+		PRBool terminated;
+		uint len = NS_StringGetData(cast(nsAString*)&str, &buffer, &terminated);
+		return buffer[0 .. len].dup;
+	}
+    
+    char[] toString()
+    {
+        return Utf.toString(this.toString16());
+    }
+    ~this()
+	{
+		NS_StringContainerFinish(&str);
+	}
+private:
+	nsStringContainer str;
+}
+
+
+scope class nsEmbedCString
+{
+	this(char[] s)
+	{
+		nsresult result;
+		result = NS_CStringContainerInit2(&str, s.ptr, s.length, 0);
+		if (XPCOM.NS_FAILED(result)) 
+			throw new Exception("Init string container fail");
+	}
+
+	this()
+	{
+		nsresult result;
+		result = NS_CStringContainerInit(&str);
+		if (XPCOM.NS_FAILED(result)) 
+			throw new Exception("Init string container fail");
+	}
+
+	nsACString* opCast()
+	{
+		return cast(nsACString*)&str;
+	}
+
+	char[] toString()
+	{
+		char* buffer = null;
+		PRBool terminated;
+		uint len = NS_CStringGetData(cast(nsACString*)&str, &buffer, &terminated);
+        return buffer[0 .. len].dup;
+	}
+
+	~this()
+	{
+		NS_CStringContainerFinish(&str);
+	}
+private:
+	nsCStringContainer str;
+}
+