dota17 commented on a change in pull request #534:
URL: https://github.com/apache/commons-lang/pull/534#discussion_r435644787



##########
File path: src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
##########
@@ -252,17 +252,58 @@ static int lastIndexOf(final CharSequence cs, final 
CharSequence searchChar, fin
      * Green implementation of regionMatches.
      *
      * @param cs the {@code CharSequence} to be processed
-     * @param ignoreCase whether or not to be case insensitive
      * @param thisStart the index to start on the {@code cs} CharSequence
      * @param substring the {@code CharSequence} to be looked for
      * @param start the index to start on the {@code substring} CharSequence
      * @param length character length of the region
      * @return whether the region matched
      */
-    static boolean regionMatches(final CharSequence cs, final boolean 
ignoreCase, final int thisStart,
-            final CharSequence substring, final int start, final int length)   
 {
+    static boolean regionMatches(final CharSequence cs, final int thisStart,
+                                 final CharSequence substring, final int 
start, final int length)    {
+        if (cs instanceof String && substring instanceof String) {
+            return ((String) cs).regionMatches(thisStart, (String) substring, 
start, length);
+        }
+        int index1 = thisStart;
+        int index2 = start;
+        int tmpLen = length;
+
+        // Extract these first so we detect NPEs the same as the 
java.lang.String version
+        final int srcLen = cs.length() - thisStart;
+        final int otherLen = substring.length() - start;
+
+        // Check for invalid parameters
+        if (thisStart < 0 || start < 0 || length < 0) {
+            return false;
+        }
+
+        // Check that the regions are long enough
+        if (srcLen < length || otherLen < length) {
+            return false;
+        }
+
+        while (tmpLen-- > 0) {

Review comment:
       while (tmpLen -- > 0) {




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to