[jruby-joni] 23/279: Add Encoding.load for lazy kcode and lazy 1.9 encoding support.

Hideki Yamane henrich at moszumanska.debian.org
Mon Nov 16 11:26:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository jruby-joni.

commit d6f8b753115681b3a175fd49610ab746472c1121
Author: Marcin Mielżyński <lopx at gazeta.pl>
Date:   Tue May 27 21:07:56 2008 +0000

    Add Encoding.load for lazy kcode and lazy 1.9 encoding support.
    
    git-svn-id: http://svn.codehaus.org/jruby/joni/trunk@6839 961051c9-f516-0410-bf72-c9f7e237a7b7
---
 src/org/joni/encoding/Encoding.java       | 19 +++++++++++++++++++
 src/org/joni/exception/ErrorMessages.java |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/src/org/joni/encoding/Encoding.java b/src/org/joni/encoding/Encoding.java
index 91cbaca..d2783ec 100644
--- a/src/org/joni/encoding/Encoding.java
+++ b/src/org/joni/encoding/Encoding.java
@@ -23,6 +23,8 @@ import org.joni.ApplyAllCaseFoldFunction;
 import org.joni.CaseFoldCodeItem;
 import org.joni.IntHolder;
 import org.joni.constants.CharacterType;
+import org.joni.exception.ErrorMessages;
+import org.joni.exception.ValueException;
 import org.joni.util.BytesHash;
 
 public abstract class Encoding {
@@ -424,4 +426,21 @@ public abstract class Encoding {
     public abstract boolean isFixedWidth();
     
     public static final byte NEW_LINE = (byte)0x0a;
+
+    public static Encoding load(String name) { 
+        String encClassName = "org.joni.encoding.specific." + name + "Encoding";
+
+        Class<?> encClass;
+        try {
+            encClass = Class.forName(encClassName);
+        } catch (ClassNotFoundException cnfe) {
+            throw new ValueException(ErrorMessages.ERR_ENCODING_CLASS_DEF_NOT_FOUND, encClassName);
+        }
+
+        try {
+            return (Encoding)encClass.getField("INSTANCE").get(encClass);
+        } catch (Exception e) {
+            throw new ValueException(ErrorMessages.ERR_ENCODING_LOAD_ERROR, encClassName);
+        }
+    }
 }
diff --git a/src/org/joni/exception/ErrorMessages.java b/src/org/joni/exception/ErrorMessages.java
index 86d019e..9b6b42f 100644
--- a/src/org/joni/exception/ErrorMessages.java
+++ b/src/org/joni/exception/ErrorMessages.java
@@ -92,4 +92,7 @@ public interface ErrorMessages {
     final String ERR_INVALID_COMBINATION_OF_OPTIONS = "invalid combination of options";
     final String ERR_OVER_THREAD_PASS_LIMIT_COUNT = "over thread pass limit count";
     final String ERR_TOO_BIG_SB_CHAR_VALUE = "too big singlebyte char value";
+
+    final String ERR_ENCODING_CLASS_DEF_NOT_FOUND = "encoding class <%n> not found";
+    final String ERR_ENCODING_LOAD_ERROR = "problem loading encoding <%n>";
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git



More information about the pkg-java-commits mailing list