Package ghidra.util

Class StringUtilities


  • public class StringUtilities
    extends java.lang.Object
    Class with static methods that deal with string manipulation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      ChangeModifier and Type Method Description
      static java.lang.String characterToString​(char c)
      Converts the character into a string.
      static boolean containsAll​(java.lang.CharSequence toSearch, java.lang.CharSequence... searches)
      Returns true if all the given searches are contained in the given string.
      static boolean containsAllIgnoreCase​(java.lang.CharSequence toSearch, java.lang.CharSequence... searches)
      Returns true if all the given searches are contained in the given string, ignoring case.
      static boolean containsAnyIgnoreCase​(java.lang.CharSequence toSearch, java.lang.CharSequence... searches)
      Returns true if any of the given searches are contained in the given string, ignoring case.
      static java.lang.String convertCodePointToEscapeSequence​(int codePoint)
      Maps known control characters to corresponding escape sequences.
      static java.lang.String convertControlCharsToEscapeSequences​(java.lang.String str)
      Replaces known control characters in a string to corresponding escape sequences.
      static java.lang.String convertEscapeSequences​(java.lang.String str)
      Replaces escaped characters in a string to corresponding control characters.
      NEWstatic java.lang.String convertTabsToSpaces​(java.lang.String str)
      Convert tabs in the given string to spaces using a default tab width of 8 spaces.
      static java.lang.String convertTabsToSpaces​(java.lang.String str, int tabSize)
      Convert tabs in the given string to spaces.
      static int countOccurrences​(java.lang.String string, char occur)
      Returns a count of how many times the 'occur' char appears in the strings.
      static boolean endsWithIgnoreCase​(java.lang.String string, java.lang.String postfix)
      Returns true if the given string ends with postfix, ignoring case.
      static boolean endsWithWhiteSpace​(java.lang.String string)  
      static boolean equals​(java.lang.String s1, java.lang.String s2, boolean caseSensitive)  
      static java.lang.String extractFromDoubleQuotes​(java.lang.String str)
      If the given string is enclosed in double quotes, extract the inner text.
      static int findLastWordPosition​(java.lang.String s)
      Finds the starting position of the last word in the given string.
      static java.lang.String findWord​(java.lang.String s, int index)
      Finds the word at the given index in the given string.
      static java.lang.String findWord​(java.lang.String s, int index, char[] charsToAllow)
      Finds the word at the given index in the given string; if the word contains the given charToAllow, then allow it in the string.
      static WordLocation findWordLocation​(java.lang.String s, int index, char[] charsToAllow)  
      static java.lang.String fixMultipleAsterisks​(java.lang.String value)
      This method looks for all occurrences of successive asterisks (i.e., "**") and replace with a single asterisk, which is an equivalent usage in Ghidra.
      static java.lang.String getLastWord​(java.lang.String s, java.lang.String separator)
      Takes a path-like string and retrieves the last non-empty item.
      static java.lang.String indentLines​(java.lang.String s, java.lang.String indent)
      Splits the given string into lines using \n and then pads each string with the given pad string.
      static int indexOfWord​(java.lang.String text, java.lang.String searchWord)
      Returns the index of the first whole word occurrence of the search word within the given text.
      static boolean isAllBlank​(java.lang.CharSequence... sequences)
      Returns true if all the given sequences are either null or only whitespace
      static boolean isAsciiChar​(char c)
      Returns true if the given character is within the ascii range.
      static boolean isAsciiChar​(int codePoint)
      Returns true if the given code point is within the ascii range.
      static boolean isControlCharacterOrBackslash​(char c)
      Returns true if the given character is a special character.
      static boolean isControlCharacterOrBackslash​(int codePoint)
      Returns true if the given codePoint (ie.
      static boolean isDisplayable​(int c)
      Returns true if the character is in displayable character range
      static boolean isDoubleQuoted​(java.lang.String str)
      Determines if a string is enclosed in double quotes (ASCII 34 (0x22))
      static boolean isValidCLanguageChar​(char c)
      Returns true if the character is OK to be contained inside C language string.
      static boolean isWholeWord​(java.lang.String text, int startIndex, int length)
      Returns true if the substring within the text string starting at startIndex and having the given length is a whole word.
      static boolean isWordChar​(char c, char[] charsToAllow)
      Loosely defined as a character that we would expected to be an normal ascii content meant for consumption by a human.
      static java.lang.String mergeStrings​(java.lang.String string1, java.lang.String string2)
      Merge two strings into one.
      static java.lang.String pad​(java.lang.String source, char filler, int length)
      Pads the source string to the specified length, using the filler string as the pad.
      static boolean startsWithIgnoreCase​(java.lang.String string, java.lang.String prefix)
      Returns true if the given string starts with prefix ignoring case.
      static java.lang.String toFixedSize​(java.lang.String s, char pad, int size)
      Enforces the given length upon the given string by trimming and then padding as necessary.
      static java.lang.String[] toLines​(java.lang.String str)
      Parses a string containing multiple lines into an array where each element in the array contains only a single line.
      static java.lang.String[] toLines​(java.lang.String s, boolean preserveTokens)
      Parses a string containing multiple lines into an array where each element in the array contains only a single line.
      static java.lang.String toQuotedString​(byte[] bytes)
      Generate a quoted string from US-ASCII character bytes assuming 1-byte chars.
      static java.lang.String toQuotedString​(byte[] bytes, int charSize)
      Generate a quoted string from US-ASCII characters, where each character is charSize bytes.
      NEWstatic java.lang.String toStingJson​(java.lang.Object o)
      Creates a JSON string for the given object using all of its fields.
      static java.lang.String toString​(int value)
      Converts an integer into a string.
      static java.lang.String toStringWithIndent​(java.lang.Object o)  
      static java.lang.String trim​(java.lang.String original, int max)
      Limits the given string to the given max number of characters.
      static java.lang.String trimMiddle​(java.lang.String s, int max)
      Trims the given string the max number of characters.
      static java.lang.String trimTrailingNulls​(java.lang.String s)  
      REMOVED String reverse(String s)
      (Removed)
      REMOVED boolean isUnicodeReplacementCodePoint(int codePoint)
      (Removed)
      • Methods inherited from class java.lang.Object

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

      • DOUBLE_QUOTED_STRING_PATTERN

        public static final java.util.regex.Pattern DOUBLE_QUOTED_STRING_PATTERN
      • LINE_SEPARATOR

        public static final java.lang.String LINE_SEPARATOR
        The platform specific string that is the line separator.
      • UNICODE_BE_BYTE_ORDER_MARK

        public static final int UNICODE_BE_BYTE_ORDER_MARK
        Unicode Byte Order Marks (BOM) characters are special characters in the Unicode character space that signal endian-ness of the text.

        The value for the BigEndian version (0xFEFF) works for both 16 and 32 bit character values.

        There are separate values for Little Endian Byte Order Marks for 16 and 32 bit characters because the 32 bit value is shifted left by 16 bits.

        See Also:
        Constant Field Values
      • UNICODE_LE16_BYTE_ORDER_MARK

        public static final int UNICODE_LE16_BYTE_ORDER_MARK
        See Also:
        Constant Field Values
      • UNICODE_LE32_BYTE_ORDER_MARK

        public static final int UNICODE_LE32_BYTE_ORDER_MARK
        See Also:
        Constant Field Values

Method Detail

  • convertTabsToSpaces NEW

    public static java.lang.String convertTabsToSpaces​(java.lang.String str)
    Convert tabs in the given string to spaces using a default tab width of 8 spaces.
    Parameters:
    str - string containing tabs
    Returns:
    string that has spaces for tabs
  • toStingJson NEW

    public static java.lang.String toStingJson​(java.lang.Object o)
    Creates a JSON string for the given object using all of its fields. To control the fields that are in the result string, see Json.

    This is here as a marker to point users to the real Json String utility.

    Parameters:
    o - the object for which to create a string
    Returns:
    the string