|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gjt.sp.jedit.MiscUtilities
Path name manipulation, string manipulation, and more.
The most frequently used members of this class are:
Some path name methods:
String comparison:
A compareStrings(String,String,boolean)
method that unlike
This class also defines several inner classes for use with the sorting features of the Java collections API:
For example, you might call:
Arrays.sort(myListOfStrings,
new MiscUtilities.StringICaseCompare());
Nested Class Summary | |
static interface |
MiscUtilities.Compare
An interface for comparing objects. |
static class |
MiscUtilities.MenuItemCompare
Compares menu item labels. |
static class |
MiscUtilities.StringCompare
Compares strings. |
static class |
MiscUtilities.StringICaseCompare
Compares strings ignoring case. |
Field Summary | |
static DecimalFormat |
KB_FORMAT
|
static DecimalFormat |
MB_FORMAT
|
static String |
UTF_8_Y
This encoding is not supported by Java, yet it is useful. |
Method Summary | |
static String |
buildToVersion(String build)
Converts an internal version number (build) into a `human-readable' form. |
static String |
canonPath(String path)
Returns the canonical form of the specified path name. |
static String |
charsToEntities(String str)
Converts <, >, & in the string to their HTML entity equivalents. |
static 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 String |
classToFile(String name)
Converts a class name to a file name. |
static int |
compareStrings(String str1,
String str2,
boolean ignoreCase)
Compares two strings. |
static int |
compareVersions(String v1,
String v2)
Deprecated. Call compareStrings() instead |
static String |
concatPath(String parent,
String path)
Like constructPath(java.lang.String, java.lang.String) , except path will be
appended to parent even if it is absolute. |
static String |
constructPath(String parent,
String path)
Constructs an absolute path name from a directory and another path name. |
static String |
constructPath(String parent,
String path1,
String path2)
Constructs an absolute path name from three path components. |
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 |
escapesToChars(String str)
Converts "\n" and "\t" escapes in the specified string to newlines and tabs. |
static String |
fileToClass(String name)
Converts a file name to a class name. |
static String |
formatFileSize(long length)
Formats the given file size into a nice string (123 bytes, 10.6 KB, 1.2 MB). |
static String[] |
getEncodings()
Returns a list of supported character encodings. |
static String |
getFileExtension(String name)
Returns the extension of the specified filename, or an empty string if there is none. |
static String |
getFileName(String path)
Returns the last component of the specified path. |
static String |
getFileNameNoExtension(String path)
Returns the last component of the specified path name without the trailing extension (if there is one). |
static String |
getFileParent(String path)
Deprecated. Call getParentOfPath() instead |
static String |
getFileProtocol(String url)
Deprecated. Call getProtocolOfURL() instead |
static int |
getLeadingWhiteSpace(String str)
Returns the number of leading white space characters in the specified string. |
static int |
getLeadingWhiteSpaceWidth(String str,
int tabSize)
Returns the width of the leading white space in the specified string. |
static String |
getLongestPrefix(List str,
boolean ignoreCase)
Returns the longest common prefix in the given set of strings. |
static String |
getLongestPrefix(Object[] str,
boolean ignoreCase)
Returns the longest common prefix in the given set of strings. |
static String |
getLongestPrefix(String[] str,
boolean ignoreCase)
Returns the longest common prefix in the given set of strings. |
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 String |
getParentOfPath(String path)
Returns the parent of the specified path. |
static String |
getProtocolOfURL(String url)
Returns the protocol specified by a URL. |
static int |
getTrailingWhiteSpace(String str)
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 |
globToRE(String glob)
Converts a Unix-style glob to a regular expression. |
static boolean |
isAbsolutePath(String path)
Returns if the specified path name is an absolute path or URL. |
static boolean |
isSupportedEncoding(String encoding)
Returns if the given character encoding is supported. |
static boolean |
isToolsJarAvailable()
If on JDK 1.2 or higher, make sure that tools.jar is available. |
static boolean |
isURL(String str)
Checks if the specified string is a URL. |
static boolean |
objectsEqual(Object o1,
Object o2)
Returns if two strings are equal. |
static int |
parsePermissions(String s)
Parse a Unix-style permission string (rwxrwxrwx). |
static void |
quicksort(List list,
Comparator compare)
Sorts the specified list. |
static void |
quicksort(Object[] obj,
Comparator compare)
Sorts the specified array. |
static void |
quicksort(Object[] obj,
MiscUtilities.Compare compare)
Sorts the specified array. |
static void |
quicksort(Vector vector,
Comparator compare)
Sorts the specified vector. |
static void |
quicksort(Vector vector,
MiscUtilities.Compare compare)
Sorts the specified vector. |
static String |
resolveSymlinks(String path)
Resolves any symbolic links in the path name specified using File.getCanonicalPath() . |
static void |
saveBackup(File file,
int backups,
String backupPrefix,
String backupSuffix,
String backupDirectory)
Saves a backup (optionally numbered) of a file. |
static void |
saveBackup(File file,
int backups,
String backupPrefix,
String backupSuffix,
String backupDirectory,
int backupTimeDistance)
Saves a backup (optionally numbered) of a file. |
static boolean |
stringsEqual(String s1,
String s2)
Deprecated. Call objectsEqual() instead. |
static String |
throwableToString(Throwable t)
Returns a string containing the stack trace of the given throwable. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String UTF_8_Y
public static final DecimalFormat KB_FORMAT
public static final DecimalFormat MB_FORMAT
Method Detail |
public static String canonPath(String path)
~
. For local path names
only.
path
- The path namepublic static String resolveSymlinks(String path)
File.getCanonicalPath()
. For local path
names only.
public static boolean isAbsolutePath(String path)
public static String constructPath(String parent, String path)
parent
- The directorypath
- The path namepublic static String constructPath(String parent, String path1, String path2)
parent
- The parent directorypath1
- The first pathpath2
- The second pathpublic static String concatPath(String parent, String path)
constructPath(java.lang.String, java.lang.String)
, except path
will be
appended to parent
even if it is absolute.
For local path names only..
path
- parent
- public static String getFileExtension(String name)
name
- The file name or pathpublic static String getFileName(String path)
path
- The path namepublic static String getFileNameNoExtension(String path)
path
- The path namepublic static String getFileParent(String path)
public static String getParentOfPath(String path)
path
- The path namepublic static String getFileProtocol(String url)
public static String getProtocolOfURL(String url)
url
- The URLpublic static boolean isURL(String str)
str
- The string to check
public static void saveBackup(File file, int backups, String backupPrefix, String backupSuffix, String backupDirectory)
file
- A local filebackups
- The number of backups. Must be >= 1. If > 1, backup
files will be numbered.backupPrefix
- The backup file name prefixbackupSuffix
- The backup file name suffixbackupDirectory
- The directory where to save backups; if null,
they will be saved in the same directory as the file itself.public static void saveBackup(File file, int backups, String backupPrefix, String backupSuffix, String backupDirectory, int backupTimeDistance)
file
- A local filebackups
- The number of backups. Must be >= 1. If > 1, backup
files will be numbered.backupPrefix
- The backup file name prefixbackupSuffix
- The backup file name suffixbackupDirectory
- The directory where to save backups; if null,
they will be saved in the same directory as the file itself.backupTimeDistance
- The minimum time in minutes when a backup
version 1 shall be moved into version 2; if 0, backups are always
moved.public static String fileToClass(String name)
name
- The file namepublic static String classToFile(String name)
name
- The class namepublic static int getLeadingWhiteSpace(String str)
str
- The stringpublic static int getTrailingWhiteSpace(String str)
str
- The stringpublic static int getLeadingWhiteSpaceWidth(String str, int tabSize)
str
- The stringtabSize
- The tab sizepublic static int getVirtualWidth(Segment seg, int tabSize)
seg
- The segmenttabSize
- The tab sizepublic static int getOffsetOfVirtualColumn(Segment seg, int tabSize, int column, int[] totalVirtualWidth)
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.
public static String createWhiteSpace(int len, int tabSize)
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()));
len
- The lengthtabSize
- The tab size, or 0 if tabs are not to be usedpublic static String createWhiteSpace(int len, int tabSize, int start)
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()));
len
- The lengthtabSize
- The tab size, or 0 if tabs are not to be usedstart
- The start offset, for tab alignmentpublic static String globToRE(String glob)
? becomes ., * becomes .*, {aa,bb} becomes (aa|bb).
glob
- The glob patternpublic static String escapesToChars(String str)
str
- The stringpublic static String charsToEscapes(String str)
str
- The stringpublic static String charsToEscapes(String str, String toEscape)
str
- The stringtoEscape
- Any characters that require escapingpublic static int compareVersions(String v1, String v2)
compareStrings()
instead
public static int compareStrings(String str1, String str2, boolean ignoreCase)
Unlike
str1
- The first stringstr2
- The second stringignoreCase
- If true, case will be ignored
public static boolean stringsEqual(String s1, String s2)
objectsEqual()
instead.
public static boolean objectsEqual(Object o1, Object o2)
o1.equals(o2)
.
public static String charsToEntities(String str)
str
- The stringpublic static String formatFileSize(long length)
length
- The sizepublic static String getLongestPrefix(List str, boolean ignoreCase)
str
- The stringsignoreCase
- If true, case insensitivepublic static String getLongestPrefix(String[] str, boolean ignoreCase)
str
- The stringsignoreCase
- If true, case insensitivepublic static String getLongestPrefix(Object[] str, boolean ignoreCase)
str
- The strings (calls toString()
on each object)ignoreCase
- If true, case insensitivepublic static void quicksort(Object[] obj, Comparator compare)
Arrays.sort()
.
obj
- The arraycompare
- Compares the objectspublic static void quicksort(Vector vector, Comparator compare)
vector
- The vectorcompare
- Compares the objectspublic static void quicksort(List list, Comparator compare)
list
- The listcompare
- Compares the objectspublic static void quicksort(Object[] obj, MiscUtilities.Compare compare)
Arrays.sort()
.
obj
- The arraycompare
- Compares the objectspublic static void quicksort(Vector vector, MiscUtilities.Compare compare)
vector
- The vectorcompare
- Compares the objectspublic static String buildToVersion(String build)
build
- The buildpublic static boolean isToolsJarAvailable()
tools.jar is searched for in the following places:
On older JDK's this method does not perform any checks, and returns
true
(even though there is no tools.jar).
false
if and only if on JDK 1.2 and tools.jar
could not be found. In this case it prints some warnings on Log,
too, about the places where it was searched for.public static int parsePermissions(String s)
s
- The string (must be 9 characters long).public static String[] getEncodings()
public static boolean isSupportedEncoding(String encoding)
public static String throwableToString(Throwable t)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |