java.lang.Object
org.gjt.sp.util.StandardUtilities
Several tools that depends on JDK only.
- Since:
- 4.3pre5
- Version:
- $Id: StandardUtilities.java 25030 2020-03-25 20:30:05Z kpouer $
- Author:
- Matthieu Casanova
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Compares objects as strings. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String[]
static final DecimalFormat
static final DecimalFormat
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
charsToEscapes
(String str) Escapes newlines, tabs, backslashes, and quotes in the specified string.static String
charsToEscapes
(String str, String toEscape) Escapes the specified characters in the specified string.static int
compareStrings
(String str1, String str2, boolean ignoreCase) Compares two strings.static String
createWhiteSpace
(int len, int tabSize) Creates a string of white space with the specified length.static String
createWhiteSpace
(int len, int tabSize, int start) Creates a string of white space with the specified length.static String
formatFileSize
(long length) Formats the given file size into a nice string (123 Bytes, 10.6 kB, 1.2 MB).static boolean
getBoolean
(Object obj, boolean def) Returns a boolean from a given object.static String
getIndentString
(String str) static int
Returns the number of leading white space characters in the specified string.static int
Returns the number of leading white space characters in the specified string.static int
getLeadingWhiteSpaceWidth
(CharSequence str, int tabSize) Returns the width of the leading white space in the specified string.static int
getLeadingWhiteSpaceWidth
(String str, int tabSize) Returns the width of the leading white space in the specified string.static int
getOffsetOfVirtualColumn
(Segment seg, int tabSize, int column, int[] totalVirtualWidth) Returns the array offset of a virtual column number (taking tabs into account) in the segment.static int
Returns the number of trailing whitespace characters in the specified string.static int
getVirtualWidth
(Segment seg, int tabSize) Returns the virtual column number (taking tabs into account) of the specified offset in the segment.static String
Converts a Unix-style glob to a regular expression.static byte[]
md5
(CharSequence charSequence) Returns the md5sum for given string.static boolean
objectsEqual
(Object o1, Object o2) Deprecated.use {java.util.Objects#equals(Object, Object}static boolean
regionMatches
(CharSequence seq, int toff, CharSequence other, int ooff, int len) Implementation of String.regionMatches() for CharSequence.static boolean
startsWith
(CharSequence seq, String str) Implementation of String.startsWith() for CharSequence.static String
truncateWhiteSpace
(int len, int tabSize, String indentStr)
-
Field Details
-
EMPTY_STRING_ARRAY
-
KB_FORMAT
-
MB_FORMAT
-
-
Method Details
-
charsToEscapes
Escapes newlines, tabs, backslashes, and quotes in the specified string.- Parameters:
str
- The string- Since:
- jEdit 4.3pre15
-
charsToEscapes
Escapes the specified characters in the specified string.- Parameters:
str
- The stringtoEscape
- Any characters that require escaping- Since:
- jEdit 4.3pre15
-
getIndentString
- Parameters:
str
- A java string- Returns:
- the leading whitespace of that string, for indenting subsequent lines.
- Since:
- jEdit 4.3pre10
-
getLeadingWhiteSpace
Returns the number of leading white space characters in the specified string.- Parameters:
str
- The string
-
getLeadingWhiteSpace
Returns the number of leading white space characters in the specified string.- Parameters:
str
- The string- Since:
- jEdit 4.3pre15
-
getTrailingWhiteSpace
Returns the number of trailing whitespace characters in the specified string.- Parameters:
str
- The string
-
getLeadingWhiteSpaceWidth
Returns the width of the leading white space in the specified string.- Parameters:
str
- The stringtabSize
- The tab size
-
getLeadingWhiteSpaceWidth
Returns the width of the leading white space in the specified string.- Parameters:
str
- The stringtabSize
- The tab size- Since:
- jEdit 4.3pre15
-
createWhiteSpace
Creates a string of white space with the specified length.To get a whitespace string tuned to the current buffer's settings, call this method as follows:
myWhitespace = MiscUtilities.createWhiteSpace(myLength, (buffer.getBooleanProperty("noTabs") ? 0 : buffer.getTabSize()));
- Parameters:
len
- The lengthtabSize
- The tab size, or 0 if tabs are not to be used
-
truncateWhiteSpace
-
createWhiteSpace
Creates a string of white space with the specified length.To get a whitespace string tuned to the current buffer's settings, call this method as follows:
myWhitespace = MiscUtilities.createWhiteSpace(myLength, (buffer.getBooleanProperty("noTabs") ? 0 : buffer.getTabSize()));
- Parameters:
len
- The lengthtabSize
- The tab size, or 0 if tabs are not to be usedstart
- The start offset, for tab alignment
-
getVirtualWidth
Returns the virtual column number (taking tabs into account) of the specified offset in the segment.- Parameters:
seg
- The segmenttabSize
- The tab size
-
getOffsetOfVirtualColumn
public static int getOffsetOfVirtualColumn(Segment seg, int tabSize, int column, int[] totalVirtualWidth) Returns the array offset of a virtual column number (taking tabs into account) in the segment.- Parameters:
seg
- The segmenttabSize
- The tab sizecolumn
- The virtual column numbertotalVirtualWidth
- If this array is non-null, the total virtual width will be stored in its first location if this method returns -1.- Returns:
- -1 if the column is out of bounds
-
compareStrings
Compares two strings.Unlike
String.compareTo()
, this method correctly recognizes and handles embedded numbers. For example, it places "My file 2" before "My file 10".- Parameters:
str1
- The first string (maybe null)str2
- The second string (maybe null)ignoreCase
- If true, case will be ignored- Returns:
- negative If str1 < str2, 0 if both are the same, positive if str1 > str2 (null < any non-null string, null = null)
- Since:
- jEdit 4.3pre5
-
objectsEqual
Deprecated.use {java.util.Objects#equals(Object, Object}Returns if two strings are equal. This correctly handles null pointers, as opposed to callingo1.equals(o2)
.- Since:
- jEdit 4.3pre6
-
globToRE
Converts a Unix-style glob to a regular expression.? becomes ., * becomes .*, {aa,bb} becomes (aa|bb).
- Parameters:
glob
- The glob pattern- Since:
- jEdit 4.3pre7
-
regionMatches
public static boolean regionMatches(CharSequence seq, int toff, CharSequence other, int ooff, int len) Implementation of String.regionMatches() for CharSequence.- Parameters:
seq
- The test CharSequence.toff
- Offset for the test sequence.other
- The sequence to compare to.ooff
- Offset of the comparison sequence.len
- How many characters to compare.- Returns:
- Whether the two subsequences are equal.
- Since:
- jEdit 4.3pre15
- See Also:
-
startsWith
Implementation of String.startsWith() for CharSequence.- Parameters:
seq
- The CharSequence.str
- String to test.- Returns:
- Whether the sequence starts with the test string.
- Since:
- jEdit 4.3pre15
-
getBoolean
Returns a boolean from a given object.- Parameters:
obj
- the objectdef
- The default value- Returns:
- the boolean value if obj is a Boolean, true if the value is "true", "yes", "on", false if the value is "false", "no", "off" def if the value is null or anything else
- Since:
- jEdit 4.3pre17
-
formatFileSize
Formats the given file size into a nice string (123 Bytes, 10.6 kB, 1.2 MB).- Parameters:
length
- The size- Since:
- jEdit 4.4pre1
-
md5
Returns the md5sum for given string. Or dummy byte array on error Suppress NoSuchAlgorithmException because MD5 algorithm always present in JRE- Parameters:
charSequence
- Given string- Returns:
- md5 sum of given string
-