Skip to content

Commit b013a23

Browse files
committed
🚸 add `@JvmOverloads annotation to decoder and encoder functions for improved flexibility
1 parent f6d01c0 commit b013a23

File tree

4 files changed

+5
-12
lines changed

4 files changed

+5
-12
lines changed

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/UriExtensions.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import java.net.URLDecoder
1111
/**
1212
* The URI query split into a map. Providing custom [options] will override the default behavior.
1313
*/
14-
fun URI.queryParametersQs(options: DecodeOptions?): Map<String, Any?> =
14+
@JvmOverloads
15+
fun URI.queryParametersQs(options: DecodeOptions? = null): Map<String, Any?> =
1516
if (!rawQuery.isNullOrEmpty()) QS.decode(rawQuery, options) else emptyMap()
1617

1718
/**
1819
* The normalized string representation of the URI. Providing custom [options] will override the
1920
* default behavior.
2021
*/
22+
@JvmOverloads
2123
fun URI.toStringQs(
2224
options: EncodeOptions =
2325
EncodeOptions(listFormat = ListFormat.REPEAT, skipNulls = false, strictNullHandling = false)

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/Utils.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ internal object Utils {
2424
* @param options Optional decode options for merging behavior.
2525
* @return The merged object.
2626
*/
27-
@JvmStatic
2827
fun merge(target: Any?, source: Any?, options: DecodeOptions = DecodeOptions()): Any? {
2928
if (source == null) {
3029
return target
@@ -199,7 +198,6 @@ internal object Utils {
199198
* https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/escape
200199
*/
201200
@Deprecated("Use URLEncoder.encode instead")
202-
@JvmStatic
203201
fun escape(str: String, format: Format = Format.RFC3986): String {
204202
val buffer = StringBuilder()
205203

@@ -243,7 +241,6 @@ internal object Utils {
243241
* https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/unescape
244242
*/
245243
@Deprecated("Use URLDecoder.decode instead")
246-
@JvmStatic
247244
fun unescape(str: String): String {
248245
val buffer = StringBuilder()
249246
var i = 0
@@ -321,7 +318,6 @@ internal object Utils {
321318
* @param format The encoding format to use. Defaults to RFC 3986.
322319
* @return The encoded string.
323320
*/
324-
@JvmStatic
325321
fun encode(
326322
value: Any?,
327323
charset: Charset? = StandardCharsets.UTF_8,
@@ -441,7 +437,6 @@ internal object Utils {
441437
* @param charset The character set to use for decoding. Defaults to UTF-8.
442438
* @return The decoded string, or null if the input is null.
443439
*/
444-
@JvmStatic
445440
fun decode(str: String?, charset: Charset? = StandardCharsets.UTF_8): String? {
446441
val strWithoutPlus = str?.replace('+', ' ')
447442

@@ -473,7 +468,6 @@ internal object Utils {
473468
* @param root The root of the Map or List structure to compact.
474469
* @return The compacted Map or List structure.
475470
*/
476-
@JvmStatic
477471
fun compact(root: MutableMap<String, Any?>): MutableMap<String, Any?> {
478472
val stack = ArrayDeque<Any>()
479473
stack.add(root)
@@ -545,7 +539,6 @@ internal object Utils {
545539
* @param b The second object to combine.
546540
* @return A list containing the combined elements.
547541
*/
548-
@JvmStatic
549542
fun <T> combine(a: Any?, b: Any?): List<T> {
550543
val result = mutableListOf<T>()
551544

@@ -573,7 +566,6 @@ internal object Utils {
573566
* @param fn The function to apply.
574567
* @return The result of applying the function, or null if the input is null.
575568
*/
576-
@JvmStatic
577569
fun <T> apply(value: Any?, fn: (T) -> T): Any? =
578570
when (value) {
579571
is Iterable<*> -> {
@@ -594,7 +586,6 @@ internal object Utils {
594586
* @param skipNulls If true, empty Strings and URIs are not considered non-nullish.
595587
* @return True if the value is a non-nullish primitive, false otherwise.
596588
*/
597-
@JvmStatic
598589
fun isNonNullishPrimitive(value: Any?, skipNulls: Boolean = false): Boolean =
599590
when (value) {
600591
is String -> if (skipNulls) value.isNotEmpty() else true
@@ -618,7 +609,6 @@ internal object Utils {
618609
* @param value The value to check.
619610
* @return True if the value is empty, false otherwise.
620611
*/
621-
@JvmStatic
622612
fun isEmpty(value: Any?): Boolean =
623613
when (value) {
624614
null,
@@ -636,7 +626,6 @@ internal object Utils {
636626
* @param str The input string potentially containing numeric entities.
637627
* @return A new string with numeric entities replaced by their corresponding characters.
638628
*/
639-
@JvmStatic
640629
fun interpretNumericEntities(str: String): String {
641630
if (str.length < 4) return str
642631
val first = str.indexOf("&#")

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/models/DecodeOptions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ data class DecodeOptions(
130130
}
131131

132132
/** Decode the input using the specified Decoder. */
133+
@JvmOverloads
133134
fun getDecoder(value: String?, charset: Charset? = null): Any? =
134135
if (decoder != null) decoder.invoke(value, charset) else Utils.decode(value, charset)
135136
}

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/models/EncodeOptions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ data class EncodeOptions(
153153
*
154154
* Uses the provided encoder if available, otherwise uses Utils.encode.
155155
*/
156+
@JvmOverloads
156157
fun getEncoder(value: Any?, charset: Charset? = null, format: Format? = null): String =
157158
encoder?.invoke(value, charset ?: this.charset, format ?: this.format)
158159
?: Utils.encode(value, charset ?: this.charset, format ?: this.format)

0 commit comments

Comments
 (0)