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 booleancontainLineBreaks(CharSequence seq)static booleancontainLineBreaks(CharSequence seq, int fromOffset, int endOffset)static booleancontainsOnlyWhiteSpaces(CharSequence chars)static booleanequals(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 voidgetChars(CharSequence src, char[] dst, int dstOffset)Copies all symbols from the given char sequence to the given arraystatic voidgetChars(CharSequence src, char[] dst, int dstOffset, int len)Copies necessary number of symbols from the given char sequence start to the given array.static voidgetChars(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 intindexOf(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 intindexOf(char[] buffer, String pattern, int fromIndex)static intindexOf(CharSequence buffer, CharSequence pattern, int fromIndex)static intindexOf(CharSequence buffer, CharSequence pattern, int fromIndex, int toIndex)Tries to find index of given pattern at the given buffer.static booleanisEmptyOrSpaces(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 intlastIndexOf(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 intlastIndexOf(char[] buffer, String pattern, int maxIndex)static intlastIndexOf(CharSequence buffer, String pattern, int maxIndex)static booleanregionMatches(char[] buffer, int start, int end, CharSequence s)static booleanregionMatches(CharSequence buffer, int start, int end, CharSequence s)static booleanregionMatches(CharSequence s1, int start1, int end1, CharSequence s2, int start2, int end2)static booleanregionMatches(CharSequence buffer, int offset, CharSequence s)static intshiftBackward(char[] buffer, int offset, String chars)static intshiftBackward(CharSequence buffer, int minOffset, int maxOffset, String chars)static intshiftBackward(CharSequence buffer, int offset, String chars)static intshiftBackwardUntil(CharSequence buffer, int offset, String chars)Calculates offset that points to the given buffer and has the following characteristics:static intshiftForward(char[] buffer, int offset, String chars)static intshiftForward(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 intshiftForward(CharSequence buffer, int offset, String chars)static intshiftForwardCarefully(CharSequence buffer, int offset, String chars)static intshiftForwardUntil(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';endOffsetotherwise
-
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;
-1otherwise
-
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;-1otherwise
-
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;-1otherwise
-
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:
trueif target region of the given text contains white space symbols only;falseotherwise
-
-