Additional fix of String.getRootName() for network names, relevant test fixes
This commit is contained in:
@@ -6,12 +6,11 @@ import java.util.NoSuchElementException
|
||||
private fun String.getRootName(): String {
|
||||
// Note: separators should be already replaced to system ones
|
||||
var first = indexOf(File.separatorChar, 0)
|
||||
println("$this.getRootName: first=$first")
|
||||
if (first == 0) {
|
||||
if (length() > 1) {
|
||||
if (length() > 1 && this[1] == File.separatorChar) {
|
||||
// Network names like //my.host/home/something ? => //my.host/home/ should be root
|
||||
// We have to consider here also /my.host/home/something because on Unix
|
||||
// File converts // just to /
|
||||
// NB: does not work in Unix because //my.host/home is converted into /my.host/home there
|
||||
// So in Windows we'll have root of //my.host/home but in Unix just /
|
||||
first = indexOf(File.separatorChar, 2)
|
||||
if (first >= 0) {
|
||||
val dot = indexOf('.', 2)
|
||||
|
||||
@@ -624,7 +624,11 @@ class FilesTest {
|
||||
checkFileElements(File("C:\\"), File("C:\\".separatorsToSystem()), listOf())
|
||||
checkFileElements(File("C:/"), File("C:/"), listOf())
|
||||
checkFileElements(File("C:"), File("C:"), listOf())
|
||||
checkFileElements(File("//host.ru/home/mike"), File("//host.ru/home"), listOf("mike"))
|
||||
if (File.separatorChar == '\\') {
|
||||
// Check only in Windows
|
||||
checkFileElements(File("\\\\host.ru\\home\\mike"), File("\\\\host.ru\\home"), listOf("mike"))
|
||||
checkFileElements(File("//host.ru/home/mike"), File("//host.ru/home"), listOf("mike"))
|
||||
}
|
||||
checkFileElements(File(""), null, listOf(""))
|
||||
checkFileElements(File("."), null, listOf("."))
|
||||
checkFileElements(File(".."), null, listOf(".."))
|
||||
@@ -646,9 +650,14 @@ class FilesTest {
|
||||
}
|
||||
|
||||
test fun subPath() {
|
||||
assertEquals(File("mike"), File("//my.host.net/home/mike/temp").subPath(0, 1))
|
||||
assertEquals(File("mike"), File("\\\\my.host.net\\home\\mike\\temp").subPath(0, 1))
|
||||
if (File.separatorChar == '\\') {
|
||||
// Check only in Windows
|
||||
assertEquals(File("mike"), File("//my.host.net/home/mike/temp").subPath(0, 1))
|
||||
assertEquals(File("mike"), File("\\\\my.host.net\\home\\mike\\temp").subPath(0, 1))
|
||||
}
|
||||
assertEquals(File("bar/gav"), File("/foo/bar/gav/hi").subPath(1, 3))
|
||||
assertEquals(File("foo"), File("/foo/bar/gav/hi").subPath(0, 1))
|
||||
assertEquals(File("gav/hi"), File("/foo/bar/gav/hi").subPath(2, 4))
|
||||
}
|
||||
|
||||
test fun normalize() {
|
||||
|
||||
Reference in New Issue
Block a user