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/03/11 18:48:35 UTC
svn commit: r1455256 -
/directory/shared/trunk/util/src/main/java/org/apache/directory/api/util/Strings.java
Author: pamarcelot
Date: Mon Mar 11 17:48:35 2013
New Revision: 1455256
URL: http://svn.apache.org/r1455256
Log:
Added methods supporting a case-sensitive flag to choose between case-sensitive and insensitive comparisons.
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=1455256&r1=1455255&r2=1455256&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 Mon Mar 11 17:48:35 2013
@@ -883,6 +883,21 @@ public final class Strings
*/
public static int areEquals( char[] chars, int index, String text )
{
+ return areEquals( chars, index, text, true );
+ }
+
+
+ /**
+ * Check if a text is present at the current position in a buffer.
+ *
+ * @param chars The buffer which contains the data
+ * @param index Current position in the buffer
+ * @param text The text we want to check
+ * @param caseSensitive If the comparison is case-sensitive
+ * @return <code>true</code> if the buffer contains the text.
+ */
+ public static int areEquals( char[] chars, int index, String text, boolean caseSensitive )
+ {
if ( ( chars == null ) || ( chars.length == 0 ) || ( chars.length <= index ) || ( index < 0 )
|| ( text == null ) )
{
@@ -892,7 +907,7 @@ public final class Strings
{
char[] data = text.toCharArray();
- return areEquals( chars, index, data );
+ return areEquals( chars, index, data, caseSensitive );
}
}
@@ -907,6 +922,21 @@ public final class Strings
*/
public static int areEquals( char[] chars, int index, char[] chars2 )
{
+ return areEquals( chars, index, chars2, true );
+ }
+
+
+ /**
+ * Check if a text is present at the current position in a buffer.
+ *
+ * @param chars The buffer which contains the data
+ * @param index Current position in the buffer
+ * @param chars2 The text we want to check
+ * @param caseSensitive If the comparison is case-sensitive
+ * @return <code>true</code> if the buffer contains the text.
+ */
+ public static int areEquals( char[] chars, int index, char[] chars2, boolean caseSensitive )
+ {
if ( ( chars == null ) || ( chars.length == 0 ) || ( chars.length <= index ) || ( index < 0 )
|| ( chars2 == null ) || ( chars2.length == 0 )
|| ( chars2.length > ( chars.length - index ) ) )
@@ -917,7 +947,16 @@ public final class Strings
{
for ( int i = 0; i < chars2.length; i++ )
{
- if ( chars[index++] != chars2[i] )
+ char c1 = chars[index++];
+ char c2 = chars2[i];
+
+ if ( !caseSensitive )
+ {
+ c1 = Character.toLowerCase( c1 );
+ c2 = Character.toLowerCase( c2 );
+ }
+
+ if ( c1 != c2 )
{
return StringConstants.NOT_EQUAL;
}