### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/core/compiler/CharOperation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/CharOperation.java,v retrieving revision 1.88 diff -u -r1.88 CharOperation.java --- compiler/org/eclipse/jdt/core/compiler/CharOperation.java 9 Aug 2010 09:43:40 -0000 1.88 +++ compiler/org/eclipse/jdt/core/compiler/CharOperation.java 18 Nov 2010 15:18:42 -0000 @@ -2939,24 +2939,62 @@ char[] prefix, char[] name, boolean isCaseSensitive) { + return prefixEquals(prefix, name, isCaseSensitive, 0); +} + +/** + * Answers true if the given name, starting from the given index, starts with the given prefix, + * false otherwise. isCaseSensitive is used to find out whether or not the comparison should be + * case sensitive. + *
+ *
+ * For example: + *
    + *
  1. + *    prefix = { 'a' , 'B' }
    + *    name = { 'c', 'd', 'a' , 'b', 'b', 'a', 'b', 'a' }
    + *    startIndex = 2
    + *    isCaseSensitive = false
    + *    result => true
    + * 
    + *
  2. + *
  3. + *    prefix = { 'a' , 'B' }
    + *    name = { 'c', 'd', 'a' , 'b', 'b', 'a', 'b', 'a' }
    + *    startIndex = 2
    + *    isCaseSensitive = true
    + *    result => false
    + * 
    + *
  4. + *
+ * + * @param prefix the given prefix + * @param name the given name + * @param isCaseSensitive to find out whether or not the comparison should be case sensitive + * @param startIndex index from which the prefix should be searched in the name + * @return true if the given name starts with the given prefix, false otherwise + * @throws NullPointerException if the given name is null or if the given prefix is null + * @since 3.7 + */ +public static final boolean prefixEquals( + char[] prefix, + char[] name, + boolean isCaseSensitive, + int startIndex) { int max = prefix.length; - if (name.length < max) + if (name.length - startIndex < max) return false; if (isCaseSensitive) { - for (int i = max; - --i >= 0; - ) // assumes the prefix is not larger than the name - if (prefix[i] != name[i]) + for (int i = max; --i >= 0;) // assumes the prefix is not larger than the name + if (prefix[i] != name[startIndex + i]) return false; return true; } - for (int i = max; - --i >= 0; - ) // assumes the prefix is not larger than the name + for (int i = max; --i >= 0;) // assumes the prefix is not larger than the name if (ScannerHelper.toLowerCase(prefix[i]) - != ScannerHelper.toLowerCase(name[i])) + != ScannerHelper.toLowerCase(name[startIndex + i])) return false; return true; } Index: model/org/eclipse/jdt/internal/core/JavadocContents.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavadocContents.java,v retrieving revision 1.3 diff -u -r1.3 JavadocContents.java --- model/org/eclipse/jdt/internal/core/JavadocContents.java 9 Aug 2010 09:43:40 -0000 1.3 +++ model/org/eclipse/jdt/internal/core/JavadocContents.java 18 Nov 2010 15:18:42 -0000 @@ -145,7 +145,7 @@ for (int i = 0; i < this.tempAnchorIndexesCount; i++) { int anchorEndStart = this.tempAnchorIndexes[i]; - if (anchorEndStart != -1 && CharOperation.indexOf(anchor, this.content, false, anchorEndStart) == anchorEndStart) { + if (anchorEndStart != -1 && CharOperation.prefixEquals(anchor, this.content, false, anchorEndStart)) { this.tempAnchorIndexes[i] = -1; @@ -165,7 +165,7 @@ this.tempLastAnchorFoundIndex = anchorEndStart; - if (CharOperation.indexOf(anchor, this.content, false, anchorEndStart) == anchorEndStart) { + if (CharOperation.prefixEquals(anchor, this.content, false, anchorEndStart)) { return computeChildRange(anchorEndStart, anchor, indexOfSectionBottom); } else { if (this.tempAnchorIndexes.length == this.tempAnchorIndexesCount) { #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/CharOperationTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CharOperationTest.java,v retrieving revision 1.10 diff -u -r1.10 CharOperationTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/CharOperationTest.java 9 Aug 2010 09:35:48 -0000 1.10 +++ src/org/eclipse/jdt/core/tests/compiler/regression/CharOperationTest.java 18 Nov 2010 15:18:42 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -22,7 +22,9 @@ public static Test suite() { return buildAllCompliancesTestSuite(testClass()); } - +public static Class testClass() { + return CharOperationTest.class; +} public void test001() { char[] array = { 'a' , 'b', 'b', 'c', 'a', 'b', 'c', 'a' }; char[] toBeReplaced = { 'b', 'c' }; @@ -120,7 +122,17 @@ char[] array2 = new char[] { 'a' , 'b', 'c', 'a', 'a'}; assertTrue(CharOperation.indexOf(array, array2, false, -1) < 0); } -public static Class testClass() { - return CharOperationTest.class; +//test new API org.eclipse.jdt.core.compiler.CharOperation.prefixEquals(char[], char[], boolean, int) +public void test010() { + char[] name = new char[] { 'a' , 'b', 'c', 'a', 'a' }; + char[] prefix = new char[] { 'c', 'a', 'a' }; + assertTrue(CharOperation.prefixEquals(prefix, name, false, 2)); + prefix = new char[] { 'c', 'a', 'a', 'a' }; + assertFalse(CharOperation.prefixEquals(prefix, name, false, 2)); + prefix = new char[] { 'c', 'a', 'A' }; + assertFalse(CharOperation.prefixEquals(prefix, name, true, 2)); + prefix = new char[] { 'b', 'c' }; + assertFalse(CharOperation.prefixEquals(prefix, name, false, 2)); + assertTrue(CharOperation.prefixEquals(prefix, name, false, 1)); } }