org.hisrc.jsonix.Jsonix.Schema.XSD.HexBinary.js Maven / Gradle / Ivy
Jsonix.Schema.XSD.HexBinary = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
name : 'HexBinary',
typeName : Jsonix.Schema.XSD.qname('hexBinary'),
charToQuartet : {},
byteToDuplet : [],
initialize : function() {
Jsonix.Schema.XSD.AnySimpleType.prototype.initialize.apply(this);
var charTableUpperCase = "0123456789ABCDEF";
var charTableLowerCase = charTableUpperCase.toLowerCase();
var i;
for (i = 0; i < 16; i++) {
this.charToQuartet[charTableUpperCase.charAt(i)] = i;
if (i >= 0xA) {
this.charToQuartet[charTableLowerCase.charAt(i)] = i;
}
}
for (i = 0; i < 256; i++) {
this.byteToDuplet[i] =
//
charTableUpperCase[i >> 4] + charTableUpperCase[i & 0xF];
}
},
print : function(value, context, output, scope) {
Jsonix.Util.Ensure.ensureArray(value);
return this.encode(value);
},
parse : function(text, context, input, scope) {
Jsonix.Util.Ensure.ensureString(text);
return this.decode(text);
},
encode : function(uarray) {
var output = "";
for ( var i = 0; i < uarray.length; i++) {
output = output + this.byteToDuplet[uarray[i] & 0xFF];
}
return output;
},
decode : function(text) {
var input = text.replace(/[^A-Fa-f0-9]/g, "");
// Round by two
var length = input.length >> 1;
var uarray = new Array(length);
for ( var i = 0; i < length; i++) {
var char0 = input.charAt(2 * i);
var char1 = input.charAt(2 * i + 1);
uarray[i] = this.charToQuartet[char0] << 4
| this.charToQuartet[char1];
}
return uarray;
},
isInstance : function(value, context, scope) {
return Jsonix.Util.Type.isArray(value);
},
CLASS_NAME : 'Jsonix.Schema.XSD.HexBinary'
});
Jsonix.Schema.XSD.HexBinary.INSTANCE = new Jsonix.Schema.XSD.HexBinary();
Jsonix.Schema.XSD.HexBinary.INSTANCE.LIST = new Jsonix.Schema.XSD.List(
Jsonix.Schema.XSD.HexBinary.INSTANCE);
© 2015 - 2024 Weber Informatics LLC | Privacy Policy