Package org.openrewrite.internal
Class StringUtils
java.lang.Object
org.openrewrite.internal.StringUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringaspectjNameToPattern(String name) static Stringcapitalize(String value) static Stringstatic booleanstatic intcountOccurrences(@NonNull String text, @NonNull String substring) Return the number of times a substring occurs within a target string.static Stringstatic StringgreatestCommonMargin(String multiline) Locate the greatest common margin of a multi-line stringstatic intstatic Stringstatic intstatic intindexOfNextNonWhitespace(int cursor, String source) static intindexOfNonWhitespace(String text) static booleanCheck if the String is null or has only whitespaces.static booleanisNotEmpty(@Nullable String string) static booleanisNullOrEmpty(@Nullable String string) Check if the String is empty string or null.static booleanstatic booleanmatchesGlob(@Nullable String value, @Nullable String globPattern) static intmostCommonIndent(SortedMap<Integer, Long> indentFrequencies) static StringreadFully(@Nullable InputStream inputStream) static StringreadFully(InputStream inputStream, Charset charset) If the input stream is coming from a stream with an unknown encoding, useEncodingDetectingInputStream.readFully()instead.static Stringstatic StringThis method will search and replace the first occurrence of a matching substring.static StringtrimIndent(String text) Detects a common minimal indent of all the input lines and removes the indent from each line.static Stringstatic Stringuncapitalize(String value)
-
Method Details
-
trimIndentPreserveCRLF
-
trimIndent
Detects a common minimal indent of all the input lines and removes the indent from each line.This is modeled after Kotlin's trimIndent and is useful for pruning the indent from multi-line text blocks.
Note: Blank lines do not affect the detected indent level.
- Parameters:
text- A string that have a common indention- Returns:
- A mutated version of the string that removed the common indention.
-
mostCommonIndent
-
isBlank
Check if the String is null or has only whitespaces.Modified from apache commons lang StringUtils.
- Parameters:
string- String to check- Returns:
trueif the String is null or has only whitespaces
-
isNullOrEmpty
Check if the String is empty string or null.- Parameters:
string- String to check- Returns:
trueif the String is null or empty string
-
isNotEmpty
-
readFully
-
readFully
If the input stream is coming from a stream with an unknown encoding, useEncodingDetectingInputStream.readFully()instead.- Parameters:
inputStream- An input stream.- Returns:
- the full contents of the input stream interpreted as a string of the specified encoding
-
capitalize
-
uncapitalize
-
containsOnlyWhitespaceAndComments
-
indexOfNonWhitespace
-
indexOf
- Parameters:
text- Text to scantest- The predicate to match- Returns:
- The index of the first character for which the predicate returns
true, or-1if no character in the string matches the predicate.
-
countOccurrences
public static int countOccurrences(@NonNull @NonNull String text, @NonNull @NonNull String substring) Return the number of times a substring occurs within a target string.- Parameters:
text- A target stringsubstring- The substring to search for- Returns:
- the number of times the substring is found in the target. 0 if no occurrences are found.
-
replaceFirst
public static String replaceFirst(@NonNull @NonNull String text, @NonNull @NonNull String match, @NonNull @NonNull String replacement) This method will search and replace the first occurrence of a matching substring. There is a a replaceFirst method on the String class but that version leverages regular expressions and is a magnitude slower than this simple replacement.- Parameters:
text- The source string to searchmatch- The substring that is being searched forreplacement- The replacement.- Returns:
- The original string with the first occurrence replaced or the original text if a match is not found.
-
repeat
-
matchesGlob
-
indent
-
greatestCommonMargin
Locate the greatest common margin of a multi-line string- Parameters:
multiline- A string of one or more lines.- Returns:
- The greatest common margin consisting only of whitespace characters.
-
commonMargin
-
isNumeric
-
aspectjNameToPattern
See https://eclipse.org/aspectj/doc/next/progguide/semantics-pointcuts.html#type-patternsAn embedded * in an identifier matches any sequence of characters, but does not match the package (or inner-type) separator ".".
The ".." wildcard matches any sequence of characters that start and end with a ".", so it can be used to pick out all types in any subpackage, or all inner types. e.g.
within(com.xerox..*)picks out all join points where the code is in any declaration of a type whose name begins with "com.xerox.". -
greatestCommonSubstringLength
-
indexOfNextNonWhitespace
- Returns:
- Considering C-style comments to be whitespace, return the index of the next non-whitespace character.
-
formatUriForPropertiesFile
-