More optimization to spaceToPlus
This commit is contained in:
parent
f8b9376f40
commit
7c8a4358b6
3 changed files with 23 additions and 24 deletions
2
.idea/copyright/Apache_License.xml
generated
2
.idea/copyright/Apache_License.xml
generated
|
@ -1,6 +1,6 @@
|
||||||
<component name="CopyrightManager">
|
<component name="CopyrightManager">
|
||||||
<copyright>
|
<copyright>
|
||||||
<option name="notice" value="Copyright 2001-&#36;today.year Geert Bevin (gbevin[remove] at uwyn dot com) Copyright &#36;today.year 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. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." />
|
<option name="notice" value="Copyright 2001-&#36;today.year Geert Bevin (gbevin[remove] at uwyn dot com) Copyright 2022-&#36;today.year 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. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." />
|
||||||
<option name="myName" value="Apache License" />
|
<option name="myName" value="Apache License" />
|
||||||
</copyright>
|
</copyright>
|
||||||
</component>
|
</component>
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -40,7 +40,7 @@ import kotlin.system.exitProcess
|
||||||
object UrlEncoder {
|
object UrlEncoder {
|
||||||
private val hexDigits = "0123456789ABCDEF".toCharArray()
|
private val hexDigits = "0123456789ABCDEF".toCharArray()
|
||||||
internal val usage =
|
internal val usage =
|
||||||
"Usage : java -jar urlencoder-*all.jar [-ed] <text>" + System.lineSeparator() +
|
"Usage : java -jar urlencoder-*all.jar [-ed] text" + System.lineSeparator() +
|
||||||
"Encode and decode URL components defensively." + System.lineSeparator() + " -e encode (default) " +
|
"Encode and decode URL components defensively." + System.lineSeparator() + " -e encode (default) " +
|
||||||
System.lineSeparator() + " -d decode"
|
System.lineSeparator() + " -d decode"
|
||||||
|
|
||||||
|
@ -160,27 +160,26 @@ object UrlEncoder {
|
||||||
out = StringBuilder(source.length)
|
out = StringBuilder(source.length)
|
||||||
out.append(source, 0, i)
|
out.append(source, 0, i)
|
||||||
}
|
}
|
||||||
if (spaceToPlus && ch == ' ') {
|
val cp = source.codePointAt(i)
|
||||||
out.append('+')
|
if (cp < 0x80) {
|
||||||
i++
|
if (spaceToPlus && ch == ' ') {
|
||||||
} else {
|
out.append('+')
|
||||||
val cp = source.codePointAt(i)
|
} else {
|
||||||
if (cp < 0x80) {
|
|
||||||
out.appendEncodedByte(cp)
|
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.
|
* Encodes and decodes URLs from the command line.
|
||||||
*
|
*
|
||||||
* - `java -jar urlencoder-*all.jar <text>`
|
* - `java -jar urlencoder-*all.jar [-ed] text`
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue