瀏覽代碼

增加bool

git 2 周之前
父節點
當前提交
b5daf02eb3
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      src/main/kotlin/cn/qqck/kotlin/tools/String.kt

+ 5 - 0
src/main/kotlin/cn/qqck/kotlin/tools/String.kt

@@ -1,6 +1,11 @@
 package cn.qqck.kotlin.tools
 
 fun String.bytes() = this.toByteArray()
+fun String.bool(): Boolean? {
+    if (this == "1" || this == "t" || this == "T" || this == "true" || this == "True" || this == "yes" || this == "Yes") return true
+    if (this == "0" || this == "f" || this == "F" || this == "false" || this == "False" || this == "no" || this == "No") return false
+    return null
+}
 
 /**
  * 从当前字符串中获取指定子字符串前的内容。