stdlib: simplify File.recurse and File.extension functions

This commit is contained in:
Denis Mekhanikov
2014-10-14 18:42:48 +04:00
committed by Ilya Ryzhenkov
parent 1a4c11cb98
commit 23397d17dc
+2 -13
View File
@@ -9,12 +9,7 @@ import java.util.*
*/ */
public fun File.recurse(block: (File) -> Unit): Unit { public fun File.recurse(block: (File) -> Unit): Unit {
block(this) block(this)
val children = listFiles() listFiles()?.forEach { it.recurse(block) }
if (children != null) {
for (child in children) {
child.recurse(block)
}
}
} }
/** /**
@@ -46,13 +41,7 @@ public val File.path: String
*/ */
public val File.extension: String public val File.extension: String
get() { get() {
val text = name return name.substringAfterLast('.', "")
val idx = text.lastIndexOf('.')
return if (idx >= 0) {
text.substring(idx + 1)
} else {
""
}
} }
/** /**