You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2005/08/08 20:59:00 UTC
svn commit: r230857 - in
/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang:
CharUtils.java StringUtils.java text/StrBuilder.java
Author: ggregory
Date: Mon Aug 8 11:58:58 2005
New Revision: 230857
URL: http://svn.apache.org/viewcvs?rev=230857&view=rev
Log:
Fix some Checkstyle and PMD warnings. Extract constants from in-lined '\n' and '\r' in StringUtils.java.
Modified:
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/CharUtils.java
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/CharUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/CharUtils.java?rev=230857&r1=230856&r2=230857&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/CharUtils.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/CharUtils.java Mon Aug 8 11:58:58 2005
@@ -49,13 +49,32 @@
private static final String[] CHAR_STRING_ARRAY = new String[128];
private static final Character[] CHAR_ARRAY = new Character[128];
+ /**
+ * <code>\u000a</code> linefeed LF ('\n').
+ *
+ * @see <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#101089">JLF: Escape Sequences
+ * for Character and String Literals</a>
+ * @since 2.2
+ */
+ public static final char LF = '\n';
+
+ /**
+ * <code>\u000d</code> carriage return CR ('\r').
+ *
+ * @see <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#101089">JLF: Escape Sequences
+ * for Character and String Literals</a>
+ * @since 2.2
+ */
+ public static final char CR = '\r';
+
+
static {
for (int i = 127; i >= 0; i--) {
CHAR_STRING_ARRAY[i] = CHAR_STRING.substring(i, i + 1);
CHAR_ARRAY[i] = new Character((char) i);
}
}
-
+
/**
* <p><code>CharUtils</code> instances should NOT be constructed in standard programming.
* Instead, the class should be used as <code>CharUtils.toString('c');</code>.</p>
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java?rev=230857&r1=230856&r2=230857&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Mon Aug 8 11:58:58 2005
@@ -3196,7 +3196,7 @@
if (str.length() == 1) {
char ch = str.charAt(0);
- if (ch == '\r' || ch == '\n') {
+ if (ch == CharUtils.CR || ch == CharUtils.LF) {
return EMPTY;
} else {
return str;
@@ -3206,11 +3206,11 @@
int lastIdx = str.length() - 1;
char last = str.charAt(lastIdx);
- if (last == '\n') {
- if (str.charAt(lastIdx - 1) == '\r') {
+ if (last == CharUtils.LF) {
+ if (str.charAt(lastIdx - 1) == CharUtils.CR) {
lastIdx--;
}
- } else if (last == '\r') {
+ } else if (last == CharUtils.CR) {
// why is this block empty?
// just to skip incrementing the index?
;
@@ -3392,8 +3392,8 @@
int lastIdx = strLen - 1;
String ret = str.substring(0, lastIdx);
char last = str.charAt(lastIdx);
- if (last == '\n') {
- if (ret.charAt(lastIdx - 1) == '\r') {
+ if (last == CharUtils.LF) {
+ if (ret.charAt(lastIdx - 1) == CharUtils.CR) {
return ret.substring(0, lastIdx - 1);
}
}
@@ -3416,8 +3416,8 @@
return EMPTY;
}
char last = str.charAt(lastIdx);
- if (last == '\n') {
- if (str.charAt(lastIdx - 1) == '\r') {
+ if (last == CharUtils.LF) {
+ if (str.charAt(lastIdx - 1) == CharUtils.CR) {
lastIdx--;
}
} else {
Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java?rev=230857&r1=230856&r2=230857&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java Mon Aug 8 11:58:58 2005
@@ -153,9 +153,7 @@
if (length < 0) {
throw new StringIndexOutOfBoundsException(length);
}
- if (length == size) {
- // ok
- } else if (length < size) {
+ if (length < size) {
size = length;
} else {
ensureCapacity(length);
@@ -286,14 +284,16 @@
/**
* Copies part of the builder's character array into a new character array.
*
- * @param startIndex the start index, inclusive, must be valid
- * @param endIndex the end index, exclusive, must be valid except
- * that if too large it is treated as end of string
+ * @param startIndex
+ * the start index, inclusive, must be valid
+ * @param endIndex
+ * the end index, exclusive, must be valid except that if too large it is treated as end of string
* @return a new array that holds part of the contents of the builder
*
- * @throws StringIndexOutOfBoundsException when <code>startIndex</code> is less than 0;
- * when <code>startIndex</code> is greater than <code>endIndex</code> (if <code>endIndex</code>
- * is larger than {@link #size() }, then it is massaged to equal {@link #size()} before the validation).
+ * @throws StringIndexOutOfBoundsException
+ * when <code>startIndex</code> is less than 0; when <code>startIndex</code> is greater than
+ * <code>endIndex</code> (if <code>endIndex</code> is larger than {@link #size() }, then it is
+ * massaged to equal {@link #size()} before the validation).
*/
public char[] toCharArray(int startIndex, int endIndex) {
endIndex = validateRange(startIndex, endIndex);
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org