public class BambooStringUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
BambooStringUtils.AffixFilteringTree
Class represent efficient way of filtering a set of strings with respect to a prefix or suffix.
|
Modifier and Type | Field and Description |
---|---|
static char |
CHAR_APOSTROPHE |
static char |
CHAR_BACKSLASH |
static char |
CHAR_DOUBLE_QUOTE |
static char |
CHAR_ELLIPSIS |
static char |
CHAR_NONE |
static char[] |
XSS_RELATED_CHARACTERS |
static String |
XSS_RELATED_CHARACTERS_FIND_STR |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsRelatedCharacters(@Nullable String string,
@NotNull char[] characters)
Deprecated.
since 5.15 please use
BambooStringUtils.containsRelatedCharacters(java.lang.String, char[]) |
static boolean |
containsRelaxedXssRelatedCharacters(@Nullable String string) |
static boolean |
containsShellInjectionRelatedCharacters(@Nullable String string) |
static boolean |
containsXssRelatedCharacters(@Nullable String string)
Returns true if the supplied string contains characters that could be used to deface a page
or trigger an XSS exploit (characters: "&'<>\).
|
static @NotNull String |
dos2unix(@NotNull String s)
Changes Dos-style line endings to Unix style line endings
|
static String |
encodeHtmlWithTagWhiteList(String string)
Escapes string but preserves few defined tags.
|
static String |
enumSetToString(@NotNull Set<? extends Enum> enumSet)
Converts collection of enums to comma delimited string
|
static @Nullable String |
firstNotBlank(String... strings)
Returns first
String from the array which is not blank (so it is neither whitespace, empty nor null). |
static @NotNull String |
forceAlphaNumeric(@Nullable String str) |
static @NotNull String |
forceValidHtmlId(@NotNull String id)
According to the HTML standard, ID and NAME tokens must begin with a letter ([A-Za-z])
and may be followed by any number of letters,
digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
|
static String |
formatTemplate(String urlTemplate,
Map<String,String> variableValues)
Expands variable references in
urlTemplate with variableValues . |
static @NotNull String |
getFirstRelatedCharacter(@Nullable String string,
@NotNull char[] characters) |
static @NotNull String |
getFirstRelaxedXssRelatedCharacter(@Nullable String string) |
static String |
getFirstShellInjectionRelatedCharacters(@Nullable String string) |
static @NotNull String |
getFirstXssRelatedCharacter(@Nullable String string)
Retrieves first unsafe character from supplied string
|
static boolean |
in(String needle,
String... haystacks) |
static int |
indexOf(String haystack,
String needle,
int n)
Returns n-th occurence of string (index is 0-based)
|
static int |
indexOfRegex(String haystack,
String needle,
int occurence)
Returns n-th occurence of regex (index is 0-based)
|
static boolean |
isMixedCase(@NotNull String value)
Returns true if the passed String contains both uppercase and lowercase characters.
|
static Iterable<String> |
lineIterator(String string) |
static Stream<String> |
lineStream(String input) |
static @Nullable String |
nullIfBlank(@Nullable String string) |
static String |
preventInlining(String constant)
Deprecated.
since 6.3 use
BambooConstantUtils.preventInlining(Object) |
static @NotNull String |
remove(@NotNull String quotedVarValue,
int index)
Removes a character at specified index from string
|
static com.google.common.base.Function<String,String> |
replaceAll(Pattern pattern,
String replacement) |
static com.google.common.base.Function<String,String> |
replaceAll(String regex,
String replacement) |
static boolean |
smartContains(@Nullable String haystack,
@Nullable String needle)
Checks if needle exists in the haystack.
|
static boolean |
startsWithAny(String string,
Collection<String> searchStrings) |
static String |
stripFullyEnclosingQuotes(String input) |
static String |
toCamelCase(@NotNull String string,
char separator)
Returns the string in camel case.
|
static String |
toCommandLineString(@NotNull Iterable<String> commandArgs)
Joins supplied argument into a valid command line, wrapping arguments in single quotes if needed.
|
static @Nullable String |
truncateAndAddEllipsis(@Nullable String string,
int maxLength)
Truncates a string to specified length.
|
static @Nullable String |
truncateAndAddEllipsisToLengthInBytes(@Nullable String string,
int maxBytes) |
static @NotNull String |
unquote(@NotNull String quotedVarValue,
boolean processBackslashes)
Removes quotes from variable using shell rules.
|
public static final char CHAR_NONE
public static final char CHAR_APOSTROPHE
public static final char CHAR_BACKSLASH
public static final char CHAR_DOUBLE_QUOTE
public static final char CHAR_ELLIPSIS
public static final char[] XSS_RELATED_CHARACTERS
public static final String XSS_RELATED_CHARACTERS_FIND_STR
@NotNull public static @NotNull String forceAlphaNumeric(@Nullable @Nullable String str)
public static boolean containsXssRelatedCharacters(@Nullable @Nullable String string)
string
- string to check@NotNull public static @NotNull String getFirstXssRelatedCharacter(@Nullable @Nullable String string)
string
- the string to checkpublic static boolean containsRelaxedXssRelatedCharacters(@Nullable @Nullable String string)
@NotNull public static @NotNull String getFirstRelaxedXssRelatedCharacter(@Nullable @Nullable String string)
public static boolean containsShellInjectionRelatedCharacters(@Nullable @Nullable String string)
public static String getFirstShellInjectionRelatedCharacters(@Nullable @Nullable String string)
@Deprecated public static boolean containsRelatedCharacters(@Nullable @Nullable String string, @NotNull @NotNull char[] characters)
BambooStringUtils.containsRelatedCharacters(java.lang.String, char[])
@NotNull public static @NotNull String getFirstRelatedCharacter(@Nullable @Nullable String string, @NotNull @NotNull char[] characters)
@NotNull public static @NotNull String forceValidHtmlId(@NotNull @NotNull String id)
public static Iterable<String> lineIterator(String string)
public static Stream<String> lineStream(String input)
public static int indexOf(String haystack, String needle, int n)
haystack
- search hereneedle
- search forn
- n-the cocurence to returnpublic static int indexOfRegex(String haystack, String needle, int occurence)
haystack
- search hereneedle
- search foroccurence
- n-the occurence to returnpublic static boolean startsWithAny(String string, Collection<String> searchStrings)
StringUtils.startsWithAny(CharSequence, CharSequence...)
public static String encodeHtmlWithTagWhiteList(String string)
string
- @NotNull public static @NotNull String unquote(@NotNull @NotNull String quotedVarValue, boolean processBackslashes)
quotedVarValue
- processBackslashes
- whether backslash should be treated as a special character or not@NotNull public static @NotNull String remove(@NotNull @NotNull String quotedVarValue, int index)
quotedVarValue
- index
- @Nullable public static @Nullable String truncateAndAddEllipsis(@Nullable @Nullable String string, int maxLength)
string
- stringmaxLength
- maximum length of the string@Nullable public static @Nullable String truncateAndAddEllipsisToLengthInBytes(@Nullable @Nullable String string, int maxBytes)
public static com.google.common.base.Function<String,String> replaceAll(Pattern pattern, String replacement)
public static com.google.common.base.Function<String,String> replaceAll(String regex, String replacement)
@NotNull public static @NotNull String dos2unix(@NotNull @NotNull String s)
public static String toCamelCase(@NotNull @NotNull String string, char separator)
string
- separator
- public static String toCommandLineString(@NotNull @NotNull Iterable<String> commandArgs)
public static String formatTemplate(String urlTemplate, Map<String,String> variableValues)
urlTemplate
with variableValues
.
The variable references look like "${foo}" and will be replaced with the value matching the that key from
variableValues
. The names may not contain '}' characters but are otherwise unconstrained. Variables
which do not have associated values in the request are unmodified.
urlTemplate
- the template to expand.variableValues
- the variable values to use when expanding the templatepublic static String enumSetToString(@NotNull @NotNull Set<? extends Enum> enumSet)
@Deprecated public static String preventInlining(String constant)
BambooConstantUtils.preventInlining(Object)
constant
- The constant to return.@Nullable public static @Nullable String firstNotBlank(String... strings)
String
from the array which is not blank (so it is neither whitespace, empty nor null). If
all strings are blank, null is returned.strings
- array of stringspublic static boolean isMixedCase(@NotNull @NotNull String value)
Character.isUpperCase(int)
and Character.isLowerCase(int)
methods are used to determine character case.value
- a string to testCopyright © 2022 Atlassian Software Systems Pty Ltd. All rights reserved.