org.gjt.sp.util
Class StandardUtilities

java.lang.Object
  extended by org.gjt.sp.util.StandardUtilities

public class StandardUtilities
extends java.lang.Object

Several tools that depends on JDK only.

Since:
4.3pre5

Nested Class Summary
static class StandardUtilities.StringCompare
          Compares objects as strings.
 
Method Summary
static int compareStrings(java.lang.String str1, java.lang.String str2, boolean ignoreCase)
          Compares two strings.
static java.lang.String createWhiteSpace(int len, int tabSize)
          Creates a string of white space with the specified length.
static java.lang.String createWhiteSpace(int len, int tabSize, int start)
          Creates a string of white space with the specified length.
static java.lang.String getIndentString(java.lang.String str)
           
static int getLeadingWhiteSpace(java.lang.String str)
          Returns the number of leading white space characters in the specified string.
static int getLeadingWhiteSpaceWidth(java.lang.String str, int tabSize)
          Returns the width of the leading white space in the specified string.
static int getOffsetOfVirtualColumn(javax.swing.text.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 getTrailingWhiteSpace(java.lang.String str)
          Returns the number of trailing whitespace characters in the specified string.
static int getVirtualWidth(javax.swing.text.Segment seg, int tabSize)
          Returns the virtual column number (taking tabs into account) of the specified offset in the segment.
static java.lang.String globToRE(java.lang.String glob)
          Converts a Unix-style glob to a regular expression.
static boolean objectsEqual(java.lang.Object o1, java.lang.Object o2)
          Returns if two strings are equal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getIndentString

public static java.lang.String getIndentString(java.lang.String str)
Parameters:
string - A java string
Returns:
the leading whitespace of that string, for indenting subsequent lines.
Since:
jEdit 4.3pre10

getLeadingWhiteSpace

public static int getLeadingWhiteSpace(java.lang.String str)
Returns the number of leading white space characters in the specified string.

Parameters:
str - The string

getTrailingWhiteSpace

public static int getTrailingWhiteSpace(java.lang.String str)
Returns the number of trailing whitespace characters in the specified string.

Parameters:
str - The string

getLeadingWhiteSpaceWidth

public static int getLeadingWhiteSpaceWidth(java.lang.String str,
                                            int tabSize)
Returns the width of the leading white space in the specified string.

Parameters:
str - The string
tabSize - The tab size

createWhiteSpace

public static java.lang.String createWhiteSpace(int len,
                                                int tabSize)
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 length
tabSize - The tab size, or 0 if tabs are not to be used

createWhiteSpace

public static java.lang.String createWhiteSpace(int len,
                                                int tabSize,
                                                int start)
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 length
tabSize - The tab size, or 0 if tabs are not to be used
start - The start offset, for tab alignment

getVirtualWidth

public static int getVirtualWidth(javax.swing.text.Segment seg,
                                  int tabSize)
Returns the virtual column number (taking tabs into account) of the specified offset in the segment.

Parameters:
seg - The segment
tabSize - The tab size

getOffsetOfVirtualColumn

public static int getOffsetOfVirtualColumn(javax.swing.text.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 segment
tabSize - The tab size
column - The virtual column number
totalVirtualWidth - 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

public static int compareStrings(java.lang.String str1,
                                 java.lang.String str2,
                                 boolean ignoreCase)
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
str2 - The second string
ignoreCase - If true, case will be ignored
Returns:
negative If str1 < str2, 0 if both are the same, positive if str1 > str2
Since:
jEdit 4.3pre5

objectsEqual

public static boolean objectsEqual(java.lang.Object o1,
                                   java.lang.Object o2)
Returns if two strings are equal. This correctly handles null pointers, as opposed to calling o1.equals(o2).

Since:
jEdit 4.3pre6

globToRE

public static java.lang.String globToRE(java.lang.String glob)
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