Package io.karatelabs.common
Class StringUtils
java.lang.Object
io.karatelabs.common.StringUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildShellCommand(String command, String... args) Builds a complete shell command from command name and arguments.static StringbuildShellCommand(String command, List<String> args) Builds a complete shell command from command name and arguments.static booleancontainsIgnoreCase(List<String> list, String str) static intcountLineFeeds(String text) static StringformatFileSize(int bytes) static StringformatJson(Object o) static StringformatJson(Object o, boolean pretty, boolean lenient, boolean sort) static StringformatJson(Object o, boolean pretty, boolean lenient, boolean sort, String indent) static <T> TgetIgnoreKeyCase(Map<String, T> map, String name) static StringgetLineContinuation(String platform) Returns the line continuation character for the specified shell platform.static booleanstatic booleanstatic Stringstatic Stringjoin(Collection<String> c, String delimiter) static booleanstatic StringrandomAlphaNumeric(int len) static voidremoveIgnoreKeyCase(Map<String, ?> map, String name) static Stringrepeat(char c, int count) static StringshellEscape(String value) Escapes a string for safe use as a shell argument.static StringshellEscapeForPlatform(String value, String platform) Escapes a string for the specified shell platform.static StringshellEscapePowerShell(String value) Escapes a string for PowerShell.static StringshellEscapeUnix(String value) Escapes a string for Unix/Mac/Linux shell (bash, sh, zsh).static StringshellEscapeWindows(String value) Escapes a string for Windows cmd.exe.splitByFirstLineFeed(String text) static Stringstatic StringtoIdString(String name) static String[]tokenizeCliCommand(String command) Tokenizes a CLI command string into individual arguments.toStringLines(String text) static Stringstatic StringtrimToNull(String s) static Stringstatic intwrappedLinesEstimate(String text, int colWidth)
-
Field Details
-
EMPTY
- See Also:
-
-
Method Details
-
looksLikeJson
-
isXml
-
truncate
-
trimToEmpty
-
trimToNull
-
repeat
-
join
-
join
-
split
-
isBlank
-
toIdString
-
splitByFirstLineFeed
-
toStringLines
-
countLineFeeds
-
wrappedLinesEstimate
-
containsIgnoreCase
-
getIgnoreKeyCase
-
removeIgnoreKeyCase
-
simplify
-
throwableToString
-
tokenizeCliCommand
Tokenizes a CLI command string into individual arguments. Handles both single-quoted and double-quoted strings.- Parameters:
command- the command string to tokenize- Returns:
- array of arguments
-
shellEscape
Escapes a string for safe use as a shell argument. Uses OS-appropriate escaping (single quotes for Unix, double quotes for Windows).- Parameters:
value- the string to escape- Returns:
- escaped string suitable for shell command
-
shellEscapeUnix
Escapes a string for Unix/Mac/Linux shell (bash, sh, zsh). Uses single quotes and escapes embedded single quotes as '\''- Parameters:
value- the string to escape- Returns:
- escaped string wrapped in single quotes
-
shellEscapeWindows
Escapes a string for Windows cmd.exe. Uses double quotes and escapes embedded double quotes and special chars.- Parameters:
value- the string to escape- Returns:
- escaped string wrapped in double quotes
-
shellEscapePowerShell
Escapes a string for PowerShell. Uses single quotes and escapes embedded single quotes by doubling them.- Parameters:
value- the string to escape- Returns:
- escaped string wrapped in single quotes
-
shellEscapeForPlatform
Escapes a string for the specified shell platform.- Parameters:
value- the string to escapeplatform- "sh" for Unix/Linux/macOS, "cmd" for Windows CMD, "ps" for PowerShell- Returns:
- escaped string suitable for the target platform
-
getLineContinuation
Returns the line continuation character for the specified shell platform.- Parameters:
platform- "sh" for Unix/Linux/macOS, "cmd" for Windows CMD, "ps" for PowerShell- Returns:
- line continuation string
-
buildShellCommand
Builds a complete shell command from command name and arguments. Properly escapes each argument for the current OS.- Parameters:
command- the command nameargs- the arguments- Returns:
- complete shell command string
-
buildShellCommand
Builds a complete shell command from command name and arguments. Properly escapes each argument for the current OS.- Parameters:
command- the command nameargs- the arguments- Returns:
- complete shell command string
-
randomAlphaNumeric
-
formatFileSize
-
formatJson
-
formatJson
-
formatJson
-