|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.intellij.openapi.util.text.StringUtil
jetbrains.buildServer.util.StringUtil
public class StringUtil
| Nested Class Summary | |
|---|---|
static interface |
StringUtil.EscapeInfoProvider
String escaping info provider. |
static interface |
StringUtil.LineProcessor
|
| Field Summary | |
|---|---|
static char[] |
DEFAULT_SEPARATORS
|
static java.lang.String |
EMPTY
|
static java.lang.String |
NA
|
static Filter<java.lang.String> |
NOT_EMPTY_STRING_FILTER
|
static StringUtil.EscapeInfoProvider |
STD_ESCAPER
|
| Method Summary | |
|---|---|
static boolean |
areEqual(java.lang.String string1,
java.lang.String string2)
Checks whether two given strings are equal. |
static java.lang.String |
biteOffPostfix(java.lang.String line,
java.lang.String postfix)
|
static java.lang.String |
collapseSpaces(java.lang.String str)
Replaces a sequence of space characters with single whitespace. |
static int |
compare(java.lang.String s1,
java.lang.String s2)
|
static void |
convertStringsToLowerCase(java.util.List<java.lang.String> strings)
Converts all strings inside the given list to lower case. |
static java.lang.String |
convertWildcardToRegexp(java.lang.String pattern)
Converts pattern with wildcards (* or ?) to regular expression. |
static java.util.Iterator<java.lang.String> |
createEscapedTokenizer(java.lang.String string,
char del)
Split string into tokens, ignores delimiters with escaping ('\') |
static java.lang.String |
dateToString(java.util.Date date)
|
static java.lang.String |
elapsedTimeToString(java.util.Date date)
|
static java.lang.String |
elapsedTimeToString(long millis)
|
static java.lang.String |
emptyIfNull(java.lang.String string)
Returns given string if it is not null, or empty string if a null given. |
static java.lang.String |
escapeForRegex(java.lang.String str)
Converts string to a form which is safe to use for regular expressions. |
static java.lang.String |
escapeHTML(java.lang.String text,
boolean replaceQuotes)
|
static java.lang.String |
escapeQuotesIfWindows(java.lang.String value)
|
static java.lang.String |
escapeStr(java.lang.String str,
StringUtil.EscapeInfoProvider p)
Escapes characters specified by provider with '\' and specified character. |
static int |
findInvalidXMLChar(java.lang.String value)
Looks for characters that cannot be presented in XML |
static java.lang.String |
formatFileSize(long fileSize)
|
static java.lang.String |
formatHtmlColor(java.awt.Color color)
Formats AWT Color to HTML hex color string |
static java.lang.String |
formatInt(int value)
|
static java.lang.String |
formatInt(int value,
int length)
|
static java.lang.String |
formatInt(int value,
int length,
char fillChar)
|
static java.lang.String |
formatTextForWeb(java.lang.String txt)
Formats text for showing on the web page preserving original text formatting. |
static java.lang.String |
generateUniqueHash()
NOTE: This could take more than 30 seconds for the first call Generates unique hash value. |
static java.lang.String |
getOrdinal(int number)
Return ordinal ending for a number, i.e. |
static int |
indexOf(java.lang.String currentString,
char findWhat,
StringUtil.EscapeInfoProvider escaper)
|
static boolean |
isAPositiveNumber(java.lang.String value)
|
static boolean |
isNumber(java.lang.String value)
|
static boolean |
isTrue(java.lang.String property)
|
static boolean |
isValidXMLChar(char c)
Section 2.2 of the XML spec describes which Unicode code points are valid in XML: #x9 | #xA | #xD | [#x20-#xD7FF] |
[#xE000-#xFFFD] | [#x10000-#x10FFFF]
Code points outside this set cannot be represented in XML. |
static java.lang.String |
join(java.lang.String separator,
java.lang.Iterable toJoin)
Simple string joiner with given separator. |
static void |
join(java.lang.String separator,
java.lang.Iterable toJoin,
java.lang.StringBuilder result)
Simple string joiner with given separator. |
static java.lang.String |
join(java.lang.String separator,
java.lang.Object... toJoin)
Simple string joiner with given separator. |
static java.lang.String |
lastPartOf(java.lang.String s,
char separator)
|
static java.lang.String |
newLineToSpaceDelimited(java.lang.String str)
|
static java.lang.String |
nullIfEmpty(java.lang.String string)
Returns given string if it is not empty, or null if it is empty. |
static java.lang.String |
peekNthDelimitedField(java.lang.String string,
char separator,
int nth,
boolean trim)
Treats the given string as a separator delimited string, and returns the nth field from this string. |
static void |
processLines(java.io.File file,
StringUtil.LineProcessor procesor)
|
static void |
processLines(java.io.InputStream in,
StringUtil.LineProcessor procesor)
|
static void |
processLines(java.lang.String str,
StringUtil.LineProcessor procesor)
|
static java.lang.String |
propertiesToString(java.util.Map<java.lang.String,java.lang.String> props,
StringUtil.EscapeInfoProvider escaper)
|
static java.lang.String |
removeLeadingSlash(java.lang.String path)
If given string starts with /, remove it and return remaining string |
static java.lang.String |
removeTailingSlash(java.lang.String path)
If given string ends with /, remove it and return remaining string |
static java.lang.String |
repeat(java.lang.String whatRepeat,
java.lang.String separator,
int times)
|
static void |
repeat(java.lang.String whatRepeat,
java.lang.String separator,
int times,
java.lang.StringBuilder builder)
|
static void |
replace(java.lang.StringBuilder buf,
java.util.regex.Pattern pattern,
java.lang.String with)
Replaces all occurences of the pattern with the with string in the specified string buffer. |
static void |
replace(java.lang.StringBuilder buf,
java.lang.String what,
java.lang.String with)
Replaces all occurences of the what substring with the with in the specified string buffer. |
static java.lang.String |
replaceInvalidXmlChars(java.lang.String str)
Replaces all unvalid xml characters with space |
static java.lang.String |
replaceNonAlphaNumericChars(java.lang.String originalStr,
char toReplace)
Replaces all characters except A-Za-z0-9_ to specified character. |
static java.util.regex.Pattern |
searchByKeywordPattern(java.lang.String keyword,
boolean caseInsensitive)
Returns RegEx pattern to search by specified keyword. |
static java.util.List<java.lang.String> |
split(java.lang.String values)
Splits values using default separators, note that empty strings are then removed from the result. |
static java.util.List<java.lang.String> |
split(java.lang.String values,
boolean removeEmpty,
char... separators)
Splits values using specified separators, empty strings are preserved. |
static java.util.List<java.lang.String> |
splitCommandArgumentsAndUnquote(java.lang.String line)
This utility differs from splitHonorQuote: it considers quote in sequence 'ddd\" -' as boundary quote. |
static java.util.List<java.lang.String> |
splitHonorQuotes(java.lang.String s)
|
static java.util.List<java.lang.String> |
splitHonorQuotes(java.lang.String s,
char separator)
|
static java.lang.String |
stackTrace(java.lang.Throwable exception)
|
static java.util.Map<java.lang.String,java.lang.String> |
stringToProperties(java.lang.String string,
StringUtil.EscapeInfoProvider escaper)
performs conversion of string to property map with string name checking. |
static java.util.Map<java.lang.String,java.lang.String> |
stringToProperties(java.lang.String string,
StringUtil.EscapeInfoProvider escaper,
boolean strictNameCheck)
Converts string to property map |
static java.lang.String |
stringValueOf(java.lang.Object obj,
java.lang.String defaultValue)
|
static java.lang.String |
stripLeftAndRight(java.lang.String s,
com.intellij.openapi.util.text.CharFilter filter)
Returns the string s stripped from the beginning and end
with symbols matched by file. |
static java.lang.String |
substringByRegex(java.lang.CharSequence text,
java.util.regex.Pattern pattern,
int groupNr)
Gets the inner part of string that specified with the regular expression. |
static java.lang.String |
trimAndNull(java.lang.String string)
Trims the given string and returns it if after trimming it is not empty; othrwise returns null. |
static java.lang.String |
trimRight(java.lang.String string)
Removes the right (end) spaces from the string. |
static void |
trimStringBuilderLeft(java.lang.StringBuilder buf)
Removes starting spaces. |
static java.lang.String |
truncateStringValue(java.lang.String str,
int maxLength)
Truncates string, returns part of the initial string with length up to max length characters. |
static java.lang.String |
truncateStringValueWithDotsAtCenter(java.lang.String str,
int maxLength)
Truncates string and adds dots to the center of the string if it was truncated. |
static java.lang.String |
truncateStringValueWithDotsAtEnd(java.lang.String str,
int maxLength)
Truncates string and adds dots to the end of the string if it was truncated. |
static java.lang.String |
unescapeStr(java.lang.String str,
StringUtil.EscapeInfoProvider p)
Unescapes characters specified by provider with '\' and specified character. |
| Methods inherited from class com.intellij.openapi.util.text.StringUtil |
|---|
assertValidSeparators, capitalize, capitalizeWithJavaBeanConvention, capitalizeWords, capitalizeWords, capitalsOnly, charsEqualIgnoreCase, commonPrefix, commonPrefixLength, commonSuffix, commonSuffixLength, compareVersionNumbers, containsAlphaCharacters, containsAnyChar, containsIgnoreCase, convertLineSeparators, convertLineSeparators, convertLineSeparators, countChars, countNewLines, decapitalize, difference, endsWith, endsWithChar, endsWithIgnoreCase, escapeProperty, escapeQuotes, escapeStringCharacters, escapeStringCharacters, escapeStringCharacters, escapeToRegexp, escapeXml, filterEmptyStrings, findFirst, first, first, firstLetterToUpperCase, fixVariableNameDerivedFromPropertyName, getLineBreakCount, getMessage, getOccurenceCount, getPackageName, getPackageName, getPropertyName, getQualifiedName, getShortName, getShortName, getShortName, getThrowableText, getThrowableText, getWordsIn, indexOf, indexOf, indexOfIgnoreCase, isEmpty, isEmptyOrSpaces, isJavaIdentifier, isJavaIdentifierPart, isJavaIdentifierStart, isNotEmpty, isPreposition, isPreposition, isQuotedString, isVowel, join, join, join, join, join, join, join, joinOrNull, last, lineColToOffset, notNullize, notNullize, offsetToLineNumber, parseInt, pluralize, pluralize, quoteReplacement, repeatSymbol, repeatSymbol, replace, replace, replace, replaceChar, replaceIgnoreCase, replaceSubstring, shiftIndentInside, split, splitByLines, startsWith, startsWithChar, startsWithConcatenationOf, startsWithIgnoreCase, stringHashCode, stringHashCode, stringHashCode, stringHashCodeInsensitive, stringHashCodeInsensitive, stringHashCodeInsensitive, strip, stripQuotesAroundValue, surround, tail, tokenize, toLowerCase, toLowerCase, toTitleCase, toUpperCase, trimEnd, trimStart, unescapeStringCharacters, unescapeXml, unpluralize, unquoteString, wordsToBeginFromUpperCase, zip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final char[] DEFAULT_SEPARATORS
public static final java.lang.String EMPTY
@NonNls public static final java.lang.String NA
public static final Filter<java.lang.String> NOT_EMPTY_STRING_FILTER
public static final StringUtil.EscapeInfoProvider STD_ESCAPER
| Method Detail |
|---|
public static boolean areEqual(@Nullable
java.lang.String string1,
@Nullable
java.lang.String string2)
string1 - the first string to compare.string2 - the second string to compare.
public static java.lang.String escapeHTML(java.lang.String text,
boolean replaceQuotes)
public static java.util.List<java.lang.String> splitCommandArgumentsAndUnquote(java.lang.String line)
public static java.lang.String biteOffPostfix(java.lang.String line,
java.lang.String postfix)
public static java.lang.String lastPartOf(java.lang.String s,
char separator)
public static java.lang.String truncateStringValue(java.lang.String str,
int maxLength)
str - string to truncatemaxLength - max length
public static java.lang.String truncateStringValueWithDotsAtEnd(java.lang.String str,
int maxLength)
str - string to truncatemaxLength - max length of the resulting string
public static java.lang.String truncateStringValueWithDotsAtCenter(java.lang.String str,
int maxLength)
str - string to truncatemaxLength - max length of the resulting string
public static boolean isValidXMLChar(char c)
#x9 | #xA | #xD | [#x20-#xD7FF] |
[#xE000-#xFFFD] | [#x10000-#x10FFFF]
Code points outside this set cannot be represented in XML.
c - The character to inspect.
public static int findInvalidXMLChar(java.lang.String value)
value - value
@NotNull
public static java.lang.String replaceInvalidXmlChars(@NotNull
java.lang.String str)
str - string to replace
public static java.lang.String generateUniqueHash()
public static java.util.regex.Pattern searchByKeywordPattern(@NotNull
java.lang.String keyword,
boolean caseInsensitive)
keyword - keywordcaseInsensitive - is case sensitive
public static java.lang.String escapeForRegex(@NotNull
java.lang.String str)
str - string to escape
public static java.lang.String convertWildcardToRegexp(java.lang.String pattern)
pattern - pattern
public static java.util.List<java.lang.String> split(java.lang.String values)
values - value to split
public static java.util.List<java.lang.String> split(java.lang.String values,
boolean removeEmpty,
char... separators)
values - values to splitremoveEmpty - if true then empty strings will not be returnedseparators - separators
public static boolean isAPositiveNumber(java.lang.String value)
public static boolean isNumber(java.lang.String value)
public static java.lang.String formatHtmlColor(java.awt.Color color)
color - color to convert
public static java.lang.String getOrdinal(int number)
number - number, whose ordinal ending should be returned
public static java.lang.String stackTrace(java.lang.Throwable exception)
public static java.lang.String join(java.lang.String separator,
java.lang.Iterable toJoin)
separator - separator for joined stringtoJoin - object to join, if an object is null, it is ignored
public static void join(java.lang.String separator,
java.lang.Iterable toJoin,
java.lang.StringBuilder result)
separator - separator for joined stringtoJoin - object to join, if an object is null, it is ignoredresult - string builder to put result to
public static java.lang.String join(java.lang.String separator,
java.lang.Object... toJoin)
separator - separator for joined stringtoJoin - object to join, if an object is null, it is ignored
public static java.util.Iterator<java.lang.String> createEscapedTokenizer(java.lang.String string,
char del)
string - string data to tokenizedel - selimiter
public static int indexOf(java.lang.String currentString,
char findWhat,
StringUtil.EscapeInfoProvider escaper)
@NotNull
public static java.util.Map<java.lang.String,java.lang.String> stringToProperties(@NotNull
java.lang.String string,
@NotNull
StringUtil.EscapeInfoProvider escaper)
throws java.text.ParseException
string - source stringescaper - escaping rule provider
java.text.ParseException - if parsing of the property sting failedstringToProperties(String, jetbrains.buildServer.util.StringUtil.EscapeInfoProvider, boolean)
@NotNull
public static java.util.Map<java.lang.String,java.lang.String> stringToProperties(@NotNull
java.lang.String string,
@NotNull
StringUtil.EscapeInfoProvider escaper,
boolean strictNameCheck)
throws java.text.ParseException
string - in a form of "name1='value' name2='value' ..."escaper - escaping rule providerstrictNameCheck - if true each name is checked to be a valid java identifier, otherwise it's only checked for absense of spaces
java.text.ParseException - if parsing of the property sting failed
public static java.lang.String propertiesToString(java.util.Map<java.lang.String,java.lang.String> props,
StringUtil.EscapeInfoProvider escaper)
public static java.lang.String repeat(java.lang.String whatRepeat,
java.lang.String separator,
int times)
public static void repeat(java.lang.String whatRepeat,
java.lang.String separator,
int times,
java.lang.StringBuilder builder)
public static boolean isTrue(java.lang.String property)
public static java.lang.String escapeQuotesIfWindows(java.lang.String value)
public static void convertStringsToLowerCase(@NotNull
java.util.List<java.lang.String> strings)
strings - list of strings.public static java.lang.String removeTailingSlash(java.lang.String path)
path - input string
public static java.lang.String removeLeadingSlash(java.lang.String path)
path - input string
public static void replace(@NotNull
java.lang.StringBuilder buf,
@NotNull
java.lang.String what,
@NotNull
java.lang.String with)
buf - string buffer where perform replacing.what - substring to find and change.with - substring that will be replaced with.
public static void replace(@NotNull
java.lang.StringBuilder buf,
@NotNull
java.util.regex.Pattern pattern,
@NotNull
java.lang.String with)
buf - string buffer where perform replacing.pattern - pattern to find.with - substring that will be replaced with.
public static int compare(@Nullable
java.lang.String s1,
@Nullable
java.lang.String s2)
public static void processLines(java.lang.String str,
StringUtil.LineProcessor procesor)
throws java.io.IOException
java.io.IOException@NotNull public static java.lang.String formatFileSize(long fileSize)
public static void processLines(java.io.InputStream in,
StringUtil.LineProcessor procesor)
throws java.io.IOException
java.io.IOException
public static void processLines(java.io.File file,
StringUtil.LineProcessor procesor)
throws java.io.IOException
java.io.IOException
public static java.lang.String escapeStr(java.lang.String str,
StringUtil.EscapeInfoProvider p)
str - initial stringp - escape info provider.
public static java.lang.String unescapeStr(java.lang.String str,
StringUtil.EscapeInfoProvider p)
str - initial stringp - escape info provider.
public static java.lang.String formatTextForWeb(java.lang.String txt)
txt - initial text
public static java.lang.String replaceNonAlphaNumericChars(java.lang.String originalStr,
char toReplace)
originalStr - original stringtoReplace - character to replace with
public static java.lang.String peekNthDelimitedField(@Nullable
java.lang.String string,
char separator,
int nth,
boolean trim)
string - delimited string; nulls are allowed.separator - fields separator.nth - number of filed to return; the first filed is 1,
the second field is 2, etc;
0 not allowed.trim - determines whether this function apply trim() before returning the field.
@Nullable
public static java.lang.String nullIfEmpty(@Nullable
java.lang.String string)
string - string to check for be empty.
@NotNull
public static java.lang.String emptyIfNull(@Nullable
java.lang.String string)
string - string to check for be a null.
@Nullable
public static java.lang.String trimAndNull(@Nullable
java.lang.String string)
string - source string.
#trimAndEmpty(String)
@Nullable
public static java.lang.String trimRight(@Nullable
java.lang.String string)
string - string to trim; nulls and empty strings are allowed.
public static void trimStringBuilderLeft(@NotNull
java.lang.StringBuilder buf)
buf - buf to remove from.
public static java.lang.String stripLeftAndRight(@NotNull
java.lang.String s,
@NotNull
com.intellij.openapi.util.text.CharFilter filter)
s stripped from the beginning and end
with symbols matched by file.
E.g. stripLeftAndRight(" foo bar \n", CharFilter.WHITESPACE_FILTER) == "foo bar".
s - the input stringfilter - char filter
@NotNull
public static java.lang.String elapsedTimeToString(@Nullable
java.util.Date date)
@NotNull public static java.lang.String elapsedTimeToString(long millis)
public static java.lang.String dateToString(@Nullable
java.util.Date date)
public static java.lang.String formatInt(int value,
int length,
char fillChar)
public static java.lang.String formatInt(int value,
int length)
public static java.lang.String formatInt(int value)
@NotNull
public static java.util.List<java.lang.String> splitHonorQuotes(@NotNull
java.lang.String s,
char separator)
public static java.lang.String substringByRegex(java.lang.CharSequence text,
java.util.regex.Pattern pattern,
int groupNr)
This function looks for the firts occurence of the specified pattern in the given text, and return the content matched the n-th groups of the regular expression.
For example, if text = "aaa bbbcccddd eee bbccdd xxx", pattern = "b+(c+)d+" and n = 1, the result will be "ccc".
text - text to look through; can be null.pattern - pattern, must contains at least one group (one pair of parentheses); not null.groupNr - number of the group to return, started from 1, or 0 for return a string matched for the whole pattern.
@NotNull
public static java.util.List<java.lang.String> splitHonorQuotes(@NotNull
java.lang.String s)
@NotNull
public static java.lang.String stringValueOf(@Nullable
java.lang.Object obj,
@NotNull
java.lang.String defaultValue)
public static java.lang.String collapseSpaces(@NotNull
java.lang.String str)
str - string where to collapse spaces
public static java.lang.String newLineToSpaceDelimited(@NotNull
java.lang.String str)
str - string to transform
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||