- anti-abuse features created
[mir.git] / source / mir / util / StringRoutines.java
index 8d3ecd3..8d7257c 100755 (executable)
@@ -116,6 +116,14 @@ public class StringRoutines {
     throw new Exception("Integer expected, "+aValue+" found");
   }
 
+  /**
+   *
+   * @param aSource
+   * @param aSearchExpression
+   * @param aReplacement
+   * @return
+   * @throws Exception
+   */
   public static String performRegularExpressionReplacement(String aSource,
       String aSearchExpression, String aReplacement) throws Exception {
 
@@ -126,6 +134,13 @@ public class StringRoutines {
     return regularExpression.substituteAll(aSource, aReplacement);
   }
 
+  /**
+   *
+   * @param aSource
+   * @param aSearchExpression
+   * @return
+   * @throws REException
+   */
   public static boolean performRegularExpressionSearch(String aSource,
       String aSearchExpression) throws REException {
     RE regularExpression;
@@ -135,6 +150,16 @@ public class StringRoutines {
     return regularExpression.isMatch(aSource);
   }
 
+  /**
+   * Separates a string based on a separator:
+   *     <code>seperateString("a:b:c", ":");</code> will lead to
+   *     a List with 3 Strings: <code>"a"</code>, <code>"b"</code> and <code>"c"</code>
+   *
+   * @param aString     The string to split
+   * @param aSeparator
+   * @return
+   */
+
   public static List splitString(String aString, String aSeparator) {
     List result= new Vector();
     int previousPosition = 0;
@@ -150,4 +175,36 @@ public class StringRoutines {
 
     return result;
   }
+
+  /**
+   * Separates a String into at most 2 parts based on a separator:
+   * <ul>
+   *   <li>
+   *     <code>seperateString("a:b:c", ":");</code> will lead to
+   *     a List with 2 Strings: <code>"a"</code> and <code>"b:c"</code>
+   *   <li>
+   *     <code>seperateString("abc", ":");</code> will lead to
+   *     a List with a single String: <code>"abc"</code>
+   * </ul>
+   *
+   *
+   * @param aString
+   * @param aSeparator
+   * @return
+   */
+  public static List separateString(String aString, String aSeparator) {
+    List result= new Vector();
+    int previousPosition = 0;
+    int position;
+    int endOfNamePosition;
+
+    if((position = aString.indexOf(aSeparator, previousPosition))>=0) {
+      result.add(aString.substring(previousPosition, position));
+      previousPosition = position + aSeparator.length();
+    }
+
+    result.add(aString.substring(previousPosition, aString.length()));
+
+    return result;
+  }
 }
\ No newline at end of file