changeset 34:068e853b9c07 experimental

Cleaned up. Updated to latest D2 compiler.
author Jacob Carlborg <doob@me.com>
date Mon, 01 Aug 2011 20:34:54 +0200
parents 4fea56a5849f
children 511d1ef4e299
files .hgignore Makefile orange/core/string.d orange/serialization/Serializer.d orange/serialization/archives/Archive.d orange/serialization/archives/XMLArchive.d orange/xml/PhobosXML.d
diffstat 7 files changed, 55 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Jul 31 17:56:44 2011 +0200
+++ b/.hgignore	Mon Aug 01 20:34:54 2011 +0200
@@ -12,7 +12,7 @@
 *.dylib
 main.d
 main
-main.d.deps
+*.deps
 *.framework
 kandil
 lib
--- a/Makefile	Sun Jul 31 17:56:44 2011 +0200
+++ b/Makefile	Mon Aug 01 20:34:54 2011 +0200
@@ -1,6 +1,8 @@
 LIBNAME		=	orange
 SRC			=	\
-	_.d \
+	core/io.d \
+	core/string.d \
+	core/_.d \
 	serialization/Events.d \
 	serialization/RegisterWrapper.d \
 	serialization/Serializable.d \
@@ -16,12 +18,11 @@
 	util/Traits.d \
 	util/Use.d \
 	util/_.d \
-	util/io.d \
-	util/string.d \
 	util/collection/Array.d \
+	util/collection/_.d \
 	xml/PhobosXML.d \
 	xml/XMLDocument.d \
-	_.d
+	xml/_.d \
 
 DC			=	dmd
 DCFLAGS		=	-I/usr/include/d -I/usr/local/include/d
@@ -60,4 +61,4 @@
 
 %.o : %.d
 	@echo Compiling $< . . .
-	@$(DC) -c $(DCFLAGS) $< -of$@ -Hfimport/$(basename $@).di
+	@$(DC) -c $< -of$@ -Hfimport/$(basename $@).di
--- a/orange/core/string.d	Sun Jul 31 17:56:44 2011 +0200
+++ b/orange/core/string.d	Mon Aug 01 20:34:54 2011 +0200
@@ -32,11 +32,12 @@
 {	
 	import std.string;
 	import std.utf;
-	import std.ctype : isxdigit;
+	static import std.ascii;
+	static import std.conv;
 	
 	version = Phobos;
 	
-	private alias std.string.tolower toFold;
+	private alias std.string.toLower toFold;
 	
 	alias std.utf.toUTF8 toString;
 	alias std.utf.toUTF16 toString16;
@@ -45,7 +46,7 @@
 	alias std.string.toStringz toStringz;
 	alias std.utf.toUTF16z toString16z;
 	
-	alias std.string.toString fromStringz;
+	alias std.ascii.isHexDigit isHexDigit;
 }
 
 import orange.util.Traits;
@@ -758,10 +759,11 @@
  *     
  * Returns: true if the given character is a hexdecimal digit character otherwise false
  */
-bool isHexDigit (dchar ch)
+version (Tango)
 {
-	version (Tango)
+	bool isHexDigit (dchar ch)
 	{
+
 		switch (ch)
 		{
 			case 'A': return true;				
@@ -770,26 +772,22 @@
 			case 'D': return true;
 			case 'E': return true;
 			case 'F': return true;
-			
+	
 			case 'a': return true;
 			case 'b': return true;
 			case 'c': return true;
 			case 'd': return true;
 			case 'e': return true;
 			case 'f': return true;
-			
+	
 			default: break;
 		}
-		
+
 		if (isDigit(ch))
 			return true;
+	
+		return false;
 	}
-
-	else
-		if (isxdigit(ch) != 0)
-			return true;
-		
-	return false;
 }
 
 /*version (Tango)
@@ -826,6 +824,19 @@
 	}
 	
 	/**
+	 * Converts a C-style 0 terminated string to a string
+	 * 
+	 * Params:
+	 *     str = the C-style 0 terminated string
+	 *     
+	 * Returns: the converted string
+	 */
+	string fromStringz (char* str)
+	{
+		return std.conv.to!(string)(str);
+	}
+	
+	/**
 	 * Converts a C-style 0 terminated string to a wstring
 	 * 
 	 * Params:
--- a/orange/serialization/Serializer.d	Sun Jul 31 17:56:44 2011 +0200
+++ b/orange/serialization/Serializer.d	Mon Aug 01 20:34:54 2011 +0200
@@ -12,12 +12,13 @@
 else
 {
 	import std.conv;
-	alias ConvError ConversionException;
+	alias ConvException ConversionException;
 }
 
 import orange.core._;
 import orange.serialization._;
-import orange.serialization.archives._;
+import orange.serialization.archives.Archive;
+import orange.serialization.archives.ArchiveException;
 import orange.util._;
 
 private
@@ -36,7 +37,7 @@
 	private char toUpper (char c)
 	{
 		if (c >= 'a' && c <= 'z')
-			return c - 32;
+			return cast(char) (c - 32);
 
 		return c;
 	}
@@ -45,8 +46,8 @@
 class Serializer
 {
 	alias void delegate (ArchiveException exception, string[] data) ErrorCallback;
-	alias UntypedData Data;
-	alias size_t Id;
+	alias Archive.UntypedData Data;
+	alias Archive.Id Id;
 	
 	private
 	{
--- a/orange/serialization/archives/Archive.d	Sun Jul 31 17:56:44 2011 +0200
+++ b/orange/serialization/archives/Archive.d	Mon Aug 01 20:34:54 2011 +0200
@@ -12,16 +12,12 @@
 else
 {
 	import std.conv;
-	alias ConvError ConversionException;
+	alias ConvException ConversionException;
 }
 
 import orange.serialization.archives.ArchiveException;
-import orange.serialization.Serializer;
 import orange.core.string;
 
-version (Tango) alias void[] UntypedData;
-else mixin ("alias immutable(void)[] UntypedData;");
-
 private enum ArchiveMode
 {
 	archiving,
@@ -30,7 +26,9 @@
 
 struct Array
 {
-	void* ptr;
+	version (Tango) void* ptr;
+	else mixin("immutable(void)* ptr;");
+
 	size_t length;
 	size_t elementSize;
 	
@@ -49,7 +47,10 @@
 
 interface Archive
 {
-	alias Serializer.Id Id;
+	alias size_t Id;
+	
+	version (Tango) alias void[] UntypedData;
+	else mixin ("alias immutable(void)[] UntypedData;");
 	
 	void beginArchiving ();
 	void beginUnarchiving (UntypedData data);
@@ -160,7 +161,7 @@
     //idouble unarchiveIdouble (string key); // currently not supported by to!()
     //ifloat unarchiveIfloat (string key); // currently not supported by to!()*/
     int unarchiveInt (string key);
-	int unarchiveInt (Id id);
+	//int unarchiveInt (Id id);
     //ireal unarchiveIreal (string key); // currently not supported by to!()
     long unarchiveLong (string key);
     real unarchiveReal (string key);
--- a/orange/serialization/archives/XMLArchive.d	Sun Jul 31 17:56:44 2011 +0200
+++ b/orange/serialization/archives/XMLArchive.d	Mon Aug 01 20:34:54 2011 +0200
@@ -555,7 +555,7 @@
 			
 			dg(length);
 			
-			return id.toId();
+			return toId(id);
 		};
 	}
 	
@@ -605,7 +605,7 @@
 			
 			dg(length);
 			
-			return id.toId();
+			return toId(id);
 		};
 	}
 	
@@ -733,34 +733,6 @@
 		};
 	}
 	
-	/*
-	 * 	Id unarchiveArray (string key, void delegate (size_t) dg)
-	{
-		return restore!(Id)(lastElement) in {			
-			auto element = getElement(Tags.arrayTag, key);
-			
-			if (!element.isValid)
-				return Id.max;
-	
-			lastElement = element;
-			auto len = getValueOfAttribute(Attributes.lengthAttribute);
-			
-			if (!len)
-				return Id.max;
-			
-			auto length = fromData!(size_t)(len);
-			auto id = getValueOfAttribute(Attributes.idAttribute);	
-			
-			if (!id)
-				return Id.max;
-			
-			dg(length);
-			
-			return id.toId();
-		};
-	}
-	 */
-	
 	Id unarchivePointer (string key, void delegate () dg)
 	{
 		return restore!(Id)(lastElement) in {
@@ -973,11 +945,6 @@
 	{
 		return unarchivePrimitive!(int)(key);
 	}
-	
-	int unarchiveInt (Id id)
-	{
-		return unarchivePrimitive!(int)(id);
-	}
 
 	// currently not suppported by to!()
     /*ireal unarchiveIreal (string key)
@@ -1031,9 +998,9 @@
 		return unarchivePrimitive!(wchar)(key);
 	}
 	
-	T unarchivePrimitive (T, U) (U keyOrId)
+	T unarchivePrimitive (T) (string key)
 	{
-		auto element = getElement(toData(T.stringof), keyOrId);
+		auto element = getElement(toData(T.stringof), key);
 
 		if (!element.isValid)
 			return T.init;
@@ -1085,19 +1052,8 @@
 		return null;
 	}
 	
-	private doc.Node getElement (T) (Data tag, T keyOrID, Data attribute = Attributes.invalidAttribute, bool throwOnError = true)
-	{
-		if (attribute == Attributes.invalidAttribute)
-		{
-			static if (is(T : Id))
-				attribute = Attributes.idAttribute;
-				
-			else
-				attribute = Attributes.keyAttribute;
-		}
-
-		auto key = toData(keyOrID);
-		
+	private doc.Node getElement (Data tag, string key, Data attribute = Attributes.keyAttribute, bool throwOnError = true)
+	{		
 		auto set = lastElement.query[tag].attribute((doc.Node node) {
 			if (node.name == attribute && node.value == key)
 				return true;
--- a/orange/xml/PhobosXML.d	Sun Jul 31 17:56:44 2011 +0200
+++ b/orange/xml/PhobosXML.d	Mon Aug 01 20:34:54 2011 +0200
@@ -131,7 +131,7 @@
 import std.string;
 import std.encoding;
 
-immutable cdata = "<![CDATA[";
+enum cdata = "<![CDATA[";
 
 final class Attribute : Element
 {
@@ -1015,7 +1015,7 @@
 				string[] b = item.pretty(indent);
 				foreach(s;b)
 				{
-					a ~= rjustify(s,s.length + indent);
+					a ~= rightJustify(s,s.length + indent);
 				}
 			}
 			a ~= tag.toEndString;