You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/08/21 01:00:13 UTC
svn commit: r433075 -
/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Author: akarasulu
Date: Sun Aug 20 16:00:12 2006
New Revision: 433075
URL: http://svn.apache.org/viewvc?rev=433075&view=rev
Log:
applying patches for DIRSERVER-631
Modified:
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=433075&r1=433074&r2=433075&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Sun Aug 20 16:00:12 2006
@@ -830,6 +830,30 @@
return sb.toString();
}
+ /**
+ * Helper function that dump an array of bytes in hex pair form,
+ * without '0x' and space chars
+ *
+ * @param buffer The bytes array to dump
+ * @return A string representation of the array of bytes
+ */
+ public static final String dumpHexPairs( byte[] buffer )
+ {
+ if ( buffer == null )
+ {
+ return "";
+ }
+
+ StringBuffer sb = new StringBuffer();
+
+ for ( int i = 0; i < buffer.length; i++ )
+ {
+ sb.append( ( char ) ( HEX_CHAR[( buffer[i] & 0x00F0 ) >> 4] ) ).append(
+ ( char ) ( HEX_CHAR[buffer[i] & 0x000F] ) );
+ }
+
+ return sb.toString();
+ }
/**
* Return the Unicode char which is coded in the bytes at position 0.
@@ -2184,6 +2208,48 @@
int end = length;
while ( ( end > 0 ) && ( str.charAt( end - 1 ) == ' ' ) )
+ {
+ if ( ( end > 1 ) && ( str.charAt( end - 2 ) == '\\' ) )
+ {
+ break;
+ }
+
+ end--;
+ }
+
+ return ( end == length ? str : str.substring( 0, end ) );
+ }
+
+ /**
+ * <p>
+ * Removes spaces (char <= 32) from end of this String, handling
+ * <code>null</code> by returning <code>null</code>.
+ * </p>
+ * Trim removes start characters <= 32.
+ *
+ * <pre>
+ * StringUtils.trimRight(null) = null
+ * StringUtils.trimRight("") = ""
+ * StringUtils.trimRight(" ") = ""
+ * StringUtils.trimRight("abc") = "abc"
+ * StringUtils.trimRight(" abc ") = " abc"
+ * </pre>
+ *
+ * @param str the String to be trimmed, may be null
+ * @param escapedSpace The last escaped space, if any
+ * @return the trimmed string, <code>null</code> if null String input
+ */
+ public static final String trimRight( String str, int escapedSpace )
+ {
+ if ( isEmpty( str ) )
+ {
+ return "";
+ }
+
+ int length = str.length();
+ int end = length;
+
+ while ( ( end > 0 ) && ( str.charAt( end - 1 ) == ' ' ) && ( end > escapedSpace ) )
{
if ( ( end > 1 ) && ( str.charAt( end - 2 ) == '\\' ) )
{