aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/commons/lang3/CharUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/apache/commons/lang3/CharUtils.java')
-rw-r--r--src/org/apache/commons/lang3/CharUtils.java110
1 files changed, 55 insertions, 55 deletions
diff --git a/src/org/apache/commons/lang3/CharUtils.java b/src/org/apache/commons/lang3/CharUtils.java
index e2ef207..6884625 100644
--- a/src/org/apache/commons/lang3/CharUtils.java
+++ b/src/org/apache/commons/lang3/CharUtils.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,18 +22,18 @@ package org.apache.commons.lang3;
* <p>This class tries to handle {@code null} input gracefully.
* An exception will not be thrown for a {@code null} input.
* Each method documents its behaviour in more detail.</p>
- *
+ *
* <p>#ThreadSafe#</p>
* @since 2.1
* @version $Id$
*/
public class CharUtils {
-
+
private static final String[] CHAR_STRING_ARRAY = new String[128];
-
+
/**
* {@code \u000a} 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
@@ -42,13 +42,13 @@ public class CharUtils {
/**
* {@code \u000d} 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 (char c = 0; c < CHAR_STRING_ARRAY.length; c++) {
@@ -70,10 +70,10 @@ public class CharUtils {
/**
* <p>Converts the String to a Character using the first character, returning
* null for empty Strings.</p>
- *
+ *
* <p>For ASCII 7 bit characters, this uses a cache that will return the
* same Character object each time.</p>
- *
+ *
* <pre>
* CharUtils.toCharacterObject(null) = null
* CharUtils.toCharacterObject("") = null
@@ -90,11 +90,11 @@ public class CharUtils {
}
return Character.valueOf(str.charAt(0));
}
-
+
//-----------------------------------------------------------------------
/**
* <p>Converts the Character to a char throwing an exception for {@code null}.</p>
- *
+ *
* <pre>
* CharUtils.toChar(' ') = ' '
* CharUtils.toChar('A') = 'A'
@@ -111,10 +111,10 @@ public class CharUtils {
}
return ch.charValue();
}
-
+
/**
* <p>Converts the Character to a char handling {@code null}.</p>
- *
+ *
* <pre>
* CharUtils.toChar(null, 'X') = 'X'
* CharUtils.toChar(' ', 'X') = ' '
@@ -131,12 +131,12 @@ public class CharUtils {
}
return ch.charValue();
}
-
+
//-----------------------------------------------------------------------
/**
* <p>Converts the String to a char using the first character, throwing
* an exception on empty Strings.</p>
- *
+ *
* <pre>
* CharUtils.toChar("A") = 'A'
* CharUtils.toChar("BA") = 'B'
@@ -154,11 +154,11 @@ public class CharUtils {
}
return str.charAt(0);
}
-
+
/**
* <p>Converts the String to a char using the first character, defaulting
* the value on empty Strings.</p>
- *
+ *
* <pre>
* CharUtils.toChar(null, 'X') = 'X'
* CharUtils.toChar("", 'X') = 'X'
@@ -176,12 +176,12 @@ public class CharUtils {
}
return str.charAt(0);
}
-
+
//-----------------------------------------------------------------------
/**
* <p>Converts the character to the Integer it represents, throwing an
* exception if the character is not numeric.</p>
- *
+ *
* <p>This method coverts the char '1' to the int 1 and so on.</p>
*
* <pre>
@@ -199,11 +199,11 @@ public class CharUtils {
}
return ch - 48;
}
-
+
/**
* <p>Converts the character to the Integer it represents, throwing an
* exception if the character is not numeric.</p>
- *
+ *
* <p>This method coverts the char '1' to the int 1 and so on.</p>
*
* <pre>
@@ -221,11 +221,11 @@ public class CharUtils {
}
return ch - 48;
}
-
+
/**
* <p>Converts the character to the Integer it represents, throwing an
* exception if the character is not numeric.</p>
- *
+ *
* <p>This method coverts the char '1' to the int 1 and so on.</p>
*
* <pre>
@@ -244,11 +244,11 @@ public class CharUtils {
}
return toIntValue(ch.charValue());
}
-
+
/**
* <p>Converts the character to the Integer it represents, throwing an
* exception if the character is not numeric.</p>
- *
+ *
* <p>This method coverts the char '1' to the int 1 and so on.</p>
*
* <pre>
@@ -267,11 +267,11 @@ public class CharUtils {
}
return toIntValue(ch.charValue(), defaultValue);
}
-
+
//-----------------------------------------------------------------------
/**
* <p>Converts the character to a String that contains the one character.</p>
- *
+ *
* <p>For ASCII 7 bit characters, this uses a cache that will return the
* same String object each time.</p>
*
@@ -289,13 +289,13 @@ public class CharUtils {
}
return new String(new char[] {ch});
}
-
+
/**
* <p>Converts the character to a String that contains the one character.</p>
- *
+ *
* <p>For ASCII 7 bit characters, this uses a cache that will return the
* same String object each time.</p>
- *
+ *
* <p>If {@code null} is passed in, {@code null} will be returned.</p>
*
* <pre>
@@ -313,18 +313,18 @@ public class CharUtils {
}
return toString(ch.charValue());
}
-
+
//--------------------------------------------------------------------------
/**
* <p>Converts the string to the Unicode format '\u0020'.</p>
- *
+ *
* <p>This format is the Java source code format.</p>
*
* <pre>
* CharUtils.unicodeEscaped(' ') = "\u0020"
* CharUtils.unicodeEscaped('A') = "\u0041"
* </pre>
- *
+ *
* @param ch the character to convert
* @return the escaped Unicode string
*/
@@ -338,12 +338,12 @@ public class CharUtils {
}
return "\\u" + Integer.toHexString(ch);
}
-
+
/**
* <p>Converts the string to the Unicode format '\u0020'.</p>
- *
+ *
* <p>This format is the Java source code format.</p>
- *
+ *
* <p>If {@code null} is passed in, {@code null} will be returned.</p>
*
* <pre>
@@ -351,7 +351,7 @@ public class CharUtils {
* CharUtils.unicodeEscaped(' ') = "\u0020"
* CharUtils.unicodeEscaped('A') = "\u0041"
* </pre>
- *
+ *
* @param ch the character to convert, may be null
* @return the escaped Unicode string, null if null input
*/
@@ -361,7 +361,7 @@ public class CharUtils {
}
return unicodeEscaped(ch.charValue());
}
-
+
//--------------------------------------------------------------------------
/**
* <p>Checks whether the character is ASCII 7 bit.</p>
@@ -374,14 +374,14 @@ public class CharUtils {
* CharUtils.isAscii('\n') = true
* CharUtils.isAscii('&copy;') = false
* </pre>
- *
+ *
* @param ch the character to check
* @return true if less than 128
*/
public static boolean isAscii(char ch) {
return ch < 128;
}
-
+
/**
* <p>Checks whether the character is ASCII 7 bit printable.</p>
*
@@ -393,14 +393,14 @@ public class CharUtils {
* CharUtils.isAsciiPrintable('\n') = false
* CharUtils.isAsciiPrintable('&copy;') = false
* </pre>
- *
+ *
* @param ch the character to check
* @return true if between 32 and 126 inclusive
*/
public static boolean isAsciiPrintable(char ch) {
return ch >= 32 && ch < 127;
}
-
+
/**
* <p>Checks whether the character is ASCII 7 bit control.</p>
*
@@ -412,14 +412,14 @@ public class CharUtils {
* CharUtils.isAsciiControl('\n') = true
* CharUtils.isAsciiControl('&copy;') = false
* </pre>
- *
+ *
* @param ch the character to check
* @return true if less than 32 or equals 127
*/
public static boolean isAsciiControl(char ch) {
return ch < 32 || ch == 127;
}
-
+
/**
* <p>Checks whether the character is ASCII 7 bit alphabetic.</p>
*
@@ -431,14 +431,14 @@ public class CharUtils {
* CharUtils.isAsciiAlpha('\n') = false
* CharUtils.isAsciiAlpha('&copy;') = false
* </pre>
- *
+ *
* @param ch the character to check
* @return true if between 65 and 90 or 97 and 122 inclusive
*/
public static boolean isAsciiAlpha(char ch) {
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
}
-
+
/**
* <p>Checks whether the character is ASCII 7 bit alphabetic upper case.</p>
*
@@ -450,14 +450,14 @@ public class CharUtils {
* CharUtils.isAsciiAlphaUpper('\n') = false
* CharUtils.isAsciiAlphaUpper('&copy;') = false
* </pre>
- *
+ *
* @param ch the character to check
* @return true if between 65 and 90 inclusive
*/
public static boolean isAsciiAlphaUpper(char ch) {
return ch >= 'A' && ch <= 'Z';
}
-
+
/**
* <p>Checks whether the character is ASCII 7 bit alphabetic lower case.</p>
*
@@ -469,14 +469,14 @@ public class CharUtils {
* CharUtils.isAsciiAlphaLower('\n') = false
* CharUtils.isAsciiAlphaLower('&copy;') = false
* </pre>
- *
+ *
* @param ch the character to check
* @return true if between 97 and 122 inclusive
*/
public static boolean isAsciiAlphaLower(char ch) {
return ch >= 'a' && ch <= 'z';
}
-
+
/**
* <p>Checks whether the character is ASCII 7 bit numeric.</p>
*
@@ -488,14 +488,14 @@ public class CharUtils {
* CharUtils.isAsciiNumeric('\n') = false
* CharUtils.isAsciiNumeric('&copy;') = false
* </pre>
- *
+ *
* @param ch the character to check
* @return true if between 48 and 57 inclusive
*/
public static boolean isAsciiNumeric(char ch) {
return ch >= '0' && ch <= '9';
}
-
+
/**
* <p>Checks whether the character is ASCII 7 bit numeric.</p>
*
@@ -507,12 +507,12 @@ public class CharUtils {
* CharUtils.isAsciiAlphanumeric('\n') = false
* CharUtils.isAsciiAlphanumeric('&copy;') = false
* </pre>
- *
+ *
* @param ch the character to check
* @return true if between 48 and 57 or 65 and 90 or 97 and 122 inclusive
*/
public static boolean isAsciiAlphanumeric(char ch) {
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9');
}
-
+
} \ No newline at end of file