Navigation Menu

Skip to content

Commit

Permalink
Minor cleanup; release 1.4.4.3
Browse files Browse the repository at this point in the history
This eliminates a seemingly-unnecessary step that wasted memory when decompressing URI-encoded text, and was putting one non-URI-safe char in URI-encoded text. It seems to encode and decode exactly the same.
  • Loading branch information
tommyettinger committed Jul 8, 2019
1 parent 8f9f246 commit 579354f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/main/java/blazing/chain/LZSEncoding.java
Expand Up @@ -15,6 +15,7 @@

public final class LZSEncoding {

private LZSEncoding() {};
private static final char[] keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray(),
keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$".toCharArray(),
valStrBase64 = new char[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand All @@ -32,7 +33,7 @@ public final class LZSEncoding {
*/
public static String compressToBase64(String uncompressed) {
if (uncompressed == null)
return "";
return null;
String res = _compress(uncompressed, 6, keyStrBase64, 0);
switch (res.length() & 3) { // To produce valid Base64
default: // When could this happen ?
Expand All @@ -58,8 +59,6 @@ public static String decompressFromBase64(String compressed) {
if (compressed.isEmpty())
return "";
final char[] input = compressed.toCharArray();
// function(index) { return getBaseValue(keyStrBase64,
// input.charAt(index)); }
return _decompress(input.length, 32, input, valStrBase64, 0);
}

Expand Down Expand Up @@ -98,7 +97,7 @@ public static String decompressFromUTF16(String compressed) {
public static String compressToEncodedURIComponent(String uncompressed) {
if (uncompressed == null)
return null;
return _compress(uncompressed, 6, keyStrUriSafe, 0) + ' ';
return _compress(uncompressed, 6, keyStrUriSafe, 0) + '+';
}
/**
* Decompresses a String that had been compressed with {@link #compressToEncodedURIComponent(String)}.
Expand All @@ -108,7 +107,6 @@ public static String compressToEncodedURIComponent(String uncompressed) {
public static String decompressFromEncodedURIComponent(String compressed) {
if (compressed == null) return null;
if (compressed.isEmpty()) return "";
compressed = compressed.replace(' ', '+');
final char[] input = compressed.toCharArray();
return _decompress(input.length, 32, input, valStrUriSafe, 0);
}
Expand Down
Expand Up @@ -11,6 +11,7 @@

public final class LZSEncoding {

private LZSEncoding() {};
private static final String keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",
valStrBase64 = new String(new char[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand All @@ -28,7 +29,7 @@ public final class LZSEncoding {
*/
public static String compressToBase64(String uncompressed) {
if (uncompressed == null)
return "";
return null;
String res = _compress(uncompressed, 6, keyStrBase64, 0);
switch (res.length() & 3) { // To produce valid Base64
default: // When could this happen ?
Expand Down Expand Up @@ -92,7 +93,7 @@ public static String decompressFromUTF16(String compressed) {
public static String compressToEncodedURIComponent(String uncompressed) {
if (uncompressed == null)
return null;
return _compress(uncompressed, 6, keyStrUriSafe, 0) + ' ';
return _compress(uncompressed, 6, keyStrUriSafe, 0) + '+';
}
/**
* Decompresses a String that had been compressed with {@link #compressToEncodedURIComponent(String)}.
Expand All @@ -102,7 +103,6 @@ public static String compressToEncodedURIComponent(String uncompressed) {
public static String decompressFromEncodedURIComponent(String compressed) {
if (compressed == null) return null;
if (compressed.isEmpty()) return "";
compressed = compressed.replace(' ', '+');
return _decompress(compressed.length(), 32, compressed, valStrUriSafe, 0);
}

Expand Down

0 comments on commit 579354f

Please sign in to comment.