Skip to content

Commit

Permalink
more documentation and some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fponticelli committed Sep 25, 2014
1 parent 5f86d02 commit 2af0702
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bin
doc/pages
doc/xml
doc/dox
.DS_Store
*.sublime-*
3 changes: 3 additions & 0 deletions doc/build_doc.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
--no-output
-D doc-gen
-D display
-D dox
-dce no
-lib thx.core
ImportAll

--each
Expand Down
3 changes: 2 additions & 1 deletion doc/doc.hxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-cmd rm -rf xml/*
-cmd haxe build_doc.hxml
-cmd rm -rf pages
-cmd haxelib run dox -r / -o pages -i xml --title "thx.core" -in thx
-cmd haxelib run dox -r / -o pages -i xml --title "thx.core" -in thx #--template-path dox/templates
#-cmd cp -r dox/resources/* pages
-cmd static pages
2 changes: 1 addition & 1 deletion src/thx/core/Arrays.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import haxe.macro.ExprTools;
#end

/**
It provides additional extension methods on top of the `Array` type.
`Arrays` provides additional extension methods on top of the `Array` type.
Note that some of the examples imply `using thx.core.Arrays;`.
**/
Expand Down
3 changes: 3 additions & 0 deletions src/thx/core/Dates.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package thx.core;

/**
`Dates` provides additional extension methods on top of the `Date` type.
**/
class Dates {
/**
It compares two dates.
Expand Down
35 changes: 23 additions & 12 deletions src/thx/core/Dynamics.hx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package thx.core;

/**
`Dynamics` provides additional extension methods on any type.
**/
class Dynamics {
public static function same<T1, T2>(a : T1, b : T2) : Bool {
// quick check
if(untyped a == b)
return true;

/**
Structural and recursive equality.
**/
public static function equals<T1, T2>(a : T1, b : T2) : Bool {
// type check
if(!Types.sameType(a, b))
return false;

// quick check
if(untyped a == b)
return true;

switch Type.typeof(a) {
case TFloat, TNull, TInt, TBool:
return false;
Expand All @@ -32,7 +38,7 @@ class Dynamics {
if (aa.length != ab.length)
return false;
for (i in 0...aa.length)
if (!same(aa[i], ab[i]))
if (!equals(aa[i], ab[i]))
return false;
return true;
}
Expand All @@ -50,7 +56,7 @@ class Dynamics {
if (ka.length != kb.length)
return false;
for (key in ka)
if (!hb.exists(key) || !same(ha.get(key), hb.get(key)))
if (!hb.exists(key) || !equals(ha.get(key), hb.get(key)))
return false;
return true;
}
Expand All @@ -64,19 +70,24 @@ class Dynamics {
return false;

for (i in 0...va.length)
if (!same(va[i], vb[i]))
if (!equals(va[i], vb[i]))
return false;
return true;
}

// custom class with equality method
var f;
if(Reflect.hasField(a, 'equals') && Reflect.isFunction(f = Reflect.field(a, 'equals')))
return Reflect.callMethod(a, f, [b]);

// custom class
var fields = Type.getInstanceFields(Type.getClass(a));
for (field in fields) {
var va = Reflect.field(a, field);
if (Reflect.isFunction(va))
continue;
var vb = Reflect.field(b, field);
if(!same(va, vb))
if(!equals(va, vb))
return false;
}
return true;
Expand All @@ -92,7 +103,7 @@ class Dynamics {
var pa = Type.enumParameters(cast a),
pb = Type.enumParameters(cast b);
for (i in 0...pa.length)
if (!same(pa[i], pb[i]))
if (!equals(pa[i], pb[i]))
return false;
return true;
case TObject :
Expand All @@ -107,7 +118,7 @@ class Dynamics {
if(Reflect.isFunction(va))
continue;
var vb = Reflect.field(b, field);
if(!same(va, vb))
if(!equals(va, vb))
return false;
}
if (fb.length > 0)
Expand All @@ -127,7 +138,7 @@ class Dynamics {
if (aa.length != ab.length)
return false;
for (i in 0...aa.length)
if (!same(aa[i], ab[i]))
if (!equals(aa[i], ab[i]))
return false;
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions src/thx/core/ERegs.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package thx.core;

/**
`ERegs` provides helper methods to use together with `EReg`.
**/
class ERegs {
static var ESCAPE_PATTERN = ~/([-[\]{}()*+?.,\\^$|#\s])/g;

/**
It escapes any characer in a string that has a special meaning when used in a regula expression.
**/
public static function escape(text : String) : String
return ESCAPE_PATTERN.replace(text, "\\$1");
}
8 changes: 8 additions & 0 deletions src/thx/core/Error.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ package thx.core;
import haxe.PosInfos;
import haxe.CallStack;

/**
**/
class Error #if js extends js.Error #end {
/**
It creates an instance of Error from any value.
If `err` is already an instance of `Error`, it is returned and nothing is created.
**/
public static function fromDynamic(err : Dynamic, ?pos : PosInfos) : Error {
if(Std.is(err, Error))
return cast err;
Expand Down
7 changes: 4 additions & 3 deletions src/thx/core/UUID.hx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package thx.core;

/**
Helper class to generate [UUID](http://en.wikipedia.org/wiki/Universally_unique_identifier) strings (version 4).
**/
class UUID {
static var itoh = '0123456789ABCDEF';

static inline function random()
return Math.floor(Math.random()*0x10);

static inline function srandom()
return ''+random();
return '${random()}';

public static function create() {
var s = [];
Expand Down

0 comments on commit 2af0702

Please sign in to comment.