Auto init
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 27 Sep 2009 18:02:22 +0000 (18:02 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 27 Sep 2009 18:02:22 +0000 (18:02 +0000)
DecoratedStr.java

index c32d6eb43d35fdfc7de38beb66aa58bab95ccff5..2981f3a244143a18e7d53678a62912915472cced 100644 (file)
@@ -7,8 +7,11 @@ public class DecoratedStr {
     protected static Hashtable<Character,String> ligatures_expansions_lower = new Hashtable<Character,String>();
     protected static Hashtable<Character,String> ligatures_expansions = new Hashtable<Character,String>();
     protected static Hashtable<String,Character> ligatures_contractions = new Hashtable<String,Character>();
+    private static boolean initialized = false;
 
     public static void init() {
+        if (initialized)
+            return;
         char_to_alternatives_lower.put('a', "àáâãäåāăą");
         char_to_alternatives_lower.put('c', "çćĉċč");
         char_to_alternatives_lower.put('d', "ďđ");
@@ -55,6 +58,7 @@ public class DecoratedStr {
         ligatures_expansions_lower.put('æ', "ae");
         //ligatures_expansions_lower.put('ij', "ij"); buggy: see http://en.wikipedia.org/wiki/Typographic_ligature
         ligatures_expansions_lower.put('œ', "oe");
+
         e = ligatures_expansions_lower.keys();
         while (e.hasMoreElements()) {
             Character k = e.nextElement();
@@ -65,9 +69,12 @@ public class DecoratedStr {
             ligatures_expansions.put(Character.toUpperCase(k), uv);
             ligatures_contractions.put(uv, Character.toUpperCase(k));
         }
+
+        initialized = true;
     }
 
     public static String remove_decoration(String txt) {
+        init();
         String result = "";
         int len = txt.length();
         char l;
@@ -88,6 +95,7 @@ public class DecoratedStr {
     }
 
     public static String decorated_match_single_char(char c, boolean case_sensitive) {
+        init();
         if (!case_sensitive)
             c = Character.toLowerCase(c);
         String result = "" + c;
@@ -107,6 +115,7 @@ public class DecoratedStr {
     }
 
     public static String decorated_match(String txt, boolean case_sensitive) {
+        init();
         String result = "";
         txt = remove_decoration(txt);
         if (!case_sensitive)
@@ -136,14 +145,13 @@ public class DecoratedStr {
     }
 
        public static void main(String argv[]) {
-        init();
         String in = "Œuf";
                System.out.println(in);
                System.out.println(remove_decoration(in));
-               System.out.println(decorated_match_single_char('m', true));
-               System.out.println(decorated_match_single_char('m', false));
-               System.out.println(decorated_match_single_char('h', true));
-               System.out.println(decorated_match_single_char('h', false));
+               //System.out.println(decorated_match_single_char('m', true));
+               //System.out.println(decorated_match_single_char('m', false));
+               //System.out.println(decorated_match_single_char('h', true));
+               //System.out.println(decorated_match_single_char('h', false));
                System.out.println(decorated_match(in, true));
                System.out.println(decorated_match(in, false));
        }