X-Git-Url: https://git.nirgal.com/?p=decoratedstr.git;a=blobdiff_plain;f=DecoratedStr.java;h=2981f3a244143a18e7d53678a62912915472cced;hp=c32d6eb43d35fdfc7de38beb66aa58bab95ccff5;hb=a42d4db3351105e68ee014c94d195d0f8e980487;hpb=a5a1230aee9bbad52a17cdba2d3d25e85eeb336b diff --git a/DecoratedStr.java b/DecoratedStr.java index c32d6eb..2981f3a 100644 --- a/DecoratedStr.java +++ b/DecoratedStr.java @@ -7,8 +7,11 @@ public class DecoratedStr { protected static Hashtable ligatures_expansions_lower = new Hashtable(); protected static Hashtable ligatures_expansions = new Hashtable(); protected static Hashtable ligatures_contractions = new Hashtable(); + 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)); }