humanize.text.util.UnicodeInterpolator Maven / Gradle / Ivy
The newest version!
package humanize.text.util;
import java.util.ArrayList;
import java.util.Collection;
import com.google.common.collect.Range;
import com.google.common.escape.UnicodeEscaper;
public class UnicodeInterpolator extends UnicodeEscaper
{
private final Replacer replacer;
private final Collection> ranges;
public UnicodeInterpolator(Replacer replacer)
{
this.replacer = replacer;
this.ranges = new ArrayList>();
}
public void addRange(int lower, int upper)
{
addRange(Range.closed(lower, upper));
}
public void addRange(Range range)
{
ranges.add(range);
}
@Override
protected char[] escape(int codePoint)
{
for (Range range : ranges)
{
if (range.contains(codePoint))
{
return replacer.replace(Integer.toHexString(codePoint)).toCharArray();
}
}
return Character.toChars(codePoint);
}
}