unioffice/algo/algo.go

15 lines
1.3 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/
2021-09-22 16:41:01 +00:00
package algo ;import _b "strconv";func _ba (_d byte )bool {return _d >='0'&&_d <='9'};func RepeatString (s string ,cnt int )string {if cnt <=0{return "";};_g :=make ([]byte ,len (s )*cnt );_ddc :=[]byte (s );for _bg :=0;_bg < cnt ;_bg ++{copy (_g [_bg :],_ddc );};return string (_g );};
2020-08-23 14:15:53 +00:00
// NaturalLess compares two strings in a human manner so rId2 sorts less than rId10
2021-09-22 16:41:01 +00:00
func NaturalLess (lhs ,rhs string )bool {_dd ,_a :=0,0;for _dd < len (lhs )&&_a < len (rhs ){_f :=lhs [_dd ];_fd :=rhs [_a ];_fb :=_ba (_f );_ef :=_ba (_fd );switch {case _fb &&!_ef :return true ;case !_fb &&_ef :return false ;case !_fb &&!_ef :if _f !=_fd {return _f < _fd ;};_dd ++;_a ++;default:_ec :=_dd +1;_fc :=_a +1;for _ec < len (lhs )&&_ba (lhs [_ec ]){_ec ++;};for _fc < len (rhs )&&_ba (rhs [_fc ]){_fc ++;};_eg ,_ :=_b .ParseUint (lhs [_dd :_ec ],10,64);_dc ,_ :=_b .ParseUint (rhs [_dd :_fc ],10,64);if _eg !=_dc {return _eg < _dc ;};_dd =_ec ;_a =_fc ;};};return len (lhs )< len (rhs );};