Class StringUtil

    • Field Detail

      • LF

        public static final char LF
        Linefeed character unicode '\n', 0x000A.
        See Also:
        Constant Field Values
      • SPACE

        public static final char SPACE
        Space character unicode ' ', 0x0020.
        See Also:
        Constant Field Values
      • WHITESPACE

        public static final String WHITESPACE
        List of ASCII & Unicode space separator, aka Whitespace.
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • isWhitespace

        public static boolean isWhitespace​(int cp)
        Return true if given codepoint in included within WHITESPACE.
      • isFullwidth

        public static boolean isFullwidth​(int cp)
        Returns true if given codepoint is a fullwidth unicode character.
      • isHalfwidth

        public static boolean isHalfwidth​(int cp)
        Returns true if given codepoint is a halfwidth unicode character.
      • getLineCount

        public static int getLineCount​(CharSequence s)
        Returns number of lines, i.e. number of non-empty lines, separated by LF.
      • trim

        public static String trim​(String text,
                                  String separators,
                                  String replacement)
        Remove all leading, trailing and duplicate-within separators unicode character from the text.

        Duplicate separators unicode character within the text are reduced to one occurrence and might be replaced with replacement if not null.

        Parameters:
        text - the source text
        separators - separator unicode characters, pass null for whitespace. Consider using WHITESPACE to cover all unicode space character.
        replacement - optional replacement string for matched separator within sequence removing duplicated. If null, the first found separator is used.
        Returns:
        stripped text
      • split

        public static List<String> split​(String text,
                                         int lineCount,
                                         String separators)
        Returns an array of split text at separators or whitespace.

        Each line's cutting point is the first separator or whitespace occurrence starting at text.length() / lineCount * 0.9.

        The separator or whitespace character at the cutting point is skipped in the resulting array of the split parts, i.e. lines.

        Parameters:
        text - the text to be split, null results in an empty list
        lineCount - number of resulting lines
        separators - separator unicode characters, pass null for whitespace. Consider using WHITESPACE to cover all unicode space character.
        See Also:
        split(String, int, String, String)
      • split

        public static String split​(String text,
                                   int lineCount,
                                   String separators,
                                   String lineSeparator)
        Returns a multi-line string of split text at separators or whitespace glued with given lineSeparator.

        Each line's cutting point is the first separator or whitespace occurrence starting at text.length() / lineCount * 0.9.

        The separator character or whitespace at the cutting point is skipped in the string of glued split parts, i.e. lines.

        Parameters:
        text - the text to be split, null results in an empty list
        lineCount - number of resulting lines
        separators - separator unicode characters, pass null for whitespace. Consider using WHITESPACE to cover all unicode space character.
        lineSeparator - the glue placed between the split lines in the concatenated result
        See Also:
        split(String, int, String)