You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/12/29 09:46:55 UTC

svn commit: r490956 - /directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java

Author: elecharny
Date: Fri Dec 29 00:46:54 2006
New Revision: 490956

URL: http://svn.apache.org/viewvc?view=rev&rev=490956
Log:
Added a normalize method, and fixed some possible NPE

Modified:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java?view=diff&rev=490956&r1=490955&r2=490956
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java Fri Dec 29 00:46:54 2006
@@ -22,6 +22,7 @@
 
 import java.io.IOException;
 
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.directory.shared.ldap.util.unicode.InvalidCharacterException;
 // import org.apache.directory.shared.ldap.util.unicode.Normalizer;
 
@@ -87,15 +88,29 @@
     
     /**
      * 
-     * TODO normalize.
+     * We have to go through 6 steps :
+     * 
+     * 1) Transcode
+     * 2) Map
+     * 3) Normalize
+     * 4) Prohibit
+     * 5) Bidi
+     * 6) Insignifiant Character Handling
+     * 
+     * The first step is already done, the step (3) is not done.
      *
      * @param str
      * @return
      * @throws IOException
      */
-    public static StringBuilder normalize( String str ) throws IOException
+    public static String normalize( String str ) throws IOException
     {
-        return null; //Normalizer.normalize( str, Normalizer.Form.KC );
+        String res = map( str );
+        prohibit( res );
+        res = bidi( res );
+        res = insignifiantSpacesString( res );
+        
+        return res;
     }
     
     /**
@@ -3928,7 +3943,10 @@
      */
     public static void prohibit( String str ) throws InvalidCharacterException
     {
-        prohibit( str.toCharArray() );
+        if ( !StringTools.isEmpty( str ) )
+        {
+            prohibit( str.toCharArray() );
+        }
     }
     
     /**
@@ -3953,6 +3971,12 @@
 
         for ( char c:array )
         {
+            // Shortcut ASCII chars
+            if ( c < 0x0221 )
+            {
+                continue;
+            }
+            
             // RFC 3454, Table A.1
             switch ( c )
             {
@@ -4477,7 +4501,7 @@
                 throw new InvalidCharacterException( c );
             }
 
-            if ( ( c == 0xFFFE ) || ( c <= 0xFFFF ) )
+            if ( ( c == 0xFFFE ) || ( c == 0xFFFF ) )
             {
                 throw new InvalidCharacterException( c );
             }
@@ -4525,7 +4549,7 @@
      */
     public static String bidi( String str )
     {
-        return bidi( str.toCharArray() ).toString();
+        return ( str == null ? str : bidi( str.toCharArray() ).toString() );
     }
     
     /**