changeset 248:10cc873babee

fix StringIndexOutOfBoundsException git-svn-id: https://luan-java.googlecode.com/svn/trunk@249 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 16 Oct 2014 04:04:52 +0000
parents b5995d77878a
children 9737ebb9aaa0
files core/src/luan/modules/StringLuan.java dist/jars/luan-core-trunk.jar dist/jars/luan-logging-trunk.jar dist/jars/luan-lucene-trunk.jar dist/jars/luan-mail-trunk.jar dist/jars/luan-web-trunk.jar
diffstat 6 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
diff -r b5995d77878a -r 10cc873babee core/src/luan/modules/StringLuan.java
--- a/core/src/luan/modules/StringLuan.java	Fri Oct 10 14:21:45 2014 +0000
+++ b/core/src/luan/modules/StringLuan.java	Thu Oct 16 04:04:52 2014 +0000
@@ -62,7 +62,8 @@
 	}
 
 	static int start(String s,int i) {
-		return i==0 ? 0 : i > 0 ? i - 1 : s.length() + i;
+		int len = s.length();
+		return i==0 ? 0 : i > 0 ? Math.min(i-1,len) : Math.max(len+i,0);
 	}
 
 	static int start(String s,Integer i,int dflt) {
@@ -70,7 +71,8 @@
 	}
 
 	static int end(String s,int i) {
-		return i==0 ? 0 : i > 0 ? i : s.length() + i + 1;
+		int len = s.length();
+		return i==0 ? 0 : i > 0 ? Math.min(i,len) : Math.max(len+i+1,0);
 	}
 
 	static int end(String s,Integer i,int dflt) {
diff -r b5995d77878a -r 10cc873babee dist/jars/luan-core-trunk.jar
Binary file dist/jars/luan-core-trunk.jar has changed
diff -r b5995d77878a -r 10cc873babee dist/jars/luan-logging-trunk.jar
Binary file dist/jars/luan-logging-trunk.jar has changed
diff -r b5995d77878a -r 10cc873babee dist/jars/luan-lucene-trunk.jar
Binary file dist/jars/luan-lucene-trunk.jar has changed
diff -r b5995d77878a -r 10cc873babee dist/jars/luan-mail-trunk.jar
Binary file dist/jars/luan-mail-trunk.jar has changed
diff -r b5995d77878a -r 10cc873babee dist/jars/luan-web-trunk.jar
Binary file dist/jars/luan-web-trunk.jar has changed