package se.kb.libris.util.charcomposer;

import se.kb.libris.util.marc.Controlfield;
import se.kb.libris.util.marc.Datafield;
import se.kb.libris.util.marc.Field;
import se.kb.libris.util.marc.MarcRecord;
import se.kb.libris.util.marc.Subfield;

import java.util.Iterator;

public class ComposeUtil {
    public static void compose(MarcRecord mr, boolean compat) {
        Iterator iter = mr.iterator();
        
        while (iter.hasNext()) {
            Field f = (Field)iter.next();
            
            if (f instanceof Controlfield) {
                Controlfield cf = (Controlfield)f;
                cf.setData(com.ibm.icu.text.Normalizer.compose(cf.getData(), compat));
            } else {
                Datafield df = (Datafield)f;
                Iterator siter = df.iterator();
                
                while (siter.hasNext()) {
                    Subfield sf = (Subfield)siter.next();
                    sf.setData(compose(sf.getData(), compat));
                }
            }
        }
    }
    
    public static void decompose(MarcRecord mr, boolean compat) {
        Iterator iter = mr.iterator();
        
        while (iter.hasNext()) {
            Field f = (Field)iter.next();
            
            if (f instanceof Controlfield) {
                Controlfield cf = (Controlfield)f;
                cf.setData(com.ibm.icu.text.Normalizer.decompose(cf.getData(), compat));
            } else {
                Datafield df = (Datafield)f;
                Iterator siter = df.iterator();
                
                while (siter.hasNext()) {
                    Subfield sf = (Subfield)siter.next();
                    sf.setData(decompose(sf.getData(), compat));
                }
            }
        }
    }

    public static String compose(String str, boolean compat) {
        return com.ibm.icu.text.Normalizer.compose(str, compat);
    }
    
    public static String decompose(String str, boolean compat) {
        return com.ibm.icu.text.Normalizer.decompose(str, compat);
    }    
}

@@ -239,16 +239,45 @@
 field;%0A%0A
+import java.text.Normalizer;%0A
 import j
@@ -650,36 +650,8 @@
 ata(
-com.ibm.icu.text.Normalizer.
 comp
@@ -1354,36 +1354,8 @@
 ata(
-com.ibm.icu.text.Normalizer.
 deco
@@ -1814,195 +1814,372 @@
  com
-.ibm.icu.text.Normalizer.compose(str, compat);%0A    %7D%0A    %0A    public static String decompose(String str, boolean compat) %7B%0A        return com.ibm.icu.text.Normalizer.decompose(str, compat
+pat %0A                ? Normalizer.normalize(str, Normalizer.Form.NFKC)%0A                : Normalizer.normalize(str, Normalizer.Form.NFC);%0A    %7D%0A    %0A    public static String decompose(String str, boolean compat) %7B%0A        return compat%0A                ? Normalizer.normalize(str, Normalizer.Form.NFKD)%0A                : Normalizer.normalize(str, Normalizer.Form.NFD
 );%0A 

Replace use of deprecated com.ibm.icu.text.Normalizer