mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fixes char-array comparison, bug 289852.
This commit is contained in:
parent
38631986c6
commit
7ad14d08db
2 changed files with 13 additions and 2 deletions
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.core.parser.tests;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
|
@ -39,4 +40,14 @@ public class CharArrayUtilsTest extends TestCase {
|
|||
Object ivalue4 = map.get("ikey4".toCharArray());
|
||||
assertEquals(ivalue4, new Integer(4));
|
||||
}
|
||||
|
||||
public void testEquals_Bug289852() {
|
||||
assertTrue(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 3, "abc".toCharArray(), false));
|
||||
assertFalse(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 4, "abcd".toCharArray(), false));
|
||||
assertTrue(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 2, "ab".toCharArray(), false));
|
||||
|
||||
assertTrue(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 3, "ABC".toCharArray(), true));
|
||||
assertFalse(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 4, "abcd".toCharArray(), true));
|
||||
assertTrue(CharArrayUtils.equals("pre_abc".toCharArray(), 4, 2, "AB".toCharArray(), true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class CharArrayUtils {
|
|||
}
|
||||
|
||||
public static final boolean equals(char[] str1, int start1, int length1, char[] str2) {
|
||||
if (length1 != str2.length || str1.length < length1 )
|
||||
if (length1 != str2.length || str1.length < length1+start1 )
|
||||
return false;
|
||||
if( str1 == str2 && start1 == 0 )
|
||||
return true;
|
||||
|
@ -104,7 +104,7 @@ public class CharArrayUtils {
|
|||
if( !ignoreCase )
|
||||
return equals( str1, start1, length1, str2 );
|
||||
|
||||
if (length1 != str2.length || str1.length < length1 )
|
||||
if (length1 != str2.length || str1.length < start1 + length1 )
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < length1; ++i)
|
||||
|
|
Loading…
Add table
Reference in a new issue