Mercurial Hosting > luan
diff core/src/luan/modules/StringLuan.java @ 646:cdc70de628b5
simplify LuanException
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Mar 2016 19:58:39 -0600 |
parents | 859c0dedc8b6 |
children | b21d82ee5756 |
line wrap: on
line diff
--- a/core/src/luan/modules/StringLuan.java Tue Mar 29 18:09:51 2016 -0600 +++ b/core/src/luan/modules/StringLuan.java Tue Mar 29 19:58:39 2016 -0600 @@ -31,8 +31,8 @@ return i==null ? dflt : end(s,i); } - @LuanMethod public static Integer[] unicode(LuanState luan,String s,Integer i,Integer j) throws LuanException { - Utils.checkNotNull(luan,s); + @LuanMethod public static Integer[] unicode(String s,Integer i,Integer j) throws LuanException { + Utils.checkNotNull(s); int start = start(s,i,1); int end = end(s,j,start+1); Integer[] chars = new Integer[end-start]; @@ -54,23 +54,23 @@ return s.getBytes(); } - public static String lower(LuanState luan,String s) throws LuanException { - Utils.checkNotNull(luan,s); + public static String lower(String s) throws LuanException { + Utils.checkNotNull(s); return s.toLowerCase(); } - public static String upper(LuanState luan,String s) throws LuanException { - Utils.checkNotNull(luan,s); + public static String upper(String s) throws LuanException { + Utils.checkNotNull(s); return s.toUpperCase(); } - public static String trim(LuanState luan,String s) throws LuanException { - Utils.checkNotNull(luan,s); + public static String trim(String s) throws LuanException { + Utils.checkNotNull(s); return s.trim(); } - public static String reverse(LuanState luan,String s) throws LuanException { - Utils.checkNotNull(luan,s); + public static String reverse(String s) throws LuanException { + Utils.checkNotNull(s); return new StringBuilder(s).reverse().toString(); } @@ -86,8 +86,8 @@ return buf.toString(); } - public static String sub(LuanState luan,String s,int i,Integer j) throws LuanException { - Utils.checkNotNull(luan,s); + public static String sub(String s,int i,Integer j) throws LuanException { + Utils.checkNotNull(s); int start = start(s,i); int end = end(s,j,s.length()); return s.substring(start,end); @@ -127,8 +127,8 @@ return rtn; } - public static LuanFunction gmatch(LuanState luan,String s,String pattern) throws LuanException { - Utils.checkNotNull(luan,s); + public static LuanFunction gmatch(String s,String pattern) throws LuanException { + Utils.checkNotNull(s); final Matcher m = Pattern.compile(pattern).matcher(s); return new LuanFunction() { @Override public Object call(LuanState luan,Object[] args) { @@ -147,7 +147,7 @@ } @LuanMethod public static Object[] gsub(LuanState luan,String s,String pattern,Object repl,Integer n) throws LuanException { - Utils.checkNotNull(luan,s); + Utils.checkNotNull(s); int max = n==null ? Integer.MAX_VALUE : n; final Matcher m = Pattern.compile(pattern).matcher(s); if( repl instanceof String ) { @@ -202,7 +202,7 @@ m.appendTail(sb); return new Object[]{ sb.toString(), i }; } - throw new LuanException(luan, "bad argument #3 to 'gsub' (string/function/table expected)" ); + throw new LuanException( "bad argument #3 to 'gsub' (string/function/table expected)" ); } // note - String.format() is too stupid to convert between ints and floats. @@ -222,8 +222,8 @@ return Luan.stringEncode(s); } - public static Number to_number(LuanState luan,String s,Integer base) throws LuanException { - Utils.checkNotNull(luan,s); + public static Number to_number(String s,Integer base) throws LuanException { + Utils.checkNotNull(s); try { if( base == null ) { return Double.valueOf(s);