[Schmitzm-commits] r1581 - in trunk/schmitzm-core/src: main/java/de/schmitzm/lang test/java/de/schmitzm/lang

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun May 15 19:56:58 CEST 2011


Author: alfonx
Date: 2011-05-15 19:56:58 +0200 (Sun, 15 May 2011)
New Revision: 1581

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
Log:


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-05-15 16:46:20 UTC (rev 1580)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-05-15 17:56:58 UTC (rev 1581)
@@ -1717,6 +1717,9 @@
 	 * <li>assertEquals("5BAUM6", LangUtil.regExBereich("12345Baum67890", "Baum", 1));
 	 */
 	static public String regExBereich(String value, String regex, int border) {
+		return regExBereich(value, regex, border, ".*", ".*");
+	}
+	static public String regExBereich(String value, String regex, int border, String pre, String post) {
 
 		if (border < 0)
 			throw new IllegalStateException("border may not be smaller 0!");
@@ -1724,7 +1727,7 @@
 		if (regex.startsWith("^"))
 			regex = regex.substring(1);
 
-		String r2 = ".*(" + regex + ").*";
+		String r2 = pre + "(" + regex + ")" + post;
 		Pattern compile = Pattern.compile(r2);
 		Matcher matcher = compile.matcher(value);
 		if (!matcher.find())

Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java	2011-05-15 16:46:20 UTC (rev 1580)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java	2011-05-15 17:56:58 UTC (rev 1581)
@@ -135,4 +135,19 @@
 				LangUtil.regExBereich("Am Ender der Absperrung war ein großer Baum zu sehen", "Baum", 3));
 
 	}
+
+	@Test
+	public void testRegExBereich2() {
+		assertEquals("BAUM", LangUtil.regExBereich("Baum", "Baum", 5, "^.*?", ""));
+		assertEquals("BAUM", LangUtil.regExBereich("Baum", "^Baum", 5, "^.*?", ""));
+		assertEquals("23BAUM", LangUtil.regExBereich("123Baum", "Baum$", 2, "^.*?", ""));
+		assertEquals("12345BAUM67890", LangUtil.regExBereich("12345Baum67890", "Baum", 5, "^.*?", ""));
+		assertEquals("12345BAUM67890", LangUtil.regExBereich("12345Baum67890", "Baum", 115, "^.*?", ""));
+		assertEquals("abcBAUMdef", LangUtil.regExBereich("abcBaumdef", "Baum", 115, "^.*?", ""));
+		assertEquals("5BAUM6", LangUtil.regExBereich("12345Baum67890", "Baum", 1, "^.*?", ""));
+
+		assertEquals("er BAUM zu",
+				LangUtil.regExBereich("Am Ender der Absperrung war ein großer Baum zu sehen", "Baum", 3));
+
+	}
 }
\ No newline at end of file



More information about the Schmitzm-commits mailing list