/* ******************************************************************************* * Copyright (C) 2009-2010, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ package com.ibm.icu.text; import java.io.IOException; /** * Normalization filtered by a UnicodeSet. * Normalizes portions of the text contained in the filter set and leaves * portions not contained in the filter set unchanged. * Filtering is done via UnicodeSet.span(..., UnicodeSet.SpanCondition.SIMPLE). * Not-in-the-filter text is treated as "is normalized" and "quick check yes". * This class implements all of (and only) the Normalizer2 API. * An instance of this class is unmodifiable/immutable. * @draft ICU 4.4 * @provisional This API might change or be removed in a future release. * @author Markus W. Scherer */ public class FilteredNormalizer2 extends Normalizer2 { /** * Constructs a filtered normalizer wrapping any Normalizer2 instance * and a filter set. * Both are aliased and must not be modified or deleted while this object * is used. * The filter set should be frozen; otherwise the performance will suffer greatly. * @param n2 wrapped Normalizer2 instance * @param filterSet UnicodeSet which determines the characters to be normalized * @draft ICU 4.4 * @provisional This API might change or be removed in a future release. */ public FilteredNormalizer2(Normalizer2 n2, UnicodeSet filterSet) { norm2=n2; set=filterSet; } /** {@inheritDoc} * @draft ICU 4.4 * @provisional This API might change or be removed in a future release. */ @Override public StringBuilder normalize(CharSequence src, StringBuilder dest) { if(dest==src) { throw new IllegalArgumentException(); } dest.setLength(0); normalize(src, dest, UnicodeSet.SpanCondition.SIMPLE); return dest; } /** {@inheritDoc} * @internal ICU 4.4 TODO: propose for 4.6 * @provisional This API might change or be removed in a future release. */ public Appendable normalize(CharSequence src, Appendable dest) { if(dest==src) { throw new IllegalArgumentException(); } return normalize(src, dest, UnicodeSet.SpanCondition.SIMPLE); } /** {@inheritDoc} * @draft ICU 4.4 * @provisional This API might change or be removed in a future release. */ @Override public StringBuilder normalizeSecondAndAppend( StringBuilder first, CharSequence second) { return normalizeSecondAndAppend(first, second, true); } /** {@inheritDoc} * @draft ICU 4.4 * @provisional This API might change or be removed in a future release. */ @Override public StringBuilder append(StringBuilder first, CharSequence second) { return normalizeSecondAndAppend(first, second, false); } /** {@inheritDoc} * @draft ICU 4.4 * @provisional This API might change or be removed in a future release. */ @Override public boolean isNormalized(CharSequence s) { UnicodeSet.SpanCondition spanCondition=UnicodeSet.SpanCondition.SIMPLE; for(int prevSpanLimit=0; prevSpanLimit