59 lines
38 KiB
Go
Raw Normal View History

//
2020-08-23 14:15:53 +00:00
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
2020-08-23 14:15:53 +00:00
// Package format provides support for parsing and evaluating
// spreadsheetml/Excel number formats.
//
// Internally spreadsheets store numbers and dates values as a text
// representation of a floating point number (e.g. 1.2345). This number is then
// displayed in Excel or another spreadsheet viewer differently depending on the
// number fornat of the cell style applied to the cell.
//
// As an example, the same value of 1.2345 can be displayed as:
// - "1" with format "0"
// - "1.2" with format "0.0"
// - "1.23" with format "0.00"
// - "1.235" with format "0.000"
// - "123%" with format "0%"
// - "1 23/100" with fornat "0 0/100"
// - "1.23E+00" with format "0.00E+00"
// - "29:37:41s" with format `[h]:mm:ss"s"`
2021-01-04 16:11:39 +00:00
package format ;import (_e "bytes";_b "fmt";_ee "github.com/unidoc/unioffice";_c "io";_f "math";_df "strconv";_g "strings";_d "time";);func (_ab FmtType )String ()string {if _ab >=FmtType (len (_gg )-1){return _b .Sprintf ("F\u006d\u0074\u0054\u0079\u0070\u0065\u0028\u0025\u0064\u0029",_ab );};return _cf [_gg [_ab ]:_gg [_ab +1]];};func Parse (s string )[]Format {_ada :=Lexer {};_ada .Lex (_g .NewReader (s ));_ada ._cedb =append (_ada ._cedb ,_ada ._bada );return _ada ._cedb ;};
2021-01-04 16:11:39 +00:00
// AddToken adds a format token to the format.
func (_abd *Format )AddToken (t FmtType ,l []byte ){if _abd ._dc {_abd ._dc =false ;return ;};switch t {case FmtTypeDecimal :_abd ._bd =true ;case FmtTypeUnderscore :_abd ._dc =true ;case FmtTypeText :_abd .Whole =append (_abd .Whole ,Token {Type :t });case FmtTypeDate ,FmtTypeTime :_abd .Whole =append (_abd .Whole ,Token {Type :t ,DateTime :string (l )});case FmtTypePercent :_abd ._gc =true ;t =FmtTypeLiteral ;l =[]byte {'%'};fallthrough;case FmtTypeDigitOpt :fallthrough;case FmtTypeLiteral ,FmtTypeDigit ,FmtTypeDollar ,FmtTypeComma :if l ==nil {l =[]byte {0};};for _ ,_gd :=range l {if _abd .IsExponential {_abd .Exponent =append (_abd .Exponent ,Token {Type :t ,Literal :_gd });}else if !_abd ._bd {_abd .Whole =append (_abd .Whole ,Token {Type :t ,Literal :_gd });}else {_abd .Fractional =append (_abd .Fractional ,Token {Type :t ,Literal :_gd });};};case FmtTypeDigitOptThousands :_abd ._db =true ;case FmtTypeFraction :_ba :=_g .Split (string (l ),"\u002f");if len (_ba )==2{_abd ._fg =true ;_abd ._ce ,_ =_df .ParseInt (_ba [1],10,64);for _ ,_cfa :=range _ba [1]{if _cfa =='?'||_cfa =='0'{_abd ._gb ++;};};};default:_ee .Log ("\u0075\u006e\u0073u\u0070\u0070\u006f\u0072t\u0065\u0064\u0020\u0070\u0068\u0020\u0074y\u0070\u0065\u0020\u0069\u006e\u0020\u0070\u0061\u0072\u0073\u0065\u0020\u0025\u0076",t );};};const _cec int =34;const (FmtTypeLiteral FmtType =iota ;FmtTypeDigit ;FmtTypeDigitOpt ;FmtTypeComma ;FmtTypeDecimal ;FmtTypePercent ;FmtTypeDollar ;FmtTypeDigitOptThousands ;FmtTypeUnderscore ;FmtTypeDate ;FmtTypeTime ;FmtTypeFraction ;FmtTypeText ;);func _bgb (_acf float64 )string {_bf :=_df .FormatFloat (_acf ,'E',-1,64);_adc :=_df .FormatFloat (_acf ,'E',5,64);if len (_bf )< len (_adc ){return _df .FormatFloat (_acf ,'E',2,64);};return _adc ;};const _cb =1e11;func IsNumber (data string )(_fdd bool ){_agb ,_gbfd ,_aafa :=0,0,len (data );_fbb :=len (data );_gfc ,_dca ,_dff :=0,0,0;_ =_dca ;_ =_dff ;_ =_gfc ;{_agb =_gbee ;_gfc =0;_dca =0;_dff =0;};{if _gbfd ==_aafa {goto _ggbe ;};switch _agb {case 0:goto _cfc ;case 1:goto _gbb ;case 2:goto _gab ;case 3:goto _aca ;case 4:goto _gae ;case 5:goto _afe ;case 6:goto _bbcd ;case 7:goto _egg ;};goto _gga ;_fca :_dca =_gbfd ;_gbfd --;{_fdd =false ;};goto _ffd ;_fee :_dca =_gbfd ;_gbfd --;{_fdd =_dca ==len (data );};goto _ffd ;_fgg :_dca =_gbfd ;_gbfd --;{_fdd =_dca ==len (data );};goto _ffd ;_ggf :switch _dff {case 2:{_gbfd =(_dca )-1;_fdd =_dca ==len (data );};case 3:{_gbfd =(_dca )-1;_fdd =false ;};};goto _ffd ;_ffd :_gfc =0;if _gbfd ++;_gbfd ==_aafa {goto _ccg ;};_cfc :_gfc =_gbfd ;switch data [_gbfd ]{case 43:goto _feed ;case 45:goto _feed ;};if 48<=data [_gbfd ]&&data [_gbfd ]<=57{goto _fbbc ;};goto _aeb ;_aeb :if _gbfd ++;_gbfd ==_aafa {goto _dag ;};_gbb :goto _aeb ;_feed :if _gbfd ++;_gbfd ==_aafa {goto _fege ;};_gab :if 48<=data [_gbfd ]&&data [_gbfd ]<=57{goto _fbbc ;};goto _aeb ;_fbbc :if _gbfd ++;_gbfd ==_aafa {goto _gabd ;};_aca :if data [_gbfd ]==46{goto _eaaf ;};if 48<=data [_gbfd ]&&data [_gbfd ]<=57{goto _fbbc ;};goto _aeb ;_eaaf :if _gbfd ++;_gbfd ==_aafa {goto _dfbb ;};_gae :if 48<=data [_gbfd ]&&data [_gbfd ]<=57{goto _aec ;};goto _aeb ;_aec :if _gbfd ++;_gbfd ==_aafa {goto _fea ;};_afe :if data [_gbfd ]==69{goto _ccf ;};if 48<=data [_gbfd ]&&data [_gbfd ]<=57{goto _aec ;};goto _aeb ;_ccf :if _gbfd ++;_gbfd ==_aafa {goto _ebb ;};_bbcd :switch data [_gbfd ]{case 43:goto _ffb ;case 45:goto _ffb ;};goto _aeb ;_ffb :_dca =_gbfd +1;_dff =3;goto _dfb ;_dge :_dca =_gbfd +1;_dff =2;goto _dfb ;_dfb :if _gbfd ++;_gbfd ==_aafa {goto _bfc ;};_egg :if 48<=data [_gbfd ]&&data [_gbfd ]<=57{goto _dge ;};goto _aeb ;_gga :_ccg :_agb =0;goto _ggbe ;_dag :_agb =1;goto _ggbe ;_fege :_agb =2;goto _ggbe ;_gabd :_agb =3;goto _ggbe ;_dfbb :_agb =4;goto _ggbe ;_fea :_agb =5;goto _ggbe ;_ebb :_agb =6;goto _ggbe ;_bfc :_agb =7;goto _ggbe ;_ggbe :{};if _gbfd ==_fbb {switch _agb {case 1:goto _fca ;case 2:goto _fca ;case 3:goto _fee ;case 4:goto _fca ;case 5:goto _fgg ;case 6:goto _fca ;case 7:goto _ggf ;};};};if _agb ==_eaf {return false ;};return ;};func _cce (_aaf _d .Time ,_acff float64 ,_cg
2020-12-17 22:07:08 +00:00
// String returns the string formatted according to the type. In format strings
// this is the fourth item, where '@' is used as a placeholder for text.
2021-01-04 16:11:39 +00:00
func String (v string ,f string )string {_gcb :=Parse (f );var _cd Format ;if len (_gcb )==1{_cd =_gcb [0];}else if len (_gcb )==4{_cd =_gcb [3];};_ggb :=false ;for _ ,_aaa :=range _cd .Whole {if _aaa .Type ==FmtTypeText {_ggb =true ;};};if !_ggb {return v ;};_dd :=_e .Buffer {};for _ ,_cea :=range _cd .Whole {switch _cea .Type {case FmtTypeLiteral :_dd .WriteByte (_cea .Literal );case FmtTypeText :_dd .WriteString (v );};};return _dd .String ();};const _gdb int =0;func (_acd *Lexer )nextFmt (){_acd ._cedb =append (_acd ._cedb ,_acd ._bada );_acd ._bada =Format {}};func _gf (_fc []byte )[]byte {for _aae :=0;_aae < len (_fc )/2;_aae ++{_ddg :=len (_fc )-1-_aae ;_fc [_aae ],_fc [_ddg ]=_fc [_ddg ],_fc [_aae ];};return _fc ;};const _cf ="\u0046\u006d\u0074\u0054\u0079\u0070\u0065\u004c\u0069\u0074\u0065\u0072a\u006c\u0046\u006d\u0074\u0054\u0079\u0070\u0065\u0044\u0069\u0067\u0069\u0074\u0046\u006d\u0074\u0054y\u0070\u0065\u0044i\u0067\u0069\u0074\u004f\u0070\u0074\u0046\u006d\u0074\u0054\u0079\u0070\u0065\u0043o\u006d\u006d\u0061\u0046\u006d\u0074\u0054\u0079\u0070\u0065\u0044\u0065\u0063\u0069\u006da\u006c\u0046\u006d\u0074\u0054\u0079\u0070\u0065Pe\u0072\u0063e\u006e\u0074\u0046\u006d\u0074\u0054\u0079\u0070e\u0044\u006f\u006c\u006c\u0061\u0072\u0046\u006d\u0074Ty\u0070\u0065\u0044i\u0067\u0069\u0074\u004f\u0070\u0074\u0054\u0068\u006f\u0075\u0073\u0061n\u0064\u0073\u0046\u006d\u0074\u0054\u0079\u0070\u0065\u0055n\u0064\u0065\u0072\u0073c\u006f\u0072\u0065\u0046\u006d\u0074T\u0079\u0070\u0065\u0044\u0061\u0074\u0065\u0046\u006d\u0074\u0054y\u0070e\u0054\u0069\u006d\u0065\u0046\u006d\u0074\u0054\u0079\u0070\u0065\u0046\u0072\u0061\u0063t\u0069\u006f\u006e\u0046\u006dt\u0054\u0079\u0070\u0065\u0054e\u0078\u0074";
2021-01-04 16:11:39 +00:00
// Token is a format token in the Excel format string.
type Token struct{Type FmtType ;Literal byte ;DateTime string ;};const _ac =1e-10;func _gbe (_eef int64 )int64 {if _eef < 0{return -_eef ;};return _eef ;};func _af (_gcf ,_cc float64 ,_fd Format )[]byte {if len (_fd .Fractional )==0{return nil ;};_cbb :=_df .AppendFloat (nil ,_gcf ,'f',-1,64);if len (_cbb )> 2{_cbb =_cbb [2:];}else {_cbb =nil ;};_be :=make ([]byte ,0,len (_cbb ));_be =append (_be ,'.');_adgf :=0;_cca :for _gdf :=0;_gdf < len (_fd .Fractional );_gdf ++{_dg :=_gdf ;_dec :=_fd .Fractional [_gdf ];switch _dec .Type {case FmtTypeDigit :if _dg < len (_cbb ){_be =append (_be ,_cbb [_dg ]);_adgf ++;}else {_be =append (_be ,'0');};case FmtTypeDigitOpt :if _dg >=0{_be =append (_be ,_cbb [_dg ]);_adgf ++;}else {break _cca ;};case FmtTypeLiteral :_be =append (_be ,_dec .Literal );default:_ee .Log ("\u0075\u006e\u0073\u0075\u0070\u0070o\u0072\u0074\u0065\u0064\u0020\u0074\u0079\u0070\u0065\u0020\u0069\u006e\u0020f\u0072\u0061\u0063\u0074\u0069\u006f\u006ea\u006c\u0020\u0025\u0076",_dec );};};return _be ;};func _cbc (_badb int64 ,_eba Format )[]byte {if !_eba .IsExponential ||len (_eba .Exponent )==0{return nil ;};_gce :=_df .AppendInt (nil ,_gbe (_badb ),10);_bbc :=make ([]byte ,0,len (_gce )+2);_bbc =append (_bbc ,'E');if _badb >=0{_bbc =append (_bbc ,'+');}else {_bbc =append (_bbc ,'-');_badb *=-1;};_adgb :=0;_fda :for _ged :=len (_eba .Exponent )-1;_ged >=0;_ged --{_bbgg :=len (_gce )-1-_adgb ;_gea :=_eba .Exponent [_ged ];switch _gea .Type {case FmtTypeDigit :if _bbgg >=0{_bbc =append (_bbc ,_gce [_bbgg ]);_adgb ++;}else {_bbc =append (_bbc ,'0');};case FmtTypeDigitOpt :if _bbgg >=0{_bbc =append (_bbc ,_gce [_bbgg ]);_adgb ++;}else {for _abg :=_ged ;_abg >=0;_abg --{_ggc :=_eba .Exponent [_abg ];if _ggc .Type ==FmtTypeLiteral {_bbc =append (_bbc ,_ggc .Literal );};};break _fda ;};case FmtTypeLiteral :_bbc =append (_bbc ,_gea .Literal );default:_ee .Log ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064 \u0074\u0079\u0070\u0065\u0020\u0069\u006e\u0020\u0065\u0078p\u0020\u0025\u0076",_gea );};};if _adgb < len (_gce ){_bbc =append (_bbc ,_gce [len (_gce )-_adgb -1:_adgb -1]...);};_gf (_bbc [2:]);return _bbc ;};
2020-10-12 13:59:12 +00:00
// Number is used to format a number with a format string. If the format
// string is empty, then General number formatting is used which attempts to mimic
// Excel's general formatting.
2021-01-04 16:11:39 +00:00
func Number (v float64 ,f string )string {if f ==""||f =="\u0047e\u006e\u0065\u0072\u0061\u006c"||f =="\u0040"{return NumberGeneric (v );};_fgd :=Parse (f );if len (_fgd )==1{return _bb (v ,_fgd [0],false );}else if len (_fgd )> 1&&v < 0{return _bb (v ,_fgd [1],true );}else if len (_fgd )> 2&&v ==0{return _bb (v ,_fgd [2],false );};return _bb (v ,_fgd [0],false );};var _gg =[...]uint8 {0,14,26,41,53,67,81,94,118,135,146,157,172,183};func _bad (_gbdd ,_eb float64 ,_bbg Format )[]byte {if len (_bbg .Whole )==0{return nil ;};_gbc :=_d .Date (1899,12,30,0,0,0,0,_d .UTC );_gbg :=_gbc .Add (_d .Duration (_eb *float64 (24*_d .Hour )));_gbg =_afd (_gbg );_dab :=_df .AppendFloat (nil ,_gbdd ,'f',-1,64);_ea :=make ([]byte ,0,len (_dab ));_bbgd :=0;_ced :=1;_gba :for _badf :=len (_bbg .Whole )-1;_badf >=0;_badf --{_bbgf :=len (_dab )-1-_bbgd ;_deg :=_bbg .Whole [_badf ];switch _deg .Type {case FmtTypeDigit :if _bbgf >=0{_ea =append (_ea ,_dab [_bbgf ]);_bbgd ++;_ced =_badf ;}else {_ea =append (_ea ,'0');};case FmtTypeDigitOpt :if _bbgf >=0{_ea =append (_ea ,_dab [_bbgf ]);_bbgd ++;_ced =_badf ;}else {for _fb :=_badf ;_fb >=0;_fb --{_fcg :=_bbg .Whole [_fb ];if _fcg .Type ==FmtTypeLiteral {_ea =append (_ea ,_fcg .Literal );};};break _gba ;};case FmtTypeDollar :for _eed :=_bbgd ;_eed < len (_dab );_eed ++{_ea =append (_ea ,_dab [len (_dab )-1-_eed ]);_bbgd ++;};_ea =append (_ea ,'$');case FmtTypeComma :if !_bbg ._db {_ea =append (_ea ,',');};case FmtTypeLiteral :_ea =append (_ea ,_deg .Literal );case FmtTypeDate :_ea =append (_ea ,_gf (_bafa (_gbg ,_deg .DateTime ))...);case FmtTypeTime :_ea =append (_ea ,_gf (_cce (_gbg ,_eb ,_deg .DateTime ))...);default:_ee .Log ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0074\u0079\u0070e\u0020i\u006e\u0020\u0077\u0068\u006f\u006c\u0065 \u0025\u0076",_deg );};};_ga :=_gf (_ea );if _bbgd < len (_dab )&&(_bbgd !=0||_bbg ._bd ){_ebf :=len (_dab )-_bbgd ;_bde :=make ([]byte ,len (_ga )+_ebf );copy (_bde ,_ga [0:_ced ]);copy (_bde [_ced :],_dab [0:]);copy (_bde [_ced +_ebf :],_ga [_ced :]);_ga =_bde ;};if _bbg ._db {_cfg :=_e .Buffer {};_ecg :=0;for _gfg :=len (_ga )-1;_gfg >=0;_gfg --{if !(_ga [_gfg ]>='0'&&_ga [_gfg ]<='9'){_ecg ++;}else {break ;};};for _fa :=0;_fa < len (_ga );_fa ++{_acg :=(len (_ga )-_fa -_ecg );if _acg %3==0&&_acg !=0&&_fa !=0{_cfg .WriteByte (',');};_cfg .WriteByte (_ga [_fa ]);};_ga =_cfg .Bytes ();};return _ga ;};
// Format is a parsed number format.
type Format struct{Whole []Token ;Fractional []Token ;Exponent []Token ;IsExponential bool ;_fg bool ;_gc bool ;_de bool ;_db bool ;_dc bool ;_bd bool ;_ce int64 ;_gb int ;};
2020-10-12 13:59:12 +00:00
2020-11-09 01:00:18 +00:00
// Value formats a value as a number or string depending on if it appears to be
// a number or string.
2021-01-04 16:11:39 +00:00
func Value (v string ,f string )string {if IsNumber (v ){_fe ,_ :=_df .ParseFloat (v ,64);return Number (_fe ,f );};return String (v ,f );};const _gbee int =0;type Lexer struct{_bada Format ;_cedb []Format ;};func _afd (_gacd _d .Time )_d .Time {_gacd =_gacd .UTC ();return _d .Date (_gacd .Year (),_gacd .Month (),_gacd .Day (),_gacd .Hour (),_gacd .Minute (),_gacd .Second (),_gacd .Nanosecond (),_d .Local );};const _aab int =-1;func _baf (_gbf []byte )[]byte {for _eff :=len (_gbf )-1;_eff > 0;_eff --{if _gbf [_eff ]=='9'+1{_gbf [_eff ]='0';if _gbf [_eff -1]=='.'{_eff --;};_gbf [_eff -1]++;};};if _gbf [0]=='9'+1{_gbf [0]='0';copy (_gbf [1:],_gbf [0:]);_gbf [0]='1';};return _gbf ;};func _egf (_fae []byte )[]byte {_agd :=len (_fae );_eea :=false ;_dabe :=false ;for _dbb :=len (_fae )-1;_dbb >=0;_dbb --{if _fae [_dbb ]=='0'&&!_dabe &&!_eea {_agd =_dbb ;}else if _fae [_dbb ]=='.'{_eea =true ;}else {_dabe =true ;};};if _eea &&_dabe {if _fae [_agd -1]=='.'{_agd --;};return _fae [0:_agd ];};return _fae ;};func _bafa (_fbf _d .Time ,_eaa string )[]byte {_agf :=[]byte {};_efb :=0;for _cbg :=0;_cbg < len (_eaa );_cbg ++{var _gdde string ;if _eaa [_cbg ]=='/'{_gdde =string (_eaa [_efb :_cbg ]);_efb =_cbg +1;}else if _cbg ==len (_eaa )-1{_gdde =string (_eaa [_efb :_cbg +1]);}else {continue ;};switch _gdde {case "\u0079\u0079":_agf =_fbf .AppendFormat (_agf ,"\u0030\u0036");case "\u0079\u0079\u0079\u0079":_agf =_fbf .AppendFormat (_agf ,"\u0032\u0030\u0030\u0036");case "\u006d":_agf =_fbf .AppendFormat (_agf ,"\u0031");case "\u006d\u006d":_agf =_fbf .AppendFormat (_agf ,"\u0030\u0031");case "\u006d\u006d\u006d":_agf =_fbf .AppendFormat (_agf ,"\u004a\u0061\u006e");case "\u006d\u006d\u006d\u006d":_agf =_fbf .AppendFormat (_agf ,"\u004aa\u006e\u0075\u0061\u0072\u0079");case "\u006d\u006d\u006dm\u006d":switch _fbf .Month (){case _d .January ,_d .July ,_d .June :_agf =append (_agf ,'J');case _d .February :_agf =append (_agf ,'M');case _d .March ,_d .May :_agf =append (_agf ,'M');case _d .April ,_d .August :_agf =append (_agf ,'A');case _d .September :_agf =append (_agf ,'S');case _d .October :_agf =append (_agf ,'O');case _d .November :_agf =append (_agf ,'N');case _d .December :_agf =append (_agf ,'D');};case "\u0064":_agf =_fbf .AppendFormat (_agf ,"\u0032");case "\u0064\u0064":_agf =_fbf .AppendFormat (_agf ,"\u0030\u0032");case "\u0064\u0064\u0064":_agf =_fbf .AppendFormat (_agf ,"\u004d\u006f\u006e");case "\u0064\u0064\u0064\u0064":_agf =_fbf .AppendFormat (_agf ,"\u004d\u006f\u006e\u0064\u0061\u0079");default:_ee .Log ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064 \u0064\u0061\u0074\u0065\u0020\u0066\u006f\u0072\u006d\u0061t\u0020\u0025\u0073",_gdde );};if _eaa [_cbg ]=='/'{_agf =append (_agf ,'/');};};return _agf ;};const _eaf int =-1;func (_bff *Lexer )Lex (r _c .Reader ){_cga ,_fgbd ,_cfga :=0,0,0;_feb :=-1;_gge ,_eaaa ,_efe :=0,0,0;_ =_eaaa ;_ =_efe ;_bdf :=1;_ =_bdf ;_cdd :=make ([]byte ,4096);_ed :=false ;for !_ed {_edf :=0;if _gge > 0{_edf =_fgbd -_gge ;};_fgbd =0;_cdg ,_gfge :=r .Read (_cdd [_edf :]);if _cdg ==0||_gfge !=nil {_ed =true ;};_cfga =_cdg +_edf ;if _cfga < len (_cdd ){_feb =_cfga ;};{_cga =_dbf ;_gge =0;_eaaa =0;_efe =0;};{if _fgbd ==_cfga {goto _fede ;};switch _cga {case 34:goto _cdb ;case 35:goto _bcf ;case 0:goto _ffbb ;case 36:goto _dcd ;case 37:goto _fbe ;case 1:goto _cecd ;case 2:goto _ggd ;case 38:goto _dfc ;case 3:goto _defb ;case 4:goto _abe ;case 39:goto _gag ;case 5:goto _ddgb ;case 6:goto _acag ;case 7:goto _cbd ;case 8:goto _eeg ;case 40:goto _egc ;case 9:goto _fgdb ;case 41:goto _ebbf ;case 10:goto _bbf ;case 42:goto _gac ;case 11:goto _ecge ;case 43:goto _afc ;case 44:goto _ccd ;case 45:goto _dbfg ;case 12:goto _fcd ;case 46:goto _dbbb ;case 13:goto _eefc ;case 14:goto _gbga ;case 15:goto _adba ;case 16:goto _bea ;case 47:goto _dae ;case 17:goto _afb ;case 48:goto _ggce ;case 18:goto _bdgd ;case 19:goto _aea ;case 20:goto _aeg ;case 49:goto _bcb ;case 50:goto _fcfe ;case 21:goto _bed ;case 22:goto _abdb ;case 23:goto _gbcc ;case 24:goto _beb ;case 25:goto _gcff ;case 51:goto
2021-01-04 16:11:39 +00:00
// FmtType is the type of a format token.
//go:generate stringer -type=FmtType
type FmtType byte ;
// NumberGeneric formats the number with the generic format which attemps to
// mimic Excel's general formatting.
func NumberGeneric (v float64 )string {if _f .Abs (v )>=_cb ||_f .Abs (v )<=_ac &&v !=0{return _bgb (v );};_daa :=make ([]byte ,0,15);_daa =_df .AppendFloat (_daa ,v ,'f',-1,64);if len (_daa )> 11{_gaa :=_daa [11]-'0';if _gaa >=5&&_gaa <=9{_daa [10]++;_daa =_daa [0:11];_daa =_baf (_daa );};_daa =_daa [0:11];}else if len (_daa )==11{if _daa [len (_daa )-1]=='9'{_daa [len (_daa )-1]++;_daa =_baf (_daa );};};_daa =_egf (_daa );return string (_daa );};func _bb (_cfaf float64 ,_ad Format ,_gfe bool )string {if _ad ._de {return NumberGeneric (_cfaf );};_ef :=make ([]byte ,0,20);_gdd :=_f .Signbit (_cfaf );_feg :=_f .Abs (_cfaf );_bg :=int64 (0);_bbe :=int64 (0);if _ad .IsExponential {for _feg >=10{_bbe ++;_feg /=10;};for _feg < 1{_bbe --;_feg *=10;};}else if _ad ._gc {_feg *=100;}else if _ad ._fg {if _ad ._ce ==0{_adg :=_f .Pow (10,float64 (_ad ._gb ));_fgb ,_eg :=1.0,1.0;_ =_fgb ;for _gfb :=1.0;_gfb < _adg ;_gfb ++{_ ,_bdb :=_f .Modf (_feg *float64 (_gfb ));if _bdb < _eg {_eg =_bdb ;_fgb =_gfb ;if _bdb ==0{break ;};};};_ad ._ce =int64 (_fgb );};_bg =int64 (_feg *float64 (_ad ._ce )+0.5);if len (_ad .Whole )> 0&&_bg > _ad ._ce {_bg =int64 (_feg *float64 (_ad ._ce ))%_ad ._ce ;_feg -=float64 (_bg )/float64 (_ad ._ce );}else {_feg -=float64 (_bg )/float64 (_ad ._ce );if _f .Abs (_feg )< 1{_ge :=true ;for _ ,_ff :=range _ad .Whole {if _ff .Type ==FmtTypeDigitOpt {continue ;};if _ff .Type ==FmtTypeLiteral &&_ff .Literal ==' '{continue ;};_ge =false ;};if _ge {_ad .Whole =nil ;};};};};_abc :=1;for _ ,_fce :=range _ad .Fractional {if _fce .Type ==FmtTypeDigit ||_fce .Type ==FmtTypeDigitOpt {_abc ++;};};_feg +=5*_f .Pow10 (-_abc );_gbd ,_def :=_f .Modf (_feg );_ef =append (_ef ,_bad (_gbd ,_cfaf ,_ad )...);_ef =append (_ef ,_af (_def ,_cfaf ,_ad )...);_ef =append (_ef ,_cbc (_bbe ,_ad )...);if _ad ._fg {_ef =_df .AppendInt (_ef ,_bg ,10);_ef =append (_ef ,'/');_ef =_df .AppendInt (_ef ,_ad ._ce ,10);};if !_gfe &&_gdd {return "\u002d"+string (_ef );};return string (_ef );};const _bc int =0;const _dbf int =34;