comparison src/luan/modules/StringLuan.java @ 1195:9a57f0b16c2b

better String.split
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 26 Feb 2018 19:07:49 -0700
parents 1a68fc55a80c
children 9fa8b8389578
comparison
equal deleted inserted replaced
1194:bd0420fb3dd0 1195:9a57f0b16c2b
237 public static boolean matches(String s,String pattern) throws LuanException { 237 public static boolean matches(String s,String pattern) throws LuanException {
238 Utils.checkNotNull(s); 238 Utils.checkNotNull(s);
239 return Pattern.compile(pattern).matcher(s).find(); 239 return Pattern.compile(pattern).matcher(s).find();
240 } 240 }
241 241
242 public static LuanTable split(String s,String pattern) throws LuanException { 242 @LuanMethod public static String[] split(String s,String pattern,Integer limit) throws LuanException {
243 Utils.checkNotNull(s); 243 Utils.checkNotNull(s);
244 return new LuanTable(Arrays.asList(s.split(pattern))); 244 int n = limit==null ? -1 : limit;
245 return s.split(pattern,n);
245 } 246 }
246 247
247 } 248 }