Class SmilyFilter
java.lang.Object
org.shredzone.commons.text.filter.SmilyFilter
- All Implemented Interfaces:
Function<CharSequence,CharSequence>
,TextFilter
A filter that detects smily sequences, and replaces them with an image. The filter
tries to find the best match by the string length of the smily code, so it can safely
distinguish between smilies like ":-)" and ":-))".
- Author:
- Richard "Shred" Körber
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a smily to be detected.apply(CharSequence text)
Applies the filter on aCharSequence
and returns a newCharSequence
with the modified text.void
setBaseUrl(String url)
Sets the base url that is prepended to the image file names.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.shredzone.commons.text.TextFilter
toStringBuilder
-
Constructor Details
-
SmilyFilter
public SmilyFilter()Creates a newSmilyFilter
.
-
-
Method Details
-
addSmily
Adds a smily to be detected.- Parameters:
smily
- Smily code to detect (e.g. ":-)")image
- Image file name to be shown instead
-
setBaseUrl
Sets the base url that is prepended to the image file names.- Parameters:
url
- Base url (e.g. "/img/smiles"), defaults to the current directory
-
apply
Description copied from interface:TextFilter
Applies the filter on aCharSequence
and returns a newCharSequence
with the modified text.- Specified by:
apply
in interfaceFunction<CharSequence,CharSequence>
- Specified by:
apply
in interfaceTextFilter
- Parameters:
text
-CharSequence
with the contents to be filtered. If this is aStringBuilder
instance, its contents may have changed after invocation, and this instance should not be used any more.- Returns:
CharSequence
with the filtered text.
-