|  |  |  | @ -2,12 +2,15 @@ package io.legado.app.utils | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import android.annotation.SuppressLint | 
			
		
	
		
			
				
					|  |  |  |  | import android.text.TextUtils.isEmpty | 
			
		
	
		
			
				
					|  |  |  |  | import java.text.DecimalFormat | 
			
		
	
		
			
				
					|  |  |  |  | import java.text.ParseException | 
			
		
	
		
			
				
					|  |  |  |  | import java.text.SimpleDateFormat | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.* | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.regex.Matcher | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.regex.Pattern | 
			
		
	
		
			
				
					|  |  |  |  | import kotlin.math.abs | 
			
		
	
		
			
				
					|  |  |  |  | import kotlin.math.log10 | 
			
		
	
		
			
				
					|  |  |  |  | import kotlin.math.pow | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | object StringUtils { | 
			
		
	
		
			
				
					|  |  |  |  |     private const val HOUR_OF_DAY = 24 | 
			
		
	
	
		
			
				
					|  |  |  | @ -97,6 +100,19 @@ object StringUtils { | 
			
		
	
		
			
				
					|  |  |  |  |         return "" | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun toSize(length: Long): String { | 
			
		
	
		
			
				
					|  |  |  |  |         if (length <= 0) return "0" | 
			
		
	
		
			
				
					|  |  |  |  |         val units = arrayOf("b", "kb", "M", "G", "T") | 
			
		
	
		
			
				
					|  |  |  |  |         //计算单位的,原理是利用lg,公式是 lg(1024^n) = nlg(1024),最后 nlg(1024)/lg(1024) = n。 | 
			
		
	
		
			
				
					|  |  |  |  |         //计算单位的,原理是利用lg,公式是 lg(1024^n) = nlg(1024),最后 nlg(1024)/lg(1024) = n。 | 
			
		
	
		
			
				
					|  |  |  |  |         val digitGroups = | 
			
		
	
		
			
				
					|  |  |  |  |             (log10(length.toDouble()) / log10(1024.0)).toInt() | 
			
		
	
		
			
				
					|  |  |  |  |         //计算原理是,size/单位值。单位值指的是:比如说b = 1024,KB = 1024^2 | 
			
		
	
		
			
				
					|  |  |  |  |         //计算原理是,size/单位值。单位值指的是:比如说b = 1024,KB = 1024^2 | 
			
		
	
		
			
				
					|  |  |  |  |         return DecimalFormat("#,##0.##") | 
			
		
	
		
			
				
					|  |  |  |  |             .format(length / 1024.0.pow(digitGroups.toDouble())) + " " + units[digitGroups] | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     @SuppressLint("DefaultLocale") | 
			
		
	
		
			
				
					|  |  |  |  |     fun toFirstCapital(str: String): String { | 
			
		
	
		
			
				
					|  |  |  |  |         return str.substring(0, 1).toUpperCase() + str.substring(1) | 
			
		
	
	
		
			
				
					|  |  |  | 
 |