From 74bc628785a4725ca51bced49f45c82f8d9c0940 Mon Sep 17 00:00:00 2001 From: CincyAndroiDeveloper <6299370+CincyAndroiDeveloper@users.noreply.github.com> Date: Mon, 16 Mar 2026 15:00:21 -0400 Subject: [PATCH] - Added `useAbbreviation` parameter to `Kapacity.toString()` to support toggling between full unit names and abbreviations (e.g., "Megabyte" vs "MB"). - Updated `KapacityUnit` enum with metric (e.g., "KB", "MB") and binary (e.g., "KiB", "MiB") abbreviation strings. - Refactored `Kapacity.toString()` logic to handle pluralization for full names and proper suffix selection based on metric/binary flags. - Added `KapacityToStringTest` to verify formatting across various units, edge cases, and unit suffix configurations. - Incremented version to `0.9.9-beta07`. --- gradle/libs.versions.toml | 2 +- .../developrofthings/kapacity/Kapacity.kt | 70 +++++++++++--- .../kapacity/KapacityToStringTest.kt | 94 +++++++++++++++++++ 3 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 kapacity/src/commonTest/kotlin/io/github/developrofthings/kapacity/KapacityToStringTest.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7c94d3f..e1e6976 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kapacity = "0.9.9-beta06" +kapacity = "0.9.9-beta07" agp = "8.11.2" android-compileSdk = "36" android-minSdk = "24" diff --git a/kapacity/src/commonMain/kotlin/io/github/developrofthings/kapacity/Kapacity.kt b/kapacity/src/commonMain/kotlin/io/github/developrofthings/kapacity/Kapacity.kt index c207bb9..86e6bbb 100644 --- a/kapacity/src/commonMain/kotlin/io/github/developrofthings/kapacity/Kapacity.kt +++ b/kapacity/src/commonMain/kotlin/io/github/developrofthings/kapacity/Kapacity.kt @@ -24,11 +24,19 @@ value class Kapacity private constructor(val rawBytes: Long) : Comparable - if (useUnitSuffix) "$byteCountStr bytes" else byteCountStr + if (useUnitSuffix) { + if (useAbbreviation) { + "$byteCountStr ${resolvedUnit.abbreviationMetric}" + } else { + if (this.rawBytes != 1L) "$byteCountStr ${resolvedUnit}s" + else "$byteCountStr $resolvedUnit" + } + } else byteCountStr } } // Double division is perfectly safe here, even for Exabytes. @@ -37,11 +45,19 @@ value class Kapacity private constructor(val rawBytes: Long) : Comparable