Mercurial Hosting > luan
comparison core/src/luan/modules/StringLuan.java @ 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 | 58752e3e4c5c |
children | 705d14f4d8ee |
comparison
equal
deleted
inserted
replaced
247:b5995d77878a | 248:10cc873babee |
---|---|
60 } | 60 } |
61 return null; | 61 return null; |
62 } | 62 } |
63 | 63 |
64 static int start(String s,int i) { | 64 static int start(String s,int i) { |
65 return i==0 ? 0 : i > 0 ? i - 1 : s.length() + i; | 65 int len = s.length(); |
66 return i==0 ? 0 : i > 0 ? Math.min(i-1,len) : Math.max(len+i,0); | |
66 } | 67 } |
67 | 68 |
68 static int start(String s,Integer i,int dflt) { | 69 static int start(String s,Integer i,int dflt) { |
69 return i==null ? dflt : start(s,i); | 70 return i==null ? dflt : start(s,i); |
70 } | 71 } |
71 | 72 |
72 static int end(String s,int i) { | 73 static int end(String s,int i) { |
73 return i==0 ? 0 : i > 0 ? i : s.length() + i + 1; | 74 int len = s.length(); |
75 return i==0 ? 0 : i > 0 ? Math.min(i,len) : Math.max(len+i+1,0); | |
74 } | 76 } |
75 | 77 |
76 static int end(String s,Integer i,int dflt) { | 78 static int end(String s,Integer i,int dflt) { |
77 return i==null ? dflt : end(s,i); | 79 return i==null ? dflt : end(s,i); |
78 } | 80 } |