diff --git a/README.md b/README.md index a1175c7..aa84972 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![License](https://img.shields.io/badge/kotlin-1.8.0-blue)](https://kotlinlang.org/) [![Nexus Snapshot](https://img.shields.io/nexus/s/net.thauvin.erik/urlencoder?server=https%3A%2F%2Foss.sonatype.org%2F)](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/urlencoder/) [![Release](https://img.shields.io/github/release/ethauvin/urlencoder.svg)](https://github.com/ethauvin/urlencoder/releases/latest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/urlencoder/badge.svg?color=blue)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/urlencoder) diff --git a/lib/src/main/kotlin/net/thauvin/erik/urlencoder/UrlEncoder.kt b/lib/src/main/kotlin/net/thauvin/erik/urlencoder/UrlEncoder.kt index 251295e..8636b28 100644 --- a/lib/src/main/kotlin/net/thauvin/erik/urlencoder/UrlEncoder.kt +++ b/lib/src/main/kotlin/net/thauvin/erik/urlencoder/UrlEncoder.kt @@ -41,18 +41,19 @@ object UrlEncoder { private val hexDigits = "0123456789ABCDEF".toCharArray() internal val usage = "Usage : java -jar urlencoder-*all.jar [-ed] text" + System.lineSeparator() + - "Encode and decode URL components defensively." + System.lineSeparator() + " -e encode (default) " + - System.lineSeparator() + " -d decode" + "Encode and decode URL components defensively." + System.lineSeparator() + + " -e encode (default) " + System.lineSeparator() + + " -d decode" // see https://www.rfc-editor.org/rfc/rfc3986#page-13 // and https://url.spec.whatwg.org/#application-x-www-form-urlencoded-percent-encode-set private val unreservedChars = BitSet('z'.code + 1).apply { - set('-') - set('.') - for (c in '0'..'9') { + set('-'.code) + set('.'.code) + for (c in '0'.code..'9'.code) { set(c) } - for (c in 'A'..'Z') { + for (c in 'A'.code..'Z'.code) { set(c) } set('_'.code) @@ -61,8 +62,6 @@ object UrlEncoder { } } - private fun BitSet.set(c: Char) = this.set(c.code) - // see https://www.rfc-editor.org/rfc/rfc3986#page-13 // and https://url.spec.whatwg.org/#application-x-www-form-urlencoded-percent-encode-set private fun Char.isUnreserved(): Boolean { @@ -117,7 +116,7 @@ object UrlEncoder { bytesBuffer[bytesPos++] = v.toByte() i += 2 } catch (e: NumberFormatException) { - throw IllegalArgumentException("Illegal characters in escape sequence: $e.message") + throw IllegalArgumentException("Illegal characters in escape sequence: $e.message", e) } } else { if (bytesBuffer != null) {