Class StringUtils

java.lang.Object
com.e1c.langtool.common.StringUtils

public class StringUtils extends Object
The common utilities to process or check string content.
  • Field Details

    • EMPTY_ARRAY

      public static final String[] EMPTY_ARRAY
      The empty array of strings
    • EMPTY

      public static final String EMPTY
      The empty string
      See Also:
    • NON_WORD_PATTERN

      public static final Pattern NON_WORD_PATTERN
      The Constant to find that string not contains words RegEx: ^[\s\W_\d]+$
    • SQUARE_BRACKETS_PARAMETER_PATTERN

      public static final Pattern SQUARE_BRACKETS_PARAMETER_PATTERN
      Regular expression pattern to extract parameters enclosed in square brackets from a string. Used for parsing and processing strings containing parameters in square brackets.
    • PERCENT_PARAMETER_PATTERN

      public static final Pattern PERCENT_PARAMETER_PATTERN
      Regular expression pattern to extract parameters enclosed in percent signs from a string. Used for parsing and processing strings containing parameters in percent signs, e.g., %Parameter%.
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • isNullOrEmpty

      public static boolean isNullOrEmpty(String string)
      Returns true if the given string is null or is the empty string.
      Parameters:
      string - a string reference to check
      Returns:
      true if the string is null or is the empty string
    • isNotEmpty

      public static boolean isNotEmpty(String string)
      Checks if given string is not empty.
      Parameters:
      string - the string to check
      Returns:
      true, if the string is not empty
    • capitalize

      public static String capitalize(String source)
      Capitalize the string. Has no effect for capitalized, null or empty strings.
      Parameters:
      source - the source string to capitalize, can be null or empty.
      Returns:
      the capitalized string
    • isCamelCase

      public static boolean isCamelCase(String text)
      Returns true if the given string is written in CamelCase.
       StringUtils.isCamelCase("MrRobot") = true
       StringUtils.isCamelCase("mrRobot") = true
       StringUtils.isCamelCase("mrrobot") = true
       StringUtils.isCamelCase("Mr Robot") = false
       StringUtils.isCamelCase(" MrRobot ") = true
       StringUtils.isCamelCase("Mr.Robot") = true
       StringUtils.isCamelCase("mr.robot") = true
       StringUtils.isCamelCase("Mr. Robot") = false
       StringUtils.isCamelCase(null) = false
       StringUtils.isCamelCase("") = false
       StringUtils.isCamelCase("  ") = false
       
      Parameters:
      text - the string to check a CamelCase notation
      Returns:
      true if the given string is written in CamelCase
    • isBlank

      public static boolean isBlank(String str)
      Returns true if the given string is whitespace or null.
       StringUtils.isBlank(null) = true
       StringUtils.isBlank(" ") = true
       StringUtils.isBlank("\t \n") = true
       StringUtils.isBlank("12") = false
       StringUtils.isBlank(" 12 ") = false
       
      Parameters:
      str - the string to check (it may be null)
      Returns:
      true if the given string is whitespace or null
    • isNotWord

      public static boolean isNotWord(String str)
      Checks if the string is not word or contains words. All special symbols ±!@#$%^&*()~`<>?/\ etc. or digits or spaces, tabs, new line etc. are non word.
      Parameters:
      str - the sting to check
      Returns:
      true, if it is not word
    • textToCamelCase

      public static String textToCamelCase(String name)
      Converts name in plain text to camel case.
      Parameters:
      name - a name in plain text
      Returns:
      the given name converted to camel case
    • nameToText

      public static String nameToText(String nameInput)
      Convert CamleCase Name string to text with spaces.
      Parameters:
      nameInput - the name input
      Returns:
      the string
    • isUpperCase

      public static boolean isUpperCase(String content)
      Checks if the content is upper case.
      Parameters:
      content - the content to check for upper case, cannot be null.
      Returns:
      true, if the content is upper case only
    • isLowerCase

      public static boolean isLowerCase(String content)
      Checks if the content is lower case.
      Parameters:
      content - the content to check for lower case, cannot be null.
      Returns:
      true, if the content is lower case only
    • getParamsIndexesFromString

      public static List<Pair<Integer,Integer>> getParamsIndexesFromString(String text, List<Pattern> patterns)
      Gets parameters from a string. Parameters can be enclosed in [parameter] or %parameter%
      Parameters:
      text - the text, cannot be null
      patterns - the patterns, list of patterns, cannot be null
      Returns:
      the list of index parameters from string, cannot be null
    • replaceStringLiteralParams

      public static List<String> replaceStringLiteralParams(String original, List<String> translations)
      Replaces parameters of the form %Parameter% or [Parameter] in the translated string with their original values. Such parameters are translated separately.
      Parameters:
      original - the original string, cannot be null
      translations - the translations, cannot be null
      Returns:
      the list of replaced translations, cannot be null