← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5904: Minor simplification in TextUtils

 

------------------------------------------------------------
revno: 5904
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-02-09 19:32:12 +0100
message:
  Minor simplification in TextUtils
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2012-02-08 16:08:43 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2012-02-09 18:32:12 +0000
@@ -39,7 +39,7 @@
 {
     public static final TextUtils INSTANCE = new TextUtils();
     
-    private static final Pattern LINK_PATTERN = Pattern.compile( "(http://|https://|www\\.).+?($| )" );
+    private static final Pattern LINK_PATTERN = Pattern.compile( "((http://|https://|www\\.).+?)($| )" );
     
     /**
      * Substitutes links in the given text with valid HTML mark-up. For instance, 
@@ -62,15 +62,14 @@
         
         while ( matcher.find() )
         {
-            String match = matcher.group();
-
-            String suffix = match.endsWith( " " ) ? " " : "";
-            
-            String ref = match.trim().startsWith( "www." ) ? "http://"; + match.trim() : match.trim();
-
-            match = "<a href=\"" + ref + "\">" + match.trim() + "</a>" + suffix;
-            
-            matcher.appendReplacement( buffer, match );
+            String url = matcher.group( 1 );            
+            String suffix = matcher.group( 3 );
+            
+            String ref = url.startsWith( "www." ) ? "http://"; + url : url;
+
+            url = "<a href=\"" + ref + "\">" + url + "</a>" + suffix;
+            
+            matcher.appendReplacement( buffer, url );
         }
         
         return matcher.appendTail( buffer ).toString();