org.prorefactor.refactor.util
Class Strings

java.lang.Object
  extended by org.prorefactor.refactor.util.Strings

public class Strings
extends java.lang.Object

Helper class to provide String manipulation functions not available in standard JDK. Copied from org.eclipse.jdt.internal.corext.util.Strings. I'm not sure why that class isn't a core Eclipse class, would have been handy there. Note that some Joanju methods have been added to the top of the class.


Constructor Summary
Strings()
           
 
Method Summary
static java.lang.String changeIndent(java.lang.String code, int codeIndentLevel, int tabWidth, java.lang.String newIndent, java.lang.String lineDelim)
          Change the indent of, possible muti-line, code range.
static java.lang.String changeIndent(java.lang.String text, java.lang.String newIndent, java.lang.String lineDelim)
          Joanju variation - change the indent on a block of code.
static int computeIndent(java.lang.String line, int tabWidth)
          Returns the indent of the given string.
static java.lang.String concatenate(java.lang.String[] lines, java.lang.String delimiter)
          Concatenate the given strings into one strings using the passed line delimiter as a delimiter.
static boolean containsOnlyWhitespaces(java.lang.String s)
          Returns true if the given string only consists of white spaces according to Java.
static java.lang.String[] convertIntoLines(java.lang.String input)
          Converts the given string into an array of lines.
static boolean equals(java.lang.String s, char[] c)
           
static java.lang.String getIndentString(java.lang.String line)
          Joanju variation - does nothing with tabwidth.
static java.lang.String getIndentString(java.lang.String line, int tabWidth)
           
static boolean isIndentChar(char ch)
          Indent char is a space char but not a line delimiters.
static boolean isLineDelimiterChar(char ch)
          Line delimiter chars are '\n' and '\r'.
static boolean isLowerCase(char ch)
          tests if a char is lower case.
static java.lang.String removeNewLine(java.lang.String message)
           
static java.lang.String[] removeTrailingEmptyLines(java.lang.String[] sourceLines)
           
static java.lang.String trimIndent(java.lang.String line, int indentsToRemove, int tabWidth)
          Removes the given number of idents from the line.
static void trimIndentation(java.lang.String[] lines, int tabWidth)
          Removes the common number of indents from all lines.
static void trimIndentation(java.lang.String[] lines, int tabWidth, boolean considerFirstLine)
          Removes the common number of indents from all lines.
static java.lang.String trimIndents(java.lang.String s, int tabWidth)
          Removes all leading indents from the given line.
static java.lang.String trimLeadingTabsAndSpaces(java.lang.String line)
          Removes leading tabs and spaces from the given string.
static java.lang.String trimTrailingTabsAndSpaces(java.lang.String line)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

public Strings()
Method Detail

changeIndent

public static java.lang.String changeIndent(java.lang.String text,
                                            java.lang.String newIndent,
                                            java.lang.String lineDelim)
Joanju variation - change the indent on a block of code. Replaces the first line's indent with the newIndent. For the rest of the lines, strips the minimum indent of all lines other than the first line, then adds the newIndent. Skips the first line, because it may be from a selection beginning mid-line. (Input a leading newline to avoid this behaviour.) This function won't work very well if the code's indent is not consistent for tabs and spaces, because it counts characters to remove - not "width".


getIndentString

public static java.lang.String getIndentString(java.lang.String line)
Joanju variation - does nothing with tabwidth.


isIndentChar

public static boolean isIndentChar(char ch)
Indent char is a space char but not a line delimiters. == Character.isWhitespace(ch) && ch != '\n' && ch != '\r'


isLowerCase

public static boolean isLowerCase(char ch)
tests if a char is lower case. Fix for 26529


isLineDelimiterChar

public static boolean isLineDelimiterChar(char ch)
Line delimiter chars are '\n' and '\r'.


removeNewLine

public static java.lang.String removeNewLine(java.lang.String message)

convertIntoLines

public static java.lang.String[] convertIntoLines(java.lang.String input)
Converts the given string into an array of lines. The lines don't contain any line delimiter characters.

Returns:
the string converted into an array of strings. Returns null if the input string can't be converted in an array of lines.

containsOnlyWhitespaces

public static boolean containsOnlyWhitespaces(java.lang.String s)
Returns true if the given string only consists of white spaces according to Java. If the string is empty, true is returned.

Returns:
true if the string only consists of white spaces; otherwise false is returned
See Also:
Character.isWhitespace(char)

trimLeadingTabsAndSpaces

public static java.lang.String trimLeadingTabsAndSpaces(java.lang.String line)
Removes leading tabs and spaces from the given string. If the string doesn't contain any leading tabs or spaces then the string itself is returned.


trimTrailingTabsAndSpaces

public static java.lang.String trimTrailingTabsAndSpaces(java.lang.String line)

computeIndent

public static int computeIndent(java.lang.String line,
                                int tabWidth)
Returns the indent of the given string.

Parameters:
line - the text line
tabWidth - the width of the '\t' character.

trimIndent

public static java.lang.String trimIndent(java.lang.String line,
                                          int indentsToRemove,
                                          int tabWidth)
Removes the given number of idents from the line. Asserts that the given line has the requested number of indents. If indentsToRemove <= 0 the line is returned.


trimIndents

public static java.lang.String trimIndents(java.lang.String s,
                                           int tabWidth)
Removes all leading indents from the given line. If the line doesn't contain any indents the line itself is returned.


trimIndentation

public static void trimIndentation(java.lang.String[] lines,
                                   int tabWidth)
Removes the common number of indents from all lines. If a line only consists out of white space it is ignored.


trimIndentation

public static void trimIndentation(java.lang.String[] lines,
                                   int tabWidth,
                                   boolean considerFirstLine)
Removes the common number of indents from all lines. If a line only consists out of white space it is ignored. If considerFirstLine is false the first line will be ignored.


getIndentString

public static java.lang.String getIndentString(java.lang.String line,
                                               int tabWidth)

removeTrailingEmptyLines

public static java.lang.String[] removeTrailingEmptyLines(java.lang.String[] sourceLines)

changeIndent

public static java.lang.String changeIndent(java.lang.String code,
                                            int codeIndentLevel,
                                            int tabWidth,
                                            java.lang.String newIndent,
                                            java.lang.String lineDelim)
Change the indent of, possible muti-line, code range. The current indent is removed, a new indent added. The first line of the code will not be changed. (It is considered to have no indent as it might start in the middle of a line)


concatenate

public static java.lang.String concatenate(java.lang.String[] lines,
                                           java.lang.String delimiter)
Concatenate the given strings into one strings using the passed line delimiter as a delimiter. No delimiter is added to the last line.


equals

public static boolean equals(java.lang.String s,
                             char[] c)


Copyright © 2008 Joanju Software. All Rights Reserved.