ICU-12450 move com.ibm.icu.dev.util.UnicodeTransform & IcuUnicodeNormalizerFactory to org.unicode.text.utility
X-SVN-Rev: 38648
This commit is contained in:
parent
f99b4ece25
commit
1649e2045e
@ -1,58 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2011-2012, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.util;
|
||||
|
||||
import com.ibm.icu.dev.util.UnicodeTransform.Type;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.text.Normalizer2;
|
||||
|
||||
/**
|
||||
* @author markdavis
|
||||
*
|
||||
*/
|
||||
public class IcuUnicodeNormalizerFactory implements UnicodeTransform.Factory {
|
||||
|
||||
public UnicodeTransform getInstance(Type type) {
|
||||
switch (type) {
|
||||
case NFC:
|
||||
return new IcuUnicodeNormalizer(Normalizer2.getNFCInstance());
|
||||
case NFKC:
|
||||
return new IcuUnicodeNormalizer(Normalizer2.getNFKCInstance());
|
||||
case NFD:
|
||||
return new IcuUnicodeNormalizer(Normalizer2.getNFDInstance());
|
||||
case NFKD:
|
||||
return new IcuUnicodeNormalizer(Normalizer2.getNFKDInstance());
|
||||
case CASEFOLD:
|
||||
return new CaseFolder();
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
private static class CaseFolder extends UnicodeTransform {
|
||||
@Override
|
||||
public String transform(String source) {
|
||||
return UCharacter.foldCase(source.toString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
private static class IcuUnicodeNormalizer extends UnicodeTransform {
|
||||
private Normalizer2 normalizer;
|
||||
|
||||
private IcuUnicodeNormalizer(Normalizer2 normalizer) {
|
||||
this.normalizer = normalizer;
|
||||
}
|
||||
|
||||
public String transform(String src) {
|
||||
return normalizer.normalize(src);
|
||||
}
|
||||
|
||||
public boolean isTransformed(String s) {
|
||||
return normalizer.isNormalized(s);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2011-2012, Google, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.util;
|
||||
|
||||
import com.ibm.icu.text.Transform;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
|
||||
/**
|
||||
* Simple wrapping for normalizer that allows for both the standard ICU normalizer, and one built directly from the UCD.
|
||||
*/
|
||||
public abstract class UnicodeTransform implements Transform<String,String> {
|
||||
public enum Type {
|
||||
NFD, NFC, NFKD, NFKC, CASEFOLD
|
||||
}
|
||||
|
||||
public interface Factory {
|
||||
public UnicodeTransform getInstance(Type type);
|
||||
}
|
||||
|
||||
private static Factory factory = new IcuUnicodeNormalizerFactory();
|
||||
|
||||
public static synchronized Factory getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
public static synchronized void setFactory(Factory factory) {
|
||||
UnicodeTransform.factory = factory;
|
||||
}
|
||||
|
||||
public static synchronized UnicodeTransform getInstance(Type type) {
|
||||
return factory.getInstance(type);
|
||||
}
|
||||
|
||||
public abstract String transform(String source);
|
||||
|
||||
/**
|
||||
* Can be overridden for performance.
|
||||
*/
|
||||
public boolean isTransformed(String source) {
|
||||
return source.equals(transform(source));
|
||||
}
|
||||
/**
|
||||
* Can be overridden for performance.
|
||||
*/
|
||||
public String transform(int source) {
|
||||
return transform(UTF16.valueOf(source));
|
||||
}
|
||||
/**
|
||||
* Can be overridden for performance.
|
||||
*/
|
||||
public boolean isTransformed(int source) {
|
||||
return isTransformed(UTF16.valueOf(source));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user