/*!
 * SAP UI development toolkit for HTML5 (SAPUI5/OpenUI5)
 * (c) Copyright 2009-2015 SAP SE or an SAP affiliate company.
 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
 */
sap.ui.define(['jquery.sap.global','sap/ui/core/LocaleData','sap/ui/core/format/NumberFormat','jquery.sap.strings'],function(q,L,N,Q){"use strict";var _=[{binaryFactor:1,decimalFactor:1,decimalUnit:"Byte",binaryUnit:"Byte"},{binaryFactor:1,decimalFactor:1,decimalUnit:"Bytes",binaryUnit:"Bytes"},{binaryFactor:Math.pow(2,10),decimalFactor:1e3,decimalUnit:"Kilobyte",binaryUnit:"Kibibyte"},{binaryFactor:Math.pow(2,20),decimalFactor:1e6,decimalUnit:"Megabyte",binaryUnit:"Mebibyte"},{binaryFactor:Math.pow(2,30),decimalFactor:1e9,decimalUnit:"Gigabyte",binaryUnit:"Gibibyte"},{binaryFactor:Math.pow(2,40),decimalFactor:1e12,decimalUnit:"Terabyte",binaryUnit:"Tebibyte"},{binaryFactor:Math.pow(2,50),decimalFactor:1e15,decimalUnit:"Petabyte",binaryUnit:"Pebibyte"},{binaryFactor:Math.pow(2,60),decimalFactor:1e18,decimalUnit:"Exabyte",binaryUnit:"Exbibyte"},{binaryFactor:Math.pow(2,70),decimalFactor:1e21,decimalUnit:"Zettabyte",binaryUnit:"Zebibyte"},{binaryFactor:Math.pow(2,80),decimalFactor:1e24,decimalUnit:"Yottabyte",binaryUnit:"Yobibyte"}];var F=sap.ui.base.Object.extend("sap.ui.core.format.FileSizeFormat",{constructor:function(f){throw new Error();}});F.getInstance=function(f,l){return this.createInstance(f,l);};F.createInstance=function(f,l){var o=q.sap.newObject(this.prototype);if(f instanceof sap.ui.core.Locale){l=f;f=undefined;}if(!l){l=sap.ui.getCore().getConfiguration().getFormatSettings().getFormatLocale();}o.oLocale=l;o.oLocaleData=L.getInstance(l);o.oNumberFormat=sap.ui.core.format.NumberFormat.getFloatInstance(f,l);o.oBundle=sap.ui.getCore().getLibraryResourceBundle("sap.ui.core",l.toString());o.bBinary=f?!!f.binaryFilesize:false;return o;};F.prototype.format=function(v){var V=null,o;if(typeof v=="string"){try{if(/^\s*[\+-]?0[xX]/.test(v)){V=parseInt(v,16);}else{V=parseFloat(v,10);}}catch(e){}}else if(typeof v=="number"){V=v;}if(V===null){return"NaN";}o=V;var u=a(V,this.bBinary),s=this.oNumberFormat.format(V/u.factor);if(!u.noSecondRounding){V=this.oNumberFormat.parse(s);if((this.bBinary&&Math.abs(V)>=1024)||(!this.bBinary&&Math.abs(V)>=1000)){u=a(V*u.factor,this.bBinary);s=this.oNumberFormat.format(o/u.factor);}}return this.oBundle.getText("FileSize."+u.unit,s);};F.prototype.parse=function(v){var u,b,V,B;if(!v){return NaN;}for(var i=0;i<_.length;i++){u=_[i];b=c(this.oBundle,u.decimalUnit,v);if(b){B=false;break;}else{b=c(this.oBundle,u.binaryUnit,v);if(b){B=true;break;}}}if(!b){b=v;B=false;u=_[0];}V=this.oNumberFormat.parse(b);return V*(B?u.binaryFactor:u.decimalFactor);};function a(B,d){var b=Math.abs(B),u,f;for(var i=_.length-1;i>=2;i--){u=_[i];f=d?u.binaryFactor:u.decimalFactor;if(b>=f){return{factor:f,unit:d?u.binaryUnit:u.decimalUnit,noSecondRounding:(i==_.length-1)};}}return{factor:1,unit:_[b>=2?1:0].decimalUnit};}function c(b,u,v){var p=b.getText("FileSize."+u),d;if(q.sap.startsWith(p,"{0}")){d=p.substr(3,p.length);if(q.sap.endsWithIgnoreCase(v,d)){return v.substr(0,v.length-d.length);}}else if(q.sap.endsWith(p,"{0}")){d=p.substr(0,p.length-3);if(q.sap.startsWithIgnoreCase(v,d)){return v.substr(d.length,v.length);}}else{d=p.split("{0}");if(d.length==2&&q.sap.startsWithIgnoreCase(v,d[0])&&q.sap.endsWithIgnoreCase(v,d[1])){return v.substr(d[0].length,v.length-d[1].length);}}return null;}return F;},true);
