[SCM] Java-based codings helper classes for Joni and JRuby branch, master, updated. debian/1.0.9-3-7-g7e5ae02
Hideki Yamane
henrich at debian.org
Tue Jun 4 11:32:51 UTC 2013
The following commit has been merged in the master branch:
commit 74190ced7d6c3c51c9cd463902678efccfb9f947
Author: Hideki Yamane <henrich at debian.org>
Date: Tue Jun 4 20:28:39 2013 +0900
Imported Upstream version 1.0.10
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..f803194
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,18 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/pom.xml b/pom.xml
index 7c42aaf..3387804 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,8 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jruby.jcodings</groupId>
<artifactId>jcodings</artifactId>
- <packaging>jar</packaging>
- <version>1.0.9</version>
+ <version>1.0.10</version>
<name>JCodings</name>
<description>
Byte based encoding support library for java
@@ -17,9 +16,9 @@
</issueManagement>
<scm>
- <connection>scm:svn:http://svn.codehaus.org/jruby</connection>
- <developerConnection>scm:svn:https://svn.codehaus.org/jruby</developerConnection>
- <url>http://svn.codehaus.org/jruby</url>
+ <connection>scm:git:git://github.com/jruby/jcodings.git</connection>
+ <developerConnection>scm:git:git://github.com/jruby/jcodings.git</developerConnection>
+ <url>http://github.com/jruby/jcodings</url>
</scm>
<licenses>
@@ -93,8 +92,8 @@
</extensions>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
+ <version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
@@ -105,8 +104,8 @@
</executions>
</plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
@@ -116,11 +115,12 @@
</execution>
</executions>
<configuration>
- <skip>true</skip>
+ <skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
@@ -128,6 +128,7 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
<configuration>
<archive>
<manifestFile>MANIFEST.MF</manifestFile>
@@ -135,8 +136,8 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
</plugin>
</plugins>
<resources>
@@ -147,6 +148,5 @@
</includes>
</resource>
</resources>
-
</build>
</project>
diff --git a/src/org/jcodings/SingleByteEncoding.java b/src/org/jcodings/SingleByteEncoding.java
index 1af34fc..72bd8de 100644
--- a/src/org/jcodings/SingleByteEncoding.java
+++ b/src/org/jcodings/SingleByteEncoding.java
@@ -24,17 +24,23 @@ import org.jcodings.exception.ErrorMessages;
public abstract class SingleByteEncoding extends AbstractEncoding {
- protected final byte[]LowerCaseTable;
+ protected final byte[] LowerCaseTable;
+ protected int codeSize = 0xff;
- protected SingleByteEncoding(String name, short[]CTypeTable, byte[]LowerCaseTable) {
+ protected SingleByteEncoding(String name, short[] CTypeTable, byte[] LowerCaseTable) {
super(name, 1, 1, CTypeTable);
this.LowerCaseTable = LowerCaseTable;
}
- protected SingleByteEncoding(String name, short[]CTypeTable, byte[]LowerCaseTable, boolean isDummy) {
+ protected SingleByteEncoding(String name, short[] CTypeTable, byte[] LowerCaseTable, boolean isDummy) {
super(name, 1, 1, CTypeTable, isDummy);
this.LowerCaseTable = LowerCaseTable;
}
+
+ protected SingleByteEncoding(String name, short[] CTypeTable, byte[] LowerCaseTable, boolean isDummy, int codeSize) {
+ this(name, CTypeTable, LowerCaseTable, isDummy);
+ this.codeSize = codeSize;
+ }
/** onigenc_single_byte_mbc_enc_len
*/
@@ -44,17 +50,17 @@ public abstract class SingleByteEncoding extends AbstractEncoding {
}
@Override
- public int length(byte[]bytes, int p, int end) {
+ public int length(byte[] bytes, int p, int end) {
return 1;
}
@Override
- public final int strLength(byte[]bytes, int p, int end) {
+ public final int strLength(byte[] bytes, int p, int end) {
return end - p;
}
@Override
- public int strCodeAt(byte[]bytes, int p, int end, int index) {
+ public int strCodeAt(byte[] bytes, int p, int end, int index) {
return bytes[index] & 0xff;
}
// onigenc_is_mbc_newline_0x0a here
@@ -62,16 +68,16 @@ public abstract class SingleByteEncoding extends AbstractEncoding {
/** onigenc_single_byte_mbc_to_code
*/
@Override
- public int mbcToCode(byte[]bytes, int p, int end){
+ public int mbcToCode(byte[] bytes, int p, int end) {
return bytes[p] & 0xff;
}
/** onigenc_single_byte_code_to_mbclen
*/
@Override
- public final int codeToMbcLength(int code) {
+ public int codeToMbcLength(int code) {
if (Config.VANILLA) {
- if (code < 0x100) return 1;
+ if (code <= codeSize) return 1;
throw new EncodingException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
} else {
return 1;
@@ -81,8 +87,9 @@ public abstract class SingleByteEncoding extends AbstractEncoding {
/** onigenc_single_byte_code_to_mbc
*/
@Override
- public final int codeToMbc(int code, byte[]bytes, int p) {
- // TODO: raise if (code > 0xff): range error "out of char range"
+ public final int codeToMbc(int code, byte[] bytes, int p) {
+ if (code > codeSize) throw new EncodingException("out of range char");
+
bytes[p] = (byte)(code & 0xff); // c implementation also uses mask here
return 1;
}
@@ -90,21 +97,21 @@ public abstract class SingleByteEncoding extends AbstractEncoding {
/** onigenc_not_support_get_ctype_code_range
*/
@Override
- public final int[]ctypeCodeRange(int ctype, IntHolder sbOut) {
+ public final int[] ctypeCodeRange(int ctype, IntHolder sbOut) {
return null;
}
/** onigenc_single_byte_left_adjust_char_head
*/
@Override
- public final int leftAdjustCharHead(byte[]bytes, int p, int s, int end) {
+ public final int leftAdjustCharHead(byte[] bytes, int p, int s, int end) {
return s;
}
/** onigenc_always_true_is_allowed_reverse_match
*/
@Override
- public final boolean isReverseMatchAllowed(byte[]bytes, int p, int end) {
+ public final boolean isReverseMatchAllowed(byte[] bytes, int p, int end) {
return true;
}
}
diff --git a/src/org/jcodings/specific/ASCIIEncoding.java b/src/org/jcodings/specific/ASCIIEncoding.java
index fadad4f..75b0f9f 100644
--- a/src/org/jcodings/specific/ASCIIEncoding.java
+++ b/src/org/jcodings/specific/ASCIIEncoding.java
@@ -32,7 +32,7 @@ public final class ASCIIEncoding extends SingleByteEncoding {
}
@Override
- public final byte[]toLowerCaseTable() {
+ public final byte[] toLowerCaseTable() {
return LowerCaseTable;
}
diff --git a/src/org/jcodings/specific/EmacsMuleEncoding.java b/src/org/jcodings/specific/EmacsMuleEncoding.java
index 7164f08..61de8c9 100644
--- a/src/org/jcodings/specific/EmacsMuleEncoding.java
+++ b/src/org/jcodings/specific/EmacsMuleEncoding.java
@@ -96,7 +96,7 @@ public final class EmacsMuleEncoding extends MultiByteEncoding {
}
private static boolean islead(int c) {
- return c - 0x81 > 0x9d - 0x81;
+ return c < 0x9d;
}
@Override
diff --git a/src/org/jcodings/specific/USASCIIEncoding.java b/src/org/jcodings/specific/USASCIIEncoding.java
index 09eb213..2ed9661 100644
--- a/src/org/jcodings/specific/USASCIIEncoding.java
+++ b/src/org/jcodings/specific/USASCIIEncoding.java
@@ -25,16 +25,16 @@ import org.jcodings.ascii.AsciiTables;
public final class USASCIIEncoding extends SingleByteEncoding {
protected USASCIIEncoding() {
- super("US-ASCII", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable);
+ super("US-ASCII", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable, false, 0x7f);
}
@Override
- public int length(byte[]bytes, int p, int end) {
+ public int length(byte[] bytes, int p, int end) {
return (bytes[p] & 0x80) == 0 ? 1 : -1;
}
-
+
@Override
- public final byte[]toLowerCaseTable() {
+ public final byte[] toLowerCaseTable() {
return LowerCaseTable;
}
diff --git a/src/org/jcodings/util/ArrayReader.java b/src/org/jcodings/util/ArrayReader.java
index 55c37d7..ed8b63c 100644
--- a/src/org/jcodings/util/ArrayReader.java
+++ b/src/org/jcodings/util/ArrayReader.java
@@ -43,6 +43,7 @@ public class ArrayReader {
bytes[i] = dis.readByte();
}
checkAvailable(dis, name);
+ dis.close();
return bytes;
} catch (IOException ioe) {
decorate(ioe, name);
@@ -59,6 +60,7 @@ public class ArrayReader {
ints[i] = dis.readInt();
}
checkAvailable(dis, name);
+ dis.close();
return ints;
} catch (IOException ioe) {
decorate(ioe, name);
@@ -81,6 +83,7 @@ public class ArrayReader {
}
checkAvailable(dis, name);
+ dis.close();
return ints;
} catch (IOException ioe) {
decorate(ioe, name);
@@ -95,4 +98,4 @@ public class ArrayReader {
static void decorate(IOException ioe, String name) {
throw new InternalException("problem reading table: " + name + ": " + ioe);
}
-}
\ No newline at end of file
+}
diff --git a/src/org/jcodings/specific/ASCIIEncoding.java b/test/org/jcodings/specific/TestASCIIEncoding.java
similarity index 52%
copy from src/org/jcodings/specific/ASCIIEncoding.java
copy to test/org/jcodings/specific/TestASCIIEncoding.java
index fadad4f..3da6e13 100644
--- a/src/org/jcodings/specific/ASCIIEncoding.java
+++ b/test/org/jcodings/specific/TestASCIIEncoding.java
@@ -19,35 +19,38 @@
*/
package org.jcodings.specific;
-import org.jcodings.SingleByteEncoding;
-import org.jcodings.ascii.AsciiTables;
+import org.jcodings.exception.EncodingException;
+import org.jcodings.specific.ASCIIEncoding;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
-public final class ASCIIEncoding extends SingleByteEncoding {
- protected ASCIIEncoding() {
- super("ASCII-8BIT", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable);
- }
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
- protected ASCIIEncoding(boolean isDummy) {
- super(isDummy ? "DUMMY" : "ASCII-8BIT", AsciiTables.AsciiCtypeTable, AsciiTables.ToLowerCaseTable, isDummy);
- }
+public class TestASCIIEncoding {
- @Override
- public final byte[]toLowerCaseTable() {
- return LowerCaseTable;
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void testValidCodeToMbcLength() {
+ assertEquals(1, ASCIIEncoding.INSTANCE.codeToMbcLength(0xff));
}
- @Override
- public String getCharsetName() {
- return "ISO-8859-1";
+ @Test
+ public void testValidCodeToMbc() {
+ byte[] buffer = new byte[1];
+ assertEquals(1, ASCIIEncoding.INSTANCE.codeToMbc(0xff, buffer, 0));
+ assertArrayEquals(new byte[]{ -1 }, buffer);
}
- /** ascii_is_code_ctype / ONIGENC_IS_ASCII_CODE_CTYPE
- */
- @Override
- public boolean isCodeCType(int code, int ctype) {
- return code < 128 ? isCodeCTypeInternal(code, ctype) : false;
+ @Test
+ public void testInvalidCodeToMbc() {
+ expectedException.expect(EncodingException.class);
+ expectedException.expectMessage("out of range char");
+
+ byte[] buffer = new byte[1];
+ assertEquals(1, ASCIIEncoding.INSTANCE.codeToMbc(0x100, buffer, 0));
}
-
- public static final ASCIIEncoding INSTANCE = new ASCIIEncoding();
- public static final ASCIIEncoding DUMMY = new ASCIIEncoding(true);
}
diff --git a/test/TestBig5.java b/test/org/jcodings/specific/TestBig5.java
similarity index 95%
rename from test/TestBig5.java
rename to test/org/jcodings/specific/TestBig5.java
index a73ca23..fdba5f1 100755
--- a/test/TestBig5.java
+++ b/test/org/jcodings/specific/TestBig5.java
@@ -1,3 +1,5 @@
+package org.jcodings.specific;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;
diff --git a/test/TestEUCJP.java b/test/org/jcodings/specific/TestEUCJP.java
similarity index 95%
rename from test/TestEUCJP.java
rename to test/org/jcodings/specific/TestEUCJP.java
index e5e4757..5624122 100755
--- a/test/TestEUCJP.java
+++ b/test/org/jcodings/specific/TestEUCJP.java
@@ -1,3 +1,5 @@
+package org.jcodings.specific;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;
diff --git a/test/org/jcodings/specific/TestEmacsMule.java b/test/org/jcodings/specific/TestEmacsMule.java
new file mode 100644
index 0000000..9bd983d
--- /dev/null
+++ b/test/org/jcodings/specific/TestEmacsMule.java
@@ -0,0 +1,15 @@
+package org.jcodings.specific;
+
+import static org.junit.Assert.assertEquals;
+import org.jcodings.specific.EmacsMuleEncoding;
+import org.junit.Test;
+
+public class TestEmacsMule {
+ @Test
+ public void testRightAdjustCharHeadAscii() {
+ byte[] str = new byte[]{(byte)'a', (byte)'b', (byte)'c', (byte)',', (byte)'d', (byte)'e', (byte)'f'};
+
+ int t = EmacsMuleEncoding.INSTANCE.rightAdjustCharHead(str, 0, 3, 7);
+ assertEquals("rightAdjustCharHead did not adjust properly", 3, t);
+ }
+}
diff --git a/test/TestGBK.java b/test/org/jcodings/specific/TestGBK.java
similarity index 98%
rename from test/TestGBK.java
rename to test/org/jcodings/specific/TestGBK.java
index 1c0b9de..03a6f33 100755
--- a/test/TestGBK.java
+++ b/test/org/jcodings/specific/TestGBK.java
@@ -1,3 +1,5 @@
+package org.jcodings.specific;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;
diff --git a/test/org/jcodings/specific/TestUSASCIIEncoding.java b/test/org/jcodings/specific/TestUSASCIIEncoding.java
new file mode 100644
index 0000000..52ec985
--- /dev/null
+++ b/test/org/jcodings/specific/TestUSASCIIEncoding.java
@@ -0,0 +1,63 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package org.jcodings.specific;
+
+import org.jcodings.exception.EncodingException;
+import org.jcodings.specific.ASCIIEncoding;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
+
+import org.jcodings.specific.USASCIIEncoding;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class TestUSASCIIEncoding {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ /**
+ * codeToMbcLength always returns 1, even when codepoint is invalid,
+ * as Config.VANILLA == false.
+ */
+ @Test
+ public void testValidCodeToMbcLength() {
+ assertEquals(1, ASCIIEncoding.INSTANCE.codeToMbcLength(0xff));
+ }
+
+ @Test
+ public void testValidCodeToMbc() {
+ byte[] buffer = new byte[1];
+ assertEquals(1, USASCIIEncoding.INSTANCE.codeToMbc(0x7f, buffer, 0));
+ assertArrayEquals(new byte[]{0x7f}, buffer);
+ }
+
+ @Test
+ public void testInvalidCodeToMbc() {
+ expectedException.expect(EncodingException.class);
+ expectedException.expectMessage("out of range char");
+
+ byte[] buffer = new byte[1];
+ assertEquals(1, USASCIIEncoding.INSTANCE.codeToMbc(0x80, buffer, 0));
+ }
+
+
+}
--
Java-based codings helper classes for Joni and JRuby
More information about the pkg-java-commits
mailing list