diff --git a/.idea/copyright/Apache_License.xml b/.idea/copyright/Apache_License.xml index ac503d7..68484aa 100644 --- a/.idea/copyright/Apache_License.xml +++ b/.idea/copyright/Apache_License.xml @@ -1,6 +1,6 @@ - \ No newline at end of file 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 37ea9c2..d0cc2c7 100644 --- a/lib/src/main/kotlin/net/thauvin/erik/urlencoder/UrlEncoder.kt +++ b/lib/src/main/kotlin/net/thauvin/erik/urlencoder/UrlEncoder.kt @@ -1,6 +1,6 @@ /* * Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com) - * Copyright 2023 Erik C. Thauvin (erik@thauvin.net) + * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ import kotlin.system.exitProcess object UrlEncoder { private val hexDigits = "0123456789ABCDEF".toCharArray() internal val usage = - "Usage : java -jar urlencoder-*all.jar [-ed] " + System.lineSeparator() + + "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" @@ -160,27 +160,26 @@ object UrlEncoder { out = StringBuilder(source.length) out.append(source, 0, i) } - if (spaceToPlus && ch == ' ') { - out.append('+') - i++ - } else { - val cp = source.codePointAt(i) - if (cp < 0x80) { + val cp = source.codePointAt(i) + if (cp < 0x80) { + if (spaceToPlus && ch == ' ') { + out.append('+') + } else { out.appendEncodedByte(cp) - i++ - } else if (Character.isBmpCodePoint(cp)) { - for (b in ch.toString().toByteArray(StandardCharsets.UTF_8)) { - out.appendEncodedByte(b.toInt()) - } - i++ - } else if (Character.isSupplementaryCodePoint(cp)) { - val high = Character.highSurrogate(cp) - val low = Character.lowSurrogate(cp) - for (b in charArrayOf(high, low).concatToString().toByteArray(StandardCharsets.UTF_8)) { - out.appendEncodedByte(b.toInt()) - } - i += 2 } + i++ + } else if (Character.isBmpCodePoint(cp)) { + for (b in ch.toString().toByteArray(StandardCharsets.UTF_8)) { + out.appendEncodedByte(b.toInt()) + } + i++ + } else if (Character.isSupplementaryCodePoint(cp)) { + val high = Character.highSurrogate(cp) + val low = Character.lowSurrogate(cp) + for (b in charArrayOf(high, low).concatToString().toByteArray(StandardCharsets.UTF_8)) { + out.appendEncodedByte(b.toInt()) + } + i += 2 } } } @@ -191,7 +190,7 @@ object UrlEncoder { /** * Encodes and decodes URLs from the command line. * - * - `java -jar urlencoder-*all.jar ` + * - `java -jar urlencoder-*all.jar [-ed] text` */ @JvmStatic fun main(args: Array) { diff --git a/lib/src/test/kotlin/net/thauvin/erik/urlencoder/UrlEncoderTest.kt b/lib/src/test/kotlin/net/thauvin/erik/urlencoder/UrlEncoderTest.kt index a99a29e..4897040 100644 --- a/lib/src/test/kotlin/net/thauvin/erik/urlencoder/UrlEncoderTest.kt +++ b/lib/src/test/kotlin/net/thauvin/erik/urlencoder/UrlEncoderTest.kt @@ -1,6 +1,6 @@ /* * Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com) - * Copyright 2023 Erik C. Thauvin (erik@thauvin.net) + * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.