[Android] Add custom string separators

Robert Stone git at videolan.org
Tue Jul 12 07:56:38 UTC 2022


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Mon Jul 11 23:59:18 2022 -0700| [ad8abfc4447d3b7ce2aa46c98b9009df0c32ff2b] | committer: Robert Stone

Add custom string separators

> https://code.videolan.org/videolan/vlc-android/commit/ad8abfc4447d3b7ce2aa46c98b9009df0c32ff2b
---

 .../src/org/videolan/vlc/util/TextUtils.kt         | 25 ++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/util/TextUtils.kt b/application/vlc-android/src/org/videolan/vlc/util/TextUtils.kt
index 6709adc68..122c961e5 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/TextUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/TextUtils.kt
@@ -38,18 +38,35 @@ object TextUtils {
      * Create a string separated by the common [separator]
      *
      * @param pieces the strings to join
-     * @return a string containing all the [pieces] if they are not blanked, spearated by the [separator]
+     * @return a string containing all the [pieces] if they are not blanked, separated by the [separator]
      */
     @JvmName("separatedStringArgs")
-    fun separatedString(vararg pieces: String?) = separatedString(arrayOf(*pieces))
+    fun separatedString(vararg pieces: String?) = separatedString(this.separator, arrayOf(*pieces))
 
     /**
      * Create a string separated by the common [separator]
      *
      * @param pieces the strings to join in an [Array]
-     * @return a string containing all the [pieces] if they are not blanked, spearated by the [separator]
+     * @return a string containing all the [pieces] if they are not blanked, separated by the [separator]
      */
-    fun separatedString(pieces: Array<String?>) = pieces.filter { it?.isNotBlank() == true }.joinToString(separator = " $separator ")
+    fun separatedString(pieces: Array<String?>) = separatedString(this.separator, pieces)
+
+    /**
+     * Create a string separated by a custom [separator]
+     *
+     * @param pieces the strings to join
+     * @return a string containing all the [pieces] if they are not blanked, separated by [separator]
+     */
+    @JvmName("separatedStringArgs")
+    fun separatedString(separator: Char, vararg pieces: String?) = separatedString(separator, arrayOf(*pieces))
+
+    /**
+     * Create a string separated by a custom [separator]
+     *
+     * @param pieces the strings to join in an [Array]
+     * @return a string containing all the [pieces] if they are not blanked, separated by [separator]
+     */
+    fun separatedString(separator: Char, pieces: Array<String?>) = pieces.filter { it?.isNotBlank() == true }.joinToString(separator = " $separator ")
 
     /**
      * Formats the chapter title by prepending "Chapter:" if the current title is made of only non alpha chars



More information about the Android mailing list