Class Parser

java.lang.Object
org.aesh.readline.util.Parser

public class Parser extends Object
String/Parser util methods
Author:
Ståle W. Pedersen invalid input: '<'stale.pedersen@jboss.org>
  • Field Details

  • Constructor Details

    • Parser

      public Parser()
  • Method Details

    • formatDisplayList

      public static String formatDisplayList(String[] displayList, int termHeight, int termWidth)
      Format completions so that they look similar to GNU Readline
      Parameters:
      displayList - to format
      termHeight - max height
      termWidth - max width
      Returns:
      formatted string to be outputted
    • formatDisplayList

      public static String formatDisplayList(List<String> displayList, int termHeight, int termWidth)
      Format completions so that they look similar to GNU Readline
      Parameters:
      displayList - to format
      termHeight - max height
      termWidth - max width
      Returns:
      formatted string to be outputted
    • formatDisplayListTerminalString

      public static String formatDisplayListTerminalString(List<TerminalString> displayList, int termHeight, int termWidth)
      Format completions so that they look similar to GNU Readline
      Parameters:
      displayList - to format
      termHeight - max height
      termWidth - max width
      Returns:
      formatted string to be outputted
    • formatDisplayCompactListTerminalString

      public static String formatDisplayCompactListTerminalString(List<TerminalString> displayList, int termWidth)
      Format output to columns with flexible sizes and no redundant space between them
      Parameters:
      displayList - to format
      termWidth - max width
      Returns:
      formatted string to be outputted
    • padRight

      public static String padRight(int n, String s)
    • padLeft

      public static String padLeft(int n, String s)
    • splitBySizeKeepWords

      public static List<String> splitBySizeKeepWords(String words, int size)
    • trimOptionName

      public static String trimOptionName(String word)
      remove leading dashes from word
    • findIfWordEndWithSpace

      public static boolean findIfWordEndWithSpace(String word)
    • findStartsWithOperation

      public static String findStartsWithOperation(List<? extends CompleteOperation> coList)
      If there is any common start string in the completion list, return it
      Parameters:
      coList - completion list
      Returns:
      common start string
    • findStartsWith

      public static String findStartsWith(List<String> completionList)
      Return the biggest common startsWith string
      Parameters:
      completionList - list to compare
      Returns:
      biggest common startsWith string
    • findStartsWithTerminalString

      public static String findStartsWithTerminalString(List<TerminalString> completionList)
      Return the biggest common startsWith string
      Parameters:
      completionList - list to compare
      Returns:
      biggest common startsWith string
    • findWordClosestToCursor

      public static String findWordClosestToCursor(String text, int cursor)
    • findCurrentWordFromCursor

      public static String findCurrentWordFromCursor(String text, int cursor)
      Return the word "connected" to cursor, the word ends at cursor position. Note that cursor position starts at 0
      Parameters:
      text - to parse
      cursor - position
      Returns:
      word connected to cursor
    • findEscapedSpaceWordCloseToEnd

      public static String findEscapedSpaceWordCloseToEnd(String text)
      Search backwards for a non-escaped space and only return work containing non-escaped space
      Parameters:
      text - text
      Returns:
      text with only non-escaped space
    • doesStringContainOpenQuote

      public static boolean doesStringContainOpenQuote(String text, int flags)
      Check if a string contain open quotes. Escaped quotes does not count.
      Parameters:
      text - text
      flags - flags, 1 to ignore double quotes, 2 to ignore single quotes. Other values will check for both.
      Returns:
      true if it contains open quotes, else false
    • doesStringContainOpenQuote

      public static boolean doesStringContainOpenQuote(String text)
    • doWordContainOnlyEscapedSpace

      public static boolean doWordContainOnlyEscapedSpace(String word)
    • doWordContainEscapedSpace

      public static boolean doWordContainEscapedSpace(String word)
    • findNumberOfSpacesInWord

      public static int findNumberOfSpacesInWord(String word)
      find number of spaces in the given word. escaped spaces are not counted
      Parameters:
      word - to check
      Returns:
      number of spaces
    • findAllOccurrences

      public static int findAllOccurrences(String word, String pattern)
    • switchEscapedSpacesToSpacesInList

      public static List<String> switchEscapedSpacesToSpacesInList(List<String> list)
    • switchEscapedSpacesToSpacesInTerminalStringList

      public static void switchEscapedSpacesToSpacesInTerminalStringList(List<TerminalString> list)
    • switchSpacesToEscapedSpacesInWord

      public static String switchSpacesToEscapedSpacesInWord(String word)
    • switchEscapedSpacesToSpacesInWord

      public static String switchEscapedSpacesToSpacesInWord(String word)
    • trim

      public static String trim(String buffer)
      Similar to String.trim(), but do not remove spaces that are escaped
      Parameters:
      buffer - input
      Returns:
      trimmed buffer
    • trimInFront

      public static String trimInFront(String buffer)
      Only trim space in front of the word
      Parameters:
      buffer - input
      Returns:
      trimmed buffer
    • findFirstWord

      public static String findFirstWord(String buffer)
      If string contain space, return the text before the first space. Spaces in the beginning and end is removed with Parser.trim(..)
      Parameters:
      buffer - input
      Returns:
      first word
    • containsNonEscapedDollar

      public static boolean containsNonEscapedDollar(String buffer)
    • containsNonEscapedSpace

      public static boolean containsNonEscapedSpace(String buffer)
    • stripAwayAnsiCodes

      public static String stripAwayAnsiCodes(String text)
    • toCodePoints

      public static int[] toCodePoints(String s)
    • fromCodePoints

      public static String fromCodePoints(int[] input)
    • isTrimmedArrayEmpty

      public static boolean isTrimmedArrayEmpty(int[] input)
    • arrayIndexOf

      public static int arrayIndexOf(int[] source, int[] target)
    • arrayIndexOf

      public static int arrayIndexOf(int[] source, int sourceOffset, int sourceCount, int[] target, int targetOffset, int targetCount, int fromIndex)
    • arrayContains

      public static boolean arrayContains(int[] source, int[] target)