jan_flanders

Untitled

Dec 19th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static function decode(a:Value):Dynamic
  2.     {
  3.         var ret:Dynamic = null;
  4.         if(a==null)
  5.             ret = null;
  6.         else
  7.         switch(a)
  8.         {
  9.             case ANumber(n): ret = n;
  10.             case AString(s): ret = s;
  11.             case AObject(o,len):
  12.                 if(len!=null)
  13.                 {
  14.                     var arr=new Array();
  15.                     for(k in o.keys())
  16.                         arr[Std.parseInt(k)] = decode(o.get(k));
  17.                     ret = arr;
  18.                 }
  19.                 else
  20.                 {
  21.                     var obj={};
  22.                     for(k in o.keys())
  23.                         Reflect.setField(obj, k, decode(o.get(k)));
  24.                     ret = obj;
  25.                 }
  26.             case AArray(a):
  27.                 var out=[];
  28.                 for(i in 0...a.length)
  29.                 {
  30.                     out[i]=decode(a[i]);
  31.                 }
  32.                 ret = out;
  33.             case ABool(b): ret = b;
  34.             case AUndefined:ret = null;
  35.             case ANull:ret = null;
  36.             case ADate(d):ret = d;
  37.         }
  38.         return ret;
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment