Class StringUtil

java.lang.Object
org.eclipse.net4j.util.StringUtil

public final class StringUtil extends Object
Various static helper methods for dealing with strings.
Author:
Eike Stepper
  • Field Details

  • Method Details

    • create

      public static String create(char c, int length)
      Since:
      3.4
    • formatException

      public static String formatException(Throwable t)
      Since:
      2.0
    • replace

      public static String replace(String text, String find, String replace)
      Since:
      3.16
    • replace

      public static String replace(String text, String[] find, String[] replace)
    • replace

      public static String replace(String str, Map<String,String> replacements)
      Since:
      3.23
    • tokenize

      public static void tokenize(String text, String separators, Consumer<String> tokenConsumer)
      Since:
      3.22
    • split

      public static List<String> split(String text, String separators, String brackets)
      Since:
      3.4
    • safe

      public static String safe(String str)
    • safe

      public static String safe(String str, String def)
      Since:
      3.4
    • safe

      public static String safe(Object object)
      Since:
      3.13
    • safe

      public static String safe(Object object, String def)
      Since:
      3.13
    • escape

      public static String escape(String str)
      Since:
      3.22
    • escape

      public static String escape(String str, char separator)
      Since:
      3.22
    • unescape

      public static String unescape(String str)
      Since:
      3.22
    • unescape

      public static String unescape(String str, char separator)
      Since:
      3.22
    • stripHTML

      public static String stripHTML(String html)
      Since:
      3.26
    • compare

      public static int compare(String s1, String s2)
    • compareIgnoreCase

      public static int compareIgnoreCase(String s1, String s2)
      Since:
      3.23
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(String s1, String s2)
      Since:
      3.23
    • isTrue

      public static boolean isTrue(String s)
      Since:
      3.22
    • isFalse

      public static boolean isFalse(String s)
      Since:
      3.22
    • capAll

      public static String capAll(String str)
      Since:
      2.0
    • cap

      public static String cap(String str)
    • uncapAll

      public static String uncapAll(String str)
      Since:
      2.0
    • uncap

      public static String uncap(String str)
    • occurrences

      public static int occurrences(String str, char c)
    • occurrences

      public static int occurrences(String str, String c)
    • translate

      public static String translate(String str, String from, String to)
      Since:
      3.8
    • convert

      public static String convert(String str, IManagedContainer container)
      Converts expressions of the form $$$name(arguments)$$$ using converters from the given container. Nested expressions are evaluated from the inside out, and argument boundaries are identified before nested values are evaluated. Built-in multi-argument converters therefore retain their argument boundaries even when a nested converter returns a comma. Other converters continue to receive one comma-separated String argument. Inside arguments, $$$name( with a non-empty name that contains no $ takes precedence as a nested expression opener. Every other $ escapes the immediately following character, and an expression closes only when an unescaped ) is immediately followed by $$$. Thus $,, $$, $(, and $) yield literal comma, dollar, and parentheses. Escapes are processed once, and only in expression arguments. For example, $$$equals_ignore_case($$$upper(ws)$$$,WS)$$$ evaluates to true. Multiple expressions are supported, and converter results are not parsed or escaped again. Unknown and malformed expressions are preserved while parsing resumes at subsequent expressions. Nested converters are all evaluated before their outer converter is invoked; boolean and and or therefore do not short-circuit. A null container leaves the string unchanged.
      Parameters:
      str - the string that may contain converter expressions
      container - the container used to resolve converters
      Returns:
      the string with recognized converter expressions evaluated
      Since:
      3.23
    • convert

      public static String convert(String str, IManagedContainer container, Pattern pattern)
      Converts matches of the supplied pattern using the first two capture groups as the converter type and argument. This overload retains the pattern-based, single-pass behavior; use convert(String, IManagedContainer) for the standard nested $$$name(arguments)$$$ syntax.
      Parameters:
      str - the string to convert
      container - the container used to resolve converters
      pattern - the pattern whose first two capture groups contain the converter type and argument
      Returns:
      the string with recognized matches converted
      Since:
      3.23
    • parse

      public static <T> T parse(String str, IManagedContainer container, Class<T> type)
      Since:
      3.23
    • parse

      public static <T> T parse(String str, IManagedContainer container, Class<T> type, boolean enumCaseSensitive)
      Since:
      3.23
    • parseEnum

      public static <E extends Enum<E>> E parseEnum(Class<E> enumType, String name, boolean caseSensitive)
      Since:
      3.29
    • isEmpty

      public static boolean isEmpty(String str)
    • appendSeparator

      public static boolean appendSeparator(StringBuilder builder, String str)
      Since:
      3.16
    • appendSeparator

      public static boolean appendSeparator(StringBuilder builder, char c)
      Since:
      3.16
    • glob

      public static boolean glob(String pattern, String string)
      Matches a string against a pattern.

      Pattern description:

      • * matches 0 or more characters
      • ? matches a single character
      • [...] matches a set and/or range of characters
      • \ escapes the following character
      Since:
      2.0
    • glob

      public static boolean glob(String pattern, String string, String[] subStrings)
      Matches a string against a pattern and fills an array with the sub-matches.

      Pattern description:

      • * matches 0 or more characters
      • ? matches a single character
      • [...] matches a set and/or range of characters
      • \ escapes the following character
      Since:
      2.0
    • equalsUpperOrLowerCase

      @Deprecated public static boolean equalsUpperOrLowerCase(String s, String upperOrLowerCase)
      Deprecated.
      Since:
      3.1