Mercurial Hosting > luan
comparison src/luan/modules/StringLuan.java @ 1562:b89212fd04b5
remove table.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 08 Nov 2020 16:50:59 -0700 |
parents | 1b397a949791 |
children | 8fbcc4747091 |
comparison
equal
deleted
inserted
replaced
1561:e1a13e707bf3 | 1562:b89212fd04b5 |
---|---|
143 return rtn; | 143 return rtn; |
144 } | 144 } |
145 }; | 145 }; |
146 } | 146 } |
147 | 147 |
148 public static Object[] gsub(String s,String pattern,Object repl,Integer n) throws LuanException { | 148 public static Object[] gsub(Luan luan,String s,String pattern,Object repl,Integer n) throws LuanException { |
149 Utils.checkNotNull(s); | 149 Utils.checkNotNull(s); |
150 int max = n==null ? Integer.MAX_VALUE : n; | 150 int max = n==null ? Integer.MAX_VALUE : n; |
151 final Matcher m = Pattern.compile(pattern).matcher(s); | 151 final Matcher m = Pattern.compile(pattern).matcher(s); |
152 if( repl instanceof String ) { | 152 if( repl instanceof String ) { |
153 String replacement = (String)repl; | 153 String replacement = (String)repl; |
164 LuanTable t = (LuanTable)repl; | 164 LuanTable t = (LuanTable)repl; |
165 int i = 0; | 165 int i = 0; |
166 StringBuffer sb = new StringBuffer(); | 166 StringBuffer sb = new StringBuffer(); |
167 while( i<max && m.find() ) { | 167 while( i<max && m.find() ) { |
168 String match = m.groupCount()==0 ? m.group() : m.group(1); | 168 String match = m.groupCount()==0 ? m.group() : m.group(1); |
169 Object val = t.get(match); | 169 Object val = t.get(luan,match); |
170 if( val != null ) { | 170 if( val != null ) { |
171 String replacement = Luan.luanToString(val); | 171 String replacement = Luan.luanToString(val); |
172 m.appendReplacement(sb,replacement); | 172 m.appendReplacement(sb,replacement); |
173 } | 173 } |
174 i++; | 174 i++; |