Skip to content

Commit

Permalink
Simplify return
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Sep 24, 2024
1 parent 9724c5d commit 2cbd36b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions app/src/main/java/com/nextcloud/utils/autoRename/AutoRename.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package com.nextcloud.utils.autoRename
import com.nextcloud.utils.extensions.StringConstants
import com.nextcloud.utils.extensions.forbiddenFilenameCharacters
import com.nextcloud.utils.extensions.forbiddenFilenameExtension
import com.nextcloud.utils.extensions.shouldRemoveNonPrintableUnicodeCharacters
import com.nextcloud.utils.extensions.shouldRemoveNonPrintableUnicodeCharactersAndConvertToUTF8
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.resources.status.NextcloudVersion
import com.owncloud.android.lib.resources.status.OCCapability
Expand Down Expand Up @@ -65,14 +65,13 @@ object AutoRename {
}
}

var result = pathSegments.joinToString(OCFile.PATH_SEPARATOR)

if (capability.shouldRemoveNonPrintableUnicodeCharacters()) {
val result = pathSegments.joinToString(OCFile.PATH_SEPARATOR)
return if (capability.shouldRemoveNonPrintableUnicodeCharactersAndConvertToUTF8()) {
val utf8Result = convertToUTF8(result)
result = removeNonPrintableUnicodeCharacters(utf8Result)
removeNonPrintableUnicodeCharacters(utf8Result)
} else {
result
}

return result
}

private fun convertToUTF8(filename: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fun OCCapability.forbiddenFilenameExtension(): List<String> = jsonToList(forbidd

fun OCCapability.forbiddenFilenameBaseNames(): List<String> = jsonToList(forbiddenFilenameBaseNamesJson)

fun OCCapability.shouldRemoveNonPrintableUnicodeCharacters(): Boolean {
fun OCCapability.shouldRemoveNonPrintableUnicodeCharactersAndConvertToUTF8(): Boolean {
return forbiddenFilenames().isNotEmpty() ||
forbiddenFilenameCharacters().isNotEmpty() ||
forbiddenFilenameExtension().isNotEmpty() ||
Expand Down

0 comments on commit 2cbd36b

Please sign in to comment.