changeset 2343:6662b0ea20c1

Added 'unbracket' StringUtil method (extracted from WaterlevelSelectState). flys-backend/trunk@2848 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 28 Sep 2011 08:17:16 +0000 (2011-09-28)
parents 3efc3942b765
children ec0ffc842573
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/utils/StringUtil.java
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Tue Sep 27 13:37:34 2011 +0000
+++ b/flys-backend/ChangeLog	Wed Sep 28 08:17:16 2011 +0000
@@ -1,3 +1,8 @@
+2011-09-28  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/StringUtil.java:
+	  (unbracket): New method (extracted from WaterlevelSelectState).
+
 2011-09-27	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/CrossSectionLine.java:
--- a/flys-backend/src/main/java/de/intevation/flys/utils/StringUtil.java	Tue Sep 27 13:37:34 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/utils/StringUtil.java	Wed Sep 28 08:17:16 2011 +0000
@@ -23,6 +23,7 @@
 import java.io.StringWriter;
 import java.io.PrintWriter;
 
+
 public final class StringUtil {
     final static String NUMBER_SEPERATOR = ";";
     final static String LINE_SEPERATOR = ":";
@@ -74,6 +75,29 @@
         return array2D;
     }
 
+    /**
+     * Remove first occurrence of "[" and "]" (if both do occur).
+     * @param value String to be stripped of [] (might be null).
+     * @return input string but with [ and ] removed, or input string if no
+     *         brackets were found.
+     */
+    public static final String unbracket(String value) {
+        // null- guard
+        if (value == null) return value;
+
+        int start = value.indexOf("[");
+        int end   = value.indexOf("]");
+
+        if (start < 0 || end < 0) {
+            return value;
+        }
+
+        value = value.substring(start + 1, end);
+
+        return value;
+    }
+
+
     public static final String [] splitLines(String s) {
         if (s == null) {
             return null;

http://dive4elements.wald.intevation.org