|  |  |  | @ -4,34 +4,41 @@ package io.legado.app.utils | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.isAbsUrl() = if (this.isNullOrBlank()) false else this.startsWith("http://", true) | 
			
		
	
		
			
				
					|  |  |  |  |         || this.startsWith("https://", true) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.isJson(): Boolean = this?.run { | 
			
		
	
		
			
				
					|  |  |  |  |     val str = this.trim() | 
			
		
	
		
			
				
					|  |  |  |  |     when { | 
			
		
	
		
			
				
					|  |  |  |  |         str.startsWith("{") && str.endsWith("}") -> true | 
			
		
	
		
			
				
					|  |  |  |  |         str.startsWith("[") && str.endsWith("]") -> true | 
			
		
	
		
			
				
					|  |  |  |  |         else -> false | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | } ?: false | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.isJsonObject(): Boolean = this?.run { | 
			
		
	
		
			
				
					|  |  |  |  |     val str = this.trim() | 
			
		
	
		
			
				
					|  |  |  |  |     str.startsWith("{") && str.endsWith("}") | 
			
		
	
		
			
				
					|  |  |  |  | } ?: false | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.isJsonArray(): Boolean = this?.run { | 
			
		
	
		
			
				
					|  |  |  |  |     val str = this.trim() | 
			
		
	
		
			
				
					|  |  |  |  |     str.startsWith("[") && str.endsWith("]") | 
			
		
	
		
			
				
					|  |  |  |  | } ?: false | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.htmlFormat(): String = if (this.isNullOrBlank()) "" else | 
			
		
	
		
			
				
					|  |  |  |  |     this.replace("(?i)<(br[\\s/]*|/*p\\b.*?|/*div\\b.*?)>".toRegex(), "\n")// 替换特定标签为换行符 | 
			
		
	
		
			
				
					|  |  |  |  |         .replace("<[script>]*.*?>| ".toRegex(), "")// 删除script标签对和空格转义符 | 
			
		
	
		
			
				
					|  |  |  |  |         .replace("\\s*\\n+\\s*".toRegex(), "\n  ")// 移除空行,并增加段前缩进2个汉字 | 
			
		
	
		
			
				
					|  |  |  |  |         .replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字 | 
			
		
	
		
			
				
					|  |  |  |  |         .replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.isAbsUrl() = | 
			
		
	
		
			
				
					|  |  |  |  |     this?.let { | 
			
		
	
		
			
				
					|  |  |  |  |         it.startsWith("http://", true) | 
			
		
	
		
			
				
					|  |  |  |  |                 || it.startsWith("https://", true) | 
			
		
	
		
			
				
					|  |  |  |  |     } ?: false | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.isJson(): Boolean = | 
			
		
	
		
			
				
					|  |  |  |  |     this?.run { | 
			
		
	
		
			
				
					|  |  |  |  |         val str = this.trim() | 
			
		
	
		
			
				
					|  |  |  |  |         when { | 
			
		
	
		
			
				
					|  |  |  |  |             str.startsWith("{") && str.endsWith("}") -> true | 
			
		
	
		
			
				
					|  |  |  |  |             str.startsWith("[") && str.endsWith("]") -> true | 
			
		
	
		
			
				
					|  |  |  |  |             else -> false | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } ?: false | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.isJsonObject(): Boolean = | 
			
		
	
		
			
				
					|  |  |  |  |     this?.run { | 
			
		
	
		
			
				
					|  |  |  |  |         val str = this.trim() | 
			
		
	
		
			
				
					|  |  |  |  |         str.startsWith("{") && str.endsWith("}") | 
			
		
	
		
			
				
					|  |  |  |  |     } ?: false | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.isJsonArray(): Boolean = | 
			
		
	
		
			
				
					|  |  |  |  |     this?.run { | 
			
		
	
		
			
				
					|  |  |  |  |         val str = this.trim() | 
			
		
	
		
			
				
					|  |  |  |  |         str.startsWith("[") && str.endsWith("]") | 
			
		
	
		
			
				
					|  |  |  |  |     } ?: false | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String?.htmlFormat(): String = | 
			
		
	
		
			
				
					|  |  |  |  |     this?.replace("(?i)<(br[\\s/]*|/*p\\b.*?|/*div\\b.*?)>".toRegex(), "\n") | 
			
		
	
		
			
				
					|  |  |  |  |         ?.replace("<[script>]*.*?>| ".toRegex(), "") | 
			
		
	
		
			
				
					|  |  |  |  |         ?.replace("\\s*\\n+\\s*".toRegex(), "\n  ") | 
			
		
	
		
			
				
					|  |  |  |  |         ?.replace("^[\\n\\s]+".toRegex(), "  ") | 
			
		
	
		
			
				
					|  |  |  |  |         ?.replace("[\\n\\s]+$".toRegex(), "") | 
			
		
	
		
			
				
					|  |  |  |  |         ?: "" | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | fun String.splitNotBlank(vararg delimiter: String): Array<String> = run { | 
			
		
	
		
			
				
					|  |  |  |  |     this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() | 
			
		
	
	
		
			
				
					|  |  |  | 
 |