Brought up to date with the private repository (feea4c7)

This commit is contained in:
S committed 2026-10-14 20:57:33 +03:00
1 parent 1aa738d692
commit 1b1df1ae48
7925 files changed
+2617237 -20

No files matched your search

@@ -0,0 +1,24 @@
package com.adobe.serialization.json
{
public class JSON
{
public function JSON()
{
super();
}
public static function encode(param1:Object) : String
{
var _loc2_:JSONEncoder = new JSONEncoder(param1);
return _loc2_.getString();
}
public static function decode(param1:String) : *
{
var _loc2_:JSONDecoder = new JSONDecoder(param1);
return _loc2_.getValue();
}
}
}
@@ -0,0 +1,125 @@
package com.adobe.serialization.json
{
public class JSONDecoder
{
private var value:*;
private var tokenizer:JSONTokenizer;
private var token:JSONToken;
public function JSONDecoder(param1:String)
{
super();
this.tokenizer = new JSONTokenizer(param1);
this.nextToken();
this.value = this.parseValue();
}
public function getValue() : *
{
return this.value;
}
private function nextToken() : JSONToken
{
return this.token = this.tokenizer.getNextToken();
}
private function parseArray() : Array
{
var _loc1_:Array = new Array();
this.nextToken();
if(this.token.type == JSONTokenType.RIGHT_BRACKET)
{
return _loc1_;
}
while(true)
{
_loc1_.push(this.parseValue());
this.nextToken();
if(this.token.type == JSONTokenType.RIGHT_BRACKET)
{
break;
}
if(this.token.type == JSONTokenType.COMMA)
{
this.nextToken();
}
else
{
this.tokenizer.parseError("Expecting ] or , but found " + this.token.value);
}
}
return _loc1_;
}
private function parseObject() : Object
{
var _loc2_:String = null;
var _loc1_:Object = new Object();
this.nextToken();
if(this.token.type == JSONTokenType.RIGHT_BRACE)
{
return _loc1_;
}
while(true)
{
if(this.token.type == JSONTokenType.STRING)
{
_loc2_ = String(this.token.value);
this.nextToken();
if(this.token.type == JSONTokenType.COLON)
{
this.nextToken();
_loc1_[_loc2_] = this.parseValue();
this.nextToken();
if(this.token.type == JSONTokenType.RIGHT_BRACE)
{
break;
}
if(this.token.type == JSONTokenType.COMMA)
{
this.nextToken();
}
else
{
this.tokenizer.parseError("Expecting } or , but found " + this.token.value);
}
}
else
{
this.tokenizer.parseError("Expecting : but found " + this.token.value);
}
}
else
{
this.tokenizer.parseError("Expecting string but found " + this.token.value);
}
}
return _loc1_;
}
private function parseValue() : Object
{
switch(this.token.type)
{
case JSONTokenType.LEFT_BRACE:
return this.parseObject();
case JSONTokenType.LEFT_BRACKET:
return this.parseArray();
case JSONTokenType.STRING:
case JSONTokenType.NUMBER:
case JSONTokenType.TRUE:
case JSONTokenType.FALSE:
case JSONTokenType.NULL:
return this.token.value;
default:
this.tokenizer.parseError("Unexpected " + this.token.value);
return null;
}
}
}
}
@@ -0,0 +1,151 @@
package com.adobe.serialization.json
{
import flash.utils.describeType;
public class JSONEncoder
{
private var jsonString:String;
public function JSONEncoder(param1:*)
{
super();
this.jsonString = this.convertToString(param1);
}
public function getString() : String
{
return this.jsonString;
}
private function convertToString(param1:*) : String
{
if(param1 is String)
{
return this.escapeString(param1 as String);
}
if(param1 is Number)
{
return isFinite(param1 as Number) ? param1.toString() : "null";
}
if(param1 is Boolean)
{
return param1 ? "true" : "false";
}
if(param1 is Array)
{
return this.arrayToString(param1 as Array);
}
if(param1 is Object && param1 != null)
{
return this.objectToString(param1);
}
return "null";
}
private function escapeString(param1:String) : String
{
var _loc3_:String = null;
var _loc6_:String = null;
var _loc7_:String = null;
var _loc2_:String = "";
var _loc4_:Number = param1.length;
var _loc5_:int = 0;
while(_loc5_ < _loc4_)
{
_loc3_ = param1.charAt(_loc5_);
switch(_loc3_)
{
case "\"":
_loc2_ += "\\\"";
break;
case "\\":
_loc2_ += "\\\\";
break;
case "\b":
_loc2_ += "\\b";
break;
case "\f":
_loc2_ += "\\f";
break;
case "\n":
_loc2_ += "\\n";
break;
case "\r":
_loc2_ += "\\r";
break;
case "\t":
_loc2_ += "\\t";
break;
default:
if(_loc3_ < " ")
{
_loc6_ = _loc3_.charCodeAt(0).toString(16);
_loc7_ = _loc6_.length == 2 ? "00" : "000";
_loc2_ += "\\u" + _loc7_ + _loc6_;
}
else
{
_loc2_ += _loc3_;
}
}
_loc5_++;
}
return "\"" + _loc2_ + "\"";
}
private function arrayToString(param1:Array) : String
{
var _loc2_:String = "";
var _loc3_:int = 0;
while(_loc3_ < param1.length)
{
if(_loc2_.length > 0)
{
_loc2_ += ",";
}
_loc2_ += this.convertToString(param1[_loc3_]);
_loc3_++;
}
return "[" + _loc2_ + "]";
}
private function objectToString(param1:Object) : String
{
var value:Object = null;
var key:String = null;
var v:XML = null;
var o:Object = param1;
var s:String = "";
var classInfo:XML = describeType(o);
if(classInfo.@name.toString() == "Object")
{
for(key in o)
{
value = o[key];
if(!(value is Function))
{
if(s.length > 0)
{
s += ",";
}
s += this.escapeString(key) + ":" + this.convertToString(value);
}
}
}
else
{
for each(v in classInfo..*.(name() == "variable" || name() == "accessor"))
{
if(s.length > 0)
{
s += ",";
}
s += this.escapeString(v.@name.toString()) + ":" + this.convertToString(o[v.@name]);
}
}
return "{" + s + "}";
}
}
}
@@ -0,0 +1,28 @@
package com.adobe.serialization.json
{
public class JSONParseError extends Error
{
private var _location:int;
private var _text:String;
public function JSONParseError(param1:String = "", param2:int = 0, param3:String = "")
{
super(param1);
this._location = param2;
this._text = param3;
}
public function get location() : int
{
return this._location;
}
public function get text() : String
{
return this._text;
}
}
}
@@ -0,0 +1,38 @@
package com.adobe.serialization.json
{
public class JSONToken
{
private var _type:int;
private var _value:Object;
public function JSONToken(param1:int = -1, param2:Object = null)
{
super();
this._type = param1;
this._value = param2;
}
public function get type() : int
{
return this._type;
}
public function set type(param1:int) : void
{
this._type = param1;
}
public function get value() : Object
{
return this._value;
}
public function set value(param1:Object) : void
{
this._value = param1;
}
}
}
@@ -0,0 +1,36 @@
package com.adobe.serialization.json
{
public class JSONTokenType
{
public static const UNKNOWN:int = -1;
public static const COMMA:int = 0;
public static const LEFT_BRACE:int = 1;
public static const RIGHT_BRACE:int = 2;
public static const LEFT_BRACKET:int = 3;
public static const RIGHT_BRACKET:int = 4;
public static const COLON:int = 6;
public static const TRUE:int = 7;
public static const FALSE:int = 8;
public static const NULL:int = 9;
public static const STRING:int = 10;
public static const NUMBER:int = 11;
public function JSONTokenType()
{
super();
}
}
}
@@ -0,0 +1,352 @@
package com.adobe.serialization.json
{
public class JSONTokenizer
{
private var obj:Object;
private var jsonString:String;
private var loc:int;
private var ch:String;
public function JSONTokenizer(param1:String)
{
super();
this.jsonString = param1;
this.loc = 0;
this.nextChar();
}
public function getNextToken() : JSONToken
{
var _loc2_:String = null;
var _loc3_:String = null;
var _loc4_:String = null;
var _loc1_:JSONToken = new JSONToken();
this.skipIgnored();
switch(this.ch)
{
case "{":
_loc1_.type = JSONTokenType.LEFT_BRACE;
_loc1_.value = "{";
this.nextChar();
break;
case "}":
_loc1_.type = JSONTokenType.RIGHT_BRACE;
_loc1_.value = "}";
this.nextChar();
break;
case "[":
_loc1_.type = JSONTokenType.LEFT_BRACKET;
_loc1_.value = "[";
this.nextChar();
break;
case "]":
_loc1_.type = JSONTokenType.RIGHT_BRACKET;
_loc1_.value = "]";
this.nextChar();
break;
case ",":
_loc1_.type = JSONTokenType.COMMA;
_loc1_.value = ",";
this.nextChar();
break;
case ":":
_loc1_.type = JSONTokenType.COLON;
_loc1_.value = ":";
this.nextChar();
break;
case "t":
_loc2_ = "t" + this.nextChar() + this.nextChar() + this.nextChar();
if(_loc2_ == "true")
{
_loc1_.type = JSONTokenType.TRUE;
_loc1_.value = true;
this.nextChar();
}
else
{
this.parseError("Expecting \'true\' but found " + _loc2_);
}
break;
case "f":
_loc3_ = "f" + this.nextChar() + this.nextChar() + this.nextChar() + this.nextChar();
if(_loc3_ == "false")
{
_loc1_.type = JSONTokenType.FALSE;
_loc1_.value = false;
this.nextChar();
}
else
{
this.parseError("Expecting \'false\' but found " + _loc3_);
}
break;
case "n":
_loc4_ = "n" + this.nextChar() + this.nextChar() + this.nextChar();
if(_loc4_ == "null")
{
_loc1_.type = JSONTokenType.NULL;
_loc1_.value = null;
this.nextChar();
}
else
{
this.parseError("Expecting \'null\' but found " + _loc4_);
}
break;
case "\"":
_loc1_ = this.readString();
break;
default:
if(this.isDigit(this.ch) || this.ch == "-")
{
_loc1_ = this.readNumber();
}
else
{
if(this.ch == "")
{
return null;
}
this.parseError("Unexpected " + this.ch + " encountered");
}
}
return _loc1_;
}
private function readString() : JSONToken
{
var _loc3_:String = null;
var _loc4_:int = 0;
var _loc1_:JSONToken = new JSONToken();
_loc1_.type = JSONTokenType.STRING;
var _loc2_:String = "";
this.nextChar();
while(this.ch != "\"" && this.ch != "")
{
if(this.ch == "\\")
{
this.nextChar();
switch(this.ch)
{
case "\"":
_loc2_ += "\"";
break;
case "/":
_loc2_ += "/";
break;
case "\\":
_loc2_ += "\\";
break;
case "b":
_loc2_ += "\b";
break;
case "f":
_loc2_ += "\f";
break;
case "n":
_loc2_ += "\n";
break;
case "r":
_loc2_ += "\r";
break;
case "t":
_loc2_ += "\t";
break;
case "u":
_loc3_ = "";
_loc4_ = 0;
while(_loc4_ < 4)
{
if(!this.isHexDigit(this.nextChar()))
{
this.parseError(" Excepted a hex digit, but found: " + this.ch);
}
_loc3_ += this.ch;
_loc4_++;
}
_loc2_ += String.fromCharCode(parseInt(_loc3_,16));
break;
default:
_loc2_ += "\\" + this.ch;
}
}
else
{
_loc2_ += this.ch;
}
this.nextChar();
}
if(this.ch == "")
{
this.parseError("Unterminated string literal");
}
this.nextChar();
_loc1_.value = _loc2_;
return _loc1_;
}
private function readNumber() : JSONToken
{
var _loc1_:JSONToken = new JSONToken();
_loc1_.type = JSONTokenType.NUMBER;
var _loc2_:String = "";
if(this.ch == "-")
{
_loc2_ += "-";
this.nextChar();
}
if(!this.isDigit(this.ch))
{
this.parseError("Expecting a digit");
}
if(this.ch == "0")
{
_loc2_ += this.ch;
this.nextChar();
if(this.isDigit(this.ch))
{
this.parseError("A digit cannot immediately follow 0");
}
}
else
{
while(this.isDigit(this.ch))
{
_loc2_ += this.ch;
this.nextChar();
}
}
if(this.ch == ".")
{
_loc2_ += ".";
this.nextChar();
if(!this.isDigit(this.ch))
{
this.parseError("Expecting a digit");
}
while(this.isDigit(this.ch))
{
_loc2_ += this.ch;
this.nextChar();
}
}
if(this.ch == "e" || this.ch == "E")
{
_loc2_ += "e";
this.nextChar();
if(this.ch == "+" || this.ch == "-")
{
_loc2_ += this.ch;
this.nextChar();
}
if(!this.isDigit(this.ch))
{
this.parseError("Scientific notation number needs exponent value");
}
while(this.isDigit(this.ch))
{
_loc2_ += this.ch;
this.nextChar();
}
}
var _loc3_:Number = Number(_loc2_);
if(isFinite(_loc3_) && !isNaN(_loc3_))
{
_loc1_.value = _loc3_;
return _loc1_;
}
this.parseError("Number " + _loc3_ + " is not valid!");
return null;
}
private function nextChar() : String
{
return this.ch = this.jsonString.charAt(this.loc++);
}
private function skipIgnored() : void
{
this.skipWhite();
this.skipComments();
this.skipWhite();
}
private function skipComments() : void
{
if(this.ch == "/")
{
this.nextChar();
switch(this.ch)
{
case "/":
do
{
this.nextChar();
}
while(this.ch != "\n" && this.ch != "");
this.nextChar();
break;
case "*":
this.nextChar();
while(true)
{
if(this.ch == "*")
{
this.nextChar();
if(this.ch == "/")
{
break;
}
}
else
{
this.nextChar();
}
if(this.ch == "")
{
this.parseError("Multi-line comment not closed");
}
}
this.nextChar();
break;
default:
this.parseError("Unexpected " + this.ch + " encountered (expecting \'/\' or \'*\' )");
}
}
}
private function skipWhite() : void
{
while(this.isWhiteSpace(this.ch))
{
this.nextChar();
}
}
private function isWhiteSpace(param1:String) : Boolean
{
return param1 == " " || param1 == "\t" || param1 == "\n";
}
private function isDigit(param1:String) : Boolean
{
return param1 >= "0" && param1 <= "9";
}
private function isHexDigit(param1:String) : Boolean
{
var _loc2_:String = param1.toUpperCase();
return this.isDigit(param1) || _loc2_ >= "A" && _loc2_ <= "F";
}
public function parseError(param1:String) : void
{
throw new JSONParseError(param1,this.loc,this.jsonString);
}
}
}
@@ -0,0 +1,106 @@
package com.adobe.utils
{
public class StringUtil
{
public function StringUtil()
{
super();
}
public static function stringsAreEqual(param1:String, param2:String, param3:Boolean) : Boolean
{
if(param3)
{
return param1 == param2;
}
return param1.toUpperCase() == param2.toUpperCase();
}
public static function trim(param1:String) : String
{
return StringUtil.ltrim(StringUtil.rtrim(param1));
}
public static function ltrim(param1:String) : String
{
var _loc2_:Number = param1.length;
var _loc3_:Number = 0;
while(_loc3_ < _loc2_)
{
if(param1.charCodeAt(_loc3_) > 32)
{
return param1.substring(_loc3_);
}
_loc3_++;
}
return "";
}
public static function rtrim(param1:String) : String
{
var _loc2_:Number = param1.length;
var _loc3_:Number = _loc2_;
while(_loc3_ > 0)
{
if(param1.charCodeAt(_loc3_ - 1) > 32)
{
return param1.substring(0,_loc3_);
}
_loc3_--;
}
return "";
}
public static function beginsWith(param1:String, param2:String) : Boolean
{
return param2 == param1.substring(0,param2.length);
}
public static function endsWith(param1:String, param2:String) : Boolean
{
return param2 == param1.substring(param1.length - param2.length);
}
public static function remove(param1:String, param2:String) : String
{
return StringUtil.replace(param1,param2,"");
}
public static function replace(param1:String, param2:String, param3:String) : String
{
var _loc9_:Number = NaN;
var _loc4_:String = new String();
var _loc5_:Boolean = false;
var _loc6_:Number = param1.length;
var _loc7_:Number = param2.length;
var _loc8_:Number = 0;
for(; _loc8_ < _loc6_; _loc8_++)
{
if(param1.charAt(_loc8_) == param2.charAt(0))
{
_loc5_ = true;
_loc9_ = 0;
while(_loc9_ < _loc7_)
{
if(param1.charAt(_loc8_ + _loc9_) != param2.charAt(_loc9_))
{
_loc5_ = false;
break;
}
_loc9_++;
}
if(_loc5_)
{
_loc4_ += param3;
_loc8_ += _loc7_ - 1;
continue;
}
}
_loc4_ += param1.charAt(_loc8_);
}
return _loc4_;
}
}
}