You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2013/02/22 14:56:14 UTC
svn commit: r1449045 -
/directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Strings.java
Author: pamarcelot
Date: Fri Feb 22 13:56:14 2013
New Revision: 1449045
URL: http://svn.apache.org/r1449045
Log:
Added utility method for chars.
Modified:
directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Strings.java
Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Strings.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Strings.java?rev=1449045&r1=1449044&r2=1449045&view=diff
==============================================================================
--- directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Strings.java (original)
+++ directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Strings.java Fri Feb 22 13:56:14 2013
@@ -938,7 +938,6 @@ public final class Strings
*/
public static int areEquals( byte[] bytes, int index, byte[] bytes2 )
{
-
if ( ( bytes == null ) || ( bytes.length == 0 ) || ( bytes.length <= index ) || ( index < 0 )
|| ( bytes2 == null ) || ( bytes2.length == 0 )
|| ( bytes2.length > ( bytes.length + index ) ) )
@@ -1545,6 +1544,33 @@ public final class Strings
/**
+ * Get the char at a given position in a byte array, checking for limits
+ *
+ * @param chars The char[] which contains the data
+ * @param index Current position in the char[]
+ * @return The byte at the given position, or '\0' if something went wrong
+ */
+ public static char charAt( char[] chars, int index )
+ {
+ if ( chars == null )
+ {
+ return '\0';
+ }
+
+ int length = chars.length;
+
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ {
+ return '\0';
+ }
+ else
+ {
+ return chars[index];
+ }
+ }
+
+
+ /**
* Thansform an array of ASCII bytes to a string. the byte array should contains
* only values in [0, 127].
*