Class DefaultExpander

  • All Implemented Interfaces:
    Expander

    public class DefaultExpander
    extends java.lang.Object
    implements Expander
    Default implementation of the Expander interface.

    This expander provides functionality for expanding special syntax in command lines, including:

    • History expansions (e.g., !!, !$, !n, etc.)
    • Variable expansions (e.g., $HOME, ${PATH})

    The history expansion syntax is similar to that used in Bash and other shells, allowing users to reference and reuse previous commands or parts of commands.

    The expander is used by the LineReader to process the command line after the user has accepted it but before it is executed or added to the history.

    See Also:
    Expander, LineReader
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultExpander()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String expandHistory​(History history, java.lang.String line)
      Expand event designator such as !!, !#, !3, etc...
      java.lang.String expandVar​(java.lang.String word)
      Expands variables in the input word.
      protected int searchBackwards​(History history, java.lang.String searchTerm, int startIndex, boolean startsWith)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultExpander

        public DefaultExpander()
    • Method Detail

      • expandHistory

        public java.lang.String expandHistory​(History history,
                                              java.lang.String line)
        Expand event designator such as !!, !#, !3, etc... See http://www.gnu.org/software/bash/manual/html_node/Event-Designators.html
        Specified by:
        expandHistory in interface Expander
        Parameters:
        history - the command history to use for expansion
        line - the input line containing history references
        Returns:
        the line with history references expanded
      • expandVar

        public java.lang.String expandVar​(java.lang.String word)
        Description copied from interface: Expander
        Expands variables in the input word.

        This method processes variable references such as $VAR or ${VAR}, replacing them with their values. The specific syntax and behavior depends on the implementation.

        Specified by:
        expandVar in interface Expander
        Parameters:
        word - the word containing variable references
        Returns:
        the word with variables expanded
      • searchBackwards

        protected int searchBackwards​(History history,
                                      java.lang.String searchTerm,
                                      int startIndex,
                                      boolean startsWith)