directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1671293 - in /directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser: LdifUtils.java model/LdifInvalidPart.java model/lines/LdifLineBase.java
Date Sat, 04 Apr 2015 18:59:07 GMT
Author: elecharny
Date: Sat Apr  4 18:59:07 2015
New Revision: 1671293

URL: http://svn.apache.org/r1671293
Log:
Added a helper method to speed up the transformation of \n and \r by a String

Modified:
    directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/LdifUtils.java
    directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifInvalidPart.java
    directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java

Modified: directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/LdifUtils.java?rev=1671293&r1=1671292&r2=1671293&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/LdifUtils.java
(original)
+++ directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/LdifUtils.java
Sat Apr  4 18:59:07 2015
@@ -193,4 +193,42 @@ public class LdifUtils
 
         return false;
     }
+    
+    
+    /**
+     * Convert all the '\n' and '\r' to a String 
+     * @param s The String to be converted
+     * @return The resulting String
+     */
+    public static String convertNlRcToString( String s )
+    {
+        if ( s == null )
+        {
+            return "";
+        }
+
+        // Worth case, the new string is three times bigger
+        char[] result = new char[s.length() * 3];
+        int pos = 0;
+
+        for ( char c : s.toCharArray() )
+        {
+            if ( c == '\n' )
+            {
+                result[pos++] = '\\';
+                result[pos++] = 'n';
+            }
+            else if ( c == '\r' )
+            {
+                result[pos++] = '\\';
+                result[pos++] = 'r';
+            }
+            else
+            {
+                result[pos++] = c;
+            }
+        }
+
+        return new String( result, 0, pos );
+    }
 }

Modified: directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifInvalidPart.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifInvalidPart.java?rev=1671293&r1=1671292&r2=1671293&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifInvalidPart.java
(original)
+++ directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifInvalidPart.java
Sat Apr  4 18:59:07 2015
@@ -22,6 +22,7 @@ package org.apache.directory.studio.ldif
 
 
 import org.apache.directory.studio.ldifparser.LdifFormatParameters;
+import org.apache.directory.studio.ldifparser.LdifUtils;
 
 
 public final class LdifInvalidPart implements LdifPart
@@ -73,8 +74,8 @@ public final class LdifInvalidPart imple
     public final String toString()
     {
         String text = toRawString();
-        text = text.replaceAll( "\n", "\\\\n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        text = text.replaceAll( "\r", "\\\\r" ); //$NON-NLS-1$ //$NON-NLS-2$
+        text = LdifUtils.convertNlRcToString( text );
+
         return getClass().getName() + " (" + getOffset() + "," + getLength() + "): '" + text
+ "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
     }
 

Modified: directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java?rev=1671293&r1=1671292&r2=1671293&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java
(original)
+++ directory/studio/trunk/plugins/ldifparser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java
Sat Apr  4 18:59:07 2015
@@ -22,6 +22,7 @@ package org.apache.directory.studio.ldif
 
 
 import org.apache.directory.studio.ldifparser.LdifFormatParameters;
+import org.apache.directory.studio.ldifparser.LdifUtils;
 import org.apache.directory.studio.ldifparser.model.LdifPart;
 
 
@@ -128,8 +129,8 @@ public abstract class LdifLineBase imple
     public final String toString()
     {
         String text = toRawString();
-        text = text.replaceAll( "\n", "\\\\n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        text = text.replaceAll( "\r", "\\\\r" ); //$NON-NLS-1$ //$NON-NLS-2$
+        text = LdifUtils.convertNlRcToString( text ); //$NON-NLS-1$ //$NON-NLS-2$
+
         return getClass().getName() + " (" + getOffset() + "," + getLength() + "): '" + text
+ "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
     }
 



Mime
View raw message