Class StringSanitizer

  • All Implemented Interfaces:
    AdditionalInformationHandler, CleanUpHandler, Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<Actor>, SizeOfHandler, Stoppable, StoppableWithFeedback, VariablesInspectionHandler, VariableChangeListener, Actor, ErrorHandler, InputConsumer, OutputProducer, Serializable, Comparable

    public class StringSanitizer
    extends AbstractStringOperation
    Removes all characters that haven't been specified as 'acceptable' characters. The matching sense can also be inverted, i.e., 'acceptable' characters become 'outlawed' ones.

    Input/output:
    - accepts:
       java.lang.String
       java.lang.String[]
    - generates:
       java.lang.String
       java.lang.String[]


    Valid options are:

    -D (property: debug)
        If set to true, scheme may output additional info to the console.
     
    -name <java.lang.String> (property: name)
        The name of the actor.
        default: StringSanitizer
     
    -annotation <adams.core.base.BaseText> (property: annotations)
        The annotations to attach to this actor.
        default:
     
    -skip (property: skip)
        If set to true, transformation is skipped and the input token is just forwarded
        as it is.
     
    -acceptable <java.lang.String> (property: acceptableChars)
        The allowed characters, all others will get removed (or replaced).
        default: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-
     
    -replace <java.lang.String> (property: replacementChar)
        The character to replace the 'unacceptable' characters with; use the empty
        string if you want to remove 'unacceptable' characters.
        default:
     
    -V (property: invertMatching)
        If set to true, then 'acceptable' characters will become 'outlaws', ie,
        replaced or removed.
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_AcceptableChars

        protected String m_AcceptableChars
        the characters that are allowed.
      • m_ReplacementChar

        protected String m_ReplacementChar
        the character to replace the unacceptable ones.
      • m_InvertMatching

        protected boolean m_InvertMatching
        whether to invert the matching.
    • Constructor Detail

      • StringSanitizer

        public StringSanitizer()
    • Method Detail

      • setAcceptableChars

        public void setAcceptableChars​(String value)
        Sets the 'acceptable' characters.
        Parameters:
        value - the characters
      • getAcceptableChars

        public String getAcceptableChars()
        Returns the 'acceptable' characters.
        Returns:
        the characters
      • acceptableCharsTipText

        public String acceptableCharsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setReplacementChar

        public void setReplacementChar​(String value)
        Sets the character to replace the unacceptable characters with. If empty, then characters will be just removed.
        Parameters:
        value - the character
      • getReplacementChar

        public String getReplacementChar()
        Returns the character to replace the unacceptable characters with. If empty, then characters will be just removed.
        Returns:
        the character
      • replacementCharTipText

        public String replacementCharTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setInvertMatching

        public void setInvertMatching​(boolean value)
        Sets whether to invert the matching sense.
        Parameters:
        value - if true then 'acceptable' characters are treated as 'outlaws'
      • getInvertMatching

        public boolean getInvertMatching()
        Returns whether all occurrences are replaced or only the first one.
        Returns:
        true if all are to be replaced, false if only the first
      • invertMatchingTipText

        public String invertMatchingTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • process

        protected String process​(String s,
                                 int index)
        Processes the string.
        Specified by:
        process in class AbstractStringOperation
        Parameters:
        s - the string to process
        index - the 0-based index of the string currently being processed
        Returns:
        the processed string or null if nothing produced