Mercurial Hosting > luan
comparison src/luan/lib/StringLib.java @ 88:6ca02b188dba
add LuanBit to clean up code;
add repr();
git-svn-id: https://luan-java.googlecode.com/svn/trunk@89 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 27 Feb 2013 23:50:32 +0000 |
parents | eaf37cfa30c2 |
children | b1e87f1bcc13 |
comparison
equal
deleted
inserted
replaced
87:eaf37cfa30c2 | 88:6ca02b188dba |
---|---|
169 String match = m.groupCount()==0 ? m.group() : m.group(1); | 169 String match = m.groupCount()==0 ? m.group() : m.group(1); |
170 Object val = t.get(match); | 170 Object val = t.get(match); |
171 if( Luan.toBoolean(val) ) { | 171 if( Luan.toBoolean(val) ) { |
172 String replacement = Luan.asString(val); | 172 String replacement = Luan.asString(val); |
173 if( replacement==null ) | 173 if( replacement==null ) |
174 throw new LuanException( luan, LuanElement.JAVA, "invalid replacement value (a "+Luan.type(val)+")" ); | 174 throw luan.JAVA.exception( "invalid replacement value (a "+Luan.type(val)+")" ); |
175 m.appendReplacement(sb,replacement); | 175 m.appendReplacement(sb,replacement); |
176 } | 176 } |
177 i++; | 177 i++; |
178 } | 178 } |
179 m.appendTail(sb); | 179 m.appendTail(sb); |
192 args = new Object[count]; | 192 args = new Object[count]; |
193 for( int j=0; j<count; j++ ) { | 193 for( int j=0; j<count; j++ ) { |
194 args[j] = m.group(j); | 194 args[j] = m.group(j); |
195 } | 195 } |
196 } | 196 } |
197 Object val = Luan.first( luan.call(fn,LuanElement.JAVA,"repl-arg",args) ); | 197 Object val = Luan.first( luan.JAVA.call(fn,"repl-arg",args) ); |
198 if( Luan.toBoolean(val) ) { | 198 if( Luan.toBoolean(val) ) { |
199 String replacement = Luan.asString(val); | 199 String replacement = Luan.asString(val); |
200 if( replacement==null ) | 200 if( replacement==null ) |
201 throw new LuanException( luan, LuanElement.JAVA, "invalid replacement value (a "+Luan.type(val)+")" ); | 201 throw luan.JAVA.exception( "invalid replacement value (a "+Luan.type(val)+")" ); |
202 m.appendReplacement(sb,replacement); | 202 m.appendReplacement(sb,replacement); |
203 } | 203 } |
204 i++; | 204 i++; |
205 } | 205 } |
206 m.appendTail(sb); | 206 m.appendTail(sb); |
207 return new Object[]{ sb.toString(), i }; | 207 return new Object[]{ sb.toString(), i }; |
208 } | 208 } |
209 throw new LuanException( luan, LuanElement.JAVA, "bad argument #3 to 'gsub' (string/function/table expected)" ); | 209 throw luan.JAVA.exception( "bad argument #3 to 'gsub' (string/function/table expected)" ); |
210 } | 210 } |
211 | 211 |
212 // note - String.format() is too stupid to convert between ints and floats. | 212 // note - String.format() is too stupid to convert between ints and floats. |
213 public static String format(String format,Object... args) { | 213 public static String format(String format,Object... args) { |
214 return String.format(format,args); | 214 return String.format(format,args); |