Package org.openrewrite.internal
Class StringUtils
java.lang.Object
org.openrewrite.internal.StringUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
aspectjNameToPattern
(String name) static String
capitalize
(String value) static String
commonMargin
(@Nullable CharSequence s1, CharSequence s2) static boolean
static int
countOccurrences
(@NonNull String text, @NonNull String substring) Return the number of times a substring occurs within a target string.static String
static String
greatestCommonMargin
(String multiline) Locate the greatest common margin of a multi-line stringstatic int
static String
static int
static int
indexOfNextNonWhitespace
(int cursor, String source) static int
indexOfNonWhitespace
(String text) static boolean
Check if the String is null or has only whitespaces.static boolean
isNotEmpty
(@Nullable String string) static boolean
isNullOrEmpty
(@Nullable String string) Check if the String is empty string or null.static boolean
static boolean
matchesGlob
(@Nullable String value, @Nullable String globPattern) static int
mostCommonIndent
(SortedMap<Integer, Long> indentFrequencies) static String
readFully
(@Nullable InputStream inputStream) static String
readFully
(InputStream inputStream, Charset charset) If the input stream is coming from a stream with an unknown encoding, useEncodingDetectingInputStream.readFully()
instead.static String
static String
replaceFirst
(@NonNull String text, @NonNull String match, @NonNull String replacement) This method will search and replace the first occurrence of a matching substring.static String
trimIndent
(String text) Detects a common minimal indent of all the input lines and removes the indent from each line.static String
trimIndentPreserveCRLF
(@Nullable String text) static String
uncapitalize
(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:
true
if the String is null or has only whitespaces
-
isNullOrEmpty
Check if the String is empty string or null.- Parameters:
string
- String to check- Returns:
true
if 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-1
if no character in the string matches the predicate.
-
countOccurrences
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 String text, @NonNull String match, @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
-