diff dwt/internal/mozilla/nsEmbedString2.d @ 278:93409d9838c5

Commit more browser/xpcom updates, including still uncoverted source.
author John Reimer<terminal.node@gmail.com>
date Thu, 31 Jul 2008 19:17:51 -0700
parents
children 44258e0b6687 3dfa75c74ed2
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/internal/mozilla/nsEmbedString2.d	Thu Jul 31 19:17:51 2008 -0700
@@ -0,0 +1,86 @@
+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);
+		wchar[] result = buffer[0 .. len].dup;
+		return result;
+	}
+
+	~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);
+		char[] result = buffer[0 .. len].dup;
+		return result;
+	}
+
+	~this()
+	{
+		NS_CStringContainerFinish(&str);
+	}
+private:
+	nsCStringContainer str;
+}
+