Class KiwiStrings2


  • @Beta
    public final class KiwiStrings2
    extends Object
    Utilities related to strings.

    These utilities could be considered for kiwi's KiwiStrings class. Or somewhere else. Or nowhere.

    • Method Detail

      • camelToSnakeCase

        public static String camelToSnakeCase​(String value)
        Convert a camelCase value to snake_case.
        Parameters:
        value - the camelCase value, must not be blank
        Returns:
        the converted snake_case value
        Throws:
        IllegalArgumentException - if value is blank
      • camelToSnakeCaseOrEmpty

        public static Optional<String> camelToSnakeCaseOrEmpty​(@Nullable String value)
        Convert a camelCase value to snake_case.
        Parameters:
        value - the camelCase value
        Returns:
        Optional containing the converted snake_case value, or an empty Optional if the input value is blank
      • camelToSnakeCaseOrNull

        public static String camelToSnakeCaseOrNull​(@Nullable String value)
        Convert a camelCase value to snake_case.
        Parameters:
        value - the camelCase value
        Returns:
        the converted snake_case value, or null if the input value is blank
      • replaceNullCharactersWithEmpty

        public static String replaceNullCharactersWithEmpty​(@Nullable String str)
        Replace null characters (Unicode U+0000) in str with an empty string.
        Parameters:
        str - the string to replace within
        Returns:
        a string with null characters replaced, or the original string if no null characters exist in it
      • replaceNullCharacters

        public static String replaceNullCharacters​(@Nullable String str,
                                                   String replacement,
                                                   @Nullable String defaultValue)
        Replace null characters (Unicode U+0000) in str with the given replacement string. If the input string is null, the default value is returned.
        Parameters:
        str - the string to replace within
        replacement - the replacement string
        defaultValue - the value to return if str is null
        Returns:
        a string with null characters replaced, or the original string if no null characters exist in it