public class StringUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char |
STRING_ESCAPE_CHARACTER
The escape character for String used by the Povray SDL:
'\' . |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
bildPath(java.lang.String path1,
java.lang.String path2)
Builds a new path from the two given parts.
|
static java.lang.String |
changeExtension(java.lang.String name,
java.lang.String extension)
Exchanges the extension of the given (file) name.
|
static boolean |
containsOnlySpaces(java.lang.String str) |
static int |
countChar(char[] array,
char c) |
java.lang.String |
ensureMaxLength(java.lang.String str,
int maxLen)
Ensures that the given String is never longer than the given maxLen.
|
static java.lang.String |
ensureMaxLineLength(java.lang.String text,
int maxLineLen)
Inserts newlines if a line would be longer than
lineLen characters. |
static java.lang.String |
ensureOnlyWhiteSpaces(java.lang.String str) |
static java.lang.String |
extractDeclarationName(java.lang.String str) |
static java.lang.String |
extractDeclarationRValue(java.lang.String str) |
static java.lang.String |
extractExpression(java.lang.String str)
Given '#ifdef (TARGET)' return 'TARGET'
FIXME: Broken for case: #ifdef /*(*/ (foo) |
static java.lang.String |
extractMacroName(java.lang.String str) |
static java.lang.String |
extractParam(java.lang.String str)
Extract a string up to the next comma.
|
static java.lang.String |
extractQuotedString(java.lang.String str,
boolean includeQuotes)
Extracts everything between the first two ocurrences of a doublequote.
|
static java.lang.String |
extractTo(java.lang.String str,
char marker)
Extract a string up to this character.
|
static java.lang.String |
extractUSNumber(java.lang.String str,
int occurence)
Extracts the n-th occurence of a US-styled number from the given String.
|
static java.lang.String |
fillup(java.lang.String str,
int len,
char fillChar,
boolean append)
Fills the given string to the given lenght
|
static java.lang.String |
getDuration(java.util.Date start,
java.util.Date end)
Creates a duration string from the given dates.
Format: HHHH:MM:SS.SSSS |
static java.lang.String |
getExtension(java.lang.String name)
Returns the extension of the given filename.
|
static java.lang.String |
getFileSeparator() |
static java.lang.String |
getFirstToken(java.lang.String str)
Gets the very first token in the String.
|
static java.lang.String |
getNameWithoutExtension(java.lang.String name)
Returns the given name without an extension.
|
static java.lang.String |
getNameWithoutPath(java.lang.String name)
Returns the given file without the path information.
|
static java.lang.String |
getNextTokenAfterOpeningBrace(java.lang.String str)
Gets the token after the first opening brace (
'{' ) |
static java.lang.String |
getNextTokenAfterOpeningBrace(java.lang.String str,
int numOpeningBrace)
Gets the token after the n-th opening character
|
static java.lang.String |
getNextTokenAfterOpeningParenthesis(java.lang.String str)
Gets the token after the first opening paranthesis (
'(' ) |
static java.lang.String |
getNextTokenAfterOpeningParenthesis(java.lang.String str,
int numOpeningParenthesis)
Gets the token after the n-th opening paranthesis (
'(' ) |
static int |
getNumericStringWidth(int n)
Determine how many characters this number needs
|
static java.lang.String |
getPartAfterLastCharacter(java.lang.String txt,
char ch)
Gives the remaining String after the last occurrence of
the character
ch in the String txt . |
static java.lang.String |
getPathForFile(java.lang.String name)
Returns the folder the given file resides.
|
static java.lang.String |
getPostfix(IDocument document,
int offset)
Get the next word token (not an operator token)
|
static java.lang.String |
getPostfix(ITextViewer viewer,
int offset)
This is a convienence method for
getPostfix(viewer.getDocument(), offset); |
static java.lang.String |
getPrefix(IDocument document,
int offset)
Extracts the prefix.
|
static java.lang.String |
getPrefix(ITextViewer viewer,
int offset)
Extracts the prefix.
|
static java.lang.String |
getStringNullsave(java.lang.String str) |
static java.lang.String |
getToken(IDocument document,
int offset) |
static java.lang.String |
getWordBelowOffset(IDocument document,
int offset)
Extracts the word below the given offset.
|
static java.lang.String |
getWordBelowOffset(ITextViewer viewer,
int offset)
Extracts the word below the given offset.
|
static java.lang.String |
getZeroFormattedString(int n,
int width) |
static boolean |
isNamingCharacter(char ch)
Checks if the character can be used within a povray naming sequence.
|
static boolean |
isNumberCharacter(char ch)
Checks if the character can be used witrhin us-styled number.
|
static boolean |
isTokenCharacter(char ch)
Checks if the character can be used within a povray naming sequence.
|
static boolean |
isUSNumberCharacter(char c)
Checks if a character is valid for usage in a US-style number.
|
static boolean |
isWhitespace(char ch) |
static java.lang.String |
readFile(java.io.File file) |
static java.lang.StringBuffer |
readInputStream(java.io.InputStreamReader streamReader)
Reads the given
InputStreamReader and return the content as
StringBuffer .In case of an exception while reading the file an empty StringBuffer
is returned. |
static boolean |
startsWithIgnoreCase(java.lang.String str,
java.lang.String start)
Indicates whether
str starts with the start String, ignoring
the case. |
public static char STRING_ESCAPE_CHARACTER
'\'
.public static java.lang.String fillup(java.lang.String str, int len, char fillChar, boolean append)
str
- The String to be filled uplen
- The filled lenghtfillChar
- The character to be used for fillingappend
- true
to append the fill char at the end,
false
to insert it at the beginning.len
str
is returned unchanged, otherwise the filled String is returned.public static java.lang.String getNameWithoutExtension(java.lang.String name)
name
- The (file) name to process.public static java.lang.String getExtension(java.lang.String name)
name
- The (file) name to process.empty
String
if there was no dot, never null
.;public static java.lang.String getNameWithoutPath(java.lang.String name)
name
- The (file) name to process.public static java.lang.String getPathForFile(java.lang.String name)
name
- The (file) name to process.public static java.lang.String changeExtension(java.lang.String name, java.lang.String extension)
name
- The (file) name to be processed.extension
- The new extensionpublic static java.lang.String getStringNullsave(java.lang.String str)
str
- The String to be checked.null
, if the given String is null
an empty
String is returned, otherwise the given string.public static boolean containsOnlySpaces(java.lang.String str)
str
- The string to be checked.true
if the given String contains only SPACES
and TABS, false
if there are other characters.public static java.lang.String ensureOnlyWhiteSpaces(java.lang.String str)
str
- The String to be processedpublic static boolean isUSNumberCharacter(char c)
'0'
to '9'
'.'
'-'
c
- The character to checktrue
if the given character is a digit valid for
US-style numbers, false
otherwise.public static java.lang.String extractUSNumber(java.lang.String str, int occurence)
str
- The String containing numbersoccurence
- The number having this index (1-based!) is returnednull
!public static java.lang.String extractQuotedString(java.lang.String str, boolean includeQuotes)
str
- The String to be processed.null
.public static java.lang.String extractTo(java.lang.String str, char marker)
str
- The string to extract frommarker
- The character to stop atpublic static java.lang.String extractExpression(java.lang.String str)
str
- public static java.lang.String extractParam(java.lang.String str)
str
- The string to extract frompublic static boolean startsWithIgnoreCase(java.lang.String str, java.lang.String start)
str
starts with the start
String, ignoring
the case.str
- The String to check if it begins with start
.start
- The beginning of the Stringnull
or str
starts with the start
ignoring the case, false
otherwise.public static java.lang.String getPrefix(ITextViewer viewer, int offset)
getPrefix(viewer.getDocument(), offset);
viewer
- The viewer to operate on.offset
- The offset of the current cursor position.public static java.lang.String getPrefix(IDocument document, int offset)
document
- The document to operate on.offset
- The offset of the current cursor position.public static boolean isNamingCharacter(char ch)
ch
- The character to be checkedtrue
if the character is a letter, digit or '_',
false
otherwise.public static boolean isNumberCharacter(char ch)
ch
- The character to be checkedtrue
if the character is a digit, '.' or '-',
false
otherwise.public static boolean isTokenCharacter(char ch)
ch
- The character to be checkedtrue
if the character is a letter, digit or
one of '_', '-', '.'
or '#'
, otherwise
false
.public static boolean isWhitespace(char ch)
public static java.lang.String getPostfix(ITextViewer viewer, int offset)
getPostfix(viewer.getDocument(), offset);
viewer
- The viewer to operate on.offset
- The offset of work with.null
.public static java.lang.String getPostfix(IDocument document, int offset)
document
- The document to operate on.offset
- The offset of work with.null
.public static java.lang.String getToken(IDocument document, int offset)
public static java.lang.String getWordBelowOffset(ITextViewer viewer, int offset)
viewer
- The viewer to work withoffset
- The offset to work withpublic static java.lang.String getWordBelowOffset(IDocument document, int offset)
document
- The document to work withoffset
- The offset to work withpublic java.lang.String ensureMaxLength(java.lang.String str, int maxLen)
str
- The String to be checkedmaxLen
- The maximum allowed string lenghtnull
if str
is null
str
if it's lenght is shorter than maxLen
maxLen-3
characters of
str
followed by "..."
public static java.lang.String ensureMaxLineLength(java.lang.String text, int maxLineLen)
lineLen
characters.
The newlines are inserted before the word making the line too long.text
- The text tobe processedmaxLineLen
- The maximum allowed line lenghtpublic static java.lang.StringBuffer readInputStream(java.io.InputStreamReader streamReader)
InputStreamReader
and return the content as
StringBuffer
.StringBuffer
is returned.streamReader
- The InputStreamReader
to be read.NULL
.public static java.lang.String getFileSeparator()
'file.separator'
.public static int countChar(char[] array, char c)
public static java.lang.String bildPath(java.lang.String path1, java.lang.String path2)
'/'
handling
between the path parts is applied.path1
- The first path partpath2
- The second path part to be appended to the first onepublic static java.lang.String getFirstToken(java.lang.String str)
str
- The String who's first token is to be extracted.public static java.lang.String getNextTokenAfterOpeningBrace(java.lang.String str)
'{'
)str
- The String to work on.'{'
)
or an empty String if none could be found. Never null
.public static java.lang.String getNextTokenAfterOpeningParenthesis(java.lang.String str)
'('
)str
- The String to work on.'('
)
or an empty String if none could be found. Never null
.public static java.lang.String getNextTokenAfterOpeningParenthesis(java.lang.String str, int numOpeningParenthesis)
'('
)str
- The String to work on.numOpeningParenthesis
- The number of opening paranthesisnumOpeningParenthesis
opening paranthesis ('('
)
or an empty String if none could be found. Never null
.public static java.lang.String getNextTokenAfterOpeningBrace(java.lang.String str, int numOpeningBrace)
str
- The String to work on.numOpeningBrace
- The number of opening bracesnumOpeningBrace
opening brace ('{'
)
or an empty String if none could be found. Never null
.public static java.lang.String getDuration(java.util.Date start, java.util.Date end)
HHHH:MM:SS.SSSS
start
- The start timeend
- The end timepublic static java.lang.String getPartAfterLastCharacter(java.lang.String txt, char ch)
ch
in the String txt
.txt
- The Striong to work on.ch
- The character to be searched for.null
than
null
is returned. If the given Strnig does not contain
the character ch
the complete String txt
is returned.public static java.lang.String readFile(java.io.File file) throws java.io.IOException
java.io.IOException
public static int getNumericStringWidth(int n)
n
- The number to checkpublic static java.lang.String getZeroFormattedString(int n, int width)
public static java.lang.String extractDeclarationName(java.lang.String str)
public static java.lang.String extractDeclarationRValue(java.lang.String str)
public static java.lang.String extractMacroName(java.lang.String str)