diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2021-03-09 14:53:11 +0530 |
|---|---|---|
| committer | Harsh Shandilya <me@msfjarvis.dev> | 2021-03-18 11:40:30 +0530 |
| commit | 774fda83ac276a635e3402034b1eedbd10be916f (patch) | |
| tree | 57783a953fcd193d32f1e3dc8df26e07f03df328 /app/src/main/java/dev/msfjarvis/aps/util/extensions/Extensions.kt | |
| parent | be31ae37f443982b377d027cd613f04d0926568d (diff) | |
| download | HardenedPass-774fda83ac276a635e3402034b1eedbd10be916f.tar.gz HardenedPass-774fda83ac276a635e3402034b1eedbd10be916f.zip | |
all: reformat with ktfmt
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/dev/msfjarvis/aps/util/extensions/Extensions.kt')
| -rw-r--r-- | app/src/main/java/dev/msfjarvis/aps/util/extensions/Extensions.kt | 65 |
1 files changed, 26 insertions, 39 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/util/extensions/Extensions.kt b/app/src/main/java/dev/msfjarvis/aps/util/extensions/Extensions.kt index 9b6d044c..a6d0066c 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/extensions/Extensions.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/extensions/Extensions.kt @@ -12,53 +12,40 @@ import java.util.Date import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.revwalk.RevCommit -/** - * The default OpenPGP provider for the app - */ +/** The default OpenPGP provider for the app */ const val OPENPGP_PROVIDER = "org.sufficientlysecure.keychain" -/** - * Clears the given [flag] from the value of this [Int] - */ +/** Clears the given [flag] from the value of this [Int] */ fun Int.clearFlag(flag: Int): Int { - return this and flag.inv() + return this and flag.inv() } -/** - * Checks if this [Int] contains the given [flag] - */ +/** Checks if this [Int] contains the given [flag] */ infix fun Int.hasFlag(flag: Int): Boolean { - return this and flag == flag + return this and flag == flag } -/** - * Checks whether this [File] is a directory that contains [other]. - */ +/** Checks whether this [File] is a directory that contains [other]. */ fun File.contains(other: File): Boolean { - if (!isDirectory) - return false - if (!other.exists()) - return false - val relativePath = runCatching { - other.relativeTo(this) - }.getOrElse { - return false + if (!isDirectory) return false + if (!other.exists()) return false + val relativePath = + runCatching { other.relativeTo(this) }.getOrElse { + return false } - // Direct containment is equivalent to the relative path being equal to the filename. - return relativePath.path == other.name + // Direct containment is equivalent to the relative path being equal to the filename. + return relativePath.path == other.name } /** - * Checks if this [File] is in the password repository directory as given - * by [PasswordRepository.getRepositoryDirectory] + * Checks if this [File] is in the password repository directory as given by + * [PasswordRepository.getRepositoryDirectory] */ fun File.isInsideRepository(): Boolean { - return canonicalPath.contains(PasswordRepository.getRepositoryDirectory().canonicalPath) + return canonicalPath.contains(PasswordRepository.getRepositoryDirectory().canonicalPath) } -/** - * Recursively lists the files in this [File], skipping any directories it encounters. - */ +/** Recursively lists the files in this [File], skipping any directories it encounters. */ fun File.listFilesRecursively() = walkTopDown().filter { !it.isDirectory }.toList() /** @@ -67,7 +54,7 @@ fun File.listFilesRecursively() = walkTopDown().filter { !it.isDirectory }.toLis * @see RevCommit.getId */ val RevCommit.hash: String - get() = ObjectId.toString(id) + get() = ObjectId.toString(id) /** * Time this commit was made with second precision. @@ -75,16 +62,16 @@ val RevCommit.hash: String * @see RevCommit.commitTime */ val RevCommit.time: Date - get() { - val epochSeconds = commitTime.toLong() - val epochMilliseconds = epochSeconds * 1000 - return Date(epochMilliseconds) - } + get() { + val epochSeconds = commitTime.toLong() + val epochMilliseconds = epochSeconds * 1000 + return Date(epochMilliseconds) + } /** - * Splits this [String] into an [Array] of [String]s, split on the UNIX LF line ending - * and stripped of any empty lines. + * Splits this [String] into an [Array] of [String] s, split on the UNIX LF line ending and stripped + * of any empty lines. */ fun String.splitLines(): Array<String> { - return split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + return split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() } |
