Class StringUtils
java.lang.Object
org.openjdk.asmtools.asmutils.StringUtils
Utility class for string operations related to ASM tools.
This class provides methods for removing comments from strings, converting UTF-8 strings to printable formats, and handling character encoding in a way that is suitable for assembly tools.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcharToUtf8String(char c) Converts a character to its UTF-8 string representation.getPrintable(byte[] buffer, int CHARS_IN_LINE) getPrintable(String rawString, int CHARS_IN_LINE) static booleanisOneOf(int i, char... list) Checks that ch is in the liststatic booleanisPrintableChar(char c) Checks if the character is printable.static StringListToString(List<String> list) Converts a list of strings to a formatted string representation.static StringListToString(List<String> list, String separators) Converts a list of strings to a formatted string representation.static StringmapToHexString(int[] array) Converts an array of integers to a hex string representation.readUtf8String(DataInputStream in, int length, int CHARS_IN_LINE) Reads the set of bytes if all bytes are printable then they will be printed as the string "String"; otherwise the byte array 0x0F 0xB6 0x00 0x11; The result is the list of lines for printing.static StringremoveCommentFrom(String str) Removes Java comments from String Spaces ahead of comments will be removed; alternatively, if no spaces precede the comment, the space after it will be deleted.static StringremoveNonPrintableAscii(String input) Removes non-printable ASCII characters from the given input string.static Stringstatic StringUtf8ToString(String utf8, String... enclosingString) Converts CONSTANT_Utf8_info string to a printable string for jdis/jdec.Utf8ToStringList(String utf8, int strLength) Converts CONSTANT_Utf8_info string to a printable list of strings
-
Field Details
-
hexTable
public static final char[] hexTable -
endWith
-
contains
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
removeCommentFrom
-
Utf8ToString
Converts CONSTANT_Utf8_info string to a printable string for jdis/jdec.- Parameters:
utf8- UTF8 string taken from within ConstantPool of a class fileenclosingString- strings to enclose output string- Returns:
- output string for jcod/jasm
-
Utf8ToStringList
Converts CONSTANT_Utf8_info string to a printable list of strings- Parameters:
utf8- UTF8 string taken from within ConstantPool of a class filestrLength- the maximum length of each string in the resulting list- Returns:
- list of strings for jcod/jasm
-
charToUtf8String
Converts a character to its UTF-8 string representation.Control characters and special characters are escaped using the appropriate escape sequences. Other characters are returned as is.
- Parameters:
c- the character to convert- Returns:
- the UTF-8 string representation of the character
-
isOneOf
public static boolean isOneOf(int i, char... list) Checks that ch is in the list- Parameters:
i- char for testinglist- of chars- Returns:
- true if char ch found in the list
-
readUtf8String
public static List<String> readUtf8String(DataInputStream in, int length, int CHARS_IN_LINE) throws IOException Reads the set of bytes if all bytes are printable then they will be printed as the string "String"; otherwise the byte array 0x0F 0xB6 0x00 0x11; The result is the list of lines for printing.- Parameters:
in- input stream to get bytes for printinglength- number of bytesCHARS_IN_LINE- max chars in line prepared for printing- Returns:
- list of lines for printing
- Throws:
IOException- exception might happen while reading DataInputStream
-
getPrintable
-
getPrintable
-
removeNonPrintableAscii
Removes non-printable ASCII characters from the given input string.Non-printable ASCII characters are those with ASCII values outside the range of 32 (space) to 126 (tilde).
- Parameters:
input- the input string to be processed- Returns:
- a new string with non-printable ASCII characters removed, or null if the input is null
-
ListToString
-
ListToString
Converts a list of strings to a formatted string representation. The output is enclosed in square brackets and elements are separated by a specified delimiter.- Parameters:
list- the list of strings to convertseparators- a string containing the prefix, delimiter, and postfix characters (e.g., "[,]"), where: - first character is the prefix, - second character is the delimiter, - third character is the postfix.- Returns:
- a formatted string representation of the list
-
mapToHexString
Converts an array of integers to a hex string representation. Each integer is converted to its hexadecimal format and joined with commas.- Parameters:
array- the array of integers to convert- Returns:
- a string representation of the array in hexadecimal format
-
repeat
-
isPrintableChar
public static boolean isPrintableChar(char c) Checks if the character is printable. A character is considered printable if it is not a control character, is not undefined, and belongs to a valid Unicode block that is not SPECIALS.- Parameters:
c- the character to check- Returns:
- true if the character is printable, false otherwise
-