Class CharArrayUtil
- java.lang.Object
-
- jetbrains.buildServer.vcs.patches.diff.apply.CharArrayUtil
-
public class CharArrayUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containLineBreaks(CharSequence seq)
static boolean
containLineBreaks(CharSequence seq, int fromOffset, int endOffset)
static boolean
containsOnlyWhiteSpaces(CharSequence chars)
static boolean
equals(char[] buffer1, int start1, int end1, char[] buffer2, int start2, int end2)
static char[]
fromSequence(CharSequence seq)
static char[]
fromSequence(CharSequence seq, int start, int end)
static char[]
fromSequenceWithoutCopying(CharSequence seq)
static void
getChars(CharSequence src, char[] dst, int dstOffset)
Copies all symbols from the given char sequence to the given arraystatic void
getChars(CharSequence src, char[] dst, int dstOffset, int len)
Copies necessary number of symbols from the given char sequence start to the given array.static void
getChars(CharSequence src, char[] dst, int srcOffset, int dstOffset, int len)
Copies necessary number of symbols from the given char sequence to the given array.static TextRange[]
getIndents(CharSequence charsSequence, int shift)
static int
indexOf(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)
.static int
indexOf(char[] buffer, String pattern, int fromIndex)
static int
indexOf(CharSequence buffer, CharSequence pattern, int fromIndex)
static int
indexOf(CharSequence buffer, CharSequence pattern, int fromIndex, int toIndex)
Tries to find index of given pattern at the given buffer.static boolean
isEmptyOrSpaces(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).static int
lastIndexOf(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)
.static int
lastIndexOf(char[] buffer, String pattern, int maxIndex)
static int
lastIndexOf(CharSequence buffer, String pattern, int maxIndex)
static boolean
regionMatches(char[] buffer, int start, int end, CharSequence s)
static boolean
regionMatches(CharSequence buffer, int start, int end, CharSequence s)
static boolean
regionMatches(CharSequence s1, int start1, int end1, CharSequence s2, int start2, int end2)
static boolean
regionMatches(CharSequence buffer, int offset, CharSequence s)
static int
shiftBackward(char[] buffer, int offset, String chars)
static int
shiftBackward(CharSequence buffer, int minOffset, int maxOffset, String chars)
static int
shiftBackward(CharSequence buffer, int offset, String chars)
static int
shiftBackwardUntil(CharSequence buffer, int offset, String chars)
Calculates offset that points to the given buffer and has the following characteristics:static int
shiftForward(char[] buffer, int offset, String chars)
static int
shiftForward(CharSequence buffer, int startOffset, int endOffset, 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.static int
shiftForward(CharSequence buffer, int offset, String chars)
static int
shiftForwardCarefully(CharSequence buffer, int offset, String chars)
static int
shiftForwardUntil(CharSequence buffer, int offset, String chars)
-
-
-
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 holderdst
- output data bufferdstOffset
- 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 holderdst
- output data bufferdstOffset
- start offset to use within the given output data bufferlen
- 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 holderdst
- output data buffersrcOffset
- source text offsetdstOffset
- start offset to use within the given output data bufferlen
- 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 checkedstartOffset
- 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;
'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 checkoffset
- initial symbols buffer offset to usechars
- 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)
-
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 patternpattern
- target characters sequence to find at the given bufferfromIndex
- start index (inclusive). Zero is used if given index is negativetoIndex
- 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 checksymbol
- target symbol which offset should be foundfromIndex
- 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 checksymbol
- target symbol which offset should be foundfromIndex
- 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 checkstart
- 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
-
-