directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r432499 - /directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Date Fri, 18 Aug 2006 06:45:41 GMT
Author: elecharny
Date: Thu Aug 17 23:45:40 2006
New Revision: 432499

URL: http://svn.apache.org/viewvc?rev=432499&view=rev
Log:
Added two methods usefull for parsing DN. The first one dumps
hex pairs and the second one trim string with a limit

Modified:
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=432499&r1=432498&r2=432499&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Thu Aug 17 23:45:40 2006
@@ -831,6 +831,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.
@@ -2185,6 +2209,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 &lt;= 32) from end of this String, handling
+     * <code>null</code> by returning <code>null</code>.
+     * </p>
+     * Trim removes start characters &lt;= 32.
+     * 
+     * <pre>
+     *  StringUtils.trimRight(null)          = null
+     *  StringUtils.trimRight(&quot;&quot;)            = &quot;&quot;
+     *  StringUtils.trimRight(&quot;     &quot;)       = &quot;&quot;
+     *  StringUtils.trimRight(&quot;abc&quot;)         = &quot;abc&quot;
+     *  StringUtils.trimRight(&quot;    abc    &quot;) = &quot;    abc&quot;
+     * </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 ) == '\\' ) )
             {



Mime
View raw message