### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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.2.4.1 diff -u -r1.2.4.1 JavadocContents.java --- model/org/eclipse/jdt/internal/core/JavadocContents.java 9 Aug 2010 09:44:39 -0000 1.2.4.1 +++ model/org/eclipse/jdt/internal/core/JavadocContents.java 17 Jan 2011 10:02:30 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. + * Copyright (c) 2009, 2011 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 @@ -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 && Util.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 (Util.prefixEquals(anchor, this.content, false, anchorEndStart)) { return computeChildRange(anchorEndStart, anchor, indexOfSectionBottom); } else { if (this.tempAnchorIndexes.length == this.tempAnchorIndexesCount) { Index: model/org/eclipse/jdt/internal/core/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v retrieving revision 1.143 diff -u -r1.143 Util.java --- model/org/eclipse/jdt/internal/core/util/Util.java 9 Apr 2010 13:38:05 -0000 1.143 +++ model/org/eclipse/jdt/internal/core/util/Util.java 17 Jan 2011 10:02:31 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -3621,4 +3621,60 @@ } } } + + /** + * 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 + */ + public static final boolean prefixEquals( + char[] prefix, + char[] name, + boolean isCaseSensitive, + int startIndex) { + + int max = prefix.length; + 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[startIndex + i]) + return false; + return true; + } + + for (int i = max; --i >= 0;) // assumes the prefix is not larger than the name + if (ScannerHelper.toLowerCase(prefix[i]) + != ScannerHelper.toLowerCase(name[startIndex + i])) + return false; + return true; + } } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/UtilTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UtilTest.java,v retrieving revision 1.37 diff -u -r1.37 UtilTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/UtilTest.java 27 Jun 2008 16:04:45 -0000 1.37 +++ src/org/eclipse/jdt/core/tests/compiler/regression/UtilTest.java 17 Jan 2011 10:02:34 -0000 @@ -15,6 +15,7 @@ //import org.apache.tools.ant.types.selectors.SelectorUtils; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.core.util.Util; //import junit.framework.AssertionFailedError; import junit.framework.Test; @@ -738,6 +739,20 @@ // Verify that there were no unexpected results assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); } + +// test org.eclipse.jdt.internal.compiler.util.Util.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(Util.prefixEquals(prefix, name, false, 2)); + prefix = new char[] { 'c', 'a', 'a', 'a' }; + assertFalse(Util.prefixEquals(prefix, name, false, 2)); + prefix = new char[] { 'c', 'a', 'A' }; + assertFalse(Util.prefixEquals(prefix, name, true, 2)); + prefix = new char[] { 'b', 'c' }; + assertFalse(Util.prefixEquals(prefix, name, false, 2)); + assertTrue(Util.prefixEquals(prefix, name, false, 1)); +} public static Class testClass() { return UtilTest.class; }