cz.jalasoft.util.text.FragmentConverters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JalasoftUtils Show documentation
Show all versions of JalasoftUtils Show documentation
A collection of utility classes that might be useful.
package cz.jalasoft.util.text;
import com.google.common.base.CharMatcher;
import cz.jalasoft.util.converter.ConversionException;
import cz.jalasoft.util.converter.Converter;
/**
* Created by honzales on 9.6.15.
*/
public class FragmentConverters {
public static > Converter withoutCharacters(final CharMatcher matcher) {
return new Converter() {
@Override
public TextFragment convert(T from) throws ConversionException {
String newText = matcher.removeFrom(from.text());
return Fragment.fromText(newText);
}
};
}
public static Converter toHtmlEscaped() {
return new Converter() {
@Override
public TextFragment convert(TextFragment from) throws ConversionException {
String text = from.text();
String newText = text.replace("&", "&");
return Fragment.fromText(newText);
}
};
}
}