Class CharArrayUtil


  • public class CharArrayUtil
    extends Object
    • Method Detail

      • getChars

        public static void getChars​(@NotNull
                                    CharSequence src,
                                    @NotNull
                                    char[] dst,
                                    int dstOffset)
        Copies all symbols from the given char sequence to the given array
        Parameters:
        src - source data holder
        dst - output data buffer
        dstOffset - start offset to use within the given output data buffer
      • getChars

        public static void getChars​(@NotNull
                                    CharSequence src,
                                    @NotNull
                                    char[] dst,
                                    int dstOffset,
                                    int len)
        Copies necessary number of symbols from the given char sequence start to the given array.
        Parameters:
        src - source data holder
        dst - output data buffer
        dstOffset - start offset to use within the given output data buffer
        len - number of source data symbols to copy to the given buffer
      • getChars

        public static void getChars​(@NotNull
                                    CharSequence src,
                                    @NotNull
                                    char[] dst,
                                    int srcOffset,
                                    int dstOffset,
                                    int len)
        Copies necessary number of symbols from the given char sequence to the given array.
        Parameters:
        src - source data holder
        dst - output data buffer
        srcOffset - source text offset
        dstOffset - start offset to use within the given output data buffer
        len - number of source data symbols to copy to the given buffer
      • fromSequenceWithoutCopying

        @Nullable
        public static char[] fromSequenceWithoutCopying​(@Nullable
                                                        CharSequence seq)
      • fromSequence

        @NotNull
        public static char[] fromSequence​(@NotNull
                                          CharSequence seq)
        Returns:
        the underlying char[] array if any, or the new chara array if not
      • fromSequence

        @NotNull
        public static char[] fromSequence​(@NotNull
                                          CharSequence seq,
                                          int start,
                                          int end)
        Returns:
        a new char array containing the sub-sequence's chars
      • shiftForward

        public static int shiftForward​(@NotNull
                                       CharSequence buffer,
                                       int offset,
                                       @NotNull
                                       String chars)
      • shiftForward

        public static int shiftForward​(@NotNull
                                       CharSequence buffer,
                                       int startOffset,
                                       int endOffset,
                                       @NotNull
                                       String chars)
        Tries to find an offset from the [startOffset; endOffset) interval such that a char from the given buffer is not contained at the given 'chars' string.

        Example: buffer="abc", startOffset=0, endOffset = 3, chars="ab". Result: 2

        Parameters:
        buffer - target buffer which symbols should be checked
        startOffset - start offset to use within the given buffer (inclusive)
        endOffset - end offset to use within the given buffer (exclusive)
        chars - pass-through symbols
        Returns:
        offset from the [startOffset; endOffset) which points to a symbol at the given buffer such as that that symbol is not contained at the given 'chars'; endOffset otherwise
      • shiftForwardCarefully

        public static int shiftForwardCarefully​(@NotNull
                                                CharSequence buffer,
                                                int offset,
                                                @NotNull
                                                String chars)
      • shiftForward

        public static int shiftForward​(@NotNull
                                       char[] buffer,
                                       int offset,
                                       @NotNull
                                       String chars)
      • shiftBackward

        public static int shiftBackward​(@NotNull
                                        CharSequence buffer,
                                        int offset,
                                        @NotNull
                                        String chars)
      • shiftBackward

        public static int shiftBackward​(@NotNull
                                        CharSequence buffer,
                                        int minOffset,
                                        int maxOffset,
                                        @NotNull
                                        String chars)
      • shiftBackward

        public static int shiftBackward​(@NotNull
                                        char[] buffer,
                                        int offset,
                                        @NotNull
                                        String chars)
      • shiftForwardUntil

        public static int shiftForwardUntil​(@NotNull
                                            CharSequence buffer,
                                            int offset,
                                            @NotNull
                                            String chars)
      • shiftBackwardUntil

        public static int shiftBackwardUntil​(@NotNull
                                             CharSequence buffer,
                                             int offset,
                                             @NotNull
                                             String chars)
        Calculates offset that points to the given buffer and has the following characteristics:

        • is less than or equal to the given offset;
        • it's guaranteed that all symbols of the given buffer that are located at (returned offset; given offset] interval differ from the given symbols;

        Example: suppose that this method is called with buffer that holds 'test data' symbols, offset that points to the last symbols and 'sf' as a chars to exclude. Offset that points to 's' symbol is returned then, i.e. all symbols of the given buffer that are located after it and not after given offset ('t data') are guaranteed to not contain given chars ('sf').

        Parameters:
        buffer - symbols buffer to check
        offset - initial symbols buffer offset to use
        chars - chars to exclude
        Returns:
        offset of the given buffer that guarantees that all symbols at (returned offset; given offset] interval of the given buffer differ from symbols of given 'chars' arguments; given offset is returned if it is outside of given buffer bounds; '-1' is returned if all document symbols that precede given offset differ from symbols of the given 'chars to exclude'
      • regionMatches

        public static boolean regionMatches​(@NotNull
                                            char[] buffer,
                                            int start,
                                            int end,
                                            @NotNull
                                            CharSequence s)
      • regionMatches

        public static boolean regionMatches​(@NotNull
                                            CharSequence buffer,
                                            int start,
                                            int end,
                                            @NotNull
                                            CharSequence s)
      • regionMatches

        public static boolean regionMatches​(@NotNull
                                            CharSequence s1,
                                            int start1,
                                            int end1,
                                            @NotNull
                                            CharSequence s2,
                                            int start2,
                                            int end2)
      • regionMatches

        public static boolean regionMatches​(@NotNull
                                            CharSequence buffer,
                                            int offset,
                                            @NotNull
                                            CharSequence s)
      • equals

        public static boolean equals​(@NotNull
                                     char[] buffer1,
                                     int start1,
                                     int end1,
                                     @NotNull
                                     char[] buffer2,
                                     int start2,
                                     int end2)
      • indexOf

        public static int indexOf​(@NotNull
                                  char[] buffer,
                                  @NotNull
                                  String pattern,
                                  int fromIndex)
      • indexOf

        public static int indexOf​(@NotNull
                                  CharSequence buffer,
                                  @NotNull
                                  CharSequence pattern,
                                  int fromIndex,
                                  int toIndex)
        Tries to find index of given pattern at the given buffer.
        Parameters:
        buffer - characters buffer which contents should be checked for the given pattern
        pattern - target characters sequence to find at the given buffer
        fromIndex - start index (inclusive). Zero is used if given index is negative
        toIndex - end index (exclusive)
        Returns:
        index of the given pattern at the given buffer if the match is found; -1 otherwise
      • indexOf

        public static int indexOf​(@NotNull
                                  char[] buffer,
                                  char symbol,
                                  int fromIndex,
                                  int toIndex)
        Tries to find index that points to the first location of the given symbol at the given char array at range [from; to).
        Parameters:
        buffer - target symbols holder to check
        symbol - target symbol which offset should be found
        fromIndex - start index to search (inclusive)
        toIndex - end index to search (exclusive)
        Returns:
        index that points to the first location of the given symbol at the given char array at range [from; to) if target symbol is found; -1 otherwise
      • lastIndexOf

        public static int lastIndexOf​(@NotNull
                                      char[] buffer,
                                      char symbol,
                                      int fromIndex,
                                      int toIndex)
        Tries to find index that points to the last location of the given symbol at the given char array at range [from; to).
        Parameters:
        buffer - target symbols holder to check
        symbol - target symbol which offset should be found
        fromIndex - start index to search (inclusive)
        toIndex - end index to search (exclusive)
        Returns:
        index that points to the last location of the given symbol at the given char array at range [from; to) if target symbol is found; -1 otherwise
      • lastIndexOf

        public static int lastIndexOf​(@NotNull
                                      CharSequence buffer,
                                      @NotNull
                                      String pattern,
                                      int maxIndex)
      • lastIndexOf

        public static int lastIndexOf​(@NotNull
                                      char[] buffer,
                                      @NotNull
                                      String pattern,
                                      int maxIndex)
      • containsOnlyWhiteSpaces

        public static boolean containsOnlyWhiteSpaces​(@Nullable
                                                      CharSequence chars)
      • getIndents

        @NotNull
        public static TextRange[] getIndents​(@NotNull
                                             CharSequence charsSequence,
                                             int shift)
      • containLineBreaks

        public static boolean containLineBreaks​(@NotNull
                                                CharSequence seq)
      • containLineBreaks

        public static boolean containLineBreaks​(@Nullable
                                                CharSequence seq,
                                                int fromOffset,
                                                int endOffset)
      • isEmptyOrSpaces

        public static boolean isEmptyOrSpaces​(@NotNull
                                              CharSequence text,
                                              int start,
                                              int end)
        Allows to answer if target region of the given text contains only white space symbols (tabulations, white spaces and line feeds).
        Parameters:
        text - text to check
        start - start offset within the given text to check (inclusive)
        end - end offset within the given text to check (exclusive)
        Returns:
        true if target region of the given text contains white space symbols only; false otherwise