diff dwt/internal/mozilla/nsEmbedString2.d @ 291:b0bd1789106b

fix: added wrong directory :(
author John Reimer<terminal.node@gmail.com>
date Wed, 06 Aug 2008 18:29:44 -0700
parents
children 3dfa75c74ed2
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/internal/mozilla/nsEmbedString2.d	Wed Aug 06 18:29:44 2008 -0700
@@ -0,0 +1,84 @@
+module dwt.internal.mozilla.nsEmbedString;
+
+import dwt.internal.mozilla.Common;
+import dwt.internal.mozilla.nsStringAPI;
+
+class nsEmbedString
+{    
+	this(wchar[] s)
+	{
+		nsresult result;
+		result = NS_StringContainerInit2(&str, s.ptr, s.length, 0);
+		if (result != 0) // TODO: convert to XPCOM fail macro
+			throw new Exception("Init string container fail");
+	}
+
+	this()
+	{
+		nsresult result;
+		result = NS_StringContainerInit(&str);
+		if (result != 0) // TODO: convert to XPCOM fail macro
+			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;
+	}
+    
+    ~this()
+	{
+		NS_StringContainerFinish(&str);
+	}
+private:
+	nsStringContainer str;
+}
+
+
+class nsEmbedCString
+{
+	this(char[] s)
+	{
+		nsresult result;
+		result = NS_CStringContainerInit2(&str, s.ptr, s.length, 0);
+		if (result != 0) // TODO: convert to XPCOM fail macro
+			throw new Exception("Init string container fail");
+	}
+
+	this()
+	{
+		nsresult result;
+		result = NS_CStringContainerInit(&str);
+		if (result != 0) // TODO: convert to XPCOM fail macro
+			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;
+}
+