提交 7f791737 编写于 作者: M martin

6940381: Wording improvements for String.indexOf, String.lastIndexOf

Summary: Make wording of javadoc clearer and more consistent
Reviewed-by: sherman
上级 0f17db6e
...@@ -1719,18 +1719,17 @@ public final class String ...@@ -1719,18 +1719,17 @@ public final class String
/** /**
* Returns the index within this string of the first occurrence of the * Returns the index within this string of the first occurrence of the
* specified substring. The integer returned is the smallest value * specified substring.
* <i>k</i> such that: *
* <p>The returned index is the smallest value <i>k</i> for which:
* <blockquote><pre> * <blockquote><pre>
* this.startsWith(str, <i>k</i>) * this.startsWith(str, <i>k</i>)
* </pre></blockquote> * </pre></blockquote>
* is <code>true</code>. * If no such value of <i>k</i> exists, then {@code -1} is returned.
* *
* @param str any string. * @param str the substring to search for.
* @return if the string argument occurs as a substring within this * @return the index of the first occurrence of the specified substring,
* object, then the index of the first character of the first * or {@code -1} if there is no such occurrence.
* such substring is returned; if it does not occur as a
* substring, <code>-1</code> is returned.
*/ */
public int indexOf(String str) { public int indexOf(String str) {
return indexOf(str, 0); return indexOf(str, 0);
...@@ -1738,17 +1737,19 @@ public final class String ...@@ -1738,17 +1737,19 @@ public final class String
/** /**
* Returns the index within this string of the first occurrence of the * Returns the index within this string of the first occurrence of the
* specified substring, starting at the specified index. The integer * specified substring, starting at the specified index.
* returned is the smallest value <tt>k</tt> for which: *
* <p>The returned index is the smallest value <i>k</i> for which:
* <blockquote><pre> * <blockquote><pre>
* k &gt;= Math.min(fromIndex, this.length()) && this.startsWith(str, k) * <i>k</i> &gt;= fromIndex && this.startsWith(str, <i>k</i>)
* </pre></blockquote> * </pre></blockquote>
* If no such value of <i>k</i> exists, then -1 is returned. * If no such value of <i>k</i> exists, then {@code -1} is returned.
* *
* @param str the substring for which to search. * @param str the substring to search for.
* @param fromIndex the index from which to start the search. * @param fromIndex the index from which to start the search.
* @return the index within this string of the first occurrence of the * @return the index of the first occurrence of the specified substring,
* specified substring, starting at the specified index. * starting at the specified index,
* or {@code -1} if there is no such occurrence.
*/ */
public int indexOf(String str, int fromIndex) { public int indexOf(String str, int fromIndex) {
return indexOf(value, offset, count, return indexOf(value, offset, count,
...@@ -1807,20 +1808,19 @@ public final class String ...@@ -1807,20 +1808,19 @@ public final class String
} }
/** /**
* Returns the index within this string of the rightmost occurrence * Returns the index within this string of the last occurrence of the
* of the specified substring. The rightmost empty string "" is * specified substring. The last occurrence of the empty string ""
* considered to occur at the index value <code>this.length()</code>. * is considered to occur at the index value {@code this.length()}.
* The returned index is the largest value <i>k</i> such that *
* <p>The returned index is the largest value <i>k</i> for which:
* <blockquote><pre> * <blockquote><pre>
* this.startsWith(str, k) * this.startsWith(str, <i>k</i>)
* </pre></blockquote> * </pre></blockquote>
* is true. * If no such value of <i>k</i> exists, then {@code -1} is returned.
* *
* @param str the substring to search for. * @param str the substring to search for.
* @return if the string argument occurs one or more times as a substring * @return the index of the last occurrence of the specified substring,
* within this object, then the index of the first character of * or {@code -1} if there is no such occurrence.
* the last such substring is returned. If it does not occur as
* a substring, <code>-1</code> is returned.
*/ */
public int lastIndexOf(String str) { public int lastIndexOf(String str) {
return lastIndexOf(str, count); return lastIndexOf(str, count);
...@@ -1829,16 +1829,18 @@ public final class String ...@@ -1829,16 +1829,18 @@ public final class String
/** /**
* Returns the index within this string of the last occurrence of the * Returns the index within this string of the last occurrence of the
* specified substring, searching backward starting at the specified index. * specified substring, searching backward starting at the specified index.
* The integer returned is the largest value <i>k</i> such that: *
* <p>The returned index is the largest value <i>k</i> for which:
* <blockquote><pre> * <blockquote><pre>
* k &lt;= Math.min(fromIndex, this.length()) && this.startsWith(str, k) * <i>k</i> &lt;= fromIndex && this.startsWith(str, <i>k</i>)
* </pre></blockquote> * </pre></blockquote>
* If no such value of <i>k</i> exists, then -1 is returned. * If no such value of <i>k</i> exists, then {@code -1} is returned.
* *
* @param str the substring to search for. * @param str the substring to search for.
* @param fromIndex the index to start the search from. * @param fromIndex the index to start the search from.
* @return the index within this string of the last occurrence of the * @return the index of the last occurrence of the specified substring,
* specified substring. * searching backward from the specified index,
* or {@code -1} if there is no such occurrence.
*/ */
public int lastIndexOf(String str, int fromIndex) { public int lastIndexOf(String str, int fromIndex) {
return lastIndexOf(value, offset, count, return lastIndexOf(value, offset, count,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册